/* ============================================================
   AMERICAN FLAG BLUE — Stylesheet
   Lo-fi pixel aesthetic, Dave the Diver vibes
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

:root {
  --bg:         #070d18;
  --bg2:        #0d1625;
  --panel:      #101c2e;
  --panel2:     #162236;
  --border:     #1e3a5f;
  --border2:    #2a5080;
  --accent:     #1b6ca8;
  --accent2:    #2287d4;
  --gold:       #c8a444;
  --gold2:      #e0bf60;
  --cream:      #e8e4d8;
  --muted:      #7899b8;
  --good:       #3d9e60;
  --good2:      #52c47a;
  --warn:       #d47a20;
  --warn2:      #f09030;
  --bad:        #b83a3a;
  --bad2:       #e04848;
  --font-pixel: 'Press Start 2P', monospace;
  --font-vt:    'VT323', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--cream);
  font-family: var(--font-vt);
  font-size: 20px;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Scanline overlay */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.04) 2px,
    rgba(0,0,0,0.04) 4px
  );
  pointer-events: none;
  z-index: 9000;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 8px 8px;
}

/* ============================================================
   HEADER
   ============================================================ */

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 2px solid var(--border);
  background: var(--bg2);
  margin-bottom: 8px;
  flex-shrink: 0;
}

#game-title {
  font-family: var(--font-pixel);
  font-size: 14px;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(200,164,68,0.5), 2px 2px 0 #5a3800;
  letter-spacing: 2px;
}

#tagline {
  font-family: var(--font-vt);
  font-size: 16px;
  color: var(--muted);
  margin-top: 4px;
  letter-spacing: 1px;
}

#hud {
  display: flex;
  gap: 24px;
  align-items: center;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.hud-label {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--muted);
  letter-spacing: 1px;
}

#date-display {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--cream);
}

.budget-value {
  font-family: var(--font-pixel);
  font-size: 12px;
  color: var(--good2);
}

.budget-value.low { color: var(--warn2); }
.budget-value.critical { color: var(--bad2); }

#days-left {
  font-family: var(--font-vt);
  font-size: 18px;
  color: var(--muted);
}

/* ============================================================
   POOL (full-width, correct 2030:167 ratio)
   ============================================================ */

#pool-section {
  flex-shrink: 0;
}

#headline-bar {
  display: flex;
  align-items: stretch;
  background: #080808;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-top: 6px;
  margin-bottom: 8px;
  overflow: hidden;
  min-height: 30px;
}

#headline-source {
  font-family: var(--font-pixel);
  font-size: 8px;
  letter-spacing: 1px;
  background: var(--bad2);
  color: #000;
  padding: 0 10px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  white-space: nowrap;
}

#headline-text {
  font-family: var(--font-vt);
  font-size: 21px;
  color: #ddd;
  padding: 0 14px;
  display: flex;
  align-items: center;
  letter-spacing: 0.5px;
}

#pool-label-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--muted);
  padding: 4px 8px;
  letter-spacing: 1px;
  margin-bottom: 6px;
}


#pool-wrapper {
  position: relative;
  border: 2px solid var(--border2);
  background: #0a1e3a;
  overflow: hidden;
}

#pool-canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

#pool-color-overlay {
  position: absolute;
  top: 6px;
  right: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-shadow: 1px 1px 4px rgba(0,0,0,0.9);
}

#pool-score-label {
  font-family: var(--font-vt);
  font-size: 20px;
  color: rgba(255,255,255,0.95);
  letter-spacing: 1px;
  line-height: 1.1;
}


/* ============================================================
   MAIN LAYOUT
   ============================================================ */

#main-area {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

#left-column {
  flex: 1.4;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

#right-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 220px;
  height: 100%;
}

/* ============================================================
   PANELS
   ============================================================ */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px 12px;
  position: relative;
}

.panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent) 0%, transparent 100%);
}

.panel-title {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--accent2);
  letter-spacing: 2px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.blocked-tag {
  color: var(--bad2);
  animation: blink 1s step-end infinite;
}

.blocked-tag.hidden { display: none; }

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ============================================================
   WEATHER
   ============================================================ */

#weather-row {
  display: flex;
}

#weather-display {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#weather-modifiers {
  margin-top: 6px;
  font-size: 17px;
  color: var(--bad2);
}

#forecast-display {
  flex: 2;
  display: flex;
}

.forecast-day {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border-left: 1px solid var(--border);
}

.fc-label {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--muted);
}

.fc-icon { font-size: 30px; }

.fc-temp {
  font-family: var(--font-pixel);
  font-size: 13px;
  color: var(--warn2);
}

