:root {
  --bg: #0b0b12;
  --surface: #15151f;
  --surface-2: #1d1d2b;
  --border: #2a2a3a;
  --text: #ececf1;
  --muted: #9aa0aa;
  --accent: #6366f1;
  --accent-2: #9333ea;
  --danger: #ef4444;
  --good: #22c55e;
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 650; }
a { color: var(--accent); }

#app { display: flex; flex-direction: column; min-height: 100dvh; }

/* Top bar */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 18px 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
#topbar-title { font-size: 22px; letter-spacing: -0.01em; }
.icon-btn {
  background: transparent; border: none; color: var(--muted);
  padding: 8px; border-radius: 12px; display: grid; place-items: center;
}
.icon-btn:active { background: var(--surface-2); color: var(--text); }

/* Main + views */
#main { flex: 1; padding: 18px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px); }
.view { animation: fade 0.18s ease; }
.view[hidden] { display: none; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Tab bar */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--border);
}
.tab {
  background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; }
.tab.is-active { color: var(--accent); }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.card + .card { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tag {
  display: inline-block; font-size: 12px; font-weight: 650; padding: 3px 9px;
  border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.tag.good { background: color-mix(in srgb, var(--good) 22%, transparent); color: #b6f0c6; }
.tag.warn { background: color-mix(in srgb, #f59e0b 22%, transparent); color: #fcd9a0; }
.tag.accent { background: color-mix(in srgb, var(--accent) 26%, transparent); color: #cdd0ff; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 12px 16px; border-radius: 12px; font-size: 15px; font-weight: 600; width: 100%;
}
.btn:active { transform: scale(0.99); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: #ffb4b4; border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { width: auto; flex: 1; }

/* Inputs */
label.field { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
input, textarea, select {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 12px; padding: 12px 14px; font-size: 16px; font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }

/* ---- Record screen ---- */
.recorder { display: flex; flex-direction: column; align-items: center; gap: 22px; padding-top: 18px; }
.rec-timer { font-size: 56px; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.rec-status { color: var(--muted); min-height: 22px; }
.rec-status.live { color: var(--danger); font-weight: 650; }

.level-meter { display: flex; align-items: flex-end; gap: 4px; height: 56px; }
.level-meter .bar { width: 6px; background: var(--accent); border-radius: 3px; height: 6px; transition: height 0.08s linear; opacity: 0.85; }

.record-btn {
  width: 96px; height: 96px; border-radius: 50%;
  border: 4px solid var(--border); background: var(--surface);
  display: grid; place-items: center; padding: 0;
}
.record-btn .dot {
  width: 64px; height: 64px; border-radius: 50%;
  background: linear-gradient(135deg, #f43f5e, var(--danger));
  transition: all 0.22s ease;
}
.record-btn.is-recording .dot { width: 34px; height: 34px; border-radius: 9px; }
.record-btn:active { transform: scale(0.96); }

.hint { font-size: 13px; color: var(--muted); text-align: center; max-width: 320px; }

/* ---- Lists ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px;
}
.list-item + .list-item { margin-top: 10px; }
.list-item .ttl { font-weight: 650; }
.list-item .sub { font-size: 13px; color: var(--muted); }
.chev { color: var(--muted); flex: none; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty svg { width: 40px; height: 40px; opacity: 0.5; margin-bottom: 12px; }

/* Notes / transcript blocks */
.notes ul { padding-left: 20px; margin: 8px 0; }
.notes li { margin: 4px 0; }
.transcript { white-space: pre-wrap; font-size: 14px; color: #d7d9e3; max-height: 320px; overflow: auto; }

/* ---- Modal ---- */
#modal-root:empty { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.18s ease;
}
.modal {
  width: 100%; max-width: 520px; background: var(--surface);
  border: 1px solid var(--border); border-bottom: none;
  border-radius: 22px 22px 0 0; padding: 20px 18px calc(20px + var(--safe-bottom));
  animation: slideup 0.22s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.modal h2 { font-size: 19px; margin-bottom: 4px; }
.modal .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: -6px auto 14px; }

/* ---- Toast ---- */
#toast-root {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
  z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4); animation: fade 0.18s ease; max-width: 90vw;
}
.toast.error { border-color: color-mix(in srgb, var(--danger) 55%, var(--border)); }
.toast.success { border-color: color-mix(in srgb, var(--good) 55%, var(--border)); }

/* Spinner */
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--text) 30%, transparent); border-top-color: var(--text);
  animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { display: flex; align-items: center; gap: 10px; color: var(--muted); }

hr.sep { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
