:root {
  --bg: #f6f1ea;
  --surface: #fffaf4;
  --text: #2a241d;
  --muted: #7a6e60;
  --line: #e4d9cb;
  --accent: #d9622b;
  --accent-ink: #ffffff;
  --accent-soft: #f6dccd;
  --danger: #b3261e;
  --ok: #3f7d4e;
  --radius: 14px;
  --tabs-h: 60px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1814;
    --surface: #26221d;
    --text: #f1ebe3;
    --muted: #a99c8c;
    --line: #3a342c;
    --accent: #ef7a43;
    --accent-ink: #1b1814;
    --accent-soft: #4a2e20;
    --danger: #f2827a;
    --ok: #79c08a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px);
}
[hidden] { display: none !important; }
h1 { font-size: 28px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0 0 6px; }
p { margin: 8px 0; }
code { font-size: 0.9em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }

.top { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 0 16px; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

button, .file {
  font: inherit;
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  cursor: pointer;
  min-height: 44px;
  color: var(--text);
  background: transparent;
  touch-action: manipulation;
}
button:disabled { opacity: 0.45; cursor: default; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.secondary { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.ghost, .file { color: var(--accent); font-weight: 600; display: inline-block; }
.danger { color: var(--danger); font-weight: 600; }
.link { color: var(--accent); padding: 4px 0; min-height: 0; font-size: 14px; }
.big { font-size: 18px; padding: 16px 28px; margin: 8px 0; }
.wide { width: 100%; }
.icon { padding: 8px 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.spread { justify-content: space-between; }

.meter { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin: 8px auto 4px; max-width: 280px; }
#meter-fill { height: 100%; width: 0; background: var(--ok); transition: width 60ms linear; }

.capture {
  width: min(70vw, 240px);
  aspect-ratio: 1;
  border-radius: 50%;
  margin: 20px auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform 120ms ease;
}
.capture:active { transform: scale(0.96); }
.capture.busy { opacity: 0.7; }
.capture-label { font-size: 24px; font-weight: 700; }
.capture-sub { font-size: 14px; opacity: 0.85; }
.import-row { text-align: center; margin-top: 8px; }
.tip { margin-top: 24px; text-align: center; }

.field { display: block; margin: 12px 0; font-size: 14px; color: var(--muted); }
input[type="text"], select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.row input[type="text"] { margin: 0; }

.chips { border: 0; padding: 0; margin: 16px 0 4px; display: flex; flex-wrap: wrap; gap: 8px; }
.chips legend { font-size: 14px; color: var(--muted); margin-bottom: 8px; padding: 0; }
.chip {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 40px;
  font-size: 15px;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

.counts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.count { font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.clip-list { list-style: none; padding: 0; margin: 0; }
.clip-list li button {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 8px;
  padding: 12px 14px;
}
.clip-ctx { font-weight: 600; }
.clip-ctx.untagged { color: var(--danger); }
.clip-meta { font-size: 13px; color: var(--muted); grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip-dur { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.ctx-list { list-style: none; padding: 0; margin: 8px 0 12px; }
.ctx-list li { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 4px 0; }
.ctx-list li:last-child { border-bottom: 0; }
.ctx-list .hint { color: var(--muted); font-size: 13px; margin-left: 6px; }

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 5;
}
.tabs button { flex: 1; max-width: 186px; height: var(--tabs-h); border-radius: 0; color: var(--muted); font-weight: 600; font-size: 15px; }
.tabs button.active { color: var(--accent); }

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  margin: auto auto 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--surface);
  color: var(--text);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet::backdrop { background: rgb(0 0 0 / 0.4); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-actions { position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); margin: 8px -16px 0; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
.wave-wrap { margin: 8px 0 4px; touch-action: none; }
#wave { width: 100%; display: block; border-radius: 10px; background: var(--bg); }
#btn-play { margin-top: 8px; }

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