/* ===========================================================================
   CIV 1 WEB — STYLES (dark, glassy, modern)
   =========================================================================== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --panel: rgba(13, 20, 36, 0.86);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #e8ecf3;
  --muted: #9aa7bd;
  --accent: #f2c14e;
  --good: #5dd39e;
  --bad: #e84545;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #070d18;
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  user-select: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* --- Start screen --------------------------------------------------------- */
#start-screen {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto;          /* scroll when the content is taller than the screen */
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(78, 168, 222, 0.14), transparent 55%),
    radial-gradient(ellipse at 75% 80%, rgba(242, 193, 78, 0.10), transparent 55%),
    #070d18;
}
/* margin:auto centres the panel when it fits and lets it scroll from the top when it doesn't */
.start-inner { text-align: center; max-width: 760px; padding: 24px; margin: auto; }
.start-inner h1 {
  font-size: 64px; letter-spacing: 14px; font-weight: 800;
  background: linear-gradient(180deg, #ffe9a8, #d99a2b);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 4px 30px rgba(242, 193, 78, 0.25);
}
.subtitle { color: var(--muted); margin: 10px 0 38px; }
.start-inner h2 { font-weight: 600; margin-bottom: 18px; }
#civ-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 16px; }
.civ-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 22px 12px 18px;
  cursor: pointer;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.civ-card:hover {
  transform: translateY(-4px);
  border-color: var(--civ);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}
.civ-card.selected {
  border-color: var(--civ);
  box-shadow: 0 0 0 2px var(--civ), 0 12px 30px rgba(0, 0, 0, 0.5);
}
.civ-swatch {
  width: 44px; height: 44px;
  margin: 0 auto 12px;
}
.civ-swatch .leader-portrait { width: 100%; height: 100%; display: block; }
.leader-portrait { display: block; }
.dip-portrait { display: inline-flex; vertical-align: middle; margin-right: 6px; }
.dip-portrait .leader-portrait { display: block; }
.dip-hero { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.dip-hero b { font-size: 16px; }
.civ-card h3 { font-size: 18px; }
.civ-card p { color: var(--muted); font-size: 13px; margin-top: 4px; }
#setup-row { margin-top: 22px; font-size: 15px;
  display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; }
#setup-row label { display: inline-flex; align-items: center; gap: 8px; }
#setup-row select, #difficulty-sel { padding: 4px 8px; font-size: 14px; border-radius: 6px;
  background: #1a2030; color: #f3f3f0; border: 1px solid #3a4358; }
#btn-start {
  margin-top: 22px; padding: 10px 30px; font-size: 17px; font-weight: 600;
  cursor: pointer; border-radius: 8px; border: 1px solid #d99a2b;
  background: linear-gradient(180deg, #ffe9a8, #d99a2b); color: #2a1c05;
  transition: transform .15s, box-shadow .15s;
}
#btn-start:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(217,154,43,0.4); }
.start-buttons { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.start-buttons.col { flex-direction: column; align-items: center; }
#btn-demo {
  margin-top: 22px; padding: 10px 24px; font-size: 16px; font-weight: 600;
  cursor: pointer; border-radius: 8px; color: var(--text);
  background: rgba(255, 255, 255, 0.07); border: 1px solid var(--panel-border);
  transition: background .15s, transform .15s;
}
#btn-demo:hover { background: rgba(255, 255, 255, 0.15); transform: translateY(-2px); }
#btn-resume {
  display: block; margin: 0; padding: 12px 34px; font-size: 18px; font-weight: 700;
  cursor: pointer; border-radius: 10px; color: #0d2a18;
  background: linear-gradient(180deg, #8ce0b8, #3aa873); border: 1px solid #2c8a5a;
  box-shadow: 0 8px 24px rgba(58,168,115,0.35); transition: transform .15s, box-shadow .15s;
}
#btn-resume:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(58,168,115,0.5); }
/* Landing: primary "Start playing" call to action */
#btn-startplaying {
  padding: 14px 46px; font-size: 19px; font-weight: 700;
  cursor: pointer; border-radius: 10px; border: 1px solid #d99a2b;
  background: linear-gradient(180deg, #ffe9a8, #d99a2b); color: #2a1c05;
  transition: transform .15s, box-shadow .15s;
}
#btn-startplaying:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(217,154,43,0.4); }
/* "How to play" menu: one consistent button per choice */
.menu-choice {
  min-width: 280px; padding: 14px 28px; font-size: 17px; font-weight: 600;
  cursor: pointer; border-radius: 10px; color: var(--text);
  background: rgba(255, 255, 255, 0.07); border: 1px solid var(--panel-border);
  transition: background .15s, transform .15s, border-color .15s;
}
.menu-choice:hover { background: rgba(255, 255, 255, 0.14); transform: translateY(-2px); border-color: #d99a2b; }
.link-back {
  margin-top: 26px; background: none; border: none; color: var(--muted);
  font-size: 15px; cursor: pointer; transition: color .15s;
}
.link-back:hover { color: var(--text); }
.start-hint { margin-top: 28px; color: var(--muted); font-size: 13px; }

/* --- Map & HUD -------------------------------------------------------------- */
#game { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map:active { cursor: grabbing; }

#topbar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 8px 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  white-space: nowrap;
  z-index: 10;
  font-size: 14px;
}
#hud-civ { font-weight: 700; margin-right: 6px; }
.hud-item { padding: 3px 10px; border-radius: 999px; }
.hud-btn { cursor: pointer; transition: background .12s; }
.hud-btn:hover { background: rgba(255, 255, 255, 0.10); }

#sidebar {
  position: absolute; right: 14px; bottom: 14px; z-index: 10;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
#minimap { border-radius: 8px; display: block; cursor: crosshair; }
#btn-endturn {
  background: linear-gradient(180deg, #2c4a72, #1d3354);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  color: var(--text);
  padding: 10px;
  font-weight: 600;
  transition: filter .12s;
}
#btn-endturn:hover { filter: brightness(1.2); }
#btn-endturn.ready {
  background: linear-gradient(180deg, #d9a62b, #a87a14);
  animation: pulse 1.6s infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 16px rgba(242, 193, 78, 0.55); } }
