/* 왕국 수비대 — 나무 판자와 금박 테두리의 작전 지도 UI (헥사 크라운과 같은 톤) */
:root {
  --wood: #2b1f17;
  --wood-2: #3a2a1e;
  --line: #6b4f33;
  --gold: #e3b046;
  --gold-2: #f5d27a;
  --parch: #f4e8cc;
  --muted: #c2ad8a;
  --red: #e2574c;
  --green: #5fc46e;
  --blue: #5aa3ff;
  --display: "Gowun Batang", "AppleMyungjo", "Batang", serif;
  --body: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #8fc4e8; color: var(--parch); font-family: var(--body); -webkit-user-select: none; user-select: none; }
#cv { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#overlay { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
button:focus-visible { outline: 2px solid var(--gold-2); outline-offset: 2px; }
kbd { font: 600 10px ui-monospace, Menlo, monospace; border: 1px solid rgba(244,232,204,.35); border-radius: 3px; padding: 0 4px; margin-left: 6px; opacity: .75; }
.coin { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffe9a0, #e3b046 55%, #9a6a1a); box-shadow: 0 0 0 1px #6b4a12; vertical-align: -2px; }

.back-btn { position: fixed; top: 12px; left: 12px; z-index: 30; display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; font-size: 13px; font-weight: 600; color: var(--parch); text-decoration: none; border-radius: 8px; background: rgba(43,31,23,.88); border: 1px solid var(--line); }
.back-btn:hover { border-color: var(--gold); }

/* 상단 */
.hud-top { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 20; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.hud-box { display: flex; align-items: center; gap: 16px; padding: 7px 16px; border-radius: 12px; background: linear-gradient(180deg, var(--wood-2), var(--wood)); border: 1px solid var(--line); box-shadow: 0 6px 16px rgba(0,0,0,.35); white-space: nowrap; }
.map-name { font: 700 15px var(--display); color: var(--gold-2); }
.hud-box b { font: 700 19px var(--display); font-variant-numeric: tabular-nums; }
.wave small { color: var(--muted); font-size: 13px; }
.lives { color: var(--red); }
.lives b { color: var(--parch); }
.lives.hurt b { color: var(--red); }
.gold { display: inline-flex; align-items: center; gap: 6px; }
.gold.flash b { animation: flash .5s; }
@keyframes flash { 0%, 100% { color: var(--parch); } 30% { color: var(--red); } }
.next-info { margin: 0; padding: 3px 12px; font-size: 12px; border-radius: 999px; background: rgba(43,31,23,.82); border: 1px solid var(--line); }
.next-info:empty { display: none; }
.next-info .boss { color: #ff9c8c; font-weight: 700; }

/* 우측 */
.hud-right { position: fixed; right: 12px; top: 12px; z-index: 20; display: grid; gap: 8px; justify-items: end; }
.wave-btn { min-width: 168px; padding: 12px 16px; border-radius: 12px; border: 1px solid #f7d98a; font: 700 16px var(--display); color: #2b1a08; background: linear-gradient(180deg, #ffd978, #e3a63a); box-shadow: 0 6px 16px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.5); }
.wave-btn kbd { color: #2b1a08; border-color: rgba(43,26,8,.4); }
.wave-btn small { display: block; font: 600 11px var(--body); opacity: .8; }
.wave-btn:disabled { filter: grayscale(.7) brightness(.7); }
.mini-row { display: flex; gap: 6px; }
.mini { width: 40px; height: 36px; border-radius: 9px; background: rgba(43,31,23,.9); border: 1px solid var(--line); font-weight: 700; }
.mini:hover { border-color: var(--gold); }
.mini[aria-pressed="true"] { border-color: var(--gold); color: var(--gold-2); }

/* 적 체력바 */
.ebar { position: absolute; left: 0; top: 0; width: 38px; height: 5px; border-radius: 3px; background: #1a0e0c; border: 1px solid #0b0705; overflow: hidden; }
.ebar i { display: block; height: 100%; background: linear-gradient(90deg, #d4423a, #ff7a5a); }
.ebar.fly i { background: linear-gradient(90deg, #4aa0d8, #8fd6ff); }
.ebar.slowed { border-color: #8fd6ff; }
.ebar.boss { width: 120px; height: 18px; overflow: visible; background: none; border: 0; }
.ebar.boss span { display: block; text-align: center; font: 700 11px var(--display); color: #ffd6cc; text-shadow: 0 1px 2px #000; margin-bottom: 2px; }
.ebar.boss i { height: 7px; border-radius: 4px; border: 1px solid #0b0705; background: linear-gradient(90deg, #a01f5a, #ff5aa0); }
.ftxt { position: absolute; left: 0; top: 0; font: 800 13px var(--body); color: #fff; text-shadow: 0 1px 2px #000, 0 0 4px #000; white-space: nowrap; }
.ftxt.gold { color: #ffd76a; font-size: 12px; }
.ftxt.leak { color: #ff7a6a; font-size: 16px; }
.ftxt.info { color: #bff4ff; }

/* 팝업 (건설 메뉴, 타워 정보) */
.pop { position: fixed; z-index: 25; width: 260px; padding: 10px; border-radius: 12px; background: linear-gradient(180deg, var(--wood-2), var(--wood)); border: 1px solid var(--gold); box-shadow: 0 10px 28px rgba(0,0,0,.5); font-size: 13px; }
.pop h3 { margin: 0 0 6px; font: 700 16px var(--display); color: var(--gold-2); display: flex; align-items: center; gap: 6px; }
.pop h3 .lv { margin-left: auto; font: 600 12px var(--body); color: var(--gold); }
.pop .close { position: absolute; right: 6px; top: 4px; width: 26px; height: 26px; border: 0; background: none; color: var(--muted); font-size: 16px; }
.build-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.build-list button { display: grid; grid-template-columns: 28px 1fr; grid-template-rows: auto auto; column-gap: 6px; align-items: center; text-align: left; padding: 7px; border-radius: 9px; background: #1f160f; border: 1px solid var(--line); }
.build-list button:hover:not(:disabled) { border-color: var(--gold); background: #2a1e14; }
.build-list button:disabled { opacity: .45; }
.build-list .ico { grid-row: span 2; font-size: 22px; text-align: center; }
.build-list b { font-size: 13px; }
.build-list .cost { font-size: 12px; color: var(--gold-2); }
.build-list kbd { margin-left: 4px; }
.pop .desc { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; min-height: 34px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin: 6px 0 8px; padding: 7px 9px; border-radius: 8px; background: rgba(0,0,0,.22); }
.stats div { display: flex; justify-content: space-between; gap: 6px; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats .up { color: var(--green); font-weight: 600; }
.act { display: grid; gap: 6px; }
.act button { padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line); background: #1f160f; text-align: left; }
.act button:hover:not(:disabled) { border-color: var(--gold); }
.act button:disabled { opacity: .45; }
.act .upg { background: linear-gradient(180deg, #4a3a14, #33280e); border-color: var(--gold); }
.act .upg b { color: var(--gold-2); }
.act .branch { display: grid; gap: 2px; }
.act .branch span { color: var(--muted); font-size: 11.5px; line-height: 1.4; }
.act .row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.act .sell { color: #ffb4a8; }
.price { float: right; color: var(--gold-2); font-weight: 700; }

/* 배너·토스트 */
.banner { position: fixed; left: 50%; top: 30%; transform: translate(-50%, -50%); z-index: 22; text-align: center; pointer-events: none; opacity: 0; }
.banner.show { animation: banner 2.2s ease forwards; }
.banner b { display: block; font: 700 40px var(--display); color: var(--gold-2); text-shadow: 0 3px 0 #3a2410, 0 0 18px rgba(0,0,0,.6); }
.banner b.boss { color: #ff8a7a; }
.banner span { font-size: 15px; text-shadow: 0 1px 3px #000; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -40%); } 15%, 75% { opacity: 1; transform: translate(-50%, -50%); } 100% { opacity: 0; transform: translate(-50%, -55%); } }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 40; padding: 8px 16px; border-radius: 999px; background: rgba(20,14,10,.92); border: 1px solid var(--line); font-size: 13px; opacity: 0; transition: .25s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 모달 */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(12,9,6,.62); overflow: auto; }
.modal[hidden] { display: none; }
.sheet { width: min(760px, 100%); padding: 22px 24px; border-radius: 16px; background: linear-gradient(180deg, var(--wood-2), var(--wood)); border: 1px solid var(--gold); box-shadow: 0 20px 50px rgba(0,0,0,.55); }
.sheet .eyebrow { margin: 0; color: var(--gold); font-size: 12px; letter-spacing: .12em; }
.sheet h2 { margin: 2px 0 8px; font: 700 30px var(--display); color: var(--gold-2); }
.sheet p { line-height: 1.55; }
.maps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0; }
.map-card { display: grid; gap: 4px; align-content: start; text-align: left; padding: 12px; border-radius: 12px; background: #1f160f; border: 1px solid var(--line); min-height: 150px; }
.map-card:hover:not(:disabled) { border-color: var(--gold); background: #2a1e14; }
.map-card:disabled { opacity: .5; }
.map-card b { font: 700 17px var(--display); color: var(--gold-2); }
.map-card .meta { font-size: 12px; color: var(--muted); }
.map-card .d { font-size: 12.5px; line-height: 1.45; }
.stars { font-size: 18px; letter-spacing: 2px; color: #5a4a36; }
.stars .on { color: var(--gold-2); text-shadow: 0 0 6px rgba(245,210,122,.6); }
.howto { margin: 6px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.6; color: var(--muted); }
.howto b { color: var(--parch); }
.primary { padding: 11px 22px; border-radius: 10px; border: 1px solid #f7d98a; font: 700 16px var(--display); color: #2b1a08; background: linear-gradient(180deg, #ffd978, #e3a63a); }
.ghost-btn { padding: 11px 18px; border-radius: 10px; border: 1px solid var(--line); background: #1f160f; font-weight: 600; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.result-stars { font-size: 44px; letter-spacing: 6px; margin: 4px 0; }

/* 로딩 */
.loading { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: #2b1f17; }
.loading[hidden] { display: none; }
.load-card { width: min(340px, 86vw); text-align: center; }
.load-card h1 { font: 700 30px var(--display); color: var(--gold-2); margin: 0 0 14px; }
.load-track { height: 8px; border-radius: 4px; background: #1a120c; overflow: hidden; border: 1px solid var(--line); }
.load-track i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #c8892a, #f5d27a); transition: width .2s; }
.load-card p { color: var(--muted); font-size: 13px; }
.load-err { max-width: 520px; padding: 0 16px; text-align: center; line-height: 1.6; }

@media (max-width: 760px) {
  .back-btn { padding: 6px 9px; font-size: 12px; }
  .hud-top { top: auto; bottom: 12px; flex-direction: column-reverse; }
  .hud-box { gap: 10px; padding: 6px 10px; }
  .map-name { display: none; }
  .hud-box b { font-size: 16px; }
  .wave-btn { min-width: 0; padding: 9px 12px; font-size: 14px; }
  .wave-btn kbd { display: none; }
  .maps { grid-template-columns: repeat(2, 1fr); }
  .map-card { min-height: 0; }
  .pop { width: min(260px, calc(100vw - 32px)); }
  .build-list kbd { display: none; }
  .toast { bottom: 84px; }
}

/* 모드 탭·무한 모드 */
.mode-tabs { display: flex; gap: 6px; margin: 12px 0 0; }
.mode-tabs button { flex: 1; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: #1f160f; font: 700 15px var(--display); color: var(--muted); }
.mode-tabs button[aria-selected="true"] { color: #2b1a08; border-color: #f7d98a; background: linear-gradient(180deg, #ffd978, #e3a63a); }
.mode-tabs button:disabled { opacity: .5; }
.mode-note { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.map-card.snow { background: linear-gradient(180deg, #1f2630, #1f160f); }
.map-card .record { font-size: 14px; color: var(--muted); }
.map-card .record b { font: 700 20px var(--display); }
.result-wave { display: grid; margin: 6px 0; }
.result-wave b { font: 700 54px var(--display); color: var(--gold-2); line-height: 1.1; }
.result-wave span { color: var(--muted); font-size: 13px; }
