:root {
  --bg: #0b0e14; --panel: #151a24; --panel2: #1d2431; --line: #2b3444; --text: #e8e6df; --muted: #9aa3b2;
  --gold: #e3b84a; --accent: #3b82f6; --danger: #e05252; --ok: #4caf50; --food: #7ed957; --prod: #e08a3c; --sci: #57b8ff; --cult: #c77dff;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer; }
button:active { filter: brightness(1.2); }
button:disabled { opacity: .45; }
button.primary { background: #2b5db8; border-color: #3f74d6; }
button.danger { background: #7d2727; border-color: #a33; }
button.ghost { background: transparent; }
button.big { font-size: 18px; padding: 14px 22px; min-width: 220px; }
button.icon { width: 40px; height: 40px; padding: 0; font-size: 18px; border-radius: 10px; }
button.small { padding: 5px 9px; font-size: 13px; border-radius: 8px; }
select, input { font: inherit; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.screen { position: fixed; inset: 0; }
[hidden] { display: none !important; }

/* Title & setup */
#title { display: flex; align-items: center; justify-content: center; background: #0b0e14; }
#title-bg { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .55; filter: saturate(.9); }
.title-inner { position: relative; text-align: center; padding: 28px 24px; max-width: 520px; background: rgba(8,11,18,.72); border: 1px solid var(--line); border-radius: 18px; backdrop-filter: blur(3px); }
.title-inner h1 { font-size: 44px; letter-spacing: 2px; margin: 0 0 8px; color: var(--gold); font-weight: 800; text-shadow: 0 2px 12px rgba(0,0,0,.6); }
.tagline { color: var(--muted); margin-bottom: 28px; }
.title-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.version { color: var(--muted); font-size: 12px; margin-top: 24px; }
#setup { overflow: auto; touch-action: pan-y; }
.setup-inner { padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bottom)); max-width: 900px; margin: 0 auto; }
.setup-inner h2 { margin: 6px 0; }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.civ-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.civ-card { border: 2px solid var(--line); border-radius: 12px; padding: 10px; background: var(--panel); cursor: pointer; }
.civ-card.selected { border-color: var(--gold); background: #2a2415; }
.civ-card .swatch { width: 100%; height: 8px; border-radius: 4px; margin-bottom: 8px; }
.civ-card b { display: block; font-size: 15px; }
.civ-card span { color: var(--muted); font-size: 12px; }
.civ-detail { margin: 14px 0; padding: 12px; background: var(--panel); border-radius: 12px; font-size: 14px; line-height: 1.45; }
.civ-detail h3 { margin: 0 0 6px; color: var(--gold); }
.setup-options { display: flex; flex-wrap: wrap; gap: 12px; margin: 12px 0 18px; }
.setup-options label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.setup-options input { width: 130px; }

/* Game HUD */
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: #08131f; }
#topbar { position: absolute; top: 0; left: 0; right: 0; padding: calc(6px + var(--safe-top)) 8px 6px; display: flex; align-items: center; gap: 8px; background: linear-gradient(rgba(11,14,20,.95), rgba(11,14,20,.75)); font-size: 14px; }
#top-yields { display: flex; gap: 10px; flex: 1; overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
#top-yields::-webkit-scrollbar { display: none; }
#top-yields .y { display: inline-flex; align-items: center; gap: 3px; padding: 4px 6px; border-radius: 8px; background: rgba(255,255,255,.05); cursor: pointer; }
#top-yields .y small { color: var(--muted); }
#top-turn { text-align: right; font-size: 12px; color: var(--muted); line-height: 1.2; min-width: 70px; }
#top-turn b { color: var(--text); font-size: 14px; }
#notifs { position: absolute; top: calc(50px + var(--safe-top)); left: 0; right: 0; display: flex; gap: 6px; padding: 4px 8px; overflow-x: auto; scrollbar-width: none; pointer-events: none; }
#notifs::-webkit-scrollbar { display: none; }
.notif { pointer-events: auto; flex: none; background: rgba(21,26,36,.94); border: 1px solid var(--line); border-radius: 20px; padding: 6px 12px; font-size: 13px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.notif.growth { border-color: var(--food); } .notif.war, .notif.attack, .notif.loss, .notif.capture { border-color: var(--danger); } .notif.tech { border-color: var(--sci); } .notif.civic { border-color: var(--cult); } .notif.wonder { border-color: var(--gold); }
#bottombar { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 8px calc(8px + var(--safe-bottom)); background: linear-gradient(rgba(11,14,20,.6), rgba(11,14,20,.97)); display: flex; align-items: flex-end; gap: 8px; }
#context { flex: 1; min-width: 0; font-size: 13px; }
#context .card { background: rgba(21,26,36,.94); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
#context .card h3 { margin: 0 0 4px; font-size: 15px; display: flex; align-items: center; gap: 6px; }
#context .card .meta { color: var(--muted); margin-bottom: 6px; }
#context .actions { display: flex; flex-wrap: wrap; gap: 6px; }
#turn-controls { display: flex; flex-direction: column; gap: 6px; }
button.turn { min-width: 118px; padding: 12px 10px; font-weight: 600; font-size: 15px; }
#btn-next.attention { background: #7a5a11; border-color: var(--gold); }
#toast { position: absolute; left: 50%; top: 40%; transform: translateX(-50%); background: rgba(21,26,36,.96); border: 1px solid var(--gold); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 80%; text-align: center; z-index: 30; }
.hpbar { height: 5px; background: #333; border-radius: 3px; overflow: hidden; margin: 4px 0; }
.hpbar i { display: block; height: 100%; background: var(--ok); }

/* Panels */
.panel { position: absolute; inset: 0; background: var(--bg); z-index: 20; display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: calc(8px + var(--safe-top)) 12px 8px; border-bottom: 1px solid var(--line); background: var(--panel); }
.panel-head h2 { margin: 0; font-size: 18px; }
.panel-body { flex: 1; overflow-y: auto; padding: 12px 12px calc(20px + var(--safe-bottom)); touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.section { margin-bottom: 16px; }
.section h3 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px; }
.row.clickable { cursor: pointer; }
.row.active { border-color: var(--accent); }
.row.done { opacity: .6; }
.row.locked { opacity: .45; }
.row .grow { flex: 1; min-width: 0; }
.row b { display: block; font-size: 14px; }
.row small { color: var(--muted); font-size: 12px; display: block; line-height: 1.35; }
.yields { display: flex; flex-wrap: wrap; gap: 8px; font-size: 14px; }
.yields span { background: var(--panel2); padding: 4px 8px; border-radius: 8px; }
.progress { height: 8px; background: #2a3140; border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress i { display: block; height: 100%; background: var(--accent); }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; overflow-x: auto; }
.tabs button { flex: none; }
.tabs button.on { background: #2b5db8; border-color: #3f74d6; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; background: var(--panel2); color: var(--muted); }
.pill.war { background: #5a1e1e; color: #ffb3b3; } .pill.peace { background: #1e4a2a; color: #b6f0c4; }
.stat { color: var(--muted); font-size: 13px; }
.food { color: var(--food); } .prod { color: var(--prod); } .sci { color: var(--sci); } .cult { color: var(--cult); } .goldc { color: var(--gold); }
.help p { line-height: 1.5; color: #d6d6d0; }
.help h3 { color: var(--gold); margin: 14px 0 4px; }
.scorebar { display: flex; gap: 6px; align-items: center; }
.scorebar i { display: block; height: 10px; background: var(--gold); border-radius: 5px; }
.victory { text-align: center; padding: 30px 10px; }
.victory h1 { color: var(--gold); font-size: 34px; }
@media (min-width: 700px) { .panel { left: 50%; transform: translateX(-50%); width: 640px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); } }

/* In-app confirm dialog (WebView has no native confirm) */
.confirm { position: absolute; inset: 0; background: rgba(0,0,0,.55); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 20px; }
.confirm-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; max-width: 360px; width: 100%; }
.confirm-box p { margin: 0 0 14px; font-size: 15px; line-height: 1.4; }
.confirm-buttons { display: flex; gap: 10px; justify-content: flex-end; }

.leader-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.leader-card { border: 2px solid var(--line); border-radius: 10px; padding: 10px; background: var(--panel2); cursor: pointer; font-size: 13px; }
.leader-card.selected { border-color: var(--gold); background: #2a2415; }
.leader-card > b { font-size: 15px; }

/* Civilopedia & city view */
.plink { color: var(--sci); text-decoration: underline; cursor: pointer; }
.pedia-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; max-height: 32vh; overflow-y: auto; }
.pedia-entry { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; line-height: 1.5; font-size: 14px; }
.pedia-entry h3 { margin: 0 0 8px; color: var(--gold); font-size: 18px; }
.pedia-entry p { margin: 6px 0; }
.cityview-wrap { position: relative; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); margin-bottom: 12px; touch-action: none; }
#cityview-canvas { display: block; width: 100%; }
.cityview-hint { position: absolute; bottom: 6px; left: 0; right: 0; text-align: center; font-size: 11px; color: rgba(255,255,255,.8); text-shadow: 0 1px 3px #000; pointer-events: none; }
.portrait { float: right; width: 72px; height: 90px; object-fit: cover; border-radius: 8px; margin: 0 0 6px 8px; border: 1px solid var(--line); }
.portrait-sm { width: 44px; height: 54px; object-fit: cover; border-radius: 6px; }

/* Quote card */
.quote-box { background: linear-gradient(180deg, #1c2230, #12161f); border: 1px solid var(--gold); border-radius: 16px; padding: 22px 22px 16px; max-width: 460px; width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.quote-kicker { font-size: 12px; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); }
.quote-box h2 { margin: 4px 0 12px; color: var(--gold); font-size: 22px; }
.quote-box p { font-size: 17px; line-height: 1.5; font-style: italic; margin: 0 0 8px; color: #f1eee6; }
.quote-by { font-size: 13px; color: var(--muted); text-align: right; margin-bottom: 12px; }
.pquote { margin: 10px 0 0; padding: 10px 14px; border-left: 3px solid var(--gold); background: rgba(255,255,255,.04); font-style: italic; }

/* to-do End Turn button, pass button, promotions, notifications, quote reveal */
#btn-end.todo { background: #7a5a11; border-color: var(--gold); text-align: left; }
#btn-end.todo small { display: block; font-size: 11px; opacity: .8; font-weight: normal; }
#btn-pass { flex: none; padding: 8px 10px; font-size: 13px; opacity: .85; }
.promo { margin: 6px 0; padding: 6px 8px; border: 1px solid var(--gold); border-radius: 8px; background: rgba(122,90,17,.25); }
.promo .actions button { display: block; text-align: left; }
.promo button small { display: block; font-size: 10px; opacity: .8; font-weight: normal; }
button.gold { border-color: var(--gold); background: #4a3a10; }
.notif { display: inline-flex; align-items: center; gap: 6px; }
.notif .nx { margin-left: 4px; opacity: .6; font-size: 15px; padding: 0 2px; } .notif .nx:hover { opacity: 1; }
.notif.clear { opacity: .7; font-size: 12px; }
.quote-art { display: block; width: 100%; max-height: 42vh; object-fit: contain; border-radius: 10px; margin: 0 0 10px; background: rgba(0,0,0,.25); }
.quote-box.reveal { animation: quoteIn .45s ease-out; }
.quote-box.reveal .quote-art { animation: artIn 1.4s cubic-bezier(.2,.8,.2,1); }
.quote-box.natural { border-color: #7fd3a6; box-shadow: 0 0 60px rgba(127,211,166,.35); }
.quote-box.natural h2 { color: #a8f0c8; }
@keyframes quoteIn { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes artIn { from { transform: scale(1.25); filter: brightness(2) blur(6px); opacity: 0; } 40% { opacity: 1; } to { transform: scale(1); filter: none; } }

.faith { color: #d9c9ff; }
.row.selected { border-color: var(--gold); }

.dtag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; margin: 2px 0; }
.dtag.easy { background: #1f4d2a; color: #9fe3b0; } .dtag.medium { background: #4d3f1f; color: #ffd98a; } .dtag.hard { background: #4d1f1f; color: #ff9f9f; }
.civ-card .emblem { width: 40px; height: 40px; display: block; margin: 0 auto 4px; object-fit: contain; }

.tip { position: absolute; z-index: 30; max-width: 240px; background: rgba(14,18,28,.96); border: 1px solid var(--gold); border-radius: 10px; padding: 8px 10px; font-size: 13px; pointer-events: none; box-shadow: 0 6px 20px rgba(0,0,0,.5); }
.tip .tip-res { margin: 4px 0; font-size: 14px; }
.tip .tip-nat { color: #ffe08a; margin: 3px 0; }

.techpic { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; flex: none; }
.pedia-pic { float: right; width: 120px; height: 120px; border-radius: 12px; object-fit: cover; margin: 0 0 8px 12px; }

/* leader screen (diplomacy) */
.leader-box { background: linear-gradient(180deg, #1c2230, #12161f); border: 1px solid var(--gold); border-radius: 16px; padding: 16px; max-width: 520px; width: 100%; max-height: 92vh; overflow: auto; box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.leader-head { display: flex; gap: 14px; align-items: flex-start; }
.leader-art { width: 108px; height: 132px; object-fit: cover; border-radius: 10px; border: 2px solid var(--gold); background: #0c1018; flex: none; }
.leader-id h2 { margin: 2px 0 4px; color: var(--gold); font-size: 21px; }
.leader-sub { font-size: 13px; color: #c9c4b8; line-height: 1.4; }
.leader-say { font-size: 15px; line-height: 1.5; font-style: italic; color: #f1eee6; margin: 12px 0 8px; }
.leader-info { font-size: 12.5px; color: #c9c4b8; line-height: 1.45; }
.leader-info .op-plus { color: #9ee29e; } .leader-info .op-minus { color: #ff9c9c; }
.leader-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.leader-actions button { flex: 1 1 46%; }
.leader-actions select { flex: 1 1 100%; background: #0c1018; color: #eee; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }

/* civilopedia art gallery */
.art-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 10px; }
.art-thumb { width: 84px; text-align: center; font-size: 11px; color: #c9c4b8; }
.art-thumb img { width: 84px; height: 84px; object-fit: contain; border-radius: 10px; background: linear-gradient(135deg, #2a3242, #1a2030); border: 1px solid var(--line); display: block; }
.art-thumb.big { width: 132px; } .art-thumb.big img { width: 132px; height: 132px; object-fit: cover; }
.art-thumb small { display: block; line-height: 1.2; margin-top: 3px; }
.pedia-entry h4 { margin: 12px 0 4px; color: var(--gold); font-size: 14px; }