#btn-endturn small { color: rgba(255, 255, 255, 0.6); font-weight: 400; }

/* --- Unit panel --------------------------------------------------------------- */
#unit-panel {
  position: absolute; left: 14px; bottom: 14px; z-index: 10;
  min-width: 260px; max-width: 330px;
  /* never let a many-action unit (e.g. a Settler's 11 buttons) grow the panel
     taller than ~45% of the viewport — the action list scrolls internally. */
  max-height: 45vh;
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.up-head { display: flex; align-items: center; gap: 8px; font-size: 16px; flex: 0 0 auto; }
#up-glyph { font-size: 22px; }
#up-stats { color: var(--muted); font-size: 13px; margin: 6px 0 4px; flex: 0 0 auto; }
#up-home { color: var(--muted); font-size: 13px; margin: 0 0 10px; flex: 0 0 auto; }
#up-home b { color: var(--text); }
#up-home .up-away { color: var(--bad); font-weight: 600; }
/* the action grid wraps cleanly and, if it still overflows the capped panel
   height, scrolls on its own rather than pushing the panel over the map. */
#up-actions {
  display: flex; flex-wrap: wrap; gap: 6px;
  overflow-y: auto; min-height: 0; flex: 1 1 auto;
  padding-right: 2px;
}
.action-btn {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 12.5px;
  transition: background .12s;
}
.action-btn:hover { background: rgba(255, 255, 255, 0.15); }
.action-btn.disabled { opacity: 0.35; cursor: default; }

