/* Layout: 상단 바 + 화면 전환(로그인·차고·등록·조종·설정). 조종 화면은 영상이 주인공이고 우측에 안전/출력 패널 */
:root {
  --paper: #F2F4F6;
  --surface: #FFFFFF;
  --sunken: #E8ECF0;
  --ink: #15202B;
  --muted: #5A6674;
  --line: #D8DFE6;
  --accent: #2847C9;
  --accent-soft: #E3E8FB;
  --on-accent: #FFFFFF;
  /* 보드 LED 색 = 상태 색 (펌웨어 tank_pwm.ino 와 동일 의미) */
  --led-wait: #2A72E8;
  --led-idle: #17915A;
  --led-drive: #C99600;
  --led-fail: #CF2E2B;
  --led-ota: #8740D3;
  --led-off: #8E99A5;
  --track-l: #2847C9;
  --track-r: #0E8A82;
  --hud-bg: rgba(10, 14, 20, 0.62);
  --hud-ink: #EEF2F6;
  --font-display: "Big Shoulders Display", "Arial Narrow", "IBM Plex Sans KR", sans-serif;
  --font-body: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Consolas", monospace;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #0E1319; --surface: #151C24; --sunken: #1B242E; --ink: #E4E9EE; --muted: #93A0AD;
    --line: #26313C; --accent: #8098FF; --accent-soft: #1D2647; --on-accent: #0E1319;
    --led-wait: #5B95F5; --led-idle: #35B877; --led-drive: #E2B42A; --led-fail: #F0605C; --led-ota: #AD7BEA; --led-off: #6B7784;
    --track-l: #8098FF; --track-r: #3CC2B8;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0E1319; --surface: #151C24; --sunken: #1B242E; --ink: #E4E9EE; --muted: #93A0AD;
  --line: #26313C; --accent: #8098FF; --accent-soft: #1D2647; --on-accent: #0E1319;
  --led-wait: #5B95F5; --led-idle: #35B877; --led-drive: #E2B42A; --led-fail: #F0605C; --led-ota: #AD7BEA; --led-off: #6B7784;
  --track-l: #8098FF; --track-r: #3CC2B8;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--paper); color: var(--ink); font-family: var(--font-body);
  font-size: 15px; line-height: 1.6; margin: 0;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { text-wrap: balance; margin: 0; line-height: 1.25; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }
.label { font-size: 12px; letter-spacing: 0.06em; color: var(--muted); font-weight: 500; }

/* 시안 표시 띠 */
.draft {
  background: var(--accent-soft); color: var(--ink); font-size: 13px;
  padding-block: 6px; padding-inline: 16px; text-align: center;
}
.draft b { color: var(--accent); }

/* 상단 바 */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar-in {
  max-width: 1240px; margin-inline: auto; padding-inline: 20px; height: 58px;
  display: flex; align-items: center; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 800; font-size: 24px; letter-spacing: 0.04em; white-space: nowrap; }
.brand svg { flex: none; }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav button {
  border: 0; background: none; padding: 8px 12px; border-radius: 7px; cursor: pointer;
  color: var(--muted); font-weight: 500; white-space: nowrap;
}
.nav button:hover { background: var(--sunken); color: var(--ink); }
.nav button[aria-current="page"] { color: var(--ink); background: var(--sunken); }
.me { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-weight: 600; font-size: 13px; }

main { max-width: 1240px; margin-inline: auto; padding-inline: 20px; padding-block: 28px 64px; }
.screen[hidden] { display: none !important; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: 26px; font-weight: 700; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); padding: 9px 16px;
  border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.danger { color: var(--led-fail); border-color: color-mix(in srgb, var(--led-fail) 45%, var(--line)); }

/* 상태 칩: 보드 LED 색을 그대로 쓴다 */
.chip {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600;
  padding: 3px 10px 3px 8px; border-radius: 999px; white-space: nowrap;
  background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c);
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent); }
.chip.blink::before { animation: blink 1s steps(1) infinite; }
.chip.fast::before { animation: blink 0.3s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0.15; } }
.c-wait { --c: var(--led-wait); } .c-idle { --c: var(--led-idle); } .c-drive { --c: var(--led-drive); }
.c-fail { --c: var(--led-fail); } .c-ota { --c: var(--led-ota); } .c-off { --c: var(--led-off); }

