/* Mobile-first: base rules below target a phone in portrait. The single breakpoint near
   the bottom promotes to the wider two-column desktop layout. Nothing below the breakpoint
   depends on hover; every control is a real tappable button sized for a thumb. */

:root {
  --ground: #10201a;
  --ground-lit: #16281f;
  --card: #182c22;
  --text: #e8ece6;
  --text-dim: #a9b6ad;
  --gold: #e5b95c;
  --teal: #5c9e9c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--ground);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  font-size: 16px;
}

.notice {
  background: var(--ground-lit);
  border-bottom: 1px solid rgba(229, 185, 92, 0.35);
  padding: 0.75rem 1rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  font-size: 0.85rem;
  line-height: 1.5;
}

.notice strong { color: var(--gold); }
.notice a { color: var(--teal); }
.notice-secondary { display: block; margin-top: 0.35rem; color: var(--text-dim); }

main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  max-width: 1200px;
  margin: 0 auto;
}

.map-panel {
  background: var(--card);
  border-radius: 16px;
  padding: 0.75rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

canvas#map {
  width: 100%;
  height: auto;
  border-radius: 12px;
  display: block;
  touch-action: manipulation;
}

.legend {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-left: 0.6rem;
}
.swatch:first-child { margin-left: 0; }
.swatch.player { background: var(--gold); }
.swatch.undecided { background: #78807a; }
.swatch.rival { background: var(--teal); }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.status-row {
  background: var(--card);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  font-size: 1rem;
}

.fund.player-fund span { color: var(--gold); font-weight: 600; }
.fund.rival-fund span { color: var(--teal); font-weight: 600; }

fieldset {
  border: none;
  background: var(--card);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  margin: 0;
}

legend {
  padding: 0 0.35rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

#regionButtons, #tacticButtons {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

button {
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  min-height: 44px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}

button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

button.selected {
  border-color: var(--gold);
  background: rgba(229, 185, 92, 0.12);
}

.tactic-btn .tactic-name { font-weight: 600; }
.tactic-btn .tactic-meta { display: block; font-size: 0.78rem; color: var(--text-dim); }

button.end-turn {
  background: var(--gold);
  color: #1b1408;
  font-weight: 700;
  text-align: center;
  padding: 0.9rem;
  font-size: 1.05rem;
  position: sticky;
  bottom: max(0.5rem, env(safe-area-inset-bottom));
}
button.end-turn:hover:not(:disabled) { background: #f0c56d; }

.region-info, .log-panel {
  background: var(--card);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

.region-info h2, .log-panel h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 0.5rem 0;
}

.bar-row { display: flex; align-items: center; gap: 0.5rem; margin: 0.3rem 0; font-size: 0.85rem; }
.bar-track { flex: 1; height: 10px; border-radius: 5px; background: rgba(255,255,255,0.08); overflow: hidden; }
.bar-fill { height: 100%; }
.bar-fill.player { background: var(--gold); }
.bar-fill.rival { background: var(--teal); }

.spread-note { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.4rem; }

.log-panel ul {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 200px;
  overflow-y: auto;
  font-size: 0.82rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column-reverse;
  gap: 0.3rem;
}

.play-log-panel {
  background: var(--card);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  font-size: 0.85rem;
  color: var(--text-dim);
}

.play-log-panel summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
  font-size: 0.82rem;
}

.play-log-panel p { line-height: 1.5; }

.play-log-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.6rem 0;
}

.play-log-controls button {
  flex: 1 1 auto;
  min-width: 130px;
  text-align: center;
  font-size: 0.85rem;
  padding: 0.6rem;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 14, 11, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}

.overlay-card {
  background: var(--card);
  border-radius: 16px;
  padding: 1.25rem;
  max-width: 520px;
  width: 100%;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.5);
}

.overlay-card .disclaimer {
  font-size: 0.8rem;
  color: var(--text-dim);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 0.75rem;
  margin-top: 0.75rem;
}

/* Desktop / wide viewport: promote to the two-column layout. */
@media (min-width: 860px) {
  main {
    display: grid;
    grid-template-columns: minmax(400px, 1fr) 360px;
    gap: 1.25rem;
    padding: 1.25rem;
  }
  .notice { padding: 0.75rem 1.25rem; font-size: 0.92rem; }
  #regionButtons, #tacticButtons { flex-direction: row; flex-wrap: wrap; }
  #regionButtons button, #tacticButtons button { flex: 1 1 auto; min-width: 140px; }
  button.end-turn { position: static; }
}

[hidden] { display: none !important; }

/* Multi-county selection UI (mobile-first) */

.county-picker {
  margin-bottom: 1rem;
}

.county-search-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

