:root {
  --bg: #f4f5f8;
  --card: #ffffff;
  --text: #1b2130;
  --muted: #667085;
  --line: #e1e5ec;
  --accent: #2457d6;
  --accent-ink: #ffffff;
  --rec: #d93025;
  --rec-ink: #ffffff;
  --ok: #1e7e34;
  --warn: #9a5b00;
  --err: #b42318;
  --banner-bg: #fff4e5;
  --banner-line: #f3c27a;
  --live-bg: #f0f4ff;
  --radius: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --card: #1b2029;
    --text: #e9ecf2;
    --muted: #98a2b3;
    --line: #2b3240;
    --accent: #7ea2ff;
    --accent-ink: #0c1222;
    --rec: #e5453b;
    --ok: #5cc27a;
    --warn: #f0b555;
    --err: #ff8a80;
    --banner-bg: #33271a;
    --banner-line: #6b4a1f;
    --live-bg: #1f2740;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.top h1 { margin: 0; font-size: 1.7rem; letter-spacing: -0.01em; }
.sub { margin: 2px 0 18px; color: var(--muted); }

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

.banner {
  background: var(--banner-bg);
  border: 1px solid var(--banner-line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

/* ---------- Recorder ---------- */
.record-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  min-height: 88px;
  border: 0;
  border-radius: 999px;
  background: var(--rec);
  color: var(--rec-ink);
  font: inherit;
  font-size: 1.6rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(217, 48, 37, 0.3);
  transition: transform 0.08s ease, filter 0.15s ease;
}
.record-btn:hover:not(:disabled) { filter: brightness(1.07); }
.record-btn:active:not(:disabled) { transform: scale(0.99); }
.record-btn:disabled { opacity: 0.7; cursor: wait; }

.rec-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: currentColor;
  transition: border-radius 0.15s ease;
}
.record-btn.is-recording { animation: pulse 1.6s ease-out infinite; }
.record-btn.is-recording .rec-icon { border-radius: 5px; }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(217, 48, 37, 0.5); }
  70%  { box-shadow: 0 0 0 20px rgba(217, 48, 37, 0); }
  100% { box-shadow: 0 0 0 0 rgba(217, 48, 37, 0); }
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin: 14px 2px 10px;
}
.status { margin: 0; color: var(--muted); }
.status[data-kind="live"] { color: var(--rec); font-weight: 600; }
.status[data-kind="ok"]   { color: var(--ok); }
.status[data-kind="warn"] { color: var(--warn); }
.status[data-kind="error"]{ color: var(--err); font-weight: 600; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; }

.live {
  min-height: 4.5em;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--live-bg);
  font-size: 1.15rem;
  overflow-wrap: anywhere;
}
.live-hint { color: var(--muted); font-size: 1rem; }
.interim { color: var(--accent); font-style: italic; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  width: min(92vw, 520px);
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 10;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  color: var(--muted);
  cursor: pointer;
}
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- Editor ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.hint { font-weight: 400; color: var(--muted); }

input[type="text"], textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: inherit;
  font: inherit;
}
textarea { min-height: 14rem; resize: vertical; line-height: 1.55; }
input[type="text"]:focus, textarea:focus, .btn:focus-visible, .record-btn:focus-visible,
.check input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 1px;
}

/* ---------- Summary (Ollama) ---------- */
.summary {
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: 12px;
  border-left: 4px solid var(--accent);
  background: var(--live-bg);
}
.summary-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
}
.summary-head h3 { margin: 0; font-size: 1.05rem; }
.summary-controls { display: flex; flex: 1 1 260px; justify-content: flex-end; gap: 8px; min-width: 0; }
.summary-controls select {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 280px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}
.summary-controls select:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.ollama-status { margin: 8px 0 0; font-size: 0.85rem; color: var(--muted); }
.ollama-status[data-kind="warn"] { color: var(--warn); }
.ollama-status code, .summary-error code, .summary-placeholder code {
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 0.9em;
  overflow-wrap: anywhere;
}

.summary-body { margin-top: 10px; }
.summary-placeholder { margin: 0; color: var(--muted); font-size: 0.95rem; }
.summary-busy { margin: 0; color: var(--accent); font-weight: 600; }
.summary-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--err);
  color: var(--err);
  background: var(--card);
}
.summary-text { margin: 0 0 10px; }
.summary-body h4 { margin: 0 0 4px; font-size: 0.95rem; }
.summary-actions { margin: 0 0 10px; padding-left: 1.3em; }
.summary-actions li { margin-bottom: 2px; }
.summary-none { margin: 0 0 10px; }
.summary-foot { margin: 0; font-size: 0.82rem; color: var(--muted); }
.summary-foot .stale { color: var(--warn); font-weight: 600; }
.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.audio-list { display: grid; gap: 10px; margin-bottom: 12px; }
.clip { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.clip-label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 6px; }
.clip audio { width: 100%; }

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
  margin-bottom: 14px;
}
.muted { color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; }

.btn {
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err); }
.btn.small { padding: 6px 12px; font-size: 0.9rem; }

/* ---------- Saved notes ---------- */
.notes-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.notes-head h2 { margin: 0; font-size: 1.2rem; }
.count {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  color: var(--muted);
  vertical-align: middle;
}

.note-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.note-list .empty { color: var(--muted); padding: 6px 2px; }

.note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.note.is-open { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.note-info { flex: 1 1 260px; min-width: 0; }
.note-title { font-weight: 600; overflow-wrap: anywhere; }
.note-meta { font-size: 0.85rem; color: var(--muted); }
.note-snippet {
  margin-top: 4px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.note-actions { display: flex; gap: 8px; }

/* ---------- Backup ---------- */
.backup { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.backup-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.backup-head h3 { margin: 0; font-size: 1.05rem; }
.backup-actions { display: flex; gap: 8px; }
.backup-info { margin: 8px 0 4px; font-size: 0.9rem; }
.backup-info[data-kind="warn"] { color: var(--warn); font-weight: 600; }
.backup-help { margin: 0; font-size: 0.82rem; color: var(--muted); }
.restore-label { display: inline-block; }
.restore-label:focus-within { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.foot { margin-top: 8px; font-size: 0.85rem; color: var(--muted); }

@media (max-width: 480px) {
  .summary-controls { flex-wrap: wrap; justify-content: stretch; }
  .summary-controls select { flex: 1 1 100%; max-width: none; }
  .summary-controls #summariseBtn { flex: 1 1 auto; }
  .record-btn { min-height: 80px; font-size: 1.45rem; }
  .actions .btn { flex: 1 1 auto; }
  .note-actions { width: 100%; }
  .note-actions .btn { flex: 1 1 0; }
}

@media (prefers-reduced-motion: reduce) {
  .record-btn.is-recording { animation: none; }
  .record-btn, .rec-icon { transition: none; }
}