/* ── 로그인 ── */
.login { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 48px; align-items: center; padding-block: 24px; }
.login h1 { font-size: clamp(30px, 4vw, 44px); font-weight: 700; letter-spacing: -0.01em; }
.login .lede { color: var(--muted); font-size: 17px; max-width: 34em; margin: 14px 0 26px; }
.chain { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.chain span { padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); font-weight: 500; }
.chain i { color: var(--muted); font-style: normal; font-family: var(--font-mono); font-size: 12px; }
.signin { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 32px; display: grid; gap: 16px; }
.signin h2 { font-size: 19px; }
.signin p { margin: 0; color: var(--muted); font-size: 14px; }
.gbtn { width: 100%; padding: 12px; font-size: 15px; gap: 12px; }
.fine { font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; }

/* ── 차고 ── */
.cars { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.car { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; display: grid; gap: 16px; }
.car-top { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.car h3 { font-family: var(--font-display); font-weight: 800; font-size: 30px; letter-spacing: 0.02em; line-height: 1; }
.car .device { color: var(--muted); font-size: 13px; margin-top: 6px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 0; }
.facts div { display: grid; gap: 1px; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; font-size: 14px; }
.car-actions { display: flex; gap: 8px; }
.car-actions .btn { flex: 1; }
.car.off h3 { color: var(--muted); }

/* ── 등록 ── */
.pair { display: grid; grid-template-columns: 1fr 380px; gap: 28px; align-items: start; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; counter-reset: s; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 40px 1fr; gap: 14px; padding-block: 18px; border-bottom: 1px solid var(--line); }
.steps li:first-child { padding-top: 0; }
.steps li::before {
  content: counter(s); width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  border: 1.5px solid var(--line); font-weight: 700; font-size: 14px; color: var(--muted);
}
.steps li.done::before { content: "✓"; background: var(--led-idle); border-color: var(--led-idle); color: var(--surface); }
.steps li.now::before { border-color: var(--accent); color: var(--accent); }
.steps h3 { font-size: 16px; font-weight: 600; }
.steps p { margin: 4px 0 0; color: var(--muted); font-size: 14px; max-width: 46em; }
.qr-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: grid; gap: 14px; justify-items: center; text-align: center; }
.qr-box { background: #FFFFFF; padding: 14px; border-radius: 10px; border: 1px solid var(--line); position: relative; }
.qr-box canvas { display: block; width: 220px; height: 220px; image-rendering: pixelated; max-width: 100%; }
.qr-box .tag { position: absolute; top: 8px; right: 8px; background: #15202B; color: #FFFFFF; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.timer { font-family: var(--font-mono); font-size: 28px; font-weight: 500; }
.timer.low { color: var(--led-fail); }
.waiting { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pin { font-family: var(--font-display); font-weight: 800; font-size: 46px; letter-spacing: 0.14em; line-height: 1.1; }
.approve { width: 100%; display: grid; gap: 10px; text-align: left; border: 1.5px solid var(--accent); background: var(--accent-soft); border-radius: 10px; padding: 14px; }
.approve p { margin: 0; font-size: 14px; }
.approve .req { display: grid; }
.approve .req b { font-size: 17px; }
.approve .req span { font-size: 13px; color: var(--muted); }
.note { font-size: 13px; color: var(--muted); background: var(--sunken); border-radius: 8px; padding: 10px 12px; text-align: left; }

/* ── 조종 ── */
.cockpit { display: grid; grid-template-columns: 1fr 330px; gap: 16px; align-items: start; }
.feed { position: relative; background: #05080B; border-radius: 12px; overflow: hidden; aspect-ratio: 16 / 9; max-width: 100%; }
.feed canvas { width: 100%; height: 100%; display: block; }
.hud { position: absolute; color: var(--hud-ink); font-family: var(--font-mono); font-size: 12.5px; }
.hud .pane { background: var(--hud-bg); backdrop-filter: blur(6px); border-radius: 8px; padding: 8px 12px; }
.hud-tl { top: 12px; left: 12px; display: grid; gap: 6px; }
.hud-tl .name { font-family: var(--font-display); font-size: 26px; font-weight: 800; letter-spacing: 0.04em; line-height: 1; }
.hud-tr { top: 12px; right: 12px; text-align: right; }
.rtt { font-family: var(--font-display); font-size: 44px; font-weight: 800; line-height: 0.9; }
.rtt small { font-size: 18px; margin-left: 2px; }
.hud-bl { bottom: 12px; left: 12px; }
.hud-tc { top: 12px; left: 50%; transform: translateX(-50%); text-align: center; }
.hud-tc .hdg { font-family: var(--font-display); font-size: 22px; font-weight: 800; letter-spacing: 0.06em; }
.hud-br { bottom: 12px; right: 12px; }
.tilt-warn { color: #FFB25A; }
.trail { width: 100%; height: auto; aspect-ratio: 2 / 1; display: block; background: var(--sunken); border-radius: 8px; max-width: 100%; }
.sens { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 0; }
.sens div { display: grid; }
.sens dt { font-size: 12px; color: var(--muted); }
.sens dd { margin: 0; font-family: var(--font-mono); font-size: 14px; }
.sens .wide { grid-column: 1 / -1; }

.hud .chip { background: rgba(0,0,0,0.45); }
.hud .c-idle { --c: #4ED48E; } .hud .c-drive { --c: #F2C53D; } .hud .c-fail { --c: #FF6B66; } .hud .c-wait { --c: #6EA6FF; }
.lost {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  background: rgba(120, 10, 10, 0.55); color: #FFFFFF; font-weight: 600; font-size: 18px; padding: 20px;
}
.lost b { display: block; font-family: var(--font-display); font-size: 40px; letter-spacing: 0.06em; }

.side { display: grid; gap: 12px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: grid; gap: 12px; }
.panel h2 { font-size: 13px; font-weight: 600; letter-spacing: 0.04em; color: var(--muted); }
.stop {
  width: 100%; border: 0; border-radius: 10px; padding: 16px; cursor: pointer;
  background: var(--led-fail); color: #FFFFFF; font-family: var(--font-display); font-weight: 800; font-size: 28px; letter-spacing: 0.12em;
}
.stop:hover { filter: brightness(1.08); }
.arm-row { display: flex; gap: 8px; }
.arm-row .btn { flex: 1; }

.tracks { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.track { display: grid; gap: 6px; justify-items: center; }
.bar { width: 34px; height: 120px; background: var(--sunken); border-radius: 6px; position: relative; overflow: hidden; }
.bar::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px dashed var(--muted); opacity: 0.6; }
.fill { position: absolute; left: 4px; right: 4px; border-radius: 3px; background: var(--led-drive); transition: all 0.08s linear; }
.track .v { font-family: var(--font-mono); font-weight: 500; font-size: 15px; }

.safety { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.safety li { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: center; padding-block: 8px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.safety li:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.safety .lim { color: var(--muted); font-size: 12px; }
.safety .age { font-family: var(--font-mono); font-size: 13px; text-align: right; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-family: var(--font-mono); }
.keys { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
kbd { font-family: var(--font-mono); font-size: 12px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; background: var(--surface); color: var(--ink); }
.sim { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sim .btn { padding: 5px 10px; font-size: 12.5px; }

/* ── 설정 ── */
.settings { display: grid; gap: 16px; max-width: 760px; }
.form { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 22px; display: grid; gap: 18px; }
.form h2 { font-size: 16px; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 600; font-size: 14px; }
.field .help { font-size: 13px; color: var(--muted); }
.field input[type="text"], .field select { border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 9px 12px; max-width: 100%; }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input { flex: 1; accent-color: var(--accent); }
.range-row output { font-family: var(--font-mono); min-width: 4.5em; text-align: right; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.danger-zone { border-color: color-mix(in srgb, var(--led-fail) 40%, var(--line)); }
.confirm { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 14px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 20; }


/* ── 캘리브레이션 ── */
.calib { display: grid; grid-template-columns: 1fr 400px; gap: 16px; align-items: start; }
.stack { display: grid; gap: 16px; }
.banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: color-mix(in srgb, var(--led-drive) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--led-drive) 40%, var(--line)); border-radius: 10px; padding: 12px 14px; font-size: 14px; margin-bottom: 16px; }
.banner label { display: flex; gap: 8px; align-items: center; font-weight: 600; white-space: nowrap; }
.banner input { accent-color: var(--accent); width: 16px; height: 16px; }
.sides { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.side-col { display: grid; gap: 14px; align-content: start; }
.side-col h3 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.swatch { width: 14px; height: 4px; border-radius: 2px; background: var(--c); display: inline-block; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.mini { display: grid; gap: 4px; }
.mini label { font-size: 13px; font-weight: 600; }
.mini .help { font-size: 12.5px; color: var(--muted); }
.tests { display: flex; flex-wrap: wrap; gap: 8px; }
.result { font-size: 14px; background: var(--sunken); border-radius: 8px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.chart-wrap { overflow-x: auto; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
#curve { min-width: 300px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.store { font-size: 13px; color: var(--muted); }

/* ── 보드 준비 ── */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 28px; }
.choice { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 22px; display: grid; gap: 12px; align-content: start; }
.choice h2 { font-size: 19px; }
.choice p { margin: 0; color: var(--muted); font-size: 14px; }
.choice ul { margin: 0; padding-left: 18px; font-size: 14px; display: grid; gap: 6px; }
.choice .foot { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.tagline { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; color: var(--accent); }
.board-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.sec-title { font-size: 17px; font-weight: 700; margin-bottom: 10px; }
.needs { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.needs li { display: grid; grid-template-columns: 20px 1fr auto; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); align-items: start; }
.needs li:last-child { border-bottom: 0; }
.needs input { accent-color: var(--accent); width: 16px; height: 16px; margin-top: 4px; }
.needs b { font-weight: 600; }
.needs .sub { display: block; font-size: 13px; color: var(--muted); }
.who { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--sunken); color: var(--muted); white-space: nowrap; }
.who.kit { background: var(--accent-soft); color: var(--accent); }
.flash { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; display: grid; gap: 12px; }
.progress { height: 8px; background: var(--sunken); border-radius: 4px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.wiring { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: grid; gap: 12px; }
#wire { min-width: 520px; }
.warns { margin: 0; padding-left: 18px; font-size: 13.5px; display: grid; gap: 4px; }
.warns li::marker { color: var(--led-fail); }
@media (max-width: 960px) { .calib, .board-grid, .choices { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .sides { grid-template-columns: 1fr; } .needs li { grid-template-columns: 20px 1fr; } .needs .who { grid-column: 2; justify-self: start; } }

@media (max-width: 960px) {
  .cockpit, .pair, .login { grid-template-columns: 1fr; }
  .me span { display: none; }
}
@media (max-width: 560px) {
  .topbar-in { gap: 12px; padding-inline: 16px; }
  main { padding-inline: 16px; }
  .brand span { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .cars { grid-template-columns: 1fr; }
  .rtt { font-size: 32px; }
  .hud-tl .name { font-size: 20px; }
  .hud-tc, .hud-br { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .chip::before, .spin { animation: none !important; }
}
