:root {
  --bg: #02070c;
  --panel: rgba(8, 20, 30, 0.86);
  --panel2: rgba(16, 34, 48, 0.92);
  --line: rgba(140, 200, 230, 0.18);
  --text: #dceef6;
  --dim: #8fb0c0;
  --accent: #5fd3e6;
  --bad: #ff7a7a;
  --good: #9be15d;
  --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(--text); 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; }
button { font-family: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; padding: 0; font-size: inherit; }
[hidden] { display: none !important; }
input, select { font-family: inherit; font-size: 15px; }

/* ── 상단 ── */
#top {
  position: fixed; top: 0; left: 0; right: 0; padding: calc(6px + var(--st)) 10px 6px; z-index: 5;
  background: linear-gradient(180deg, rgba(2, 7, 12, 0.92), rgba(2, 7, 12, 0.55) 80%, transparent);
  pointer-events: none;
}
#top .row { display: flex; align-items: center; gap: 8px; pointer-events: auto; }
#top .row.sub { margin-top: 4px; font-size: 11.5px; color: var(--dim); gap: 10px; flex-wrap: wrap; pointer-events: none; }
#top .row.sub b { color: var(--text); font-weight: 600; }
#clock { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 46px; font-size: 13px; }
#pops { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; padding-right: 2px; }
#pops::-webkit-scrollbar { display: none; }
.pop { display: flex; align-items: center; gap: 4px; padding: 3px 6px; border-radius: 99px; background: rgba(255, 255, 255, 0.06); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pop i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.pop.zero { opacity: 0.35; }
#speedbox { display: flex; gap: 4px; }
.chip { padding: 6px 10px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); font-weight: 700; font-size: 13px; min-width: 40px; }
.chip.paused { background: #6a3a1a; }

/* ── 측면 버튼 ── */
#side { position: fixed; right: 10px; top: calc(84px + var(--st)); display: flex; flex-direction: column; gap: 8px; z-index: 4; }
.round { width: 40px; height: 40px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line); font-size: 18px; }
.round.on { background: #164a5a; border-color: var(--accent); }
.round.speed { font-size: 13px; font-weight: 800; }
.round.paused { background: #6a3a1a; border-color: #c8763a; }
#ovLegend {
  position: fixed; right: 58px; top: calc(184px + var(--st)); z-index: 4; padding: 6px 10px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); font-size: 12px; display: flex; align-items: center; gap: 8px;
}
#ovLegend .bar { width: 70px; height: 8px; border-radius: 4px; }

/* ── 도크 ── */
#dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + var(--sb)); background: rgba(4, 12, 18, 0.94); border-top: 1px solid var(--line);
}
#dock button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; border-radius: 10px; color: var(--dim); max-width: 90px; }
#dock button i { font-style: normal; font-size: 19px; line-height: 22px; }
#dock button span { font-size: 11px; }
#dock button.on { color: var(--text); background: rgba(95, 211, 230, 0.14); }

/* ── 도구 옵션 띠 ── */
#toolopts {
  position: fixed; left: 8px; right: 8px; bottom: calc(66px + var(--sb)); z-index: 6; padding: 8px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
