/* ─────────────────────────────────────────────────────────────
   색 토큰. 다크가 기본, [data-theme="light"]에서 덮어쓴다.
   (data-theme은 index.html 머리의 짧은 스크립트가 그리기 전에 정한다:
    저장된 설정 → 없으면 시스템 설정 따라감)
   ───────────────────────────────────────────────────────────── */
:root {
  color-scheme: dark;
  --bg: #0d0f13; --bg2: #11141a; --panel: #151922; --panel2: #1b202b; --panel3: #232a37;
  --line: #2a3140; --line2: #3c475c; --text: #e7e9ee; --muted: #8b93a3; --dim: #5d6576;
  --hover: #2b3342; --choice-hover: #1f2633;
  --accent: #7dd3fc; --primary: #2563eb; --primary-hover: #1d4ed8; --on-primary: #fff;
  --ok: #34d399; --warn: #fbbf24; --bad: #f87171; --inf: #a3e635;
  --good-bg: #065f46; --good-border: #10b981; --good-tx: #ecfdf5;
  --danger-bg: #7f1d1d; --danger-border: #b91c1c; --danger-tx: #fef2f2;

  /* 집단: 면/선 색(공통) + 글자 색(테마별 대비 보정) */
  --f1: #2bb3a3; --f2: #e8a33d; --f3: #d4506f;
  --f1-tx: #4fd1c1; --f2-tx: #f2b75b; --f3-tx: #f07a98;
  --neutral: #3a4150;

  --glass: rgba(21, 25, 34, .92); --scrim: rgba(5, 6, 9, .72); --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --sw-border: rgba(255, 255, 255, .35);
  --chip-on-bg: #1e3a5f; --chip-on-tx: #fff; --kw-on-bg: #3b82f6; --kw-on-border: #60a5fa;
  --st-ok-bg: #064e3b; --st-ok-tx: #6ee7b7; --st-warn-bg: #78350f; --st-warn-tx: #fde68a;
  --st-dead-bg: #3f0d12; --st-dead-tx: #fca5a5; --st-zombie-bg: #365314; --st-zombie-tx: #d9f99d;
  --type-bg: #1e1b4b; --type-tx: #c7d2fe; --type-border: #312e81;
  --gold-bg: #3b2f0b; --gold-tx: #fcd34d; --here-bg: #1e3a5f; --here-tx: #dbeafe;
  --tag-bad: #fca5a5; --tag-warn: #fcd34d; --tag-inf: #bef264;
  --pen-bg: #3f1d1d; --pen-tx: #fecaca;
  --act-bad-bg: #3f0d12; --act-bad-tx: #fecaca; --act-good-bg: #10251f; --act-good-tx: #6ee7b7;
  --roll-ok: #134e3a; --roll-no: #3b1d22; --roll-mark: #fff;
  --tbar-mid: #4b5567; --edited-tx: #fff;
  --npc-bg: linear-gradient(90deg, #1f2533, #151922); --npc-border: #36405a;
  --toast-bg: #1f2633; --toast-border: #3a465c; --toast-bad-bg: #2a1517; --toast-good-bg: #10251f;

  /* 지도 */
  --map-land: #10141b; --map-land2: #141a24; --map-river: #17324a; --map-stream: #1a3349;
  --map-casing: #10141b; --map-label: #cfd5df; --map-label-strong: #fff; --map-halo: #0d0f13;
  --st-dot: #eef1f5; --st-edge: #0d0f13; --me-ring: #fff; --river-label: #4d7ba3;

  /* 채팅 말풍선: 집단별 '내 것(진한 색)'과 '남의 것(옅은 색)' */
  --bub1-m: #13786d; --bub1-m-tx: #fff; --bub2-m: #e9a940; --bub2-m-tx: #241704; --bub3-m: #b23a5c; --bub3-m-tx: #fff;
  --bub1-o: #173531; --bub2-o: #372b16; --bub3-o: #371c26; --bub-o-tx: #e7e9ee;

  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef0f3; --bg2: #f7f8fa; --panel: #ffffff; --panel2: #f3f4f6; --panel3: #e5e8ed;
  --line: #dde1e7; --line2: #c3c9d3; --text: #171a21; --muted: #5b6473; --dim: #8a93a2;
  --hover: #e2e6ec; --choice-hover: #eef4ff;
  --accent: #0284c7; --primary: #2563eb; --primary-hover: #1d4ed8; --on-primary: #fff;
  --ok: #059669; --warn: #b45309; --bad: #dc2626; --inf: #4d7c0f;
  --good-bg: #059669; --good-border: #047857; --good-tx: #fff;
  --danger-bg: #dc2626; --danger-border: #b91c1c; --danger-tx: #fff;

  --f1-tx: #0f766e; --f2-tx: #a15c07; --f3-tx: #be123c;
  --neutral: #cdd2da;

  --glass: rgba(255, 255, 255, .94); --scrim: rgba(15, 23, 42, .38); --shadow: 0 8px 24px rgba(15, 23, 42, .14);
  --sw-border: rgba(0, 0, 0, .22);
  --chip-on-bg: #dbeafe; --chip-on-tx: #1e3a8a; --kw-on-bg: #2563eb; --kw-on-border: #1d4ed8;
  --st-ok-bg: #d1fae5; --st-ok-tx: #065f46; --st-warn-bg: #fef3c7; --st-warn-tx: #92400e;
  --st-dead-bg: #fee2e2; --st-dead-tx: #991b1b; --st-zombie-bg: #ecfccb; --st-zombie-tx: #3f6212;
  --type-bg: #eef2ff; --type-tx: #3730a3; --type-border: #c7d2fe;
  --gold-bg: #fef3c7; --gold-tx: #92400e; --here-bg: #dbeafe; --here-tx: #1e3a8a;
  --tag-bad: #b91c1c; --tag-warn: #b45309; --tag-inf: #4d7c0f;
  --pen-bg: #fee2e2; --pen-tx: #991b1b;
  --act-bad-bg: #fee2e2; --act-bad-tx: #991b1b; --act-good-bg: #d1fae5; --act-good-tx: #065f46;
  --roll-ok: #bbf7d0; --roll-no: #fecaca; --roll-mark: #111827;
  --tbar-mid: #b6bdc8; --edited-tx: #000;
  --npc-bg: linear-gradient(90deg, #eef2f8, #ffffff); --npc-border: #d3dae6;
  --toast-bg: #ffffff; --toast-border: #d6dbe3; --toast-bad-bg: #fef2f2; --toast-good-bg: #ecfdf5;

  --map-land: #f3f3ef; --map-land2: #f7f7f4; --map-river: #c4def3; --map-stream: #cfe4f5;
  --map-casing: #f6f6f3; --map-label: #3a414c; --map-label-strong: #0b0e14; --map-halo: #ffffff;
  --st-dot: #ffffff; --st-edge: #2b313b; --me-ring: #111827; --river-label: #6f9cc4;

  --bub1-o: #dcf2ee; --bub2-o: #fcedd3; --bub3-o: #fbe2ea; --bub-o-tx: #171a21;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, system-ui, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: not-allowed; opacity: .45; }
[data-busy] { opacity: .6; pointer-events: none; cursor: progress; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 12.5px; }
.tiny { font-size: 11px; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }
.stack > * + * { margin-top: 10px; }
.hide { display: none !important; }
.nowrap { white-space: nowrap; }

/* ── screens ── */
.screen { display: none; }
body[data-screen="auth"] #screen-auth,
body[data-screen="create"] #screen-create { display: block; height: 100dvh; overflow-y: auto; }
body[data-screen="game"] #app { display: grid; }
.boot { display: none; height: 100dvh; place-items: center; align-content: center; gap: 8px; text-align: center; }
body[data-screen="boot"] .boot { display: grid; }
.logo-big { font-weight: 900; letter-spacing: .18em; font-size: 28px; background: linear-gradient(90deg, var(--f1), var(--f2), var(--f3)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo { font-weight: 900; letter-spacing: .14em; font-size: 14px; white-space: nowrap; }
.logo b { color: var(--accent); }
.theme-fab { position: fixed; top: 12px; right: 12px; z-index: 20; }
body[data-screen="game"] .theme-fab, body[data-screen="boot"] .theme-fab { display: none; }

/* ── buttons / inputs ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 14px; border-radius: 10px; background: var(--panel3); border: 1px solid var(--line); font-weight: 600; transition: background .15s, transform .05s; min-height: 42px; }
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.good { background: var(--good-bg); border-color: var(--good-border); color: var(--good-tx); }
.btn.danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-tx); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 6px 10px; min-height: 32px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; background: var(--glass); border: 1px solid var(--line); font-size: 18px; display: grid; place-items: center; backdrop-filter: blur(6px); box-shadow: var(--shadow); }
.icon-btn.sm { width: 32px; height: 32px; font-size: 15px; border-radius: 8px; box-shadow: none; }
.input, select.input, textarea.input { width: 100%; padding: 10px 12px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line); outline: none; }
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 70px; }
label.field { display: block; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel2); font-size: 13.5px; transition: background .12s, border-color .12s; }
.chip:hover { border-color: var(--line2); }
.chip.on { background: var(--chip-on-bg); border-color: var(--accent); color: var(--chip-on-tx); }
.chip .sw { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--sw-border); flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--panel3); white-space: nowrap; }
.badge.gold { background: var(--gold-bg); color: var(--gold-tx); }
.badge.here { background: var(--here-bg); color: var(--here-tx); }
.badge.tag-bad { color: var(--tag-bad); }
.badge.tag-warn { color: var(--tag-warn); }
.badge.tag-inf { color: var(--tag-inf); }
.fbadge { color: #0d0f13; }
.line-badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; color: #fff; font-size: 11px; font-weight: 800; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card.tight { padding: 10px 12px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 18px 0 8px; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; }
.section-title:first-child { margin-top: 0; }
.bar { position: relative; height: 8px; border-radius: 99px; background: var(--panel3); overflow: hidden; }
.bar > i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; }
.pips { display: inline-flex; gap: 2px; }
.pips i { width: 7px; height: 7px; border-radius: 50%; background: var(--panel3); }
.empty { text-align: center; color: var(--dim); padding: 24px 8px; font-size: 14px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { padding: 8px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--panel3); color: var(--text); }

/* ── auth ── */
.auth-wrap { max-width: 420px; margin: 0 auto; padding: 48px 20px 40px; }
.auth-wrap .tagline { color: var(--muted); margin: 6px 0 28px; }
.auth-wrap .seg { margin-bottom: 16px; }
.faction-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 28px; }
.faction-strip div { border-radius: 10px; padding: 10px; font-size: 12px; border: 1px solid var(--line); background: var(--panel); }
.faction-strip b { display: block; font-size: 13px; }
.err { color: var(--bad); font-size: 13.5px; min-height: 20px; }

/* ── create wizard ── */
.wiz { max-width: 860px; margin: 0 auto; padding: 18px 16px 120px; }
.wiz-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; padding-right: 44px; }
.steps { display: flex; gap: 4px; flex: 1; }
.steps i { flex: 1; height: 4px; border-radius: 4px; background: var(--panel3); }
.steps i.on { background: var(--accent); }
.wiz h2 { margin: 6px 0 4px; font-size: 21px; }
.wiz .desc { color: var(--muted); margin: 0 0 16px; font-size: 14px; }
.wiz-foot { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + var(--safe-b)); background: linear-gradient(transparent, var(--bg) 30%); }
.wiz-foot .inner { max-width: 860px; margin: 0 auto; display: flex; gap: 8px; align-items: center; }
.preview { background: var(--panel); border: 1px dashed var(--line2); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kw-layout { display: grid; grid-template-columns: 1fr 300px; gap: 14px; align-items: start; }
.kw-side { position: sticky; top: 8px; }
.kw-cat { margin-bottom: 14px; }
.kw-cat h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.kw-btn { padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel2); font-size: 13.5px; }
.kw-btn.on { background: var(--kw-on-bg); border-color: var(--kw-on-border); color: #fff; }
.fcard { text-align: left; padding: 14px; border-radius: var(--radius); border: 2px solid var(--line); background: var(--panel); transition: border-color .15s, transform .1s; }
.fcard:hover { transform: translateY(-1px); }
.fcard.on { border-color: var(--fc); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fc) 25%, transparent); }
.fcard h3 { margin: 4px 0; color: var(--ft); }
.npc-preview { position: relative; padding: 10px 14px 10px 40px; background: var(--panel); border-radius: 12px; font-size: 13.5px;
  box-shadow: 0 0 0 1px var(--line), 0 3px 10px rgba(0, 0, 0, .12); }
.npc-preview::before { content: '\201C'; position: absolute; left: 10px; top: 4px; font-family: Georgia, 'Times New Roman', 'Noto Serif KR', 'Nanum Myeongjo', serif;
  font-size: 40px; line-height: 1; color: var(--nc, var(--accent)); opacity: .6; }

/* ── trait bars ── */
.traits { display: grid; gap: 7px; }
.trait .lbl { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); }
.trait .lbl b { color: var(--text); font-weight: 700; font-size: 12px; }
.tbar { position: relative; height: 10px; border-radius: 99px; background: var(--panel3); }
.tbar::after { content: ''; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 2px; background: var(--tbar-mid); }
.tbar i { position: absolute; top: 0; bottom: 0; border-radius: 99px; transition: left .25s, width .25s; }
.type-label { font-size: 12.5px; color: var(--type-tx); background: var(--type-bg); border: 1px solid var(--type-border); padding: 6px 10px; border-radius: 8px; }