/* --- Collapsible panels (unit actions, map overview) + nav hamburger ----------- */
.panel-toggle {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 5px 8px;
  transition: background .12s;
}
.panel-toggle:hover { background: rgba(255, 255, 255, 0.16); }
/* unit-panel: the toggle sits at the right edge of the header */
#up-collapse { margin-left: auto; }
#unit-panel.collapsed { min-width: 0; max-width: 220px; }
#unit-panel.collapsed #up-stats,
#unit-panel.collapsed #up-home,
#unit-panel.collapsed #up-actions { display: none; }
/* map overview: the toggle sits above the minimap; collapsing hides only the map
   (End Turn stays reachable) */
#mini-collapse { align-self: stretch; }
#sidebar.collapsed #minimap { display: none; }
.menu-sep { height: 1px; background: var(--panel-border); margin: 6px 2px; }

/* --- Toasts & tooltip ----------------------------------------------------------- */
#toasts {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  z-index: 20; pointer-events: none;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  max-width: 560px;
  transition: opacity .6s;
}
.toast-good { border-left-color: var(--good); }
.toast-bad { border-left-color: var(--bad); }
.toast-science { border-left-color: var(--accent); }
.toast.fade { opacity: 0; }

#tooltip {
  position: fixed; z-index: 30; pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 12.5px;
  line-height: 1.5;
  box-shadow: var(--shadow);
}

/* --- Modals ---------------------------------------------------------------------- */
.modal-back {
  position: fixed; inset: 0; z-index: 60;   /* above #start-screen (50) + #scorecard-panel (50) so modals (e.g. the MP lobby) overlay every screen */
  background: rgba(4, 7, 14, 0.6);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  width: min(560px, 92vw);
  max-height: 84vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-wide { width: min(860px, 94vw); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--panel-border);
}
.modal-head h2 { font-size: 18px; font-weight: 700; }
.modal-close {
  background: none; border: none; color: var(--muted); font-size: 16px;
}
.modal-close:hover { color: var(--text); }
.modal > div:not(.modal-head) { padding: 16px 18px; overflow-y: auto; }

