:root {
  --ink: #eef6ff;
  --muted: #9fb4cb;
  --panel: rgba(13, 22, 38, .82);
  --line: rgba(170, 214, 244, .22);
  --gold: #ffd86a;
  --aqua: #71f1dc;
  --red: #ff6c79;
  --shadow: 0 18px 44px rgba(0, 0, 0, .4);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; min-height: 100%; margin: 0; background: #10182a; overscroll-behavior: none; }
body { color: var(--ink); font-family: Nunito, system-ui, sans-serif; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; background: none; padding: 0; }
img { -webkit-user-drag: none; }
[hidden] { display: none !important; }

#app { position: relative; width: 100%; height: 100dvh; overflow: hidden; isolation: isolate; background: #141d30; }
#battlefield { position: absolute; inset: 0; display: block; width: 100%; height: 100%; z-index: 0; touch-action: none; }

/* ── 상단 HUD ─────────────────────────────────────────── */
.hud-top { position: absolute; z-index: 5; top: max(10px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.panel-chip { display: flex; align-items: center; gap: 8px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel); box-shadow: 0 6px 18px rgba(0, 0, 0, .28); backdrop-filter: blur(10px); }
.hud-icon { width: 24px; height: 24px; object-fit: contain; }
.wall-meter { position: relative; width: 128px; height: 18px; border-radius: 9px; background: #0a1322; overflow: hidden; box-shadow: inset 0 1px 3px rgba(0,0,0,.6); }
.wall-meter i { position: absolute; inset: 0; width: 100%; border-radius: inherit; background: linear-gradient(90deg, #7ef598, #c8f76d); transition: width .25s, background .3s; }
.wall-meter.hurt i { background: linear-gradient(90deg, #ffb35e, #ff7d68); }
.wall-meter.crit i { background: linear-gradient(90deg, #ff7566, #ff4d5e); }
.wall-meter b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; color: #08131f; text-shadow: 0 1px 0 rgba(255,255,255,.35); }
.chip-btn { display: flex; align-items: center; gap: 4px; padding: 4px 9px; border-radius: 9px; background: rgba(120, 170, 220, .16); border: 1px solid var(--line); font-size: 13px; font-weight: 900; transition: .15s; }
.chip-btn:hover { background: rgba(140, 195, 245, .3); }
.chip-btn:disabled { opacity: .4; cursor: not-allowed; }
.chip-btn em { font-style: normal; font-family: 'DM Mono', monospace; font-size: 11px; color: var(--gold); }
.hud-wave { gap: 7px; }
.hud-wave .wave-label { font-family: 'DM Mono', monospace; font-size: 9px; letter-spacing: 1.4px; color: var(--aqua); }
.hud-wave b { font-size: 16px; font-weight: 900; }
.hud-wave .wave-name { max-width: 150px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 11px; font-weight: 800; color: var(--muted); }
.wave-clock { display: grid; place-items: center; min-width: 30px; height: 24px; padding: 0 6px; border-radius: 8px; background: rgba(255, 216, 106, .16); border: 1px solid rgba(255, 216, 106, .4); color: var(--gold); font-family: 'DM Mono', monospace; font-size: 13px; font-style: normal; }
.hud-right { display: flex; gap: 7px; align-items: center; }
.coin-chip b { font-size: 16px; font-weight: 900; color: var(--gold); min-width: 42px; text-align: right; }
.icon-btn { display: flex; align-items: center; justify-content: center; white-space: nowrap; min-width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); font-size: 15px; font-weight: 900; box-shadow: 0 6px 16px rgba(0, 0, 0, .22); backdrop-filter: blur(8px); transition: .15s; }
.icon-btn:hover { transform: translateY(-2px); background: #263c5c; }
.icon-btn span { font-family: 'DM Mono', monospace; font-size: 13px; }

/* ── 보스 배너 ────────────────────────────────────────── */
.boss-banner { position: absolute; z-index: 4; top: 62px; left: 50%; transform: translateX(-50%); flex-direction: column; gap: 4px; padding: 8px 16px; min-width: 260px; border-color: rgba(255, 130, 150, .45); }
.boss-banner span { font-size: 12px; font-weight: 900; color: #ffc7d2; letter-spacing: .5px; }
.boss-meter { width: 100%; height: 9px; border-radius: 5px; background: #140a14; overflow: hidden; }
.boss-meter i { display: block; width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #ff5d75, #ffa25e); transition: width .15s; }

/* ── 하단 독 ──────────────────────────────────────────── */
.dock { position: absolute; z-index: 5; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 9px; padding: 8px; border-radius: 18px; border: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow); backdrop-filter: blur(14px); }
.dock-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 92px; padding: 8px 14px; border-radius: 12px; font-weight: 900; transition: .15s; position: relative; }
.dock-btn:hover { transform: translateY(-2px); filter: brightness(1.1); }
.dock-btn:active { transform: translateY(1px); }
.dock-btn:disabled { filter: grayscale(.75); opacity: .5; cursor: not-allowed; transform: none; }
.dock-btn .dock-ico { font-size: 19px; line-height: 1; }
.dock-btn b { font-size: 12px; }
.dock-btn.summon { background: linear-gradient(140deg, #ffd873, #ffab55); color: #3a2410; }
.dock-btn.wave { background: linear-gradient(140deg, #8ff2de, #b9f79c); color: #103227; }
.dock-btn.book { border: 1px solid var(--line); background: rgba(72, 104, 148, .32); }
.dock-btn .cost { display: flex; align-items: center; gap: 3px; font-style: normal; font-family: 'DM Mono', monospace; font-size: 11px; }
.dock-btn .cost img { width: 13px; height: 13px; }
.dock-btn .bonus { position: absolute; top: -8px; right: -6px; padding: 2px 7px; border-radius: 9px; background: #ffd86a; color: #4a3208; font-style: normal; font-family: 'DM Mono', monospace; font-size: 10px; font-weight: 700; box-shadow: 0 3px 8px rgba(0,0,0,.3); }

/* ── 선택 유닛 카드 ───────────────────────────────────── */
.unit-card { position: absolute; z-index: 5; left: max(12px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom)); display: flex; gap: 10px; align-items: center; width: min(370px, calc(100vw - 24px)); padding: 10px; border-radius: 15px; border: 1px solid rgba(255, 226, 130, .38); background: var(--panel); box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.uc-thumb { flex: none; width: 58px; height: 58px; border-radius: 12px; background-color: rgba(90, 130, 180, .18); background-repeat: no-repeat; border: 1px solid var(--line); }
.uc-body { flex: 1; min-width: 0; }
.uc-head { display: flex; align-items: baseline; gap: 6px; }
.uc-head b { font-size: 14px; }
.uc-tier { padding: 1px 6px; border-radius: 6px; background: rgba(113, 241, 220, .16); color: var(--aqua); font-family: 'DM Mono', monospace; font-size: 9px; }
.uc-rank { color: var(--gold); font-size: 11px; letter-spacing: 1px; }
.uc-trait { margin: 3px 0 4px; font-size: 10px; font-weight: 700; color: var(--muted); line-height: 1.35; }
.uc-stats { display: flex; gap: 12px; font-size: 10px; color: var(--muted); }
.uc-stats b { color: #fff; font-family: 'DM Mono', monospace; margin-left: 3px; }
.uc-actions { display: flex; flex-direction: column; gap: 5px; }
#uc-sell { padding: 7px 11px; border-radius: 10px; background: linear-gradient(140deg, #ff9a76, #ff7566); color: #401410; font-size: 11px; font-weight: 900; }
#uc-sell em { font-style: normal; font-family: 'DM Mono', monospace; font-size: 10px; }
#uc-close { align-self: flex-end; width: 26px; height: 26px; border-radius: 8px; background: rgba(120, 150, 190, .22); font-size: 15px; line-height: 1; }

/* ── 토스트 ───────────────────────────────────────────── */
.toast { position: absolute; z-index: 8; top: 66px; left: 50%; max-width: min(400px, 88vw); padding: 10px 16px; border: 1px solid rgba(153, 249, 226, .5); border-radius: 12px; background: rgba(10, 32, 50, .93); font-size: 12.5px; font-weight: 900; text-align: center; box-shadow: var(--shadow); transform: translate(-50%, -12px); opacity: 0; pointer-events: none; transition: .22s; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.warn { border-color: #ffae72; color: #ffe9cf; }

/* ── 모달 공통 ────────────────────────────────────────── */
.modal { position: absolute; z-index: 10; inset: 0; display: grid; place-items: center; padding: 18px; background: rgba(6, 11, 22, .55); backdrop-filter: blur(5px); overflow-y: auto; }
.modal[hidden] { display: none; }
.eyebrow { color: var(--aqua); font-family: 'DM Mono', monospace; font-size: 10px; letter-spacing: 2.2px; }
.x { position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; border-radius: 10px; background: rgba(110, 140, 180, .25); font-size: 21px; line-height: 1; }

/* 메뉴 */
.menu-box { width: min(680px, 100%); padding: 26px 28px; border-radius: 22px; border: 1px solid var(--line); background: linear-gradient(160deg, rgba(16, 30, 54, .93), rgba(9, 16, 32, .94)); box-shadow: var(--shadow); text-align: center; }
.game-title { margin: 10px 0 8px; font-family: 'Black Han Sans', sans-serif; font-weight: 400; font-size: clamp(40px, 6.5vw, 62px); line-height: 1.05; letter-spacing: -1.5px; color: #ffe9ad; text-shadow: 0 4px 0 #3a2c4e, 0 16px 44px rgba(255, 190, 90, .25); }
.game-title span { display: block; margin-top: 4px; font-family: 'DM Mono', monospace; font-size: 12px; letter-spacing: 7px; color: var(--aqua); text-shadow: none; }
.menu-copy { margin: 0 0 18px; color: #c9d8e8; font-size: 13px; font-weight: 700; line-height: 1.6; }
.menu-copy b { color: var(--gold); }
.diff-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: left; }
.diff { position: relative; min-height: 96px; padding: 11px 11px 9px; border: 1px solid rgba(160, 204, 230, .22); border-radius: 14px; background: rgba(24, 44, 74, .55); transition: .16s; }
.diff:hover { transform: translateY(-3px); background: rgba(40, 70, 110, .7); }
.diff i { font-style: normal; font-family: 'DM Mono', monospace; font-size: 9px; color: #86b7d6; }
.diff b { display: block; margin: 8px 0 3px; font-size: 13.5px; }
.diff small { color: #b3c6da; font-family: 'DM Mono', monospace; font-size: 8.5px; }
.diff .best { position: absolute; top: 8px; right: 9px; font-style: normal; font-size: 10px; }
.diff.is-on { border-color: #ffe58d; background: linear-gradient(150deg, rgba(105, 92, 55, .8), rgba(42, 52, 70, .85)); box-shadow: 0 0 0 1px rgba(255, 226, 118, .45), 0 10px 24px rgba(0, 0, 0, .25); }
.diff.danger.is-on { border-color: #ff8790; background: linear-gradient(150deg, rgba(114, 50, 62, .8), rgba(52, 32, 50, .88)); }
.menu-foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 15px; text-align: left; }
.menu-foot > span { flex: 1; color: #a7c0d7; font-size: 11.5px; font-weight: 700; line-height: 1.45; }
.cta { min-width: 158px; height: 46px; padding: 0 20px; border-radius: 13px; background: linear-gradient(110deg, #f8ec9d, #f4c46c); color: #1d2a3d; font-size: 14px; font-weight: 900; transition: .16s; }
.cta:hover { filter: brightness(1.07); transform: translateY(-2px); }
.hint { margin: 15px 0 0; color: #8fa6bd; font-size: 9.5px; font-weight: 700; }
kbd { padding: 1px 4px; border: 1px solid #7a90ac; border-radius: 4px; font-family: 'DM Mono', monospace; font-size: 8.5px; }

/* 조합식 도감 */
.book-box { position: relative; width: min(640px, 100%); max-height: min(86dvh, 720px); overflow-y: auto; padding: 22px 24px; border-radius: 20px; border: 1px solid var(--line); background: linear-gradient(160deg, rgba(16, 30, 54, .95), rgba(9, 16, 32, .96)); box-shadow: var(--shadow); }
.book-box h2 { margin: 6px 0 6px; font-family: 'Black Han Sans', sans-serif; font-weight: 400; font-size: 26px; }
.book-copy { margin: 0 0 14px; color: #b8cbdd; font-size: 11.5px; line-height: 1.5; }
.book-copy b { color: var(--gold); }
.tier-head { margin: 13px 0 7px; display: flex; align-items: center; gap: 8px; color: var(--aqua); font-family: 'DM Mono', monospace; font-size: 10px; letter-spacing: 1.6px; }
.tier-head::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.recipe-row { display: grid; grid-template-columns: 44px 14px 44px 20px 44px 1fr; align-items: center; gap: 6px; padding: 6px 9px; margin-bottom: 6px; border: 1px solid rgba(161, 208, 233, .15); border-radius: 12px; background: rgba(48, 74, 107, .22); }
.recipe-row .op { color: #94b2ca; font-weight: 900; text-align: center; font-size: 13px; }
.recipe-row .info { min-width: 0; padding-left: 4px; }
.recipe-row .info b { display: block; font-size: 12px; }
.recipe-row .info em { display: block; margin-top: 1px; color: #9feade; font-size: 9.5px; font-style: normal; font-weight: 700; }
.sprite-thumb { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background-color: rgba(90, 130, 180, .16); background-repeat: no-repeat; }
.base-strip { display: flex; gap: 7px; flex-wrap: wrap; }
.base-cell { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 64px; padding: 7px 3px 6px; border: 1px solid rgba(161, 208, 233, .15); border-radius: 12px; background: rgba(48, 74, 107, .22); }
.base-cell span { font-size: 9.5px; font-weight: 800; color: #d7e6f3; }

/* 결과 */
.result-box { position: relative; width: min(430px, 100%); padding: 26px 24px; border-radius: 20px; border: 1px solid var(--line); background: linear-gradient(160deg, rgba(16, 30, 54, .95), rgba(9, 16, 32, .96)); box-shadow: var(--shadow); text-align: center; }
.result-icon { display: grid; place-items: center; width: 66px; height: 66px; margin: 0 auto 8px; border-radius: 22px; background: linear-gradient(145deg, #fdefa5, #67e7d9); font-size: 34px; box-shadow: 0 0 40px rgba(115, 235, 215, .3); }
.result-box h2 { margin: 6px 0 8px; font-family: 'Black Han Sans', sans-serif; font-weight: 400; font-size: 27px; }
.result-box p { min-height: 34px; margin: 0 0 14px; color: #bdcfdf; font-size: 12px; line-height: 1.55; }
.result-stats { display: flex; justify-content: space-around; margin: 0 0 18px; padding: 11px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.result-stats span { color: #9db3ca; font-size: 9.5px; font-weight: 800; }
.result-stats b { display: block; margin-top: 3px; color: #fff5be; font-family: 'DM Mono', monospace; font-size: 14px; }
.result-box .cta { width: 100%; }

/* ── 모바일 ───────────────────────────────────────────── */
@media (max-width: 760px) {
  .hud-top { gap: 6px; }
  .panel-chip { padding: 5px 8px; gap: 5px; border-radius: 11px; }
  .hud-icon { width: 19px; height: 19px; }
  .wall-meter { width: 84px; height: 15px; }
  .wall-meter b { font-size: 9px; }
  .chip-btn { padding: 3px 6px; font-size: 11px; }
  .hud-wave b { font-size: 13px; }
  .hud-wave .wave-name { display: none; }
  .coin-chip b { font-size: 13px; min-width: 34px; }
  .icon-btn { min-width: 32px; height: 32px; font-size: 12px; border-radius: 10px; }
  #fs-btn { display: none; }
  .boss-banner { top: 52px; min-width: 200px; padding: 6px 12px; }
  .dock { gap: 6px; padding: 6px; border-radius: 15px; }
  .dock-btn { min-width: 76px; padding: 6px 10px; border-radius: 11px; }
  .dock-btn .dock-ico { font-size: 16px; }
  .dock-btn b { font-size: 10.5px; }
  .unit-card { bottom: calc(78px + env(safe-area-inset-bottom)); width: min(320px, calc(100vw - 20px)); padding: 8px; gap: 8px; }
  .uc-thumb { width: 46px; height: 46px; }
  .uc-head b { font-size: 12px; }
  .uc-trait { font-size: 9px; }
  .toast { top: 56px; font-size: 11px; padding: 8px 12px; }
  .diff-grid { grid-template-columns: repeat(2, 1fr); }
  .diff { min-height: 78px; padding: 9px; }
  .menu-box { padding: 20px 16px; }
  .menu-foot { flex-direction: column; align-items: stretch; text-align: center; }
  .menu-foot > span { font-size: 10px; }
  .recipe-row { grid-template-columns: 36px 12px 36px 16px 36px 1fr; }
  .sprite-thumb { width: 36px; height: 36px; }
}