.fc-cond {
  font-family: var(--font-vt);
  font-size: 22px;
  color: var(--muted);
  text-align: center;
}

/* ============================================================
   METERS
   ============================================================ */

.meter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.meter-row:last-of-type {
  margin-bottom: 0;
}

.meter-label {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--muted);
  width: 44px;
  flex-shrink: 0;
}

.meter-track {
  flex: 1;
  height: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  position: relative;
}

.goal-mark {
  position: absolute;
  left: 90%;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--gold2);
  pointer-events: none;
}

.meter-fill {
  height: 100%;
  transition: width 0.4s ease, background-color 0.4s ease;
  background: var(--accent);
}

.meter-fill.bad { background: var(--bad); }
.meter-fill.good { background: var(--good); }
.meter-fill.warn { background: var(--warn); }

.meter-val {
  font-family: var(--font-pixel);
  font-size: 11px;
  width: 34px;
  text-align: right;
  color: var(--cream);
}

.trend-arrow {
  font-family: var(--font-vt);
  font-size: 22px;
  width: 14px;
  text-align: center;
  flex-shrink: 0;
  line-height: 1;
}

.trend-good { color: var(--good2); }
.trend-bad  { color: var(--bad2); }
.trend-flat { color: var(--muted); }

.stat-grid {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 4px 8px;
  margin-top: 8px;
  align-items: center;
}

.stat-label {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--muted);
}

.stat-value {
  font-family: var(--font-vt);
  font-size: 20px;
  color: var(--accent2);
}

#system-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.badge {
  font-family: var(--font-pixel);
  font-size: 7px;
  padding: 3px 6px;
  background: var(--good);
  color: #fff;
  letter-spacing: 1px;
}

/* ============================================================
   ACTIONS
   ============================================================ */

#actions-panel {
  flex-shrink: 0;
}

#actions-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.action-btn {
  width: 100%;
  text-align: left;
  background: var(--panel2);
  border: 1px solid var(--border2);
  color: var(--cream);
  font-family: var(--font-vt);
  font-size: 19px;
  padding: 6px 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  position: relative;
}

.action-btn:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent2);
  color: #fff;
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.action-btn.active {
  background: #1a2a10;
  border-color: var(--good);
  color: var(--good2);
  cursor: default;
}

.action-btn.done {
  background: #0a1a0a;
  border-color: var(--good);
  color: var(--good);
  cursor: default;
  opacity: 0.7;
}

.action-tooltip {
  font-size: 15px;
  color: var(--muted);
  margin-left: 4px;
}

/* ============================================================
   CONTROLS BAR
   ============================================================ */

#controls-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.main-btn {
  font-family: var(--font-pixel);
  font-size: 11px;
  background: var(--accent);
  color: #fff;
  border: 2px solid var(--accent2);
  padding: 10px 20px;
  cursor: pointer;
  letter-spacing: 2px;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.main-btn:hover { background: var(--accent2); }
.main-btn:active { transform: translateY(1px); }
.main-btn.ready {
  background: var(--good);
  border-color: var(--good2);
  animation: pulse-btn 1.2s ease-in-out infinite;
}
@keyframes pulse-btn {
  0%, 100% { box-shadow: 0 0 0 0 rgba(61,158,96,0.5); }
  50%       { box-shadow: 0 0 0 6px rgba(61,158,96,0); }
}
.main-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

#action-progress {
  font-family: var(--font-vt);
  font-size: 19px;
  color: var(--good2);
  padding: 4px 10px;
  border: 1px solid var(--good);
  background: #0a1a0a;
}

#action-progress.hidden { display: none; }

#active-action-mobile {
  display: none;
  font-family: var(--font-vt);
  font-size: 19px;
  color: var(--good2);
  padding: 6px 8px;
  border: 1px solid var(--good);
  background: #0a1a0a;
  margin-bottom: 10px;
}
#active-action-mobile.hidden { display: none !important; }
@media (max-width: 800px) {
  #active-action-mobile:not(.hidden) { display: block; }
}

/* ============================================================
   LOG
   ============================================================ */

#log-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#log-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
  min-height: 0;
}

.log-entry {
  font-family: var(--font-vt);
  font-size: 18px;
  color: var(--muted);
  padding: 2px 0;
  border-bottom: 1px solid rgba(30,58,95,0.4);
}

.log-entry.log-good { color: var(--good2); }
.log-entry.log-warn { color: var(--warn2); }
.log-entry.log-bad  { color: var(--bad2); }

/* ============================================================
   OVERLAYS
   ============================================================ */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,5,15,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}

.overlay.hidden { display: none; }

