:root {
  --bg: #f6f1ea;
  --surface: #fffdf9;
  --text: #2a2622;
  --muted: #7a7168;
  --line: #e6ddd1;
  --accent: #d9624a;
  --accent-text: #fff;
  --soft: #f1e7da;
  --danger: #b3261e;
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191d;
    --surface: #20242a;
    --text: #ece7e0;
    --muted: #9c968d;
    --line: #333942;
    --accent: #ee8068;
    --accent-text: #1b1210;
    --soft: #2a2f37;
    --danger: #ff8a80;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center-text { text-align: center; }
[hidden] { display: none !important; }

.top, main { max-width: 620px; margin: 0 auto; padding: 0 16px; }
.top { padding-top: calc(18px + env(safe-area-inset-top)); padding-bottom: 6px; }
.top p { margin: 2px 0 0; font-size: 0.875rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}
.card.center { text-align: center; padding: 28px 16px 20px; }
.card.note { background: var(--soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--accent); border-radius: 999px;
  background: var(--accent); color: var(--accent-text);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); font-weight: 500; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Record button */
.rec {
  width: 112px; height: 112px; border-radius: 50%;
  border: 4px solid var(--line); background: var(--surface);
  display: inline-grid; place-items: center; cursor: pointer; padding: 0;
}
.rec-dot { width: 68px; height: 68px; border-radius: 50%; background: var(--accent); transition: all .2s; }
.rec.on { border-color: var(--accent); animation: pulse 1.4s infinite; }
.rec.on .rec-dot { width: 40px; height: 40px; border-radius: 10px; }
.rec:disabled { opacity: 0.45; cursor: default; }
@keyframes pulse { 50% { box-shadow: 0 0 0 14px color-mix(in srgb, var(--accent) 18%, transparent); } }
@media (prefers-reduced-motion: reduce) { .rec.on { animation: none; } .rec-dot { transition: none; } }
.rec-label { font-weight: 600; margin: 14px 0 2px; }
.file-btn { margin-top: 12px; }

audio { width: 100%; height: 40px; margin: 6px 0; }

/* Prediction bars */
.guess { font-size: 1.25rem; font-weight: 700; margin: 4px 0 12px; }
.bar-row { display: grid; grid-template-columns: 7.5rem 1fr 3rem; align-items: center; gap: 8px; margin: 6px 0; font-size: 0.9rem; }
.bar { height: 10px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--muted); border-radius: 999px; }
.bar-row.best .bar i { background: var(--accent); }
.bar-row .pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

.sub { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 8px; }

/* Tag chips */
.chips { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.chip {
  display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 6px 12px; text-align: left;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer;
}
.chip .e { font-size: 1.4rem; }
.chip small { display: block; color: var(--muted); font-size: 0.72rem; line-height: 1.2; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); box-shadow: inset 0 0 0 1px var(--accent); }

input[type=text], select {
  width: 100%; min-height: 44px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text); font: inherit;
}

/* Library */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 8px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 8px 0; }
.item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; background: var(--soft); font-size: 0.85rem; font-weight: 600; }
.badge.plain { font-weight: 400; color: var(--muted); background: transparent; border: 1px solid var(--line); }
.item-head .when { margin-left: auto; color: var(--muted); font-size: 0.8rem; }
.item-note { font-size: 0.875rem; color: var(--muted); margin: 4px 0 0; overflow-wrap: anywhere; }
.item-actions { display: flex; gap: 8px; }
.item-actions select { flex: 1; min-width: 0; }
.similar { display: grid; gap: 4px; }
.similar .badge { margin-top: 6px; justify-self: start; }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 7px 4px; border-bottom: 1px solid var(--line); }
th:not(:first-child), td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
progress { width: 100%; height: 10px; accent-color: var(--accent); margin-bottom: 10px; }

/* Bottom tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; max-width: 207px; min-height: 60px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); text-decoration: none; font-size: 0.75rem; font-weight: 600;
}
.tabs a span { font-size: 1.25rem; line-height: 1.3; filter: grayscale(1); opacity: .7; }
.tabs a.active { color: var(--accent); }
.tabs a.active span { filter: none; opacity: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px; z-index: 10;
  background: var(--text); color: var(--bg); font-size: 0.9rem; text-align: center;
}
