:root {
  color-scheme: dark;
  --ink: #eef3ec;
  --muted: #9eafa9;
  --bg: #101c24;
  --panel: #172831;
  --panel-2: #20343d;
  --line: rgba(226, 236, 218, .12);
  --gold: #edc777;
  --gold-2: #f4dda4;
  --green: #82b990;
  --red: #df7772;
  --blue: #78b9cb;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); }
button { font: inherit; color: inherit; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: .45; cursor: default; }
[hidden] { display: none !important; }
#app { height: 100dvh; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
.hud { min-height: 58px; display: flex; align-items: center; gap: 9px; padding: 8px 10px; background: #13232c; border-bottom: 1px solid var(--line); z-index: 4; }
.brand { display: flex; align-items: center; gap: 7px; background: none; padding: 0; font-family: Georgia, serif; font-size: 19px; letter-spacing: .02em; }
.brand-mark { display: grid; place-items: center; width: 29px; height: 29px; background: var(--gold); color: #23302b; border-radius: 8px; font-weight: 800; transform: rotate(-5deg); }
.resources { display: flex; gap: 9px; margin-left: 4px; font-size: 12px; color: var(--gold-2); }
.resources span { display: flex; align-items: center; gap: 4px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.gold { background: var(--gold); }.dot.science { background: var(--blue); }
.research-chip { margin-left: auto; text-align: left; background: #1d3039; border: 1px solid var(--line); border-radius: 9px; padding: 5px 9px; max-width: 142px; line-height: 1.1; }
.research-chip span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 11px; }
.research-chip small { color: var(--blue); font-size: 10px; }
.turn-pill { font-size: 11px; color: var(--muted); white-space: nowrap; }
.turn-pill strong { color: var(--ink); }
#board-wrap { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #0e1a21; }
#board { display: block; width: 100%; height: 100%; touch-action: none; }
.map-tools { position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; gap: 7px; }
.map-tools button { width: 40px; height: 40px; border-radius: 12px; background: rgba(20, 38, 47, .9); border: 1px solid var(--line); font-size: 22px; box-shadow: 0 4px 18px #0004; }
.map-tools button:last-child { font-size: 18px; }
.map-legend { position: absolute; left: 10px; top: 11px; display: flex; gap: 9px; padding: 5px 8px; border-radius: 8px; background: #11212ac9; color: var(--muted); font-size: 10px; pointer-events: none; }
.map-legend span { display: flex; align-items: center; gap: 4px; }
.map-legend i { width: 7px; height: 7px; border-radius: 50%; }.map-legend .you { background: var(--gold); }.map-legend .rival { background: var(--red); }.map-legend .camp { background: #ae7aaf; }
.busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px; background: #0c1820b8; font-family: Georgia, serif; font-size: 20px; z-index: 5; }
.busy span { width: 20px; height: 20px; border: 2px solid #fff3; border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.selection { background: var(--panel); border-top: 1px solid var(--line); padding: 12px 13px 10px; max-height: 39dvh; overflow-y: auto; z-index: 3; }
.selection-head { display: flex; align-items: flex-start; gap: 10px; }
.selection-title { flex: 1; min-width: 0; }
.selection-title h3 { margin: 0 0 3px; font: 600 19px Georgia, serif; }
.selection-title p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.close-small { background: none; color: var(--muted); font-size: 24px; padding: 0 2px; }
.stat-row { display: flex; gap: 7px; flex-wrap: wrap; margin: 10px 0; }
.stat { background: #20343d; padding: 5px 8px; border-radius: 7px; font-size: 11px; color: #c9d4cf; }
.stat b { color: var(--ink); }
.action-row { display: flex; gap: 7px; overflow-x: auto; padding-top: 3px; }
.action-row button, .small-btn { white-space: nowrap; padding: 9px 12px; border-radius: 9px; background: #2a414b; font-size: 12px; font-weight: 600; }
.action-row button.primary-small { background: var(--gold); color: #22302b; }
.action-row button.danger { color: #ffc1b9; }
.dock { display: flex; gap: 5px; padding: 8px 9px calc(8px + env(safe-area-inset-bottom)); background: #13232c; border-top: 1px solid var(--line); z-index: 4; }
.dock button { min-height: 48px; display: flex; align-items: center; justify-content: center; gap: 5px; flex-direction: column; flex: 1; background: none; color: var(--muted); font-size: 10px; border-radius: 9px; }
.dock-icon { font-size: 20px; line-height: 19px; color: #c4d1cb; }
.dock .end-turn { flex: 1.45; flex-direction: row; gap: 9px; background: var(--gold); color: #1f2e29; font-size: 14px; font-weight: 750; }
.dock .end-turn .dock-icon { color: #1f2e29; }
.overlay { position: fixed; inset: 0; z-index: 20; }
.start-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 28px; background: radial-gradient(ellipse at 50% 20%, #28464b 0, #152a33 38%, #0d1921 78%); }
.start-art { width: 220px; height: 154px; position: relative; margin-bottom: 20px; overflow: hidden; }
.sun { position: absolute; width: 90px; height: 90px; border-radius: 50%; background: #edc7771c; left: 65px; top: 0; box-shadow: 0 0 70px #edc77722; }
.mountain { position: absolute; bottom: 12px; width: 0; height: 0; border-left: 72px solid transparent; border-right: 72px solid transparent; border-bottom: 100px solid #29444a; }
.mountain.m1 { left: 5px; }.mountain.m2 { right: -5px; border-bottom-color: #203a42; border-bottom-width: 82px; }
.start-hex { position: absolute; left: 84px; bottom: 8px; width: 54px; height: 60px; display: grid; place-items: center; background: var(--gold); color: #23352f; font: 700 30px Georgia, serif; clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); }
.eyebrow { color: var(--gold); font-size: 10px; letter-spacing: .22em; margin: 0 0 8px; }
.start-screen h1 { font: 500 58px/1 Georgia, serif; margin: 0; letter-spacing: -.03em; }
.tagline { color: #b4c2bc; font: 16px/1.55 Georgia, serif; margin: 15px 0 27px; }
.primary { display: flex; align-items: center; justify-content: space-between; width: min(100%, 330px); padding: 16px 19px; background: var(--gold); color: #20322a; font-weight: 750; border-radius: 12px; box-shadow: 0 6px 26px #0003; }
.secondary { width: min(100%, 330px); padding: 14px; margin-top: 10px; border: 1px solid #c4d0c344; border-radius: 12px; background: #ffffff09; }
.text-btn { background: none; color: #b6c4bd; padding: 16px; text-decoration: underline; text-underline-offset: 4px; }
.save-note { position: absolute; bottom: calc(18px + env(safe-area-inset-bottom)); color: #7f958c; font-size: 11px; }
.modal { display: flex; align-items: flex-end; justify-content: center; background: #071219b8; backdrop-filter: blur(3px); }
.modal-card { width: 100%; max-height: 82dvh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom); }
.modal-head { display: flex; align-items: center; padding: 16px 17px 11px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font: 500 24px Georgia, serif; }
.close { margin-left: auto; background: none; color: var(--muted); font-size: 30px; line-height: 1; }
.modal-body { padding: 13px 16px 19px; overflow-y: auto; }
.modal-body h3 { font: 500 18px Georgia, serif; margin: 16px 0 8px; }
.modal-body p { font-size: 13px; color: #b8c7c0; line-height: 1.55; }
.option { display: block; width: 100%; text-align: left; background: #20343d; border: 1px solid transparent; border-radius: 11px; padding: 12px; margin-bottom: 8px; }
.option:active { border-color: var(--gold); }
.option strong { display: block; font-size: 14px; margin-bottom: 4px; }
.option small { display: block; color: var(--muted); line-height: 1.4; }
.option .option-meta { float: right; color: var(--gold); font-size: 12px; }
.option.selected { border-color: var(--gold); background: #3c4237; }
.city-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 12px 4px; background: none; border-bottom: 1px solid var(--line); }
.city-row .city-badge { width: 36px; height: 36px; display: grid; place-items: center; background: #3b4b40; color: var(--gold); border-radius: 9px; font: 700 17px Georgia, serif; }
.city-row strong { display: block; }.city-row small { color: var(--muted); }
.log-entry { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; line-height: 1.45; }
.log-entry b { color: var(--gold); font-weight: 500; margin-right: 6px; }
.toast { position: fixed; left: 50%; bottom: calc(83px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40; width: max-content; max-width: 90%; padding: 10px 15px; background: #e8ddbd; color: #26332e; border-radius: 10px; font-size: 12px; box-shadow: 0 5px 24px #0006; text-align: center; }
.help-list { padding-left: 19px; color: #b8c7c0; font-size: 13px; line-height: 1.6; }
.help-list b { color: var(--ink); }
.victory { text-align: center; padding: 12px 5px; }
.victory .victory-mark { font: 500 60px Georgia, serif; color: var(--gold); }
.victory h3 { font-size: 27px; }
.production-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 9px; }
.production-grid .option { margin: 0; padding: 10px; }
.progress { height: 6px; background: #0e2028; border-radius: 8px; overflow: hidden; margin: 8px 0; }
.progress i { display: block; height: 100%; background: var(--gold); }
@media (min-width: 760px) {
  #app { max-width: 1280px; margin: 0 auto; }
  .hud { padding-left: 18px; padding-right: 18px; }
  .resources { font-size: 14px; gap: 16px; }
  .research-chip { max-width: 230px; padding: 7px 12px; }
  .research-chip span { font-size: 12px; }
  .selection { position: absolute; right: 18px; top: 78px; width: 330px; max-height: calc(100dvh - 170px); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 40px #0006; }
  .dock { padding-left: 18px; padding-right: 18px; }
  .dock button { max-width: 150px; }
  .dock .end-turn { margin-left: auto; }
  .modal { align-items: center; }
  .modal-card { max-width: 550px; border-radius: 18px; }
}
@media (max-width: 380px) {
  .brand > span:last-child { display: none; }
  .resources { gap: 6px; margin-left: 0; }
  .research-chip { max-width: 125px; }
}

/* --- accounts ------------------------------------------------------------ */
.auth-form { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 6px; }
.auth-form label { display: block; font-size: 12px; color: var(--muted); letter-spacing: .02em; }
.auth-form input {
  display: block; width: 100%; margin-top: 5px; padding: 13px 12px; min-height: 46px;
  background: #16262e; border: 1px solid var(--line); border-radius: 10px;
  color: var(--ink); font-size: 16px; /* 16px stops iOS auto-zoom on focus */
}
.auth-form input:focus { outline: none; border-color: var(--gold); background: #1b2d36; }
.auth-actions { display: flex; gap: 8px; }
.auth-actions button { flex: 1; margin: 0; }
.auth-actions .text-btn { flex: 0 0 auto; padding: 0 10px; }
.modal-body p.auth-error {
  color: #ffb4a6; font-size: 12.5px; font-weight: 600; margin: 2px 0 0;
  background: rgba(223, 119, 114, .14); border-left: 3px solid #df7772;
  padding: 8px 10px; border-radius: 8px;
}
.modal-body p.auth-error[hidden] { display: none; }
.auth-note { font-size: 12px; color: var(--muted); line-height: 1.5; }

.game-row {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 12px 4px; background: none; border-bottom: 1px solid var(--line); color: inherit;
}
.game-row:active { background: #1d2f37; }
.game-row .city-badge {
  width: 36px; height: 36px; flex: 0 0 36px; display: grid; place-items: center;
  background: #3b4b40; color: var(--gold); border-radius: 9px; font: 700 17px Georgia, serif;
}
.game-row strong { display: block; font-size: 14px; }
.game-row small { color: var(--muted); font-size: 12px; }
.game-row .game-when { margin-left: auto; color: var(--muted); font-size: 11px; }

/* --- manual -------------------------------------------------------------- */
.manual { font-size: 13px; line-height: 1.6; color: #c2d0c8; }
.manual-lead { color: var(--ink) !important; font-size: 13.5px !important; }
.manual h4 {
  font: 500 15px Georgia, serif; color: var(--gold); margin: 20px 0 6px;
  padding-top: 12px; border-top: 1px solid var(--line);
}
.manual h4:first-of-type { border-top: none; padding-top: 0; }
.manual p { margin: 0 0 8px; }
.manual ul, .manual ol { margin: 0 0 10px; padding-left: 20px; }
.manual li { margin-bottom: 6px; }
.manual b { color: var(--ink); font-weight: 600; }

@media (max-width: 355px) {
  .auth-actions { flex-direction: column; }
  .auth-actions .text-btn { padding: 10px 0; }
}

/* account control on the map tools */
.map-tools .account-tool { position: relative; font-size: 19px; line-height: 1; }
.map-tools .account-tool .account-dot {
  position: absolute; top: 6px; right: 6px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 0 2px rgba(20, 38, 47, .92); display: none;
}
.map-tools .account-tool.signed-out .account-dot { display: block; animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.build-stamp { margin: 14px 0 0; font-size: 10.5px; letter-spacing: .04em; color: #6d8189; text-align: center; }
.map-tools .account-tool svg { width: 19px; height: 19px; display: block; margin: 0 auto; color: var(--ink); }
.map-tools .account-tool.signed-out svg { color: var(--gold); }
