:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #13202e;
  --muted: #66758a;
  --line: #dde3ea;
  --accent: #0e9f6e;
  --accent-ink: #ffffff;
  --peak: #e8590c;
  --warn: #d9480f;
  --warn-bg: #fff1e8;
  --info-bg: #e8f1ff;
  --band: rgba(14, 159, 110, 0.07);
  --danger: #c92a2a;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1621;
    --card: #17212e;
    --text: #e8eef5;
    --muted: #8b9bb0;
    --line: #273445;
    --accent: #2fd59a;
    --accent-ink: #062016;
    --peak: #ff922b;
    --warn: #ff8a50;
    --warn-bg: #3a2216;
    --info-bg: #1b2a40;
    --band: rgba(47, 213, 154, 0.08);
    --danger: #ff6b6b;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1621;
  --card: #17212e;
  --text: #e8eef5;
  --muted: #8b9bb0;
  --line: #273445;
  --accent: #2fd59a;
  --accent-ink: #062016;
  --peak: #ff922b;
  --warn: #ff8a50;
  --warn-bg: #3a2216;
  --info-bg: #1b2a40;
  --band: rgba(47, 213, 154, 0.08);
  --danger: #ff6b6b;
  color-scheme: dark;
}

* { 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;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 6px;
  max-width: 560px; margin: 0 auto;
}

h1 { font-size: 1.2rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0; }

main { max-width: 560px; margin: 0 auto; padding: 8px 16px 32px; display: grid; gap: 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  min-width: 0;
}

.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

button, select, input {
  font: inherit; color: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  min-height: 44px;
}

button:disabled { opacity: 0.45; cursor: default; }
button.ghost { background: transparent; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
button.danger { color: var(--danger); }
button.tiny { min-height: 32px; padding: 4px 10px; }

select, input[type="number"], input[type="date"], input:not([type]) {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 10px;
  padding: 9px 10px;
  min-height: 44px;
}

input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 44px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; min-height: 36px; padding: 6px 12px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.racket-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px; }
.racket-bar select { flex: 1; min-width: 0; }
.racket-info { flex-basis: 100%; margin: 0 4px; }
.racket-info:empty { display: none; }

.reading.hit { animation: hit 0.35s ease-out; }
@keyframes hit {
  0% { box-shadow: 0 0 0 0 var(--accent); }
  100% { box-shadow: 0 0 0 10px transparent; }
}

details.sizes { margin: 4px 0 8px; }
details.sizes > summary { font-size: 0.9rem; color: var(--muted); }

.reading { text-align: center; display: grid; gap: 10px; }
.big { font-size: 4.2rem; font-weight: 700; line-height: 1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; margin-top: 4px; }
.big .unit { font-size: 1.3rem; font-weight: 600; color: var(--muted); margin-left: 6px; letter-spacing: 0; }
.sub { color: var(--muted); font-variant-numeric: tabular-nums; }
.sub .dot { margin: 0 8px; }
.status { margin: 0; color: var(--muted); font-size: 0.92rem; min-height: 2.6em; }

.taps { display: flex; justify-content: center; gap: 8px; }
.taps span { width: 10px; height: 10px; border-radius: 50%; background: var(--line); transition: background 0.15s; }
.taps span.on { background: var(--accent); }

#listenBtn { font-size: 1.05rem; min-height: 54px; }
#listenBtn.live { background: var(--peak); color: #fff; }

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > button { flex: 1 1 0; }

.alert { border-radius: 12px; padding: 10px 12px; font-size: 0.92rem; text-align: left; }
.alert.warn { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.alert.info { background: var(--info-bg); }

canvas { display: block; width: 100%; }

.meter { height: 4px; background: var(--line); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.meter div { height: 100%; width: 0; background: var(--accent); transition: width 0.06s linear; }

.history { list-style: none; margin: 10px 0 0; padding: 0; }
.history li {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  padding: 8px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.history li.muted { display: block; border-top: 0; }
.history li span { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

details > summary { cursor: pointer; font-weight: 600; min-height: 24px; }
details[open] > summary { margin-bottom: 12px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
label { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); text-align: left; }
label.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
label.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.prose { font-size: 0.92rem; }
.prose p { margin-top: 0; }
.prose ul { padding-left: 20px; margin: 0; }
.prose li { margin-bottom: 6px; }

dialog {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  color: var(--text);
  padding: 18px;
  width: min(480px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(5, 10, 18, 0.55); }
dialog h2 { margin-bottom: 12px; }
dialog form > label { margin-bottom: 10px; }

@media (max-width: 380px) {
  .grid { grid-template-columns: 1fr; }
  .big { font-size: 3.4rem; }
}