.popup {
  background: var(--panel);
  border: 2px solid var(--border2);
  padding: 28px 32px;
  max-width: 620px;
  width: 95%;
  text-align: center;
  box-shadow: 0 0 40px rgba(27,108,168,0.3), inset 0 1px 0 rgba(255,255,255,0.05);
  position: relative;
}

.popup::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255,255,255,0.05);
  pointer-events: none;
}

.popup-title {
  font-family: var(--font-pixel);
  font-size: 13px;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(200,164,68,0.5);
  margin-bottom: 16px;
  letter-spacing: 2px;
}

.popup-body {
  font-family: var(--font-vt);
  font-size: 22px;
  color: var(--cream);
  line-height: 1.6;
  margin-bottom: 20px;
}

.popup-body p { margin-bottom: 8px; }
.popup-body strong { color: var(--gold2); }

.popup-btn {
  font-family: var(--font-pixel);
  font-size: 11px;
  background: transparent;
  color: var(--gold2);
  border: 2px solid var(--gold);
  padding: 10px 24px;
  cursor: pointer;
  letter-spacing: 2px;
  transition: background 0.15s, color 0.15s;
}

.popup-btn:hover {
  background: var(--gold);
  color: var(--bg);
}

/* Intro specific */
.intro-popup { max-width: 560px; }

.disclaimer {
  font-size: 16px !important;
  color: var(--muted) !important;
  font-style: italic;
}

/* Choice buttons */
#notif-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-bottom: 4px;
}

#notif-choices .popup-btn {
  width: 100%;
  font-size: 9px;
  padding: 10px 12px;
}

/* Notification specific */
.notif-popup { border-color: var(--warn); }
.notif-popup::before { content: ''; position: absolute; inset: 0; border: 1px solid rgba(212,122,32,0.3); pointer-events: none; }
.notif-popup .popup-title { color: var(--warn2); text-shadow: 0 0 10px rgba(212,122,32,0.5); }

/* End screen specific */
.end-popup { max-width: 620px; }

#end-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.end-intro {
  font-family: var(--font-vt);
  font-size: 20px;
  color: var(--muted);
  margin-bottom: 16px;
}

.end-score {
  font-family: var(--font-pixel);
  font-size: 40px;
  color: #fff;
  text-shadow: 0 0 20px rgba(100,180,255,0.8);
  margin: 8px 0;
}

.end-label {
  font-family: var(--font-pixel);
  font-size: 14px;
  color: var(--gold2);
  text-shadow: 0 0 10px rgba(200,164,68,0.6);
  margin-bottom: 10px;
  letter-spacing: 2px;
}

.end-subtitle {
  font-family: var(--font-vt);
  font-size: 22px;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 16px;
}

.end-stats {
  font-family: var(--font-vt);
  font-size: 19px;
  color: var(--muted);
  margin-bottom: 20px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.end-stat-line { margin: 4px 0; }
.end-stat-val { color: var(--cream); }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 800px) {
  #main-area { flex-direction: column; }

  /* Flatten columns so panels can be reordered independently */
  #left-column, #right-column { display: contents; }

  #weather-panel { order: 1; }
  #meters-panel  { order: 2; }
  #actions-panel { order: 3; }
  #controls-bar  { order: 4; }
  #log-panel     { order: 5; }

  #game-title { font-size: 10px; }
  .hud-item:last-child { display: none; }
}

@media (max-width: 600px) {
  /* Taller pool — override the auto height from the 12:1 aspect ratio */
  #pool-canvas { height: 72px; }

  /* Full-width advance button, easier to tap */
  #controls-bar { flex-direction: column; align-items: stretch; }
  .main-btn { width: 100%; text-align: center; }

  /* Minimum 44px touch targets for action and popup buttons */
  .action-btn { min-height: 44px; padding: 10px; }
  .popup-btn  { padding: 14px 16px; }
  #notif-choices .popup-btn { padding: 12px; }
}

@media (max-width: 500px) {
  #header { flex-direction: column; gap: 8px; align-items: center; }
  #title-block { text-align: center; }
  #hud { gap: 12px; justify-content: center; }
  #game-title { font-size: 8px; }

  /* Bump up small pixel-font labels so they stay legible */
  .panel-title  { font-size: 8px; }
  .hud-label    { font-size: 7px; }
  #date-display { font-size: 10px; }
  .budget-value { font-size: 11px; }

  /* Popups */
  .popup { padding: 20px 16px; }
  .popup-title { font-size: 11px; }
  .popup-body  { font-size: 20px; }

  /* End screen */
  .end-score { font-size: 30px; }
  .end-label { font-size: 12px; }
}

/* ============================================================
   UTILITY
   ============================================================ */

.hidden { display: none !important; }

/* Pixel-style scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }
