:root {
  --bg: #e7dfd2;
  --surface: #fffdfa;
  --text: #1d1915;
  --muted: #7a7067;
  --line: #d9cfc2;
  --accent: #d9452b;
  --accent-text: #fff;
  --ok: #2f7d4f;
  --warn: #b26a00;
  --radius: 14px;

  /* the device has its own fixed dark palette, like a real object */
  --body-hi: #2b2927;
  --body-lo: #191817;
  --body-edge: #3a3734;
  --hole: #050505;
  --engrave: #7d7770;
  --red: #d63b22;
  --red-lo: #a3260f;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16120f;
    --surface: #1e1a17;
    --text: #efe8e0;
    --muted: #9b9086;
    --line: #2f2925;
    --accent: #ff6a4d;
    --accent-text: #1a0d09;
    --ok: #63c48b;
    --warn: #e7a43a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
.error { color: var(--accent); min-height: 1.2em; }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 0.6rem; }

button {
  font: inherit; border: 0; border-radius: 10px; padding: 10px 16px;
  background: var(--text); color: var(--bg); cursor: pointer;
}
button:disabled { opacity: 0.4; cursor: default; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.small { padding: 4px 10px; font-size: 0.85rem; }
input {
  font: inherit; padding: 10px 12px; border-radius: 10px; width: 100%;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}

/* ---------- setup ---------- */
.setup { max-width: 420px; margin: 0 auto; padding-top: 18dvh; }
#token-form { display: flex; gap: 8px; }

/* ---------- the device (fills the screen) ---------- */
.radio-page, html:has(.radio-page) { background: var(--body-lo); color: #e9e4dd; color-scheme: dark; }
.radio-page:has(#device:not([hidden])) { padding: 0; }
.radio-page .setup input { background: #24221f; border-color: #3a3734; color: #e9e4dd; }
.radio-page .setup button { background: #e9e4dd; color: #191817; }
.device {
  position: relative;
  display: flex; flex-direction: column;
  width: 100%; height: 100dvh; min-height: 520px;
  padding: max(14px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
           max(22px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: linear-gradient(170deg, var(--body-hi), var(--body-lo));
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .06), inset 0 -14px 30px rgb(0 0 0 / .35);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overflow: hidden;
}
.device > * { width: 100%; max-width: 520px; margin-left: auto; margin-right: auto; }

.device-top { display: flex; align-items: center; gap: 10px; }
.badge {
  flex: 1; font: 800 15px/1 ui-rounded, system-ui, sans-serif; letter-spacing: .32em;
  color: var(--engrave); text-shadow: 0 -1px 0 rgb(0 0 0 / .8);
}
.led {
  width: 10px; height: 10px; border-radius: 50%; background: #3d3a36;
  box-shadow: inset 0 1px 2px rgb(0 0 0 / .5);
}
.led[data-state="on"] { background: #63d36b; box-shadow: 0 0 8px #63d36b; }
.led[data-state="air"] { background: #63d36b; box-shadow: 0 0 10px #63d36b; animation: blink 1.6s ease-in-out infinite; }
.led[data-state="warn"] { background: #f0a23a; box-shadow: 0 0 10px #f0a23a; animation: blink 2.4s ease-in-out infinite; }
.led[data-state="rec"] { background: #ff4a2a; box-shadow: 0 0 12px #ff4a2a; animation: blink .8s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .45; } }

/* power switch */
.power {
  display: flex; align-items: center; gap: 6px; padding: 6px 4px;
  background: transparent; color: #57534e; font: 700 10px/1 system-ui, sans-serif; letter-spacing: .12em;
}
.power-track {
  position: relative; width: 46px; height: 24px; border-radius: 12px;
  background: #0d0c0b; box-shadow: inset 0 2px 4px rgb(0 0 0 / .8), 0 1px 0 rgb(255 255 255 / .06);
}
.power-knob {
  position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: linear-gradient(#d9d5cf, #8f8a83); box-shadow: 0 1px 2px rgb(0 0 0 / .7);
  transition: transform .15s ease;
}
.power[aria-checked="true"] .power-knob { transform: translateX(22px); }
.power[aria-checked="true"] .power-track { background: #4f6b3a; }
.power[aria-checked="true"] .power-on, .power[aria-checked="false"] .power-off { color: #c9c3ba; }

/* speaker */
.speaker-well {
  flex: 1; min-height: 0; display: grid; place-items: center;
  container-type: size; margin-top: 12px; margin-bottom: 16px;
}
.speaker {
  width: min(100cqw, 100cqh, 460px); aspect-ratio: 1; border-radius: 50%; padding: 6%;
  background: linear-gradient(160deg, #141312, #2a2826);
  box-shadow: inset 0 4px 10px rgb(0 0 0 / .7), 0 1px 0 rgb(255 255 255 / .07);
}
.grille {
  width: 100%; height: 100%; border-radius: 50%;
  background: radial-gradient(circle, var(--hole) 0 2.6px, rgb(255 255 255 / .05) 3.1px, transparent 3.6px) center / 13px 13px;
  -webkit-mask: radial-gradient(circle, #000 66%, transparent 70%);
          mask: radial-gradient(circle, #000 66%, transparent 70%);
}
.device[data-playing] .grille { animation: thump .5s ease-in-out infinite alternate; }
@keyframes thump { to { transform: scale(1.018); filter: brightness(1.35); } }

/* controls */
.controls { display: flex; flex-direction: column; align-items: center; margin-top: 8px; padding-bottom: 18px; }
.label { display: block; text-align: center; font: 700 10px/1 system-ui, sans-serif; letter-spacing: .14em; color: var(--engrave); margin-top: 10px; }

/* recording light, above the button */
.rec-indicator { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.rec-indicator .label { margin-top: 0; }
.rec-led {
  width: 12px; height: 12px; border-radius: 50%; background: #3a1712;
  box-shadow: inset 0 1px 2px rgb(0 0 0 / .7);
}
.rec-led[data-state="on"], .rec-led[data-state="short"] {
  background: #ff3b1f; box-shadow: 0 0 6px #ff3b1f, 0 0 18px #ff3b1f99;
}
/* blinking = keep holding, it's not long enough yet; steady = long enough to send */
.rec-led[data-state="short"] { animation: blink .35s steps(1) infinite; }
.rec-led[data-state="on"] + .label, .rec-led[data-state="short"] + .label { color: #ff6a50; }
.ptt {
  width: clamp(170px, 52vw, 230px); height: auto; aspect-ratio: 1; border-radius: 50%; padding: 7%;
  background: linear-gradient(#55524d, #1f1e1c);
  box-shadow: 0 8px 18px rgb(0 0 0 / .6), inset 0 2px 0 rgb(255 255 255 / .12);
  touch-action: none;
}
.ptt-cap {
  display: block; width: 100%; height: 100%; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #ff7a5c, var(--red) 45%, var(--red-lo));
  box-shadow: 0 7px 0 #6e1807, 0 10px 14px rgb(0 0 0 / .5);
  transition: transform .06s, box-shadow .06s;
}
.ptt[data-held] .ptt-cap { transform: translateY(6px); box-shadow: 0 1px 0 #6e1807, 0 2px 4px rgb(0 0 0 / .5); }
.ptt[data-held] .ptt-cap { background: radial-gradient(circle at 40% 35%, #ff9a7c, #ff4a2a 45%, #c2300f); }
.ptt[data-disabled] .ptt-cap { filter: saturate(.3) brightness(.6); }

.speaker[data-tap] { cursor: pointer; }

/* debug log */
.log-toggle {
  position: absolute; max-width: none; width: auto; margin: 0;
  left: max(10px, env(safe-area-inset-left)); bottom: max(10px, env(safe-area-inset-bottom));
  padding: 8px 6px; background: transparent; color: #5c5853;
  font: 700 9px/1 system-ui, sans-serif; letter-spacing: .18em;
}
.log-toggle[aria-expanded="true"] { color: #b5aea5; }
.log {
  /* covers the speaker, leaves the talk button usable */
  position: absolute; width: auto; max-width: none; margin: 0; z-index: 5;
  top: max(52px, calc(env(safe-area-inset-top) + 44px));
  left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right));
  height: min(56%, calc(100% - 300px)); min-height: 180px;
  display: flex; flex-direction: column;
  background: rgb(8 8 7 / .95); color: #e6ddd0; border: 1px solid #2f2d2a;
  border-radius: 16px; box-shadow: 0 10px 30px rgb(0 0 0 / .35);
  padding: 10px 12px;
  user-select: text; -webkit-user-select: text;
}
.log-head { display: flex; align-items: center; gap: 6px; padding-bottom: 8px; border-bottom: 1px solid #2f2925; }
.log-title { flex: 1; font-weight: 600; font-size: .9rem; }
.log .small { background: #e6ddd0; color: #16120f; }
.log .small.ghost { background: transparent; color: #e6ddd0; border-color: #3a332d; }
.log-lines {
  flex: 1; overflow: auto; margin: 0; padding: 6px 0 0; list-style: none;
  font: 11px/1.45 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.log-lines li { padding: 1px 0; white-space: pre-wrap; word-break: break-word; }
.log-lines time { color: #8a8077; margin-right: 6px; }
.log-lines [data-level="warn"] { color: #f0b45a; }
.log-lines [data-level="error"] { color: #ff7a62; }

/* tiny admin screw */
.screw {
  position: absolute; width: 30px; height: 30px; max-width: none;
  right: max(8px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom));
  display: grid; place-items: center;
}
.screw::before {
  content: ""; width: 11px; height: 11px; border-radius: 50%;
  background: linear-gradient(135deg, #6d6964, #2f2d2a);
  box-shadow: inset 0 0 0 1px #1a1918;
}
.screw::after {
  content: ""; position: absolute; width: 7px; height: 1.5px; background: #141312; transform: rotate(-35deg);
}

/* help dialog */
.help {
  max-width: min(92vw, 420px); border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 18px 20px;
}
.help::backdrop { background: rgb(0 0 0 / .55); }
.help h2 { margin-top: 0; }
.help ol { padding-left: 1.2em; }
.help li { margin: 4px 0; }
.help-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- admin page ---------- */
.admin { max-width: 620px; margin: 0 auto; }
.admin-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; }
.admin-top a { color: var(--muted); text-decoration: none; }
.chip {
  font-size: 0.8rem; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); background: var(--surface);
}
.chip[data-state="good"] { color: var(--ok); border-color: currentColor; }
.chip[data-state="poor"] { color: var(--warn); border-color: currentColor; }
.chip[data-state="manual"] { color: var(--accent); border-color: currentColor; }
.panel { margin-top: 12px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.panel h2 { margin-top: 0; }
.panel ol { padding-left: 1.2em; }

.dev summary { cursor: pointer; color: var(--muted); }
#manual-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.bg-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.bg-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.bg-form p, .bg-form div { grid-column: 1 / -1; margin: 0; font-size: 0.85rem; }
.clip .reset-wear { margin-top: 6px; }

.clips { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.clip {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
}
.clip[data-locked] { opacity: 0.6; }
.clip .play {
  flex: none; width: 44px; height: 44px; border-radius: 50%; padding: 0;
  background: var(--accent); color: var(--accent-text); font-size: 1rem;
}
.clip .meta { flex: 1; min-width: 0; }
.clip .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip[data-heard] .who { color: var(--muted); font-weight: 500; }
.clip .sub { font-size: 0.85rem; color: var(--muted); }
.clip progress { width: 100%; height: 4px; accent-color: var(--accent); display: block; margin-top: 6px; }
.empty { color: var(--muted); text-align: center; padding: 16px 0; }

.map { height: min(60dvh, 520px); margin-top: 8px; border-radius: var(--radius); border: 1px solid #000; overflow: hidden; }
.map, .leaflet-container { background: #000 !important; }
.leaflet-container { font: inherit; }
.map-hint { font-size: 0.85rem; }
.pin {
  display: grid; place-items: center; border-radius: 50%;
  background: #ff6a4d; color: #1a0d09; font: 600 13px/1 system-ui, sans-serif;
  border: 2px solid #000; box-shadow: 0 0 0 2px #ff6a4d55, 0 0 14px #ff6a4d88;
}
.map .leaflet-tooltip.ring-label {
  background: transparent; border: 0; box-shadow: none; padding: 0 4px;
  color: #8a8077; font-size: 11px; font-weight: 500;
}
.map .leaflet-tooltip.ring-label::before { display: none; }
.map .leaflet-bar { border-color: #2f2925; }
.map .leaflet-bar a, .map .leaflet-bar a:hover { background: #1e1a17; color: #efe8e0; border-color: #2f2925; }
.map .leaflet-control-scale-line { background: rgb(0 0 0 / .6); color: #9b9086; border-color: #5b524b; }
.leaflet-popup-content { margin: 10px 14px; }
.foot { display: flex; justify-content: space-between; align-items: center; padding: 20px 0; font-size: 0.85rem; }

/* No blue tap flash, selection or focus line on the device's controls when touched.
   Keyboard users still get a subtle focus ring. */
.device, .device * { -webkit-tap-highlight-color: transparent; }
.device ::selection { background: transparent; }
.device button:focus, .device a:focus { outline: none; }
.device button:focus-visible, .device a:focus-visible { outline: 2px solid #ff6a5066; outline-offset: 4px; }
.device .log, .device .log * { -webkit-tap-highlight-color: initial; }
.device .log ::selection { background: #3d6fb3; }