#toolopts .hint { font-size: 12px; color: var(--dim); margin-bottom: 6px; }
.hscroll { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.hscroll::-webkit-scrollbar { display: none; }
.sbtn {
  flex: none; display: flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line); font-size: 13px; white-space: nowrap;
}
.sbtn.on { border-color: var(--accent); background: rgba(95, 211, 230, 0.16); }
.sbtn i.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.optrow { display: flex; gap: 6px; align-items: center; margin-top: 7px; flex-wrap: wrap; font-size: 12px; color: var(--dim); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { padding: 6px 10px; font-size: 12.5px; color: var(--dim); }
.seg button.on { background: rgba(95, 211, 230, 0.22); color: var(--text); }
.warnbtn { padding: 6px 10px; border-radius: 9px; border: 1px solid rgba(255, 122, 122, 0.4); color: var(--bad); font-size: 12.5px; }

/* ── 시트 ── */
#sheet {
  position: fixed; left: 0; right: 0; bottom: var(--dockH, 64px); z-index: 7; display: flex; flex-direction: column;
  max-height: calc(100% - var(--dockH, 64px) - 70px - var(--st));
  background: rgba(6, 16, 24, 0.97); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  animation: up 0.18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 720px) { #sheet { left: 50%; width: 560px; margin-left: -280px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 8px; }
.sheet-head b { font-size: 16px; }
.x { width: 34px; height: 34px; border-radius: 50%; background: rgba(255, 255, 255, 0.06); font-size: 15px; }
#sheetBody { overflow-y: auto; padding: 0 14px 18px; -webkit-overflow-scrolling: touch; user-select: text; -webkit-user-select: text; }
h3 { font-size: 13px; color: var(--dim); font-weight: 600; margin: 16px 0 8px; letter-spacing: 0.02em; }
.card2 { background: rgba(255, 255, 255, 0.035); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.list .item { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.list .item:last-child { border-bottom: 0; }
.item .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.item .grow { flex: 1; min-width: 0; }
.item .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: 11.5px; color: var(--dim); }
.mini { padding: 6px 9px; border-radius: 8px; background: rgba(255, 255, 255, 0.07); font-size: 12px; white-space: nowrap; }
.mini.warn { color: var(--bad); }
.primary { background: #1d7e93; color: #fff; padding: 10px 14px; border-radius: 11px; font-weight: 700; }
.ghost { background: rgba(255, 255, 255, 0.07); padding: 10px 14px; border-radius: 11px; }
.danger { background: rgba(255, 90, 90, 0.16); color: var(--bad); padding: 10px 14px; border-radius: 11px; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btnrow > * { flex: 1; }

/* 슬라이더 */
.slider { margin: 10px 0 4px; }
.slider .lab { display: flex; justify-content: space-between; font-size: 13px; }
.slider .lab b { font-variant-numeric: tabular-nums; color: var(--accent); }
.slider .tr { font-size: 11px; color: var(--dim); margin-top: 2px; line-height: 1.35; }
.slider .tr .p { color: #9be15d; }
.slider .tr .m { color: #ffae7a; }
input[type=range] { width: 100%; height: 30px; margin: 2px 0 0; background: none; -webkit-appearance: none; appearance: none; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.14); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); margin-top: -8px; border: 3px solid #0b2530; }
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.14); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); border: 3px solid #0b2530; }
.mark { position: relative; height: 0; }
.mark i { position: absolute; top: -21px; width: 2px; height: 10px; background: rgba(255, 255, 255, 0.5); border-radius: 1px; pointer-events: none; }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; font-size: 13.5px; }
.sw { width: 46px; height: 28px; border-radius: 14px; background: rgba(255, 255, 255, 0.15); position: relative; flex: none; }
.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: #1d7e93; }
.sw.on::after { left: 21px; }
.textin { width: 100%; padding: 9px 10px; border-radius: 9px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); color: var(--text); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.swatches button { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; }
.swatches button.on { border-color: #fff; }
.typegrid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.typecard { text-align: left; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); }
.typecard b { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.typecard p { margin: 4px 0 0; font-size: 12px; color: var(--dim); line-height: 1.45; }
.typecard .nm2 { font-size: 11.5px; color: var(--text); margin-top: 4px; }

/* 파생 수치 표 */
.derived { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 12.5px; }
.derived span:nth-child(odd) { color: var(--dim); }
.derived span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }
.budget { margin-top: 8px; }
.budget .bar { height: 10px; border-radius: 5px; background: rgba(255, 255, 255, 0.08); overflow: hidden; display: flex; }
.budget .bar i { display: block; height: 100%; }
.budget .lg { display: flex; gap: 10px; font-size: 11px; color: var(--dim); margin-top: 4px; flex-wrap: wrap; }
.budget .lg i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 3px; }
.verdict { margin-top: 8px; font-size: 12.5px; padding: 8px 10px; border-radius: 9px; background: rgba(255, 255, 255, 0.05); line-height: 1.45; }

/* ── 인스펙터 ── */
#inspector {
  position: fixed; left: 8px; right: 8px; bottom: calc(66px + var(--sb)); z-index: 7; padding: 10px 12px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  max-height: 46vh; overflow-y: auto; font-size: 12.5px;
}
@media (min-width: 720px) { #inspector { left: auto; right: 60px; top: calc(80px + var(--st)); bottom: auto; width: 340px; max-height: 70vh; } }
#inspector .hd { display: flex; align-items: center; gap: 8px; }
#inspector .hd .dot { width: 14px; height: 14px; border-radius: 50%; }
#inspector .hd b { font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#inspector .st { margin: 4px 0 6px; color: var(--dim); }
#inspector .st b { color: var(--text); }
.meter { margin: 5px 0; }
.meter .lb { display: flex; justify-content: space-between; color: var(--dim); font-size: 11.5px; }
.meter .lb b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.meter .bar { height: 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); overflow: hidden; margin-top: 2px; position: relative; }
.meter .bar i { display: block; height: 100%; border-radius: 4px; }
.meter .bar s { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(255, 255, 255, 0.8); text-decoration: none; }
.kv { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px 12px; margin-top: 6px; font-size: 11.5px; color: var(--dim); }
.kv b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.traits { display: grid; grid-template-columns: auto 1fr auto; gap: 3px 8px; align-items: center; margin-top: 6px; font-size: 11.5px; }
.traits .tb { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); position: relative; }
.traits .tb i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; background: var(--accent); }
.traits .tb s { position: absolute; top: -2px; bottom: -2px; width: 2px; background: #fff; opacity: 0.6; }
.traits .d { font-variant-numeric: tabular-nums; color: var(--dim); min-width: 34px; text-align: right; }
.traits .d.up { color: #9be15d; } .traits .d.dn { color: #ffae7a; }
.insp-btns { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.dead { color: var(--bad); font-weight: 700; }
details summary { cursor: pointer; color: var(--dim); margin-top: 6px; font-size: 12px; }

/* ── 토스트 ── */
#toasts { position: fixed; left: 0; right: 0; top: calc(64px + var(--st)); z-index: 9; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { padding: 7px 12px; border-radius: 10px; background: rgba(10, 26, 36, 0.92); border: 1px solid var(--line); font-size: 12.5px; animation: fade 4s forwards; max-width: 90vw; }
.toast.bad { border-color: rgba(255, 122, 122, 0.5); }
.toast.good { border-color: rgba(155, 225, 93, 0.5); }
@keyframes fade { 0% { opacity: 0; transform: translateY(-6px); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ── 차트 ── */
.chart { width: 100%; height: 170px; display: block; border-radius: 10px; background: rgba(255, 255, 255, 0.03); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11.5px; color: var(--dim); margin-top: 5px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; }
.events { font-size: 12px; max-height: 180px; overflow-y: auto; }
.events div { padding: 4px 0; border-bottom: 1px solid var(--line); color: var(--dim); }
.events div b { color: var(--text); font-weight: 500; }
table.deaths { width: 100%; border-collapse: collapse; font-size: 11.5px; }
table.deaths td, table.deaths th { padding: 4px 3px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
table.deaths th { color: var(--dim); font-weight: 500; }
table.deaths td:first-child, table.deaths th:first-child { text-align: left; }
select.textin { appearance: none; -webkit-appearance: none; }

/* ── 인트로 ── */
#intro { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(2, 7, 12, 0.72); padding: 20px; }
#intro .card { max-width: 420px; background: rgba(8, 22, 32, 0.96); border: 1px solid var(--line); border-radius: 18px; padding: 20px; line-height: 1.55; }
#intro h1 { margin: 0 0 8px; font-size: 24px; letter-spacing: 0.04em; }
#intro p { margin: 6px 0; font-size: 14px; }
#intro ol { margin: 6px 0; padding-left: 20px; font-size: 13px; }
.dim { color: var(--dim); }
.small { font-size: 12px; }
#intro .btns { display: flex; flex-direction: column; gap: 8px; margin: 14px 0 6px; }
#intro .btns button { padding: 12px; border-radius: 12px; font-weight: 700; background: rgba(255, 255, 255, 0.07); }
#intro .btns .primary { background: #1d7e93; }
