:root {
  --bg: #f4f1ea;
  --card: #fffdf8;
  --ink: #1d1f22;
  --muted: #6d6a63;
  --line: #e4ded2;
  --accent: #0f7b6c;
  --accent-ink: #ffffff;
  --accent-soft: #d9efe9;
  --warn: #b4442c;
  --floor: #cfe6df;
  --wall: #3d4a52;
  --track: #e0802f;
  --shadow: 0 1px 2px rgb(40 30 10 / .06), 0 8px 24px rgb(40 30 10 / .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181b;
    --card: #1f2226;
    --ink: #ecebe7;
    --muted: #9a978f;
    --line: #2e3237;
    --accent: #3cc2a9;
    --accent-ink: #0d1614;
    --accent-soft: #1d3a35;
    --warn: #ef8a6e;
    --floor: #24473f;
    --wall: #b8c4cb;
    --track: #f0a257;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(24px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
svg { fill: currentColor; }

.top, main { max-width: 560px; margin: 0 auto; padding: 0 16px; }
.top { display: flex; align-items: center; justify-content: space-between; padding-top: 20px; padding-bottom: 12px; }
h1 { font-size: 26px; margin: 0; letter-spacing: -.02em; }
.sub { margin: 0; color: var(--muted); font-size: 14px; }
.link { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted);
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; }
.link i { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.link[data-state="on"] i { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

main { display: grid; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 18px; box-shadow: var(--shadow); }
.card h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 10px; }
.card h2:first-child, .card-head h2 { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.card-head h2 { margin-bottom: 10px; }

.hero { display: flex; gap: 18px; align-items: center; }
.battery { position: relative; width: 108px; height: 108px; flex: none; }
.battery svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.battery circle { fill: none; stroke-width: 9; }
.battery .track { stroke: var(--line); }
.battery .fill { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: var(--level) 100; transition: stroke-dasharray .6s; }
.battery.low .fill { stroke: var(--warn); }
.battery-text { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.battery-text b { font-size: 26px; font-variant-numeric: tabular-nums; }
.battery-text span { font-size: 12px; color: var(--muted); }
.hero-info { min-width: 0; flex: 1; }
.state { font-size: 22px; font-weight: 650; margin: 0 0 10px; letter-spacing: -.01em; }
.facts { display: grid; gap: 4px; margin: 0; }
.facts div { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 550; }
.error { margin: 10px 0 0; color: var(--warn); font-size: 14px; font-weight: 550; }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.action { display: grid; justify-items: center; gap: 6px; padding: 14px 8px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow); font-weight: 600; font-size: 15px; }
.action svg { width: 28px; height: 28px; }
.action.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.action:active, .dpad button:active { transform: scale(.97); }
button[disabled] { opacity: .45; pointer-events: none; }
button.busy { opacity: .6; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 8px 14px; font-size: 14px; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button { border: 0; background: transparent; border-radius: 9px; padding: 9px 4px; font-size: 14px; }
.chips button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); font-weight: 600; }
.segmented button[aria-pressed="true"] { background: var(--card); box-shadow: 0 1px 3px rgb(0 0 0 / .12); font-weight: 600; }

.row { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; }
.switch { width: 52px; height: 32px; border-radius: 999px; border: 0; background: var(--line); position: relative; transition: background .2s; }
.switch i { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .25); transition: transform .2s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] i { transform: translateX(20px); }

.ghost { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 4px; }
.map-wrap { position: relative; aspect-ratio: 1; border-radius: 14px; background: var(--bg); overflow: hidden; }
#map { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.map-empty { position: absolute; inset: 0; display: grid; place-content: center; margin: 0; color: var(--muted); font-size: 14px; }
.map-meta { margin: 10px 0 0; font-size: 14px; color: var(--muted); }

.hint { margin: -4px 0 14px; color: var(--muted); font-size: 14px; }
.dpad { display: grid; grid-template-columns: repeat(3, 72px); grid-template-rows: repeat(3, 72px); gap: 8px; justify-content: center; touch-action: none; user-select: none; -webkit-user-select: none; }
.dpad button { border: 1px solid var(--line); background: var(--bg); border-radius: 18px; display: grid; place-items: center; -webkit-touch-callout: none; }
.dpad button svg { width: 30px; height: 30px; }
.dpad button.held { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.dpad [data-dir="forward"] { grid-column: 2; }
.dpad [data-dir="left"] { grid-column: 1; grid-row: 2; }
.dpad-center { grid-column: 2; grid-row: 2; border-radius: 50%; margin: 18px; background: var(--line); }
.dpad [data-dir="right"] { grid-column: 3; grid-row: 2; }
.dpad [data-dir="back"] { grid-column: 2; grid-row: 3; }

.login { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; padding: 16px; z-index: 10; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; }
.login-card .sub { margin-top: -8px; }
.login-card input { font: inherit; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.login-card input:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.login-card .action { grid-auto-flow: column; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px); }

@media (max-width: 360px) {
  .hero { flex-direction: column; align-items: stretch; }
  .battery { margin: 0 auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
