:root {
  --bg: #030b10;
  --ink: #e4f2f6;
  --dim: #8fb0bd;
  --line: rgba(150, 210, 230, 0.16);
  --panel: rgba(6, 20, 28, 0.9);
  --gold: #ffd66e;
  --gold2: #c99a3a;
  --teal: #5fd3e6;
  --bad: #ff7a7a;
  --good: #9be15d;
  --r-c: #8fb7c4;
  --r-r: #b48cff;
  --r-l: #ffc44d;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Pretendard', 'Noto Sans KR', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }
canvas#view { position: fixed; inset: 0; display: block; touch-action: none; }
#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.55)); }
button { font-family: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; padding: 0; font-size: inherit; }
[hidden] { display: none !important; }
.screen { position: fixed; inset: 0; z-index: 5; }
.dim { color: var(--dim); }
.small { font-size: 12px; }

/* ── 타이틀 ── */
#sTitle { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: calc(20px + var(--st)) 24px calc(20px + var(--sb));
  background: radial-gradient(ellipse at 50% 38%, rgba(3, 11, 16, 0.2), rgba(3, 11, 16, 0.75)); }
.logo { display: flex; flex-direction: column; align-items: center; line-height: 1; margin-top: -40px; }
.logo b { font-size: 64px; letter-spacing: 0.18em; margin-right: -0.18em; font-weight: 800;
  background: linear-gradient(180deg, #fff6d6, #ffd66e 45%, #c98a2a); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 24px rgba(255, 200, 90, 0.35)); }
.logo i { font-style: normal; font-size: 14px; letter-spacing: 0.9em; margin-right: -0.9em; color: var(--dim); margin-top: 8px; }
.tagline { text-align: center; color: #cfe6ee; line-height: 1.6; margin: 6px 0 18px; font-size: 14px; text-shadow: 0 1px 8px #000; }
.menu { display: flex; flex-direction: column; gap: 10px; width: min(300px, 100%); }
.menu button { padding: 13px; border-radius: 14px; background: rgba(10, 30, 40, 0.75); border: 1px solid var(--line); font-weight: 600; font-size: 15px; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.menu button.big { padding: 16px; font-size: 17px; }
.menu button.gold, .gold-btn { background: linear-gradient(180deg, #ffd66e, #d39a35); color: #2a1a05; border: 0; }
.credit { position: absolute; bottom: calc(14px + var(--sb)); color: var(--dim); font-size: 11.5px; text-align: center; }

/* ── 패널 화면 ── */
.panel { display: flex; flex-direction: column; background: linear-gradient(180deg, rgba(3, 11, 16, 0.94), rgba(3, 11, 16, 0.97)); padding-top: var(--st); }
.phead { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; gap: 8px; }
.phead b { font-size: 16px; }
.phead .back { width: 38px; height: 38px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); font-size: 20px; }
.phead span { min-width: 38px; text-align: right; font-size: 13px; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 14px calc(20px + var(--sb)); }
.tabs { display: flex; gap: 4px; margin: 0 14px 8px; background: rgba(255, 255, 255, 0.05); border-radius: 12px; padding: 4px; }
.tabs button { flex: 1; padding: 8px 0; border-radius: 9px; color: var(--dim); font-weight: 600; font-size: 13px; }
.tabs button.on { background: rgba(95, 211, 230, 0.18); color: var(--ink); }

/* 시조 카드 */
.fcard { display: grid; grid-template-columns: 76px 1fr; gap: 12px; padding: 12px; border-radius: 16px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); margin-bottom: 10px; text-align: left; width: 100%; }
.fcard canvas { width: 76px; height: 76px; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #0f3446, #061520); }
.fcard b { font-size: 16px; display: block; margin-bottom: 3px; }
.fcard p { margin: 0; font-size: 12.5px; color: var(--dim); line-height: 1.5; }
.fcard .ftag { font-size: 11px; color: var(--gold); margin-top: 4px; display: block; }
.fcard.locked { opacity: 0.45; }
.fcard.locked .ftag { color: var(--dim); }
#ascRow { padding: 8px 14px calc(12px + var(--sb)); }

/* ── 지도 ── */
.lineageBar { display: flex; align-items: center; gap: 10px; margin: 0 12px 6px; padding: 8px 10px; border-radius: 14px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); }
.lineageBar canvas { width: 46px; height: 46px; flex: none; }
.lineageBar .lb-t { flex: 1; min-width: 0; }
.lineageBar .lb-t b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lineageBar .lb-t span { font-size: 11.5px; color: var(--dim); }
.lineageBar button { padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.07); font-size: 12px; }
#mapInner { position: relative; }
.act { position: relative; padding: 10px 0 16px; }
.act h2 { font-size: 13px; color: var(--dim); text-align: center; font-weight: 600; letter-spacing: 0.1em; margin: 6px 0 10px; }
.floor { display: flex; justify-content: space-around; padding: 14px 0; position: relative; z-index: 1; }
.node { width: 64px; height: 64px; border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: radial-gradient(circle at 35% 30%, rgba(160, 230, 250, 0.35), rgba(20, 60, 80, 0.85) 60%); border: 1.5px solid rgba(160, 220, 240, 0.35);
  box-shadow: inset 0 -6px 12px rgba(0, 0, 0, 0.35), 0 4px 12px rgba(0, 0, 0, 0.4); position: relative; }
.node i { font-style: normal; font-size: 20px; line-height: 1; }
.node em { font-style: normal; font-size: 9.5px; color: #cfe6ee; max-width: 60px; text-align: center; line-height: 1.1; }
.node.hazard { border-color: rgba(255, 150, 90, 0.6); }
.node.boss { width: 82px; height: 82px; border-color: rgba(255, 214, 110, 0.75); background: radial-gradient(circle at 35% 30%, rgba(255, 220, 140, 0.35), rgba(70, 30, 20, 0.85) 60%); }
.node.rest, .node.spring { border-color: rgba(155, 225, 93, 0.6); }
.node.avail { animation: pulse 1.6s ease-in-out infinite; border-color: var(--gold); }
.node.done { opacity: 0.55; }
.node.lost::after, .node.won::after { position: absolute; right: -4px; top: -4px; width: 20px; height: 20px; border-radius: 50%; font-size: 12px; display: flex; align-items: center; justify-content: center; }
.node.won::after { content: '✓'; background: #2f7a3a; }
.node.lost::after { content: '✕'; background: #8a3030; }
.node.here { box-shadow: 0 0 0 3px rgba(255, 214, 110, 0.9), 0 0 24px rgba(255, 214, 110, 0.5); }
.node.far { opacity: 0.4; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); box-shadow: 0 0 22px rgba(255, 214, 110, 0.45); } }
svg.links { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }

/* ── 시트 ── */
.sheetwrap { display: flex; align-items: flex-end; justify-content: center; background: rgba(0, 0, 0, 0.45); }
.sheetwrap.full { align-items: stretch; }
.sheet { width: min(560px, 100%); max-height: 88vh; overflow-y: auto; background: rgba(7, 20, 28, 0.97); border: 1px solid var(--line); border-bottom: 0; border-radius: 22px 22px 0 0;
  padding: 16px 16px calc(18px + var(--sb)); animation: up 0.2s ease-out; -webkit-overflow-scrolling: touch; }
.sheetwrap.full .sheet { max-height: none; border-radius: 0; padding-top: calc(14px + var(--st)); }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet h1 { font-size: 22px; margin: 2px 0 4px; }
.sheet h3 { font-size: 12.5px; color: var(--dim); font-weight: 600; margin: 14px 0 6px; letter-spacing: 0.04em; }
.sheet p { line-height: 1.55; margin: 6px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; border-radius: 99px; background: rgba(255, 255, 255, 0.06); font-size: 12px; }
.chip.warn { background: rgba(255, 120, 90, 0.16); color: #ffb8a0; }
.chip.ok { background: rgba(155, 225, 93, 0.12); color: #cfeeb0; }
.badge { display: inline-block; padding: 3px 8px; border-radius: 8px; font-size: 11px; font-weight: 700; background: rgba(255, 255, 255, 0.1); }
.badge.hazard { background: rgba(255, 140, 80, 0.2); color: #ffbe96; }
.badge.boss { background: rgba(255, 214, 110, 0.2); color: var(--gold); }
.goalbox { padding: 10px 12px; border-radius: 14px; background: rgba(255, 214, 110, 0.08); border: 1px solid rgba(255, 214, 110, 0.25); margin-top: 10px; }
.goalbox b { color: var(--gold); }
.btns { display: flex; gap: 8px; margin-top: 16px; }
.btns > * { flex: 1; padding: 14px; border-radius: 14px; font-weight: 700; font-size: 15px; background: rgba(255, 255, 255, 0.08); }
.btns .go { background: linear-gradient(180deg, #ffd66e, #d39a35); color: #2a1a05; }
.btns .go:disabled { opacity: 0.4; }
.reslist .rrow { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.reslist .rrow:last-child { border-bottom: 0; }
.reslist .rrow span { flex: 1; }
.reslist .rrow em { font-style: normal; color: var(--dim); font-size: 12px; }

/* ── 들어가는 중 ── */
#sLoading { display: flex; align-items: center; justify-content: center; background: rgba(3, 11, 16, 0.6); }
.loading { text-align: center; }
.loading .drop { width: 46px; height: 46px; margin: 0 auto 12px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: radial-gradient(circle at 35% 35%, #bff3ff, #2c8aa6); animation: bob 1.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: rotate(-45deg) translate(4px, -4px); } }
.pbar { width: 200px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); overflow: hidden; margin: 10px auto 0; }
.pbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #2c8aa6, #bff3ff); }

/* ── HUD ── */
.hud { pointer-events: none; }
.hud > * { pointer-events: auto; }
.hudTop { position: absolute; top: calc(8px + var(--st)); left: 8px; right: 8px; display: flex; gap: 8px; align-items: center; }
.hbtn { width: 42px; height: 42px; border-radius: 13px; background: rgba(6, 20, 28, 0.82); border: 1px solid var(--line); font-weight: 800; font-size: 13px; flex: none; }
.hbtn.lag { border-color: #ffb347; color: #ffd28a; }
.goal { flex: 1; padding: 6px 10px; border-radius: 13px; background: rgba(6, 20, 28, 0.82); border: 1px solid var(--line); min-width: 0; }
.gline { display: flex; align-items: center; gap: 6px; font-size: 12.5px; }
.gline b { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.gline em { font-style: normal; color: var(--dim); font-variant-numeric: tabular-nums; }
.gbar { position: relative; height: 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); margin-top: 5px; overflow: hidden; }
.gbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #c99a3a, #ffd66e); transition: width 0.25s; }
.gbar i.hold { background: linear-gradient(90deg, #6fd36a, #c8ff9a); animation: glow 0.8s ease-in-out infinite; }
@keyframes glow { 50% { filter: brightness(1.4); } }
.gbar s { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; opacity: 0.7; }
.hudSub { position: absolute; top: calc(60px + var(--st)); left: 10px; right: 10px; display: flex; align-items: center; gap: 8px; font-size: 13px; }
#hLives { color: #ff8aa8; letter-spacing: 2px; text-shadow: 0 1px 4px #000; }
.energy { flex: 1; max-width: 190px; position: relative; height: 16px; border-radius: 8px; background: rgba(6, 20, 28, 0.82); border: 1px solid var(--line); overflow: hidden; }
.energy i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(90deg, #2a8a5a, #8ff0b0); }
.energy b { position: relative; display: block; text-align: center; font-size: 10.5px; line-height: 14px; text-shadow: 0 1px 2px #000; }
#hEvents { display: flex; gap: 4px; }
#hEvents span { padding: 2px 7px; border-radius: 99px; background: rgba(255, 120, 90, 0.25); font-size: 11.5px; }
#banner { position: absolute; top: calc(92px + var(--st)); left: 50%; transform: translateX(-50%); padding: 9px 14px; border-radius: 14px; background: rgba(40, 14, 8, 0.88); border: 1px solid rgba(255, 140, 90, 0.5);
  font-size: 13px; text-align: center; max-width: 92vw; pointer-events: none; animation: drop 0.3s ease-out; }
#banner.good { background: rgba(10, 36, 18, 0.88); border-color: rgba(155, 225, 93, 0.5); }
#banner b { display: block; font-size: 15px; margin-bottom: 2px; }
@keyframes drop { from { transform: translate(-50%, -10px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
#placeHint { position: absolute; left: 50%; bottom: calc(110px + var(--sb)); transform: translateX(-50%); padding: 12px 16px; border-radius: 16px; background: rgba(6, 20, 28, 0.9); border: 1px solid rgba(255, 214, 110, 0.5);
  text-align: center; font-size: 13.5px; width: min(340px, 90vw); pointer-events: none; line-height: 1.5; }
#placeHint b { color: var(--gold); font-size: 15px; display: block; }
.hudBottom { position: absolute; left: 0; right: 0; bottom: calc(10px + var(--sb)); display: flex; justify-content: center; gap: 10px; padding: 0 10px; }
.pw { width: 68px; height: 68px; border-radius: 20px; background: rgba(6, 20, 28, 0.86); border: 1.5px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative; overflow: hidden; }
.pw i { font-style: normal; font-size: 22px; line-height: 1; }
.pw span { font-size: 10px; color: var(--dim); }
.pw b { position: absolute; top: 3px; right: 6px; font-size: 10px; color: #8ff0b0; }
.pw.off { opacity: 0.4; }
.pw.armed { border-color: var(--gold); box-shadow: 0 0 18px rgba(255, 214, 110, 0.5); background: rgba(60, 44, 10, 0.9); }
.pw .cd { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); }
#cellCard { position: absolute; left: 10px; right: 10px; bottom: calc(92px + var(--sb)); padding: 9px 12px; border-radius: 14px; background: rgba(6, 20, 28, 0.9); border: 1px solid var(--line); font-size: 12.5px; }
#cellCard b { font-size: 13.5px; }
#cellCard .lim { margin-top: 4px; padding: 5px 8px; border-radius: 9px; border-left: 3px solid var(--c, #7fd35a); background: rgba(255, 255, 255, 0.04); }

/* ── 결과·카드 ── */
.verdict { text-align: center; padding: 8px 0 4px; }
.verdict h1 { font-size: 28px; margin: 0; letter-spacing: 0.08em; }
.verdict.win h1 { color: var(--gold); text-shadow: 0 0 24px rgba(255, 214, 110, 0.45); }
.verdict.lose h1 { color: var(--bad); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0; }
.stats div { text-align: center; padding: 8px 4px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); }
.stats b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 10.5px; color: var(--dim); }
.why .wrow { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.why .wrow small { color: var(--dim); }
.bias { margin: 10px 0 4px; padding: 9px 11px; border-radius: 12px; background: rgba(180, 140, 255, 0.1); border: 1px solid rgba(180, 140, 255, 0.25); font-size: 12.5px; line-height: 1.5; }
.cards { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.card { text-align: left; width: 100%; border-radius: 18px; padding: 12px; border: 1.5px solid var(--r-c); background: linear-gradient(160deg, rgba(30, 60, 72, 0.55), rgba(8, 22, 30, 0.9)); display: grid; grid-template-columns: 72px 1fr; gap: 12px; position: relative; transition: transform 0.15s; }
.card.r { border-color: var(--r-r); background: linear-gradient(160deg, rgba(80, 50, 130, 0.45), rgba(12, 14, 34, 0.92)); }
.card.l { border-color: var(--r-l); background: linear-gradient(160deg, rgba(130, 90, 20, 0.5), rgba(28, 16, 6, 0.92)); box-shadow: 0 0 22px rgba(255, 196, 77, 0.25); }
.card.sel { transform: scale(1.02); box-shadow: 0 0 0 2px #fff, 0 0 26px rgba(255, 255, 255, 0.25); }
.card canvas { width: 72px; height: 72px; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #0f3446, #061520); }
.card .ck { font-size: 10.5px; letter-spacing: 0.05em; color: var(--dim); }
.card b.cn { display: block; font-size: 16px; margin: 1px 0 4px; }
.card p { margin: 0; font-size: 12.5px; color: #cfe2ea; line-height: 1.45; }
.card .fit { position: absolute; top: -8px; right: 10px; padding: 2px 8px; border-radius: 99px; background: #6b4fb0; font-size: 10.5px; font-weight: 700; }
.deltas { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.deltas span { font-size: 11px; padding: 2px 7px; border-radius: 99px; background: rgba(255, 255, 255, 0.07); }
.deltas .up { color: #b8f08a; } .deltas .dn { color: #ffb08a; }
.phys { margin-top: 5px; font-size: 11.5px; color: var(--dim); line-height: 1.5; }
.phys u { text-decoration: none; color: var(--ink); }

/* ── 끝 ── */
.endhead { text-align: center; padding: calc(30px + var(--st)) 0 10px; }
.endhead h1 { font-size: 34px; margin: 6px 0; letter-spacing: 0.1em; }
.endhead.win h1 { color: var(--gold); }
.trail { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.trail div { display: flex; gap: 8px; align-items: center; font-size: 12.5px; padding: 6px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.04); }
.trail div em { font-style: normal; margin-left: auto; }
.unlock { margin: 12px 0; padding: 12px; border-radius: 14px; background: rgba(255, 214, 110, 0.1); border: 1px solid rgba(255, 214, 110, 0.35); text-align: center; }
.unlock b { color: var(--gold); }

/* 도감 */
.cgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cg { padding: 10px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); font-size: 12px; }
.cg b { display: block; font-size: 13.5px; margin-bottom: 3px; }
.cg.unseen { opacity: 0.35; }
.cg.r { border-color: rgba(180, 140, 255, 0.45); } .cg.l { border-color: rgba(255, 196, 77, 0.55); }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.sw { width: 48px; height: 28px; border-radius: 14px; background: rgba(255, 255, 255, 0.15); position: relative; }
.sw::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #cfe3ea; transition: left 0.15s; }
.sw.on { background: #2a8a9a; } .sw.on::after { left: 23px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { padding: 7px 12px; color: var(--dim); font-size: 13px; }
.seg button.on { background: rgba(95, 211, 230, 0.2); color: var(--ink); }

/* 토스트 */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(96px + var(--sb)); z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { padding: 8px 13px; border-radius: 12px; background: rgba(8, 24, 32, 0.94); border: 1px solid var(--line); font-size: 12.5px; animation: fade 3s forwards; max-width: 90vw; }
@keyframes fade { 0% { opacity: 0; transform: translateY(-6px); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