/* Multiplayer lobby modal controls */
.lobby-create { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.lobby-create select { padding: 6px 8px; font-size: 14px; border-radius: 6px; background: #1a2030; color: var(--text); border: 1px solid #3a4358; }
.lobby-create label { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.lobby-btn { padding: 8px 16px; font-size: 14px; font-weight: 600; border-radius: 6px; color: #20180a; background: var(--accent); border: 1px solid var(--accent); }
.lobby-btn:hover { filter: brightness(1.08); }
.lobby-btn + .lobby-btn, .pick-item .lobby-btn { margin-left: 8px; }

.btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 14px;
  transition: background .12s;
}
.btn:hover { background: rgba(255, 255, 255, 0.16); }
.btn.disabled { opacity: 0.4; cursor: default; }
.btn.small { padding: 3px 12px; }
.muted { color: var(--muted); font-size: 13.5px; margin-bottom: 10px; }
.section-title { font-weight: 700; margin: 14px 0 8px; font-size: 14px; color: var(--accent); }

/* city screen */
.city-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 30px; border-radius: 50%;
  color: #fff; font-weight: 700;
}
.city-faces { font-size: 17px; letter-spacing: 1px; }
.city-faces .cf { vertical-align: middle; }
.city-faces .cf-happy { font-size: 21px; }          /* happy citizens read a touch larger */
.city-faces .cf-spec { margin-left: 6px; }          /* set the specialists apart at the back */
.disorder { color: var(--bad); font-weight: 800; animation: pulse 1.2s infinite; }
.celebrate { background: linear-gradient(#f2c14e, #5dd39e); color: #1a2410; font-weight: 800;
  border-radius: 10px; padding: 1px 8px; font-size: 11px; letter-spacing: 0.5px; }
.city-stats { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; margin-bottom: 12px; }
.city-stats .pos { color: var(--good); }
.city-stats .neg { color: var(--bad); }
.bar-label { font-size: 12.5px; color: var(--muted); margin: 8px 0 4px; }
.bar {
  height: 10px; border-radius: 5px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 5px; transition: width .3s; }
.bar-food { background: linear-gradient(90deg, #5dd39e, #8ce0b8); }
.bar-prod { background: linear-gradient(90deg, #4ea8de, #7fc2ec); }
.bld-list { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; }
.chip {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 3px 10px;
}

/* city-screen citizen management: fat-cross map + specialists */
.city-map {
  display: grid;
  grid-template-columns: repeat(5, 52px);
  gap: 3px;
  justify-content: center;
  margin: 8px 0 12px;
}
.cmap-cell {
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 10px; line-height: 1.25;
  user-select: none;
}
.cmap-cell .cmap-y { pointer-events: none; }
.cmap-cell.blank { background: transparent; border-color: transparent; }
.cmap-cell.fog { background: rgba(0, 0, 0, 0.35); border-style: dashed; }
.cmap-cell.center { background: rgba(255, 255, 255, 0.1); flex-direction: column; gap: 2px; cursor: default; }
.cmap-cell.center .cmap-glyph { font-size: 18px; }
.cmap-cell.worked {
  background: linear-gradient(180deg, rgba(94,211,158,0.30), rgba(94,211,158,0.14));
  border-color: rgba(94, 211, 158, 0.6);
  cursor: pointer;
}
.cmap-cell.worked:hover { border-color: rgba(94, 211, 158, 0.9); }
.cmap-cell:not(.worked):not(.center):not(.fog):not(.blank):not(.blocked) { cursor: pointer; }
.cmap-cell:not(.worked):not(.center):not(.fog):not(.blank):not(.blocked):hover {
  background: rgba(255, 255, 255, 0.12);
}
.cmap-cell.blocked { opacity: 0.4; cursor: not-allowed; }
.city-specialists { display: flex; gap: 10px; justify-content: center; margin-bottom: 12px; flex-wrap: wrap; }
.spec-group {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 6px 10px;
  text-align: center;
  background: rgba(255, 255, 255, 0.04);
}
.spec-group .spec-head { font-size: 12.5px; margin-bottom: 6px; }
.spec-group .city-row { justify-content: center; margin-bottom: 0; gap: 6px; }

/* pick lists (production, research, government) */
.pick-list { display: flex; flex-direction: column; gap: 5px; }
.pick-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.pick-item:hover { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.25); }
.pick-item.disabled { opacity: 0.45; cursor: default; }
.pick-item small { color: var(--muted); }

/* rates */
.rate-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.rate-label { flex: 1; }

/* civilopedia */
.pedia { display: flex; flex-direction: column; min-height: 420px; }
.pedia-tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.pedia-tab {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 13.5px;
}
.pedia-tab.active { background: var(--accent); color: #20180a; font-weight: 700; }
.pedia-main { display: flex; gap: 14px; min-height: 0; flex: 1; }
.pedia-list {
  width: 220px; flex-shrink: 0;
  overflow-y: auto; max-height: 52vh;
  display: flex; flex-direction: column; gap: 3px;
}
.pedia-item {
  padding: 7px 10px; border-radius: 7px; font-size: 13.5px; cursor: pointer;
}
.pedia-item:hover { background: rgba(255, 255, 255, 0.08); }
.pedia-item.active { background: rgba(242, 193, 78, 0.18); }
.pedia-detail { flex: 1; overflow-y: auto; max-height: 52vh; font-size: 14px; line-height: 1.55; }
.pedia-detail h3 { margin-bottom: 10px; }
.pedia-detail p { margin-bottom: 10px; }
.pedia-table { border-collapse: collapse; width: 100%; font-size: 13.5px; margin: 6px 0 14px; }
.pedia-table td, .pedia-table th {
  border: 1px solid var(--panel-border);
  padding: 6px 10px; text-align: left;
}
.pedia-table td:first-child { color: var(--muted); width: 45%; }

.chip-wonder {
  background: linear-gradient(180deg, rgba(242,193,78,0.25), rgba(242,193,78,0.12));
  border-color: rgba(242, 193, 78, 0.5);
  color: #ffe9a8;
}

/* diplomacy */
.dip-quote { font-style: italic; color: var(--text); margin: 0 0 10px; }
.att-friendly { color: #5dd39e; font-weight: 600; }
.att-cordial  { color: #9bd97a; font-weight: 600; }
.att-cautious { color: #d9c46a; font-weight: 600; }
.att-hostile  { color: #e8915a; font-weight: 600; }
.att-furious  { color: #e84545; font-weight: 600; }
.trade-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.trade-row label { width: 110px; color: var(--muted); font-size: 13.5px; }
.trade-row select {
  flex: 1; background: rgba(255,255,255,0.07); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 7px; padding: 6px 10px; font: inherit;
}

/* cosmetic flavor: throne room (Plan 13 A) */
.throne-room {
  text-align: center;
  line-height: 1.5;
  padding-top: 6px;
  border-top: 3px solid var(--civ, var(--accent));
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(0,0,0,0.25));
  border-radius: 10px;
}
.throne-stage {
  font-size: clamp(28px, 6vw, 56px);
  letter-spacing: 6px;
  margin: 2px 0;
  text-shadow: 0 0 14px rgba(242, 193, 78, 0.35);
}
.throne-row .throne-seat { margin: 0 14px; }
.throne-rug {
  color: var(--accent);
  letter-spacing: 8px;
  font-size: 18px;
  opacity: 0.75;
  margin: 4px 0 10px;
}
.throne-caption {
  font-weight: 700;
  color: var(--accent);
  font-size: 15px;
  margin-top: 6px;
}
.throne-sub { margin-top: 4px; }

/* cosmetic flavor: advisors (Plan 13 B) */
.advisor-glyph { font-size: 20px; margin-right: 8px; }

/* cosmetic flavor: leader rating (Plan 13 C) */
.rating-block {
  border: 1px solid rgba(242, 193, 78, 0.45);
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(8px);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 10px 0 14px;
}
.rating-title { font-weight: 700; color: var(--accent); font-size: 16px; }
.rating-peer { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.pedia-table tr.rating-you { background: rgba(242, 193, 78, 0.14); }

/* scrollbars */
::-webkit-scrollbar { width: 9px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

/* clickable cross-references in the Civilopedia */
.pedia-link {
  color: var(--accent);
  cursor: pointer;
  border-bottom: 1px dotted rgba(242, 193, 78, 0.5);
}
.pedia-link:hover { color: #ffe9a8; border-bottom-color: #ffe9a8; }

/* ===========================================================================
   Mobile / small screens & touch
   =========================================================================== */
@media (max-width: 700px) {
  .start-inner { padding: 16px 12px 28px; }
  .start-inner h1 { font-size: clamp(22px, 7vw, 40px); letter-spacing: 2px; }
  .subtitle { margin: 6px 0 18px; font-size: 12.5px; }
  .start-inner h2 { font-size: 16px; margin-bottom: 12px; }
  #civ-grid { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px; }
  .civ-card { padding: 12px 6px 10px; }
  .civ-swatch { width: 34px; height: 34px; margin-bottom: 8px; }
  .civ-card h3 { font-size: 14px; }
  .civ-card p { font-size: 11px; }
  #setup-row { gap: 12px; font-size: 13px; margin-top: 16px; }
  .start-hint { font-size: 11px; margin-top: 18px; }

  /* the HUD pill spans the width and wraps onto a second line when the items don't
     fit on one (instead of scrolling sideways) */
  #topbar {
    left: 8px; right: 8px; transform: none; max-width: none;
    gap: 3px 2px; padding: 6px 10px; font-size: 12.5px;
    flex-wrap: wrap; white-space: normal; justify-content: flex-start;
  }
  .hud-item { padding: 3px 7px; }

  /* mobile: keep the at-a-glance pills (civ / year / turn / gold / mp clock) plus
     Research and Government in the bar; route the rest into the ☰ Main menu so the
     top bar stays compact. #btn-menu (☰) is the single hamburger. */
  #topbar .hud-btn:not(#btn-research):not(#btn-gov):not(#btn-diplomacy):not(#btn-rates):not(#btn-menu) { display: none; }

  /* shrink the corner panels so they don't dominate a phone screen */
  #sidebar { right: 8px; bottom: 8px; padding: 7px; gap: 7px; }
  #minimap { width: 132px; height: auto; }
  #btn-endturn { padding: 8px; font-size: 13px; }
  #unit-panel { left: 8px; bottom: 8px; min-width: 0; max-width: 52vw; padding: 9px 10px; }
  .up-head { font-size: 14px; }
  #up-stats, #up-home { font-size: 11.5px; }
  .action-btn { padding: 7px 9px; font-size: 12px; }  /* bigger tap targets */

  .modal, .modal-wide { width: 96vw; max-height: 88vh; }
  .pedia-list { width: 130px; }
  .pedia-tab { padding: 5px 10px; font-size: 12.5px; }
}

/* --- Tech tree overlay (classic Civ1 "Advances" chart: parchment + boxes) ---- */
#techtree-overlay { position: fixed; inset: 0; background: #d8c79c; z-index: 5000;
  display: flex; flex-direction: column; color: #2a2216; font-size: 12px; }
.tt-header { padding: 8px 12px; background: #3a2f1c; color: #f0e6cf; display: flex; align-items: center; gap: 10px; }
.tt-muted { color: #c9b78a; }
.tt-zoom { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.tt-zoom .btn { color: #f0e6cf; border-color: rgba(240,230,207,0.4); padding: 2px 10px; font-size: 15px; line-height: 1; }
.tt-zoom .btn:hover { background: rgba(240,230,207,0.18); }
.tt-zoom-label { color: #c9b78a; min-width: 42px; text-align: center; }
.tt-close { cursor: pointer; color: #f0e6cf; border-color: rgba(240,230,207,0.4); }
.tt-close:hover { background: rgba(240,230,207,0.18); }
.tt-grid { position: relative; flex: 1; overflow: auto; background: #d8c79c; -webkit-overflow-scrolling: touch; }
.tt-canvas { position: relative; transform-origin: 0 0; }
.tt-lines { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 0; }
.tt-node { position: absolute; z-index: 1; width: 200px; box-sizing: border-box;
  border: 1px solid #7a6438; border-radius: 4px; padding: 5px 8px; background: #f4ecd6;
  color: #2a2216; cursor: pointer; box-shadow: 1px 1px 0 rgba(80,60,20,0.35); }
.tt-node small { display: block; color: #6f5d38; font-size: 10px; margin-top: 2px; }
.tt-unlocks { margin-top: 3px; }
.tt-unlock { display: block; color: #6f5d38; font-size: 10px; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tt-node.researched { background: #cfe0b8; border-color: #5f8a3f; }
.tt-node.current    { background: #f6e9a8; border-color: #b8951f; box-shadow: 0 0 7px #d9a62b; }
.tt-node.queued     { background: #d7d8f0; border-color: #6a6ab0; }
.tt-node.available  { background: #fbf6e6; border-color: #b8951f; }
.tt-node.locked     { background: #e7dcc0; border-color: #9a8a64; opacity: 0.82; cursor: default; }
.tt-node.tt-hi      { outline: 2px solid #c0392b; outline-offset: 1px; }
.tt-q { position: absolute; top: -7px; right: -7px; background: #6a6ab0; color: #fff;
  border-radius: 50%; width: 16px; height: 16px; text-align: center; line-height: 16px; font-size: 10px; }
.tt-line { fill: none; stroke: #6a5226; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }

/* Engine worker: AI turn is computing off-thread. */
#btn-endturn.thinking { opacity: .6; pointer-events: none; }
body.turn-thinking { cursor: progress; }

/* Multiplayer: readied state for the End Turn / Ready button */
#btn-endturn.mp-readied { background: #2f6b2f; color: #eaffea; }
