:root {
  --bg: #122c47; --panel: #1c2b3d; --panel2: #243a52; --line: rgba(255, 255, 255, 0.12);
  --text: #eef3f8; --dim: #9fb3c8; --accent: #f2b63a; --accent2: #e39a12; --ok: #4fd18b; --bad: #ff6b6b; --blue: #5aa9ff;
  --r: 14px; --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }
[hidden] { display: none !important; }
a { color: var(--blue); }
.screen { position: fixed; inset: 0; }
.back-btn { position: fixed; top: calc(10px + var(--safe-t)); left: 12px; z-index: 5; display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.1); border: 1px solid var(--line); color: var(--text); text-decoration: none; font-size: 0.85rem; font-weight: 700; }
.back-btn:hover { background: rgba(255, 255, 255, 0.18); }

/* ── 메뉴 ── */
#menu { overflow-y: auto; background: radial-gradient(ellipse at 50% -10%, #2d5a8a 0%, #122c47 55%, #0b1b2e 100%); }
.menu-wrap { max-width: 720px; margin: 0 auto; padding: calc(56px + var(--safe-t)) 16px 40px; }
.logo { text-align: center; margin-bottom: 14px; }
.logo-hex { width: 96px; margin: 0 auto 6px; }
.logo-hex svg { width: 100%; }
.lh-bg { fill: #f2b63a; } .lh-in { fill: #1c2b3d; }
.logo h1 { margin: 0; font-size: clamp(34px, 8vw, 48px); letter-spacing: -0.02em; }
.logo h1 span { color: var(--accent); }
.tagline { color: var(--dim); margin: 6px 0 0; line-height: 1.6; font-size: 0.95rem; }
.tabs { display: flex; gap: 6px; justify-content: center; margin: 14px 0 10px; }
.tab { border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); border-radius: 999px; padding: 8px 16px; font-weight: 700; }
.tab.on { background: var(--accent); color: #1a1a1a; border-color: var(--accent); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 8px; font-size: 1rem; color: var(--accent); }
.panel p { margin: 6px 0; line-height: 1.6; }
.sub { color: var(--dim); font-size: 0.85rem; }
.opt-group { margin-bottom: 14px; }
.opt-label { font-size: 0.85rem; color: var(--dim); margin-bottom: 6px; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); border-radius: 10px; padding: 8px 12px; font-weight: 700; font-size: 0.9rem; display: flex; align-items: center; gap: 6px; }
.chip.on { background: var(--accent); color: #1a1a1a; border-color: var(--accent); }
.chip small { font-weight: 500; opacity: 0.8; }
.civ-chip { flex-direction: column; align-items: flex-start; gap: 2px; min-width: 120px; }
.civ-chip .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; border: 1px solid rgba(0, 0, 0, 0.3); }
.civ-chip small { font-size: 0.75rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn { border: 1px solid var(--line); background: var(--panel2); color: var(--text); border-radius: 12px; padding: 10px 16px; font-weight: 800; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.btn:hover { filter: brightness(1.1); }
.btn.primary { background: var(--accent); color: #1a1a1a; border-color: var(--accent); }
.btn.big { padding: 14px 24px; font-size: 1.05rem; width: 100%; }
.btn.ghost { background: rgba(255, 255, 255, 0.06); }
.btn.danger { background: #5a2a2a; border-color: #7a3a3a; }
.btn.sm { padding: 6px 10px; font-size: 0.85rem; border-radius: 9px; }
.cont-box { background: rgba(242, 182, 58, 0.12); border: 1px solid rgba(242, 182, 58, 0.4); border-radius: 12px; padding: 12px; margin-bottom: 14px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--panel2); border-radius: 10px; padding: 10px; }
.stat b { display: block; font-size: 1.3rem; }
.stat span { color: var(--dim); font-size: 0.8rem; }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.ach { background: var(--panel2); border-radius: 10px; padding: 10px; display: flex; gap: 8px; align-items: center; }
.ach.off { opacity: 0.4; filter: grayscale(1); }
.ach .ico { font-size: 1.5rem; }
.ach b { display: block; font-size: 0.9rem; }
.ach small { color: var(--dim); font-size: 0.75rem; }
.help h4 { margin: 14px 0 4px; color: var(--accent); font-size: 0.95rem; }
.help ul { margin: 4px 0; padding-left: 18px; line-height: 1.6; }
.help table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
.help td, .help th { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; }
kbd { background: rgba(255, 255, 255, 0.12); border-radius: 4px; padding: 1px 6px; font-family: inherit; font-size: 0.85em; border: 1px solid var(--line); }

/* ── 게임 ── */
#game { background: #122c47; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#map.drag { cursor: grabbing; }
.hud { position: absolute; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; gap: 6px; padding: 6px 8px; padding-top: calc(6px + var(--safe-t)); background: linear-gradient(180deg, rgba(8, 18, 32, 0.92), rgba(8, 18, 32, 0.75)); border-bottom: 1px solid var(--line); font-size: 0.88rem; white-space: nowrap; overflow-x: auto; scrollbar-width: none; }
.hud::-webkit-scrollbar { display: none; }
.hud-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08); font-size: 1.05rem; flex: none; display: inline-flex; align-items: center; justify-content: center; }
.hud-btn:hover { background: rgba(255, 255, 255, 0.16); }
.hud-btn.alert { box-shadow: 0 0 0 2px var(--accent); }
.hud-civ { font-weight: 800; display: flex; align-items: center; gap: 6px; padding: 0 4px; }
.hud-civ .dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.4); }
.hud-stat { padding: 6px 8px; border-radius: 9px; background: rgba(255, 255, 255, 0.06); font-weight: 700; flex: none; }
.hud-link { border: 1px solid var(--line); text-align: left; }
.hud-link.alert { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.hud-right { margin-left: auto; display: flex; gap: 6px; }
.hud .ok { color: var(--ok); } .hud .bad { color: var(--bad); }
.prog { display: inline-block; width: 70px; height: 6px; background: rgba(255, 255, 255, 0.12); border-radius: 3px; vertical-align: middle; margin-left: 6px; overflow: hidden; }
.prog i { display: block; height: 100%; background: var(--blue); }

.toasts { position: absolute; top: calc(52px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 12; display: flex; flex-direction: column; gap: 6px; pointer-events: none; max-width: min(92vw, 420px); }
.toast { background: rgba(8, 18, 32, 0.92); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 0.85rem; font-weight: 700; animation: pop 0.25s ease-out; pointer-events: auto; cursor: pointer; box-shadow: var(--shadow); }
.toast.war { border-color: var(--bad); } .toast.good { border-color: var(--ok); } .toast.gold { border-color: var(--accent); }
@keyframes pop { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

.side { position: absolute; right: 8px; top: calc(54px + var(--safe-t)); max-height: calc(100% - 140px); width: min(340px, 46vw); z-index: 11; background: rgba(20, 32, 48, 0.96); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow-y: auto; padding: 12px; font-size: 0.88rem; }
.side h3 { margin: 0 0 6px; font-size: 1.05rem; display: flex; align-items: center; gap: 6px; }
.side h3 .x { margin-left: auto; }
.side .meta { color: var(--dim); font-size: 0.82rem; margin-bottom: 8px; line-height: 1.5; }
.side .acts { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.yields { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.yields span { background: rgba(255, 255, 255, 0.07); border-radius: 8px; padding: 4px 8px; font-weight: 700; }
.bar { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); overflow: hidden; margin: 4px 0 2px; }
.bar i { display: block; height: 100%; background: var(--ok); }
.bar.p i { background: var(--accent); }
.list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.item { display: flex; align-items: center; gap: 8px; background: rgba(255, 255, 255, 0.06); border: 1px solid transparent; border-radius: 10px; padding: 7px 9px; text-align: left; width: 100%; }
.item:hover { background: rgba(255, 255, 255, 0.12); }
.item.on { border-color: var(--accent); background: rgba(242, 182, 58, 0.14); }
.item.off { opacity: 0.45; }
.item .ico { font-size: 1.2rem; width: 26px; text-align: center; }
.item .nm { font-weight: 800; }
.item small { display: block; color: var(--dim); font-size: 0.75rem; line-height: 1.3; }
.item .cost { margin-left: auto; font-weight: 800; white-space: nowrap; font-size: 0.82rem; text-align: right; }
.item .cost small { display: block; }
.buy { margin-left: 4px; }
.sect { margin-top: 10px; font-weight: 800; color: var(--accent); font-size: 0.85rem; }
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg button { flex: 1; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); border-radius: 8px; padding: 5px 6px; font-size: 0.8rem; font-weight: 700; }
.seg button.on { background: var(--accent); color: #1a1a1a; border-color: var(--accent); }

.bottom { position: absolute; left: 8px; right: 8px; bottom: calc(8px + var(--safe-b)); z-index: 10; display: flex; align-items: flex-end; gap: 8px; pointer-events: none; }
.bottom > * { pointer-events: auto; }
.tip { flex: 1; min-width: 0; background: rgba(8, 18, 32, 0.85); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; font-size: 0.8rem; color: var(--dim); line-height: 1.4; max-height: 56px; overflow: hidden; }
.tip:empty { display: none; }
.turn-box { display: flex; gap: 6px; }
#endBtn { padding: 12px 18px; font-size: 1rem; box-shadow: 0 6px 18px rgba(242, 182, 58, 0.35); }
#endBtn.pulse { animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 6px 18px rgba(242, 182, 58, 0.35); } 50% { box-shadow: 0 6px 26px rgba(242, 182, 58, 0.8); } }
#idleCnt:empty { display: none; }
#idleCnt { background: var(--bad); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 0.75rem; }
#mini { position: absolute; left: 8px; bottom: calc(60px + var(--safe-b)); z-index: 9; border: 1px solid var(--line); border-radius: 8px; background: #0d2238; box-shadow: var(--shadow); cursor: pointer; }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.55); display: grid; place-items: center; padding: 12px; }
.modal-box { width: min(640px, 100%); max-height: calc(100vh - 24px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); font-size: 0.9rem; }
.modal-box h2 { margin: 0 0 8px; font-size: 1.2rem; display: flex; align-items: center; gap: 8px; }
.modal-box h2 .x { margin-left: auto; }
.tier { margin-top: 10px; }
.tier h4 { margin: 0 0 4px; color: var(--dim); font-size: 0.8rem; }
.tech-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.tech { border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); border-radius: 10px; padding: 8px; text-align: left; font-size: 0.82rem; }
.tech.done { opacity: 0.5; border-style: dashed; }
.tech.avail { border-color: var(--blue); }
.tech.on { border-color: var(--accent); background: rgba(242, 182, 58, 0.14); }
.tech.lock { opacity: 0.35; }
.tech b { display: block; }
.tech small { color: var(--dim); display: block; line-height: 1.35; }
.dip { display: flex; align-items: center; gap: 10px; background: rgba(255, 255, 255, 0.05); border-radius: 10px; padding: 10px; margin-bottom: 6px; }
.dip .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 1px solid rgba(0, 0, 0, 0.4); }
.dip .nm { font-weight: 800; }
.dip small { color: var(--dim); display: block; }
.dip .acts { margin-left: auto; display: flex; gap: 4px; }
.score-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.score-table td, .score-table th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; font-size: 0.85rem; }
.score-table tr.me { background: rgba(242, 182, 58, 0.12); }
.log { display: flex; flex-direction: column; gap: 3px; }
.log button { text-align: left; background: rgba(255, 255, 255, 0.05); border: 0; border-radius: 8px; padding: 6px 8px; font-size: 0.85rem; }
.log button b { color: var(--dim); font-weight: 600; margin-right: 6px; }
.win-big { text-align: center; font-size: 2.4rem; margin: 6px 0; }
.ach-pop { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 60; background: var(--accent); color: #1a1a1a; font-weight: 800; padding: 10px 16px; border-radius: 999px; box-shadow: var(--shadow); animation: pop 0.3s; }

.err-box { max-width: 480px; margin: 20vh auto; background: var(--panel); border-radius: var(--r); padding: 20px; text-align: center; }

@media (max-width: 640px) {
  .side { left: 8px; right: 8px; width: auto; top: auto; bottom: calc(66px + var(--safe-b)); max-height: 46vh; padding: 10px; }
  .side:not([hidden]) ~ .bottom .tip { display: none; }
  #mini { width: 100px; height: 72px; }
  .hud-civ span.nm { display: none; }
  .hud { font-size: 0.8rem; }
  .prog { width: 44px; }
  .tip { font-size: 0.75rem; }
  #endBtn { padding: 10px 14px; }
  .modal-box { padding: 12px; }
}