/* ── game layout ── */
#app {
  height: 100dvh; grid-template-columns: 1fr minmax(360px, 420px); grid-template-rows: auto auto 1fr;
  grid-template-areas: "hud hud" "map tabs" "map panel";
}
#hud { grid-area: hud; display: flex; align-items: center; gap: 14px; padding: 8px 14px; background: var(--bg2); border-bottom: 1px solid var(--line); min-width: 0; }
#map-wrap { grid-area: map; position: relative; overflow: hidden; background: radial-gradient(ellipse at 50% 45%, var(--map-land2) 0%, var(--map-land) 75%); }
#tabs { grid-area: tabs; display: flex; gap: 2px; padding: 6px 8px 0; background: var(--bg2); border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); }
#tabs button { flex: 1; position: relative; white-space: nowrap; padding: 8px 4px; border-radius: 8px 8px 0 0; color: var(--muted); font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 5px; border-bottom: 2px solid transparent; }
#tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
#tabs .m-only { display: none; }
#panel { grid-area: panel; overflow-y: auto; background: var(--bg2); border-left: 1px solid var(--line); min-height: 0; overscroll-behavior: contain; }
#panel-body { padding: 14px; }

/* hud */
.hud-score { flex: 1; min-width: 120px; max-width: 420px; }
.score-bar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--panel3); }
.score-bar i { transition: width .4s; }
.score-nums { display: flex; justify-content: space-between; font-size: 11.5px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.vitals { display: flex; gap: 10px; align-items: center; font-variant-numeric: tabular-nums; font-size: 13px; }
.vital { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.vital .vb { width: 44px; height: 5px; border-radius: 9px; background: var(--panel3); overflow: hidden; }
.vital .vb i { display: block; height: 100%; }
.status-pill { padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.st-ok { background: var(--st-ok-bg); color: var(--st-ok-tx); }
.st-fainted, .st-broken { background: var(--st-warn-bg); color: var(--st-warn-tx); }
.st-dead { background: var(--st-dead-bg); color: var(--st-dead-tx); }
.st-zombie { background: var(--st-zombie-bg); color: var(--st-zombie-tx); }
.online { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.online::before { content: ''; display: inline-block; width: 7px; height: 7px; background: var(--ok); border-radius: 50%; margin-right: 4px; }

/* ── map ── */
#map { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
#map.dragging { cursor: grabbing; }
#map .river { fill: none; stroke: var(--map-river); stroke-linecap: round; stroke-linejoin: round; }
#map .stream { fill: none; stroke: var(--map-stream); stroke-linecap: round; stroke-linejoin: round; }
#map .river-lb { fill: var(--river-label); font-style: italic; font-weight: 700; letter-spacing: .5em; pointer-events: none; }
#map .cas { fill: none; stroke: var(--map-casing); stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; stroke-width: calc(var(--lw, 3.4px) + 2.6px); }
#map .ln { fill: none; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; stroke-width: var(--lw, 3.4px); }
#map .st { cursor: pointer; }
#map .sv { transform: scale(var(--ss, 1)); transform-box: view-box; }
#map .hit { fill: transparent; }
#map .arc { fill: none; stroke-width: 1.7; }
#map .arc.n { stroke: var(--neutral); }
#map .dot { fill: var(--st-dot); stroke: var(--st-edge); stroke-width: .55; }
#map .st.tx .dot { stroke-width: .8; }
#map .lb { fill: var(--map-label); paint-order: stroke; stroke: var(--map-halo); stroke-width: 3px; stroke-linejoin: round; font-weight: 600; pointer-events: none; dominant-baseline: central; }
#map .lb.tx { fill: var(--map-label-strong); font-weight: 800; }
#map .lb.off { display: none; }
#map .me-ring { fill: none; stroke: var(--me-ring); stroke-width: 1.2; animation: pulse 1.6s ease-out infinite; transform-origin: center; transform-box: fill-box; }
#map .me-dot { fill: var(--me-ring); }
#map .sel-ring { fill: none; stroke: var(--accent); stroke-width: 1.2; stroke-dasharray: 2 1.4; }
#map .mk { font-size: 7px; pointer-events: none; }
@keyframes pulse { 0% { transform: scale(.6); opacity: 1; } 100% { transform: scale(1.8); opacity: 0; } }
.map-ctrl { position: absolute; right: 10px; top: 10px; display: grid; gap: 6px; }
.m-legend { display: none; }
.legend { position: absolute; left: 10px; top: 10px; display: flex; flex-wrap: wrap; gap: 4px; max-width: 60%; pointer-events: none; }
.legend button { pointer-events: auto; display: inline-flex; align-items: center; gap: 4px; font: inherit; font-size: 11px; padding: 2px 8px 2px 6px; border-radius: 99px;
  background: var(--glass); border: 1px solid var(--line); color: var(--muted); cursor: pointer; transition: opacity .15s, background .15s, border-color .15s; }
.legend button:hover { color: var(--map-label-strong); border-color: var(--lc, var(--accent)); }
.legend i { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--lc); }
.legend.filtering button:not(.on):not(.clear) { opacity: .55; }
.legend button.on { color: var(--map-label-strong); border-color: var(--lc); background: color-mix(in srgb, var(--lc) 22%, var(--glass)); font-weight: 700; }
.legend button.on i { box-shadow: 0 0 0 2px color-mix(in srgb, var(--lc) 35%, transparent); }
.legend button.clear { color: var(--accent); border-color: var(--accent); font-weight: 700; }
.legend button.clear .ic { width: 1em; height: 1em; }
.m-legend.on { border-color: var(--accent); color: var(--accent); }
/* 노선 강조 중: 고른 노선만 또렷하게 */
#map .ln, #map .cas, #map .st { transition: opacity .2s; }
#map.filtered .ln:not(.on) { opacity: .12; }
#map.filtered .cas:not(.on) { opacity: 0; }
#map.filtered .st:not(.on) { opacity: .22; }
.peek { position: absolute; left: 10px; right: 10px; bottom: 10px; max-width: 460px; margin: 0 auto; background: var(--glass); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); backdrop-filter: blur(8px); }

/* ── station panel ── */
.st-head h2 { margin: 2px 0 0; font-size: 22px; }
.zone { display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; align-items: start; padding: 11px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--zc, var(--neutral)); }
.zone + .zone { margin-top: 8px; }
.zone .zi { font-size: 22px; line-height: 1; padding-top: 2px; text-align: center; }
.zone .zn { font-weight: 700; }
.zone .trace-pv { font-size: 12.5px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.zone .za { display: grid; gap: 5px; justify-items: end; }
.player { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }
.player + .player { margin-top: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.npc-card { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--npc-bg); border: 1px solid var(--npc-border); }
.npc-card + .npc-card { margin-top: 8px; }
.npc-card .ni { font-size: 26px; }

/* ── modal ── */
.modal { position: fixed; inset: 0; z-index: 50; background: var(--scrim); display: grid; place-items: center; padding: 16px; backdrop-filter: blur(3px); }
.modal[hidden] { display: none; }
.modal-card { width: 100%; max-width: 560px; max-height: calc(100dvh - 32px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; animation: up .18s ease-out; overscroll-behavior: contain; box-shadow: var(--shadow); }
@keyframes up { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-card h3 { margin: 0; font-size: 18px; }
.script { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 14.5px; line-height: 1.7; }
.script p { margin: 0 0 6px; }
.script p:last-child { margin: 0; }
.script .edited { border-left: 3px solid var(--tc); padding-left: 9px; color: var(--edited-tx); }
.script .edited small { display: block; color: var(--tt); font-size: 11.5px; }
.graffiti { margin-top: 10px; padding: 8px 12px; border-radius: 8px; font-weight: 700; transform: rotate(-.6deg); border: 1px dashed var(--tc); color: var(--tt); font-size: 14px; }
.choice { width: 100%; text-align: left; padding: 12px 14px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; transition: border-color .12s, background .12s; }
.choice:hover:not(:disabled) { border-color: var(--accent); background: var(--choice-hover); }
.choice + .choice { margin-top: 8px; }
.choice .cl { font-weight: 600; }
.choice .cs { font-size: 12px; color: var(--muted); grid-column: 1; }
.choice .cp { grid-row: 1 / span 2; grid-column: 2; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.choice.sab { border-color: #7c3aed; }
.result { text-align: center; padding: 6px 0 4px; }
.result .big { font-size: 26px; font-weight: 900; letter-spacing: .06em; }
.result .big.ok { color: var(--ok); }
.result .big.no { color: var(--bad); }
.rollbar { position: relative; height: 12px; border-radius: 99px; background: var(--roll-no); overflow: visible; margin: 10px 0 4px; }
.rollbar .ch { position: absolute; inset: 0 auto 0 0; background: var(--roll-ok); border-radius: 99px; }
.rollbar .rl { position: absolute; top: -4px; width: 3px; height: 20px; background: var(--roll-mark); border-radius: 2px; transform: translateX(-1px); }
.fx { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 10px; }
.fx span { padding: 4px 10px; border-radius: 99px; background: var(--panel3); font-size: 13px; font-weight: 600; }
.fx .neg { color: var(--bad); }
.fx .pos { color: var(--ok); }
.act-msg { margin-top: 10px; padding: 10px; border-radius: 10px; font-weight: 700; text-align: center; }
.act-msg.bad { background: var(--act-bad-bg); color: var(--act-bad-tx); }
.act-msg.good { background: var(--act-good-bg); color: var(--act-good-tx); }
.act-msg.fac { background: color-mix(in srgb, var(--fc) 16%, transparent); color: var(--ft); }
/* NPC 대사: 그림자 있는 말풍선 + 큰 명조 따옴표 장식 (첫 줄에만 초상 쪽을 가리키는 꼬리) */
.npc-lines p { position: relative; margin: 0 0 10px; padding: 14px 16px 13px 42px; background: var(--panel2); border-radius: 14px;
  box-shadow: 0 0 0 1px var(--line), 0 4px 14px rgba(0, 0, 0, .16); line-height: 1.6; }
.npc-lines p::before { content: '\201C'; position: absolute; left: 11px; top: 4px; font-family: Georgia, 'Times New Roman', 'Noto Serif KR', 'Nanum Myeongjo', serif;
  font-size: 46px; line-height: 1; color: var(--nc, var(--accent)); opacity: .6; pointer-events: none; }
.npc-lines p:first-child::after { content: ''; position: absolute; top: -6px; left: 22px; width: 12px; height: 12px; background: var(--panel2);
  transform: rotate(45deg); box-shadow: -1px -1px 0 var(--line); }
.pen { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.pen span { font-size: 11.5px; padding: 2px 8px; border-radius: 99px; background: var(--pen-bg); color: var(--pen-tx); }

/* ── lists ── */
.quest { padding: 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.quest + .quest { margin-top: 8px; }
.quest.done { border-color: var(--ok); }
.quest.claimed { opacity: .55; }
.inv { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.item { padding: 10px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); display: grid; gap: 4px; }
.item .ic-wrap { display: inline-flex; color: var(--accent); }
.fscore { padding: 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--fc); }
.fscore + .fscore { margin-top: 8px; }
.news { font-size: 13px; padding: 7px 10px; border-left: 3px solid var(--nc, var(--line)); background: var(--panel); border-radius: 0 8px 8px 0; }
.news + .news { margin-top: 5px; }
.news time { color: var(--dim); font-size: 11px; margin-right: 6px; font-variant-numeric: tabular-nums; }
table.hist { width: 100%; border-collapse: collapse; font-size: 13px; }
table.hist td, table.hist th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }

/* ── chat: 메신저 말풍선 ── */
body[data-tab="chat"] #panel { overflow: hidden; }
body[data-tab="chat"] #panel-body { height: 100%; display: flex; flex-direction: column; padding-bottom: 10px; }
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.chat-head { padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.chat-head .row { flex-wrap: wrap; gap: 4px 8px; }
.chat-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; padding: 4px 4px 8px; overscroll-behavior: contain; }
.mrow { display: flex; flex-direction: column; align-items: flex-start; margin-top: 3px; }
.mrow.first { margin-top: 10px; }
.mrow.mine { align-items: flex-end; }
.mrow.f1.other { --bub: var(--bub1-o); --bub-tx: var(--bub-o-tx); --ft: var(--f1-tx); }
.mrow.f2.other { --bub: var(--bub2-o); --bub-tx: var(--bub-o-tx); --ft: var(--f2-tx); }
.mrow.f3.other { --bub: var(--bub3-o); --bub-tx: var(--bub-o-tx); --ft: var(--f3-tx); }
.mrow.f1.mine { --bub: var(--bub1-m); --bub-tx: var(--bub1-m-tx); }
.mrow.f2.mine { --bub: var(--bub2-m); --bub-tx: var(--bub2-m-tx); }
.mrow.f3.mine { --bub: var(--bub3-m); --bub-tx: var(--bub3-m-tx); }
.mname { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); margin: 0 0 3px 10px; }
.mname b { color: var(--ft); font-weight: 700; }
.mname .badge { font-size: 10.5px; padding: 0 6px; }
.mline { display: flex; align-items: flex-end; gap: 6px; max-width: 84%; margin: 0 9px; }
.mrow.mine .mline { flex-direction: row-reverse; }
.bub { position: relative; padding: 7px 12px; border-radius: 16px; background: var(--bub); color: var(--bub-tx); white-space: pre-wrap; word-break: break-word; font-size: 14.5px; line-height: 1.45; }
/* 묶음의 첫 말풍선만 바깥쪽 위 모서리가 뾰족하다 */
.mrow.first.other .bub { border-top-left-radius: 0; }
.mrow.first.mine .bub { border-top-right-radius: 0; }
.mrow.first .bub::before { content: ''; position: absolute; top: 0; width: 10px; height: 12px; background: inherit; }
.mrow.first.other .bub::before { left: -8px; clip-path: polygon(0 0, 100% 0, 100% 100%); }
.mrow.first.mine .bub::before { right: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.mline time { font-size: 10.5px; color: var(--dim); white-space: nowrap; font-variant-numeric: tabular-nums; flex: none; }
.mline time[hidden] { display: none; }
.chat-sys { align-self: center; font-size: 11.5px; color: var(--dim); text-align: center; margin: 10px 0 2px; }
.chat-form { display: flex; gap: 6px; }
.chat-form .input { flex: 1; min-width: 0; border-radius: 20px; padding: 10px 14px; }
.chat-form .btn { border-radius: 20px; }
.tab-badge { position: absolute; top: 3px; right: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--bad); color: #fff; font-size: 10px; font-style: normal; font-weight: 800; display: grid; place-items: center; line-height: 1; }
.tab-badge[hidden] { display: none; }

/* ── toasts ── */
#toasts { position: fixed; z-index: 60; left: 50%; top: 12px; transform: translateX(-50%); display: grid; gap: 6px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--toast-bg); border: 1px solid var(--toast-border); border-radius: 12px; padding: 10px 14px; font-size: 14px; box-shadow: var(--shadow); animation: up .2s ease-out; pointer-events: auto; }
.toast.bad { border-color: var(--bad); background: var(--toast-bad-bg); }
.toast.good { border-color: var(--ok); background: var(--toast-good-bg); }

/* ── mobile ── */
@media (max-width: 860px) {
  body { font-size: 14.5px; }
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; grid-template-areas: "hud" "map" "tabs"; }
  #hud { flex-wrap: wrap; gap: 6px 10px; padding: 8px 10px; }
  .hud-score { order: 3; flex-basis: 100%; max-width: none; }
  .vitals { gap: 8px; font-size: 12.5px; }
  .vital .vb { display: none; }
  #hud .icon-btn.sm { width: 30px; height: 30px; font-size: 14px; }
  #panel { grid-area: map; z-index: 5; border-left: 0; display: none; }
  body[data-tab="station"] #panel, body[data-tab="me"] #panel, body[data-tab="quests"] #panel, body[data-tab="rank"] #panel, body[data-tab="chat"] #panel { display: block; }
  #tabs { border-left: 0; border-top: 1px solid var(--line); border-bottom: 0; padding: 4px 4px calc(4px + var(--safe-b)); }
  #tabs .m-only { display: flex; }
  #tabs button { flex-direction: column; gap: 0; font-size: 11px; border-radius: 8px; border-bottom: 0; padding: 6px 2px; min-width: 0; }
  #tabs button span { font-size: 18px; }
  #tabs button.on { background: var(--panel2); }
  .kw-layout { grid-template-columns: 1fr; }
  .kw-side { position: static; order: -1; }
  .grid3 { grid-template-columns: 1fr; }
  .modal { padding: 0; align-items: end; }
  .modal-card { border-radius: 16px 16px 0 0; max-height: 92dvh; padding-bottom: calc(18px + var(--safe-b)); }
  .m-legend { display: grid; }
  .legend { max-width: calc(100% - 70px); display: none; }
  .legend.open { display: flex; }
}
@media (max-width: 480px) { #hud > .logo { display: none; } .vitals { flex: 1; justify-content: space-between; } }
@media (max-width: 380px) { .grid2 { grid-template-columns: 1fr; } }

code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; padding: 1px 5px; border-radius: 5px; background: var(--panel3); }
details summary { cursor: pointer; }

/* SVG 아이콘 */
.ic { width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex: none; display: inline-block; }
.ic.lg { width: 1.6em; height: 1.6em; }
.ic.xl { width: 2.2em; height: 2.2em; }
.vital.lvl b { font-size: 12px; color: var(--accent); }
@media (max-width: 860px) { .vital.lvl .vb { display: block; width: 28px; } }

/* ── 아이콘 · 레벨 · 칭호 · 소문 · 상점 · 도전과제 ── */
.ic.sm { width: .9em; height: .9em; }
.zone .zi, .npc-card .ni, .npc-face, .rumor > .ic { color: var(--accent); display: inline-flex; gap: 2px; }
.npc-card .ni .ic, .npc-face .ic { width: 34px; height: 34px; }
.icon-btn .ic, #tabs .ic { width: 20px; height: 20px; }
#tabs [data-ic] { display: inline-flex; }
.badge.lv { background: var(--accent); color: #fff; font-size: 11px; padding: 1px 7px; }
.badge.title { background: var(--gold-bg); color: var(--gold-tx); font-size: 11px; padding: 1px 7px; }
.badge.good { background: var(--here-bg); color: var(--ok); }
.mname .badge.title { margin-left: 2px; }
.rumor { display: flex; align-items: flex-start; gap: 10px; padding: 9px 12px; border-radius: 10px; background: var(--panel); border: 1px dashed var(--line); }
.rumor + .rumor { margin-top: 6px; }
.rumor-t { font-size: 13px; color: var(--muted); font-style: italic; margin-top: 2px; }
.shop-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.shop-row > .ic { color: var(--accent); }
.pen .pen-good { background: var(--here-bg); color: var(--ok); }
.fx.gain .badge { font-size: 13px; padding: 4px 10px; }
.fx .gain-xp { color: var(--accent); }
.fx .gain-won { color: var(--gold-tx); }
.ach-list summary { cursor: pointer; color: var(--muted); padding: 4px 0; }
.ach { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--panel); margin-top: 6px; opacity: .78; }
.ach.done { opacity: 1; border: 1px solid var(--gold-bg); }
.ach-ic { color: var(--dim); display: inline-flex; }
.ach.done .ach-ic { color: var(--gold-tx); }
.ach .tier { color: var(--gold-tx); display: inline-flex; gap: 1px; vertical-align: middle; }
.bar.thin { height: 4px; margin-top: 4px; }
.news .ic { margin-right: 4px; color: var(--nc, var(--muted)); }
.credit { margin-top: 10px; text-align: right; }
.credit a { color: inherit; }
#map .mk-hq use { stroke-width: 3; }
#map .mk-hq { pointer-events: none; }
#map .mk-npc { pointer-events: none; color: var(--accent); }
#map .mk-npc circle { fill: var(--panel); stroke: var(--accent); stroke-width: .5; }
#map .mk-npc use { fill: currentColor; }
@media (max-width: 480px) {
  #hud .online, #hud .vital.lvl .vb { display: none; }
  .vitals { gap: 4px; font-size: 12px; }
  .vital { gap: 2px; }
  .vitals .ic { width: 1em; height: 1em; }
}

/* 새 버전 알림 띠 */
.update-bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--safe-b, 0px)); z-index: 60; display: flex; align-items: center; gap: 10px;
  width: min(520px, calc(100% - 24px)); padding: 10px 12px 10px 14px; border-radius: 12px; background: var(--glass); border: 1px solid var(--accent);
  box-shadow: var(--shadow); backdrop-filter: blur(8px); font-size: 13.5px; }
.update-bar > .ic { color: var(--accent); }
@media (max-width: 860px) { .update-bar { bottom: calc(68px + var(--safe-b, 0px)); } }

/* hidden 속성은 .btn 등의 display 지정보다 우선 */
[hidden] { display: none !important; }
/* 결투 */
.duel-pill { display: inline-flex; align-items: center; gap: 4px; font: inherit; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 99px;
  border: 1px solid var(--bad); color: var(--bad); background: transparent; cursor: pointer; white-space: nowrap; }
.duel-pill.hot { background: var(--bad); color: #fff; animation: duelPulse 1.4s ease-in-out infinite; }
@keyframes duelPulse { 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--bad) 30%, transparent); } }
.duel-vs { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; margin-top: 10px; }
.duel-vs .vs { font-weight: 900; color: var(--muted); font-size: 13px; }
.duelist { display: grid; gap: 6px; min-width: 0; padding: 10px; border-radius: 12px; background: var(--panel2); }
.duelist b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.duel-chk { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--panel2); font-size: 13px; }
.duel-chk .k { font-weight: 800; min-width: 4.5em; color: var(--muted); }
.duel-log { margin-top: 12px; max-height: 160px; overflow-y: auto; display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }
.duel-log .neg { color: var(--bad); }
.loot-grid { display: grid; gap: 6px; }
.loot-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--panel2); }
.loot-item > .ic { color: var(--accent); }
.loot-item .cnt { min-width: 1.4em; text-align: center; }