#countySearch {
  flex: 1;
  padding: 0.75rem;
  min-height: 44px;  /* Minimum touch target */
  font-size: 1rem;
  border: 1px solid #3a4a3a;
  border-radius: 4px;
  background: #1a2a1a;
  color: #e8ece6;
}

#countySearch:focus {
  outline: 2px solid #5c8c7a;
  border-color: #5c8c7a;
}

#clearCountiesBtn {
  padding: 0.75rem 1rem;
  min-height: 44px;  /* Minimum touch target */
  white-space: nowrap;
}

.county-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 3rem;
  margin-bottom: 0.75rem;
  padding: 0.5rem;
  background: rgba(255,255,255,0.02);
  border-radius: 4px;
}

.county-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  background: #2a4a3a;
  color: #e8ece6;
  border: 1px solid #3a5a4a;
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.15s;
}

.county-chip:hover {
  background: #3a5a4a;
}

.chip-remove {
  font-size: 1.2rem;
  font-weight: bold;
  opacity: 0.7;
}

.county-chip:hover .chip-remove {
  opacity: 1;
}

.no-selection {
  font-size: 0.9rem;
  color: #8a9a8a;
  margin: 0;
}

.county-results {
  position: relative;
  max-height: 200px;
  overflow-y: auto;
  background: #1a2a1a;
  border: 1px solid #3a4a3a;
  border-radius: 4px;
  margin-top: -0.5rem;
  z-index: 10;
}

.county-result {
  padding: 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid #2a3a2a;
}

.county-result:hover {
  background: #2a4a3a;
}

.county-result:last-child {
  border-bottom: none;
}

.no-results {
  padding: 0.75rem;
  color: #8a9a8a;
  font-style: italic;
}

/* Demographic filters (mobile-first) */

.demographic-filters {
  margin-bottom: 1rem;
}

.filter-group {
  margin-bottom: 0.75rem;
}

.filter-group summary {
  padding: 0.75rem;
  background: rgba(255,255,255,0.03);
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.filter-group summary:hover {
  background: rgba(255,255,255,0.05);
}

.synthetic-badge, .unverified-badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
  font-weight: bold;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.synthetic-badge {
  background: #7a5a3a;
  color: #ffd966;
}

.unverified-badge {
  background: #7a3a3a;
  color: #ffaa66;
}

.filter-note {
  font-size: 0.85rem;
  color: #8a9a8a;
  margin: 0.5rem 0;
}

.filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem;
}

.filter-btn {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  background: #1a2a1a;
  color: #a8b2a8;
  border: 1px solid #3a4a3a;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-btn:hover {
  background: #2a3a2a;
  border-color: #4a5a4a;
}

.filter-btn.active {
  background: #3a6a5a;
  color: #e8ece6;
  border-color: #5c8c7a;
  font-weight: bold;
}

/* Tactic buttons updated for cost display */

.tactic-btn {
  width: 100%;
  text-align: left;
  padding: 0.75rem;
  background: #1a2a1a;
  color: #e8ece6;
  border: 1px solid #3a4a3a;
  border-radius: 4px;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: all 0.15s;
  display: block;
}

.tactic-btn:hover:not(:disabled) {
  background: #2a4a3a;
  border-color: #5c8c7a;
}

.tactic-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tactic-name {
  display: block;
  font-weight: bold;
  margin-bottom: 0.25rem;
}

.tactic-meta {
  display: block;
  font-size: 0.85rem;
  color: #a8b2a8;
}

/* Map adjustments for 100 counties */

#map {
  width: 100%;
  height: auto;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* Responsive tweaks for phone width (390px) */

@media (max-width: 480px) {
  .county-search-row {
    flex-direction: column;
  }

  #clearCountiesBtn {
    width: 100%;
  }

  .filter-buttons {
    padding: 0.5rem;
  }

  .filter-btn {
    flex: 1 1 calc(50% - 0.25rem);
    min-width: 0;
    text-align: center;
  }
}

/* Desktop layout (unchanged from original) */

@media (min-width: 860px) {
  main {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1.5rem;
  }

  .map-panel {
    grid-row: 1;
  }

  .sidebar {
    grid-row: 1;
  }
}

/* Touch target minimum sizes for mobile (44px) */

#seedInput,
button,
input[type="text"],
input[type="number"],
.county-chip,
.filter-btn,
.tactic-btn,
.county-result {
  min-height: 44px;
}

#seedInput {
  padding: 0.75rem;
}

/* Prevent horizontal overflow on narrow screens */

* {
  max-width: 100%;
}

canvas,
.county-results,
.county-chips,
fieldset {
  max-width: 100%;
  overflow-x: hidden;
}
