/* Voice Coach UI — compact, touch-first app shell. Bright, calm, fully offline.
   Every surface and accent comes from a theme token; dark mode only overrides
   tokens on :root[data-theme="dark"], so geometry stays identical. */

:root,
:root[data-theme="light"] {
  color-scheme: light;

  /* Brand + semantic accents */
  --lime: #4ecb00;
  --lime-deep: #2f7d00;
  --lime-soft: #eaf9e0;
  --blue: #1a9be0;
  --blue-ink: #0a5f8c;
  --blue-soft: #e7f5fe;
  --amber: #c77a00;
  --amber-ink: #8a4b00;
  --amber-soft: #fff4e2;
  --red: #d63232;
  --red-ink: #a31616;
  --red-soft: #fdeaea;
  --lime-border: #bde89a;
  --blue-border: #c4e8fb;
  --amber-border: #ffdca8;
  --red-border: #ffc9c9;
  --on-danger: #ffffff;

  /* Accent system shared by buttons, chips, pills, tabs and the mic meter */
  --accent: #2f7d00;
  --accent-hover: #276a00;
  --accent-ink: #2f7d00;
  --accent-soft: #eaf9e0;
  --accent-border: #bde89a;
  --on-accent: #ffffff;
  --bright-ink: #102400;
  --accent-gradient: linear-gradient(160deg, #63d812, #3aa800);
  --primary-gradient: linear-gradient(160deg, #3aa800, #2f7d00);
  --progress-gradient: linear-gradient(90deg, #4ecb00, #8ee000);
  --user-bubble-bg: linear-gradient(160deg, #5fd400, #43b300);
  --danger-gradient: linear-gradient(160deg, #ff7070, #d63232);
  --baseline-bg: linear-gradient(180deg, #f5fcef, #eef9e4);
  --streak-bg: linear-gradient(120deg, #fff8ec, #fffdf8);
  --file-drop-active: #dcf0fd;
  --halo: rgba(88, 204, 2, .4);
  --danger-halo: rgba(214, 50, 50, .55);

  /* Neutrals + surfaces */
  --ink: #1f2a37;
  --muted: #5c6a7e;
  --line: #e1e7f0;
  --canvas: #f6f8fc;
  --card: #ffffff;
  --surface: #f6f8fc;
  --surface-strong: #eef3f8;
  --glass: rgba(255, 255, 255, .82);
  --glass-strong: rgba(255, 255, 255, .94);
  --glow-1: rgba(78, 203, 0, .10);
  --glow-2: rgba(26, 155, 224, .10);
  --dots: #a9b6c7;
  --spark-empty: #a7b7c7;
  --focus: #0a5f8c;

  /* Depth */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 10px 28px rgba(16, 24, 40, .07);
  --accent-shadow: 0 2px 8px rgba(47, 125, 0, .28);
  --mic-shadow: 0 5px 16px rgba(58, 168, 0, .34), inset 0 -2px 0 rgba(0, 0, 0, .08);
  --danger-shadow: 0 5px 18px rgba(214, 50, 50, .34);

  --radius: 22px;
  --radius-sm: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui,
          "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  /* Dark accents stay luminous enough for text on a #10151d canvas. */
  --lime: #79dc35;
  --lime-deep: #a5ef68;
  --lime-soft: rgba(121, 220, 53, .15);
  --blue: #59c2f3;
  --blue-ink: #9bd9ff;
  --blue-soft: rgba(89, 194, 243, .15);
  --amber: #ffb74d;
  --amber-ink: #ffd18a;
  --amber-soft: rgba(255, 183, 77, .14);
  --red: #ff6b6b;
  --red-ink: #ffb3b3;
  --red-soft: rgba(255, 107, 107, .16);
  --lime-border: rgba(121, 220, 53, .38);
  --blue-border: rgba(89, 194, 243, .34);
  --amber-border: rgba(255, 183, 77, .34);
  --red-border: rgba(255, 107, 107, .36);
  --on-danger: #200505;

  --accent: #71d43a;
  --accent-hover: #85e04f;
  --accent-ink: #bff59a;
  --accent-soft: rgba(113, 212, 58, .16);
  --accent-border: rgba(113, 212, 58, .38);
  --on-accent: #0d2402;
  --bright-ink: #0b1f02;
  --accent-gradient: linear-gradient(160deg, #8bea48, #4caf19);
  --primary-gradient: linear-gradient(160deg, #71d43a, #4caf19);
  --progress-gradient: linear-gradient(90deg, #4caf19, #8bea48);
  --user-bubble-bg: linear-gradient(160deg, #61c428, #419916);
  --danger-gradient: linear-gradient(160deg, #ff8080, #d63f3f);
  --baseline-bg: linear-gradient(180deg, rgba(113, 212, 58, .12), rgba(113, 212, 58, .05));
  --streak-bg: linear-gradient(120deg, rgba(255, 183, 77, .12), rgba(255, 183, 77, .04));
  --file-drop-active: rgba(89, 194, 243, .25);
  --halo: rgba(113, 212, 58, .45);
  --danger-halo: rgba(255, 107, 107, .6);

  --ink: #eaf1f9;
  --muted: #a8b7c9;
  --line: #2b3949;
  --canvas: #0f151d;
  --card: #18222e;
  --surface: #1a2532;
  --surface-strong: #22303e;
  --glass: rgba(14, 20, 28, .86);
  --glass-strong: rgba(14, 20, 28, .95);
  --glow-1: rgba(113, 212, 58, .09);
  --glow-2: rgba(89, 194, 243, .09);
  --dots: #5b6b7d;
  --spark-empty: #5b6b7d;
  --focus: #7dd3fc;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .45);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .38);
  --accent-shadow: 0 2px 8px rgba(0, 0, 0, .4);
  --mic-shadow: 0 5px 16px rgba(0, 0, 0, .48), inset 0 -2px 0 rgba(0, 0, 0, .16);
  --danger-shadow: 0 5px 18px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, var(--glow-1), transparent 22rem),
    radial-gradient(circle at 96% 100%, var(--glow-2), transparent 22rem),
    var(--canvas);
  line-height: 1.5;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button, a, input, select, textarea, label { touch-action: manipulation; }

/* ---------- App shell ---------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 100%;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.appbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 4px;
  margin: -4px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  color: var(--bright-ink);
  background: var(--accent-gradient);
  box-shadow: var(--accent-shadow);
}

.brand-name { font-size: 18px; font-weight: 800; letter-spacing: -.02em; }
.brand-name strong { color: var(--accent-ink); }

.appbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.session-pill { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--surface-strong); color: var(--muted); white-space: nowrap; }
.session-pill[data-kind="listening"] { background: var(--accent-soft); color: var(--accent-ink); }
.session-pill[data-kind="thinking"] { background: var(--amber-soft); color: var(--amber-ink); }
.session-pill[data-kind="speaking"] { background: var(--blue-soft); color: var(--blue-ink); }

.streak-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--amber-border);
  background: var(--amber-soft);
  color: var(--amber-ink);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.streak-word { font-weight: 600; color: var(--muted); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .1s ease;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent-soft); border-color: var(--accent-border); }
.icon-btn .icon-off { display: none; }
.icon-btn[aria-pressed="false"] .icon-off { display: block; }
.icon-btn[aria-pressed="false"] .icon-on { display: none; }

/* The header toggle always shows the action for the resolved theme. */
.theme-toggle { flex: none; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ---------- Tabs ---------- */

.tabbar {
  flex: none;
  order: 3;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--glass-strong);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  z-index: 6;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 48px;
  padding: 5px 4px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .01em;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.tab svg { opacity: .85; }
.tab.is-active { background: var(--accent-soft); color: var(--accent-ink); }
.tab.is-active svg { opacity: 1; }
.tab:active { background: var(--surface-strong); }

/* ---------- Views ---------- */

.views {
  flex: 1 1 auto;
  order: 2;
  display: flex;
  min-height: 0;
  position: relative;
}

.view {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px 14px 22px;
}

.view[hidden] { display: none !important; }

/* Practice is a fixed chat column: the thread scrolls, the dock stays put. */
.view-practice {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px 14px 0;
}

.view-head { margin: 4px 2px 12px; }
.view-head h1 {
  margin: 2px 0 4px;
  font-size: 24px;
  line-height: 1.18;
  letter-spacing: -.02em;
}
.view-head.compact {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.view-head.compact h1 { margin-bottom: 0; }

.eyebrow {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--accent-ink);
}

.hint, .muted {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.pill {
  flex: none;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Session strip + setup ---------- */

.session-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 2px;
  margin-bottom: 10px;
}

.progress-track {
  flex: 1 1 auto;
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--progress-gradient);
  transition: width .45s cubic-bezier(.2, .8, .2, 1);
}

.steps {
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.step {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.step-dot {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--card);
  border: 1.5px solid var(--line);
  font-size: 10px;
  transition: background .2s ease, color .2s ease, border-color .2s ease;
}

.step.done { color: var(--accent-ink); }
.step.done .step-dot { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.setup-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.mode-switch {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
}

.mode-btn {
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.mode-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-ink); }

.goals {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.goal-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.goal-chip input { width: 14px; height: 14px; accent-color: var(--accent); margin: 0; }
.goal-chip:has(input:checked) {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.first-run-note {
  margin: 0 0 10px;
  padding: 8px 12px;
  border: 1px dashed var(--accent-border);
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 12.5px;
  font-weight: 600;
}
[hidden] { display: none !important; }

.link-btn {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--blue-ink);
  font-family: inherit;
  font-size: inherit;
  font-weight: 800;
  text-decoration: underline;
  cursor: pointer;
}

.baseline-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px dashed var(--accent-border);
  border-radius: var(--radius-sm);
  background: var(--baseline-bg);
}
.baseline-copy strong { display: block; font-size: 13.5px; }
.baseline-copy .hint { font-size: 12px; }
.baseline-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.baseline-actions .status { margin: 0; }

/* ---------- Thread ---------- */

.thread {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 4px 2px 12px;
  scroll-padding-bottom: 12px;
}

.thread-empty {
  margin: auto;
  max-width: 320px;
  padding: 18px 8px;
  text-align: center;
  color: var(--muted);
}
.thread-empty-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 10px;
  border-radius: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  font-size: 26px;
}
.thread-empty strong { display: block; color: var(--ink); font-size: 15px; }
.thread-empty p { margin: 4px 0 0; font-size: 13px; }

.msg {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  max-width: 100%;
  animation: fade-up .28s ease both;
}
.msg.user { justify-content: flex-end; }
.msg.coach { justify-content: flex-start; }

.turn { display: flex; flex-direction: column; gap: 12px; }
.meta-dot { opacity: .55; }
.bubble.error { background: var(--red-soft); border: 1px solid var(--red-border); }
.msg.user .bubble.error {
  background: var(--red-soft);
  color: var(--red-ink);
  box-shadow: none;
}
.msg.user .bubble.error .bubble-meta { color: var(--red-ink); opacity: .8; }

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-bottom: 2px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: var(--bright-ink);
  font-size: 11px;
  font-weight: 800;
  box-shadow: var(--accent-shadow);
}

.bubble {
  position: relative;
  max-width: min(86%, 560px);
  padding: 9px 13px 11px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.msg.user .bubble {
  background: var(--user-bubble-bg);
  color: var(--bright-ink);
  border-bottom-right-radius: 6px;
  box-shadow: var(--accent-shadow);
}
.msg.coach .bubble {
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-sm);
}

.bubble-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}
.msg.user .bubble-meta { color: var(--bright-ink); opacity: .8; }

.bubble p { margin: 0; }
.msg.user .quote { font-weight: 600; }
.reply-text { font-size: 15px; color: var(--ink); }

.bubble-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.mini {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--blue-ink);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background .12s ease, transform .1s ease;
}
.mini:active { transform: scale(.96); }
.mini.ghost { background: transparent; color: var(--muted); }
.mini svg { flex: none; }

.metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px dashed var(--line);
}
.metric {
  flex: 1 1 86px;
  max-width: 150px;
  padding: 6px 8px;
  border-radius: 10px;
  background: var(--surface);
}
.metric-label {
  display: block;
  font-size: 9.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}
.metric-value { font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }

.details { margin-top: 8px; }
.details summary {
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}
.json {
  margin: 6px 0 0;
  max-height: 180px;
  overflow: auto;
  padding: 8px;
  border-radius: 10px;
  background: var(--surface);
  font-size: 11px;
  -webkit-overflow-scrolling: touch;
}

.dots { display: inline-flex; gap: 4px; padding: 4px 2px; }
.dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dots);
  animation: bounce 1.1s infinite ease-in-out;
}
.dots span:nth-child(2) { animation-delay: .16s; }
.dots span:nth-child(3) { animation-delay: .32s; }

/* ---------- Dock ---------- */

.dock {
  flex: none;
  margin: 0 -14px;
  padding: 8px 14px 10px;
  background: var(--glass-strong);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}

.dock-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.status {
  flex: 1 1 auto;
  margin: 0;
  padding: 5px 10px;
  min-height: 28px;
  display: flex;
  align-items: center;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.status[data-kind="busy"] { color: var(--blue-ink); background: var(--blue-soft); border-color: var(--blue-border); }
.status[data-kind="ok"] { color: var(--accent-ink); background: var(--accent-soft); border-color: var(--accent-border); }
.status[data-kind="warn"] { color: var(--amber-ink); background: var(--amber-soft); border-color: var(--amber-border); }
.status[data-kind="error"] { color: var(--red-ink); background: var(--red-soft); border-color: var(--red-border); }

.status-inline {
  flex: 0 1 auto;
  min-height: 0;
  padding: 3px 8px;
  font-size: 11.5px;
  background: transparent;
}

.rec-timer {
  flex: none;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--red-soft);
  color: var(--red-ink);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.dock-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

.dock-side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dock-side.left { justify-self: start; }
.dock-side.right { justify-self: end; }

.round-btn {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--blue-ink);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .1s ease, background .15s ease;
}
.round-btn:active { transform: scale(.93); }
.round-btn.stop { color: var(--on-danger); background: var(--red); border-color: var(--red); }
.round-btn[hidden] { display: none !important; }

.mic-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--bright-ink);
  background: var(--accent-gradient);
  box-shadow: var(--mic-shadow);
  cursor: pointer;
  transition: transform .12s ease, background .2s ease, box-shadow .2s ease;
}
.mic-btn:active { transform: scale(.95); }
.mic-btn .stop-icon { display: none; }
.mic-btn.is-recording {
  background: var(--danger-gradient);
  box-shadow: var(--danger-shadow);
}
.mic-btn.is-recording .mic-icon { display: none; }
.mic-btn.is-recording .stop-icon { display: block; }

.mic-halo {
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 3px solid var(--halo);
  opacity: .55;
  transform: scale(1);
  transition: transform .1s linear, opacity .1s linear;
  pointer-events: none;
}
.mic-btn.is-recording .mic-halo {
  border-color: var(--danger-halo);
  opacity: calc(.4 + var(--level, 0) * .6);
  transform: scale(calc(1 + var(--level, 0) * .3));
}

.dock-hint {
  margin: 6px 0 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
}

.file-picked {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 6px 6px 6px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.file-picked-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: 13px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 800;
  letter-spacing: .02em;
  text-decoration: none;
  cursor: pointer;
  transition: transform .1s ease, filter .15s ease, background .15s ease;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 7px 13px; font-size: 12.5px; }

.btn-primary { color: var(--on-accent); background: var(--accent); box-shadow: var(--accent-shadow); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.05); }
.btn-ghost { color: var(--blue-ink); background: var(--surface); border: 1px solid var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--blue-soft); }

/* ---------- Panels ---------- */

.panel {
  margin-bottom: 12px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.panel h2, .panel-title { margin: 0 0 8px; font-size: 16px; letter-spacing: -.01em; }
.panel-head { margin-bottom: 10px; }
.panel-head h2 { margin-bottom: 2px; }

.streak-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--streak-bg);
  border-color: var(--amber-border);
}
.streak-big { display: inline-flex; align-items: baseline; gap: 6px; }
.streak-big span:first-child { font-size: 22px; }
.streak-big strong { font-size: 30px; line-height: 1; color: var(--amber-ink); font-variant-numeric: tabular-nums; }
.streak-big span:last-child { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.streak-panel .hint { flex: 1 1 160px; font-size: 12px; }

.field { margin-bottom: 12px; }
.field-label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

.select, .text-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
}
.select { font-weight: 600; }
.text-input { resize: vertical; min-height: 64px; }
.select:focus-visible, .text-input:focus-visible { background: var(--card); }

.setting-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
}
.setting-row:last-child { margin-bottom: 0; }
.setting-row input { width: 19px; height: 19px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.setting-row strong { display: block; font-size: 14px; }
.setting-row small { display: block; font-size: 12px; color: var(--muted); line-height: 1.4; }

.setting-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.setting-actions .status { margin: 0; }

.stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }

.file-name {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-drop {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 10px;
  padding: 11px;
  border: 1px dashed var(--blue-border);
  border-radius: 14px;
  background: var(--blue-soft);
  cursor: pointer;
}
.file-drop:active { background: var(--file-drop-active); }
.file-drop-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--card);
  font-size: 19px;
}
.file-drop-copy { display: flex; flex-direction: column; min-width: 0; }
.file-drop-copy strong { font-size: 13.5px; }
.file-drop-copy small { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.report-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

/* ---------- Analysis ---------- */

.analysis { margin-top: 12px; }
.analysis-head { margin: 0 0 6px; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

.gap-list { display: flex; flex-direction: column; gap: 6px; }
.gap-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 10px;
  padding: 7px 9px;
  border-radius: 10px;
  background: var(--surface);
  font-size: 13px;
}
.gap-left { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; min-width: 0; }
.gap-values { color: var(--muted); white-space: nowrap; font-size: 12px; }
.gap-delta, .gap-percent { justify-self: end; }
.gap-delta {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.gap-delta.up { background: var(--amber-soft); color: var(--amber-ink); }
.gap-delta.down { background: var(--red-soft); color: var(--red-ink); }
.gap-delta.flat { background: var(--accent-soft); color: var(--accent-ink); }
.gap-percent { color: var(--muted); font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.tag {
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber-ink);
  font-size: 9.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.notes { margin: 10px 0 0; padding-left: 18px; font-size: 13px; }
.notes li { margin-bottom: 5px; }

.empty {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 13px;
}
.empty p { margin: 0; }
.empty-icon { font-size: 20px; }

/* ---------- Trends ---------- */

.trends-grid { display: flex; flex-direction: column; gap: 8px; }

.trend-row {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.trend-row:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.trend-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.trend-label {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.trend-latest {
  font-size: 16px;
  font-weight: 800;
  color: var(--accent-ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sparkline {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 100 / 32;
  overflow: visible;
}
.spark-line {
  fill: none;
  stroke: var(--accent-ink);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.spark-dot { fill: var(--accent-ink); stroke: var(--card); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark-empty { stroke: var(--spark-empty); stroke-width: 2.4; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }

.trend-history {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}
.trend-point {
  display: flex;
  flex-direction: column;
  min-width: 52px;
  padding: 4px 7px;
  border-radius: 8px;
  background: var(--card);
}
.trend-point-value { font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.trend-point-time { font-size: 10px; color: var(--muted); }

/* ---------- Accessibility + motion ---------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:where(button, a, input, select, textarea, summary, label):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .55; }
  30% { transform: translateY(-4px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .thread { scroll-behavior: auto; }
}

/* ---------- Tablet ---------- */

@media (min-width: 600px) {
  .view { padding: 18px 22px 24px; }
  .view-practice { padding: 16px 22px 0; }
  .view-head h1 { font-size: 27px; }
  .bubble { max-width: min(76%, 600px); font-size: 15.5px; }
  .mic-btn { width: 76px; height: 76px; }
  .dock { margin: 0 -22px; padding: 10px 22px 12px; }
  .trends-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .panel { padding: 16px; }
  .dock-hint { font-size: 12px; }
}

/* Tablets: a floating, centred tab pill reads better than a stretched bar. */
@media (min-width: 600px) and (max-width: 939px) {
  .tabbar {
    width: min(560px, calc(100% - 32px));
    margin: 0 auto calc(8px + env(safe-area-inset-bottom));
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow-sm);
  }
}

/* ---------- Wide screens: sidebar navigation ---------- */

@media (min-width: 940px) {
  body { overflow: hidden; }

  .app {
    display: grid;
    grid-template-columns: 228px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 14px 20px;
    max-width: 1120px;
    margin: 0 auto;
    padding: 16px 20px 18px;
  }

  .appbar {
    grid-column: 1 / -1;
    padding: 2px 4px;
    background: transparent;
    border: 0;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .brand-mark { width: 38px; height: 38px; }
  .brand-name { font-size: 20px; }

  .tabbar {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-self: start;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
  }
  .tab {
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    min-height: 44px;
    padding: 9px 12px;
    font-size: 13.5px;
    border-radius: 12px;
  }
  .tab:active { background: var(--accent-soft); }

  .views { grid-column: 2; grid-row: 2; }

  .view { padding: 0 4px 8px 0; }

  .view-practice {
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow: hidden;
    padding: 0;
  }

  .thread { padding: 4px 4px 12px; }
  .dock { margin: 0; border: 1px solid var(--line); border-radius: 18px; padding: 10px 14px 12px; }
  .view-head { margin-top: 0; }
}

/* Keep the new theme action on the same appbar row on phones: the word
   "day streak" is redundant next to the flame + number at these widths. */
@media (max-width: 430px) {
  .appbar { gap: 6px; }
  .appbar-actions { gap: 6px; }
  .streak-word { display: none; }
  .theme-toggle { width: 36px; height: 36px; }
}

/* ---------- Small phones ---------- */

@media (max-width: 380px) {
  .view { padding: 12px 11px 20px; }
  .view-head h1 { font-size: 21px; }
  .dock { margin: 0 -11px; padding: 8px 11px 10px; }
  .brand-name { font-size: 16px; }
  .step-label { display: none; }
  .mic-btn { width: 62px; height: 62px; }
  .bubble { max-width: 90%; }
  .thread { gap: 10px; }
}

/* ---------- Short screens (phone landscape) ---------- */

@media (max-height: 520px) and (max-width: 939px) {
  .session-strip, .baseline-banner { display: none; }
  .view-head.compact { margin-bottom: 4px; }
  .view-head h1 { font-size: 19px; }
  .mic-btn { width: 56px; height: 56px; }
  .dock-hint { display: none; }
  .thread-empty { padding: 4px; }
  .thread-empty-icon { display: none; }
}
