/* RETSOF design system.
   One stylesheet for both screens. Everything visual comes from the
   variables below; the dark theme only swaps colour and surface values. */

:root {
  /* Type: four sizes only, plus one display size for the welcome screen */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro", "Segoe UI", Inter, sans-serif;
  --text-display: clamp(2.75rem, 13vw, 5.5rem);
  --text-title: 2.125rem;
  --text-section: 1.25rem;
  --text-body: 1rem;
  --text-caption: 0.8125rem;
  --leading: 1.55;
  --leading-tight: 1.2;

  /* Shape and space */
  --radius-card: 16px;
  --radius-bubble: 18px;
  --radius-field: 14px;
  --radius-pill: 999px;
  --column: 720px;
  --gutter: 20px;
  --header-height: 52px;

  /* Motion */
  --fast: 150ms;
  --step: 400ms; /* signup: one step to the next */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* Colour: light theme */
  color-scheme: light;
  --bg: #f5f5f7;
  --bg-translucent: rgba(245, 245, 247, 0.8);
  --surface: #ffffff;
  --field: #ffffff;
  --bubble: #e9e9eb;
  --fill: rgba(0, 0, 0, 0.05);
  --fill-hover: rgba(0, 0, 0, 0.09);
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --line: rgba(0, 0, 0, 0.1);
  --card-border: transparent;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 24px rgba(0, 0, 0, 0.06);
  --shadow-float: 0 2px 6px rgba(0, 0, 0, 0.08), 0 12px 32px rgba(0, 0, 0, 0.14);
  --scrim: rgba(0, 0, 0, 0.22);
  --accent: #e86a00;
  --accent-hover: #cf5e00;
  --accent-ink: #b85400; /* papaya for small marks on a light ground */
  --on-accent: #ffffff;
  --red: #c41220;
  --red-fill: #fff0ef;
  --red-line: rgba(196, 18, 32, 0.22);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1c1c1e;
  --bg-translucent: rgba(28, 28, 30, 0.8);
  --surface: #2c2c2e;
  --field: #1c1c1e;
  --bubble: #3a3a3c;
  --fill: rgba(255, 255, 255, 0.08);
  --fill-hover: rgba(255, 255, 255, 0.14);
  --text: #f5f5f7;
  --text-secondary: #a1a1a6;
  --line: rgba(255, 255, 255, 0.12);
  --card-border: rgba(255, 255, 255, 0.1);
  --shadow-card: none;
  --shadow-float: 0 12px 32px rgba(0, 0, 0, 0.5);
  --scrim: rgba(0, 0, 0, 0.5);
  --accent: #ff8000;
  --accent-hover: #ff9326;
  --accent-ink: #ff8000;
  --red: #ff6b62;
  --red-fill: rgba(255, 69, 58, 0.12);
  --red-line: rgba(255, 105, 97, 0.3);
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--text-body)/var(--leading) var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }

button, input, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.muted { color: var(--text-secondary); }

.label {
  display: block;
  font-size: var(--text-caption);
  font-weight: 500;
  color: var(--text-secondary);
}

.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;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
}

@keyframes fade {
  from { opacity: 0; }
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1); }
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-translucent);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(var(--column) + 2 * var(--gutter));
  height: var(--header-height);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.header-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.brand {
  font-weight: 600;
  letter-spacing: 0.14em;
}

.header-meta {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-size: var(--text-caption);
  color: var(--text-secondary);
  white-space: nowrap;
}

.chief { color: var(--text); font-weight: 600; }

.theme-toggle {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-right: -6px;
  padding: 0;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: background var(--fast), color var(--fast), transform var(--fast);
}

.theme-toggle:hover { background: var(--fill); color: var(--text); }
.theme-toggle:active { transform: scale(0.92); }

/* The icon shows what a click switches to. */
.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; }

/* ---------- Page ---------- */

.page {
  max-width: calc(var(--column) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter) 150px;
}

.page-title {
  padding-top: 40px;
  font-size: var(--text-title);
  font-weight: 700;
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
}

#boot { padding-top: 24px; }

.section {
  margin-top: 48px;
  animation: fade 0.5s ease-out both;
}

.section-title {
  margin-bottom: 16px;
  font-size: var(--text-section);
  font-weight: 600;
  line-height: var(--leading-tight);
  letter-spacing: -0.01em;
}

.count {
  margin-left: 4px;
  font-size: var(--text-caption);
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-secondary);
}

/* ---------- Cards ---------- */

.cards { display: grid; gap: 16px; }

.card {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

/* Cards rise in on load only; app.js adds .is-settled so that later
   re-renders (after Approve) do not replay the entrance. */
body:not(.is-settled) .cards > .card { animation: rise 0.6s var(--ease-out) both; }
body:not(.is-settled) .cards > .card:nth-child(2) { animation-delay: 70ms; }
body:not(.is-settled) .cards > .card:nth-child(3) { animation-delay: 140ms; }
body:not(.is-settled) .cards > .card:nth-child(n + 4) { animation-delay: 210ms; }

.card-sentence { margin-top: 6px; font-weight: 600; }
.card-recommendation { margin-top: 4px; color: var(--text-secondary); }

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

/* Red lives here and nowhere else. */
.card-wrong {
  background: var(--red-fill);
  border-color: var(--red-line);
  box-shadow: none;
}

.card-wrong .label { color: var(--red); font-weight: 600; }
.card-wrong .card-recommendation { color: var(--text); }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 18px;
  font-weight: 500;
  color: var(--text);
  background: var(--fill);
  border: 0;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--fast), opacity var(--fast), transform var(--fast);
}

.btn:hover { background: var(--fill-hover); }
.btn:active { transform: scale(0.97); }

.btn-primary { color: var(--on-accent); background: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }

.btn:disabled { opacity: 0.45; cursor: default; transform: none; }

.btn-quiet {
  min-height: 32px;
  padding: 0 12px;
  font-size: var(--text-caption);
  color: var(--text-secondary);
  background: transparent;
}

.btn-quiet:hover { color: var(--text); }

.btn-large { min-height: 50px; padding: 0 28px; font-weight: 600; }

/* ---------- Disclosure rows ---------- */

summary { list-style: none; cursor: pointer; }
summary::-webkit-details-marker { display: none; }

.decided { margin-top: 16px; }

.decided summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin-left: -10px;
  font-size: var(--text-caption);
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-pill);
  transition: background var(--fast);
}

.decided summary:hover { background: var(--fill); }

.decided summary::after,
.bot summary::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--text-secondary);
  border-bottom: 1.5px solid var(--text-secondary);
  transform: translateY(-2px) rotate(45deg);
  transition: transform var(--fast);
}

.decided[open] summary::after,
.bot[open] summary::after { transform: translateY(2px) rotate(225deg); }

.decided-items {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  font-size: var(--text-caption);
  color: var(--text-secondary);
}

.decided-mark {
  margin-right: 8px;
  padding: 2px 8px;
  font-weight: 600;
  color: var(--text);
  background: var(--fill);
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

/* ---------- Today: one grouped list ---------- */

.today-list {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.today-list > li + li { border-top: 1px solid var(--line); }

.bot summary {
  position: relative;
  padding: 14px 48px 14px 20px;
  transition: background var(--fast);
}

.bot summary:hover { background: var(--fill); }
.bot summary:focus-visible { outline-offset: -2px; }

.bot summary::after {
  position: absolute;
  top: 23px;
  right: 22px;
}

.bot-name { font-weight: 600; }

.bot-report { padding: 2px 20px 20px; animation: fade 0.3s ease-out; }

.bot-report p {
  margin-top: 6px;
  white-space: pre-line;
}

/* ---------- Side panel ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--scrim);
  animation: fade 0.3s ease-out;
}

.panel {
  position: fixed;
  top: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100% - 24px));
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  box-shadow: var(--shadow-float);
  animation: panel-in 0.42s var(--ease-out);
}

@keyframes panel-in {
  from { transform: translateX(calc(100% + 12px)); }
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-head h2 {
  font-size: var(--text-section);
  font-weight: 600;
  line-height: var(--leading-tight);
  letter-spacing: -0.01em;
}

.panel-head .btn-quiet { margin-right: -8px; }

.panel-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  margin: 0 -6px 16px;
  padding: 4px 6px;
  overflow-y: auto;
}

.panel-form {
  flex: none;
  display: grid;
  gap: 10px;
}

.panel-form .btn { justify-self: end; }

textarea,
.other-text {
  width: 100%;
  padding: 11px 14px;
  line-height: 1.4;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--radius-field);
  transition: border-color var(--fast), box-shadow var(--fast);
}

textarea { display: block; resize: none; }

textarea:focus,
.other-text:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

textarea::placeholder,
.other-text::placeholder { color: var(--text-secondary); opacity: 1; }

.panel textarea { background: var(--bg); }

/* ---------- Chat bubbles (panel and signup) ---------- */

.msg {
  max-width: 85%;
  padding: 9px 14px;
  border-radius: var(--radius-bubble);
  white-space: pre-line;
  overflow-wrap: anywhere;
  animation: rise 0.4s var(--ease-out);
}

.msg-chief {
  align-self: flex-start;
  background: var(--bubble);
  border-bottom-left-radius: 6px;
}

.msg-user {
  align-self: flex-end;
  color: var(--on-accent);
  background: var(--accent);
  border-bottom-right-radius: 6px;
}

/* An answer that could not be given: outlined, so it does not read as one. */
.msg-error {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

/* Thinking: one soft pulsing dot. The word stays for screen readers. */
.thinking {
  padding: 14px 16px;
  font-size: 0;
}

.thinking::before {
  content: "";
  display: block;
  width: 9px;
  height: 9px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: pulse 1.4s ease-in-out infinite;
}

/* ---------- Signup: seven steps, all clicks ---------- */

.step-count {
  font-size: var(--text-caption);
  color: var(--text-secondary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* The slim progress indicator: one segment per step, on the header's lower edge. */
.progress {
  display: flex;
  gap: 4px;
  max-width: calc(var(--column) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter) 8px;
}

.progress span {
  flex: 1;
  height: 3px;
  background: var(--fill-hover);
  border-radius: 2px;
  transition: background var(--step) ease;
}

.progress span.is-on { background: var(--accent); }

.page.signup {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--header-height) - 12px);
  min-height: calc(100svh - var(--header-height) - 12px);
  padding-bottom: 0;
  overflow-x: clip; /* a sliding step must not widen the page */
}

/* One step shows at a time. Moving on slides the old one out and the new one
   in, with a fade; --dir is 1 going forward and -1 going back (signup.js). */
.steps {
  position: relative;
  flex: 1;
  padding-bottom: 32px;
}

.step.is-entering { animation: step-in var(--step) var(--ease-out) both; }

.step.is-leaving {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  pointer-events: none;
  animation: step-out 220ms ease both;
}

@keyframes step-in {
  from { opacity: 0; transform: translateX(calc(var(--dir, 1) * 32px)); }
}

@keyframes step-out {
  to { opacity: 0; transform: translateX(calc(var(--dir, 1) * -32px)); }
}

.step .page-title { text-wrap: balance; }
.step .page-title:focus { outline: none; }

.step-hint {
  margin: 8px 0 28px;
  color: var(--text-secondary);
}

.is-swapped { animation: fade var(--step) ease both; }

/* Back and Continue stay at the foot of the screen on every step. */
.step-nav {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 calc(-1 * var(--gutter));
  padding: 12px var(--gutter) max(16px, env(safe-area-inset-bottom));
  background: var(--bg-translucent);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
}

.step-nav .btn { min-height: 46px; padding: 0 22px; }
.step-nav .btn-primary { min-width: 132px; font-weight: 600; }

/* Step 1: large tiles, pick one. */
.tiles {
  position: relative; /* the chosen tile's offset is measured from here */
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  min-height: 132px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease, transform var(--fast);
}

.tile:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.tile:active { transform: scale(0.98); }

.tile-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: var(--text-secondary);
  background: var(--fill);
  border-radius: 12px;
  transition: color 0.25s ease, background 0.25s ease;
}

.tile-title { font-weight: 600; line-height: 1.3; }

/* The tick in the corner says "selected" without relying on colour alone. */
.tile-mark {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  transition: background 0.25s ease, border-color 0.25s ease;
}

.tile-mark::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2.5px;
  width: 5px;
  height: 9px;
  border-right: 2px solid var(--surface);
  border-bottom: 2px solid var(--surface);
  transform: rotate(45deg) scale(0.4);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.25s var(--ease-out);
}

.tile:has(input:checked) {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.tile:has(input:checked) .tile-icon {
  color: var(--accent-ink);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.tile:has(input:checked) .tile-mark { background: var(--accent); border-color: var(--accent); }
.tile:has(input:checked) .tile-mark::after { opacity: 1; transform: rotate(45deg) scale(1); }
.tile:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Step 2: the follow-up chips open in place, as a full-width row under the
   chosen tile's row. Closed, the row has no height and gives back its gap. */
.details {
  position: relative;
  grid-column: 1 / -1;
  display: grid;
  grid-template-rows: 0fr;
  margin-top: -12px;
  opacity: 0;
  scroll-margin: calc(var(--header-height) + 24px) 0 96px;
  transition: grid-template-rows var(--step) var(--ease-out), margin-top var(--step) var(--ease-out), opacity var(--step) ease;
}

.details.is-open {
  grid-template-rows: 1fr;
  margin-top: 0;
  opacity: 1;
}

.details.no-anim,
.details.no-anim::before { transition: none; }

.details-inner {
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

/* A small pointer from the panel up to the tile it belongs to. */
.details::before {
  content: "";
  position: absolute;
  top: -6px;
  left: var(--caret-x, 50%);
  width: 12px;
  height: 12px;
  margin-left: -6px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  border-top-left-radius: 3px;
  transform: rotate(45deg);
}

.details-body {
  display: grid;
  gap: 20px;
  padding: 20px;
}

.chip-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.chip-group legend { margin-bottom: 10px; padding: 0; }

/* Chips: tap to switch on, tap again to switch off. */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 16px;
  font-weight: 500;
  line-height: 1.25;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease, transform var(--fast);
}

.details .chip { background: var(--bg); }

.chip:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.chip:active { transform: scale(0.97); }

/* The tick grows in beside the words, so "on" never depends on colour alone. */
.chip-tick {
  position: relative;
  flex: none;
  width: 0;
  height: 12px;
  opacity: 0;
  transition: width 0.25s var(--ease-out), margin 0.25s var(--ease-out), opacity 0.2s ease;
}

.chip-tick::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 0;
  width: 5px;
  height: 9px;
  border-right: 2px solid var(--accent-ink);
  border-bottom: 2px solid var(--accent-ink);
  transform: rotate(45deg);
}

.chip:has(input:checked) {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.chip:has(input:checked) .chip-tick { width: 13px; margin-right: 8px; opacity: 1; }
.chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.chips-large { gap: 12px; }
.chips-large .chip { min-height: 52px; padding: 0 22px; }

.other-text { min-height: 48px; }
.details .other-text { background: var(--bg); }

/* Step 4: each chosen chip, written out as the rule it becomes. */
.rules { margin-top: 36px; }
.rules .label { margin-bottom: 10px; }
.rules-list { display: grid; gap: 8px; }

.rules-list li {
  padding: 12px 16px;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-field);
  box-shadow: var(--shadow-card);
}

.rules-list li.is-new { animation: rise var(--step) var(--ease-out) both; }

/* Step 6: one small field under the suggested names. */
.name-own {
  display: block;
  max-width: 260px;
  margin-top: 20px;
}

/* Step 7: the proposed team. */
.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}

.role-card { display: flex; flex-direction: column; }
.role-name { font-size: var(--text-body); font-weight: 600; }
.role-name::first-letter { text-transform: uppercase; }
.role-description { flex: 1; margin-top: 4px; color: var(--text-secondary); }
.role-card .btn { align-self: flex-start; margin-top: 16px; }
.role-note { margin-top: 16px; font-size: var(--text-caption); line-height: 40px; }

.team-restore { margin: 16px 0 0 -12px; }
.team-error { margin-top: 16px; font-size: var(--text-caption); }

/* ---------- Welcome ---------- */

/* One screen, centred. The name is the only place the display size is used. */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100svh;
  padding: 48px var(--gutter) max(48px, env(safe-area-inset-bottom));
  text-align: center;
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

/* The welcome screen has its own ground: warm off-white in light, near-black
   in dark, and dark text on the papaya button. Home and signup are untouched. */
:root.on-welcome {
  --bg: #fbf6ef;
  --on-accent: #1d1d1f;
  --welcome-glow: color-mix(in srgb, var(--accent) 34%, transparent);
  --welcome-glow-soft: color-mix(in srgb, var(--accent) 13%, transparent);
}

:root.on-welcome[data-theme="dark"] {
  --bg: #0a0a0b;
  --welcome-glow: color-mix(in srgb, var(--accent) 50%, transparent);
  --welcome-glow-soft: color-mix(in srgb, var(--accent) 17%, transparent);
}

/* A large soft papaya glow rising from the bottom edge, drifting slowly. */
.welcome::before {
  content: "";
  position: absolute;
  inset: 0 -30% -2%;
  z-index: -1;
  background:
    radial-gradient(58% 52% at 50% 100%, var(--welcome-glow), var(--welcome-glow-soft) 48%, transparent 76%),
    radial-gradient(34% 30% at 68% 100%, var(--welcome-glow-soft), transparent 72%);
  transform-origin: 50% 100%;
  animation: drift 22s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes drift {
  from { transform: translate3d(-7%, 0, 0) scale(1, 0.94); }
  to { transform: translate3d(7%, 0, 0) scale(1.08, 1.1); }
}

@keyframes blink {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 0.1; }
}

.welcome > * { animation: rise 0.7s var(--ease-out) both; }
.welcome > :nth-child(2) { animation-delay: 80ms; }
.welcome > :nth-child(3) { animation-delay: 160ms; }
.welcome > :nth-child(4) { animation-delay: 240ms; }

/* While the sentence types (welcome.js), the button and card wait, keeping
   their space; then they fade in, button first. */
.welcome.is-typing > .btn,
.welcome.is-typing > .welcome-card {
  visibility: hidden;
  animation: none;
}

.welcome.is-typed > .btn { animation: fade 0.8s ease-out both; }
.welcome.is-typed > .welcome-card { animation: fade 0.9s ease-out 0.6s both; }

.welcome-untyped { visibility: hidden; }

/* Zero-width, so the cursor never moves the letters around it. */
.welcome-cursor { position: relative; }

.welcome-cursor::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.1em;
  bottom: 0.1em;
  width: 2px;
  background: var(--accent);
  border-radius: 1px;
  animation: blink 1.1s ease-in-out infinite;
}

.welcome.is-typed .welcome-cursor::after { animation: blink 1.1s ease-in-out 3, fade 0.6s ease-in 3.3s reverse forwards; }

/* A home-screen decision card, with its lines stacked so they can crossfade. */
.welcome-card {
  display: grid;
  align-items: center;
  width: min(100%, 340px);
  margin-top: 40px;
  text-align: left;
}

.welcome-card-line {
  grid-area: 1 / 1;
  margin-top: 0;
  opacity: 0;
  transition: opacity 0.9s ease;
}

.welcome-card-line.is-current { opacity: 1; }

.welcome-name {
  /* The tracking adds space after the last letter; pull it back to stay centred. */
  margin-right: -0.14em;
  font-size: var(--text-display);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.14em;
}

.welcome-line {
  max-width: 24em;
  margin-top: 20px;
  font-size: var(--text-section);
  line-height: 1.4;
  color: var(--text-secondary);
  text-wrap: balance;
}

.welcome .btn {
  margin-top: 40px;
  text-decoration: none;
}

/* ---------- Phone ---------- */

@media (max-width: 520px) {
  :root {
    --text-title: 1.75rem;
    --gutter: 16px;
  }

  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { min-height: 124px; padding: 14px; }
  .tile-mark { top: 12px; right: 12px; }
  .details { margin-top: -10px; }
  .details-body { padding: 16px; }
  .step-hint { margin-bottom: 22px; }
  .step-nav .btn { flex: 1 1 0; }
  .step-nav .btn-primary { flex-grow: 2; }
  .name-own { max-width: none; }

  .welcome-line { font-size: 1.0625rem; }
  .welcome .btn { margin-top: 32px; }

  .header-meta {
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    line-height: 1.3;
  }

  .page-title { padding-top: 28px; }
  .section { margin-top: 40px; }
  .card { padding: 18px; }
  .card-actions .btn { flex: 1 1 0; }
  .msg { max-width: 88%; }

  .panel {
    inset: 0;
    width: 100%;
    padding: 16px;
    border: 0;
    border-radius: 0;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- Live data: source label, practice book, activity feed ---------- */

.data-source {
  margin-top: 6px;
  font-size: var(--text-caption);
  color: var(--text-secondary);
}

.data-label {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 9px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--fill);
  border-radius: var(--radius-pill);
}

.section-book { margin-top: 28px; }

.book-worth {
  margin-top: 2px;
  font-size: var(--text-title);
  font-weight: 700;
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.book-today { margin-top: 4px; font-weight: 600; font-variant-numeric: tabular-nums; }
.book-facts { font-size: var(--text-caption); }
.book-missing { margin-top: 6px; }

.bot-note { font-size: var(--text-caption); }

.feed {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.feed > li {
  display: flex;
  gap: 16px;
  padding: 12px 20px;
}

.feed > li + li { border-top: 1px solid var(--line); }

.feed-time {
  flex: none;
  width: 6.5rem;
  padding-top: 3px;
  font-size: var(--text-caption);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.feed-text { min-width: 0; overflow-wrap: anywhere; }

@media (max-width: 520px) {
  .feed > li { flex-direction: column; gap: 0; padding: 12px 18px; }
  .feed-time { width: auto; padding-top: 0; }
}

.cards + .muted { margin-top: 12px; }

/* ---------- Sign-in and settings ---------- */

.header-nav { flex: none; display: flex; align-items: center; gap: 4px; }
.header-nav .btn { text-decoration: none; }
.brand-link { color: inherit; text-decoration: none; }

.auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: calc(400px + 2 * var(--gutter));
  margin: 0 auto;
  padding: clamp(40px, 12vh, 120px) var(--gutter) 80px;
  text-align: center;
}

.auth-title {
  font-size: var(--text-title);
  font-weight: 700;
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
}

.auth-hint { margin-top: 8px; color: var(--text-secondary); }
.auth-card { width: 100%; margin-top: 28px; padding: 24px; text-align: left; animation: rise 0.6s var(--ease-out) both; }
.auth-submit { width: 100%; margin-top: 20px; }
.auth-foot { margin-top: 18px; font-size: var(--text-caption); color: var(--text-secondary); }

.field { display: block; margin-top: 16px; }
.field:first-of-type { margin-top: 0; }
.form-note + .field { margin-top: 16px; }
.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: var(--text-caption);
  font-weight: 500;
  color: var(--text-secondary);
}

.field input {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--radius-field);
  transition: border-color var(--fast), box-shadow var(--fast);
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.code-input { font-variant-numeric: tabular-nums; font-size: 1.25rem; letter-spacing: 0.3em; text-align: center; }

.form-note {
  margin-bottom: 4px;
  padding: 10px 14px;
  font-size: var(--text-caption);
  border-radius: var(--radius-field);
}

.form-note-error { color: var(--red); background: var(--red-fill); border: 1px solid var(--red-line); }
.form-note-ok { color: var(--accent-ink); background: color-mix(in srgb, var(--accent) 12%, transparent); }

.settings form { max-width: 420px; }
.settings form .btn { margin-top: 18px; }
.settings .card > .muted { margin-bottom: 16px; }
.settings .signout { margin-top: 40px; }

.facts { display: grid; gap: 14px; margin: 0; }
.facts > div { display: flex; justify-content: space-between; gap: 16px; }
.facts dt { color: var(--text-secondary); }
.facts dd { margin: 0; font-weight: 500; text-align: right; overflow-wrap: anywhere; }

.qr-wrap { width: 208px; max-width: 100%; margin: 16px 0; padding: 8px; background: #fff; border-radius: 12px; }
.qr { display: block; width: 100%; height: auto; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--text-caption); overflow-wrap: anywhere; user-select: all; }
.twofa-new form { margin-top: 16px; }

.audit-card { overflow-x: auto; }
.audit { width: 100%; border-collapse: collapse; font-size: var(--text-caption); }
.audit th { padding: 0 12px 8px 0; font-weight: 500; color: var(--text-secondary); text-align: left; }
.audit td { padding: 8px 12px 8px 0; border-top: 1px solid var(--line); vertical-align: top; }
.audit td:first-child { white-space: nowrap; }

.header-icon { margin-right: 0; text-decoration: none; }
.header-meta { min-width: 0; }
.header-meta time { overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 520px) { .header-meta time { max-width: 100%; } }


/* ---------- Screens: trail, tabs, transitions ---------- */

.crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  max-width: calc(var(--column) + 2 * var(--gutter));
  min-height: 44px;
  margin: 0 auto;
  padding: 12px calc(var(--gutter) - 8px) 0;
  font-size: var(--text-caption);
  color: var(--text-secondary);
}

.crumbs a,
.crumb-here,
.crumb-back {
  padding: 4px 8px;
  border-radius: var(--radius-pill);
}

.crumbs a { color: inherit; text-decoration: none; transition: background var(--fast), color var(--fast); }
.crumbs a:hover { color: var(--text); background: var(--fill); }
.crumb-here { font-weight: 600; color: var(--text); animation: fade 0.4s ease-out; }
.crumb-sep { opacity: 0.55; }

.crumb-back {
  margin-right: 6px;
  font: inherit;
  font-weight: 500;
  color: var(--accent-ink);
  background: var(--fill);
  border: 0;
  cursor: pointer;
}

.crumb-back:hover { background: var(--fill-hover); }

.crumbs + .page .page-title { padding-top: 20px; }

@keyframes screen-in {
  from { opacity: 0; transform: translateX(28px); }
}

.screen-in { animation: screen-in 0.45s var(--ease-out) both; }

.screen-note { margin-top: 24px; }

.tabs {
  display: inline-flex;
  gap: 2px;
  margin-top: 22px;
  padding: 3px;
  background: var(--fill);
  border-radius: var(--radius-pill);
}

.tabs a {
  padding: 6px 16px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-pill);
  transition: background var(--fast), color var(--fast);
}

.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--text); background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
:root[data-theme="dark"] .tabs a[aria-current="page"] { background: var(--fill-hover); box-shadow: none; }

.tab-panel { margin-top: 24px; animation: fade 0.35s ease-out; }

.report-text { margin-top: 10px; white-space: pre-line; overflow-wrap: anywhere; }

.btn-small { min-height: 34px; padding: 0 14px; font-size: 0.9375rem; text-decoration: none; display: inline-flex; align-items: center; }

/* ---------- Stan's decisions ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  padding: 6px 14px;
  font-size: var(--text-caption);
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  background: var(--fill);
  border-radius: var(--radius-pill);
  transition: background var(--fast), color var(--fast);
}

.chip:hover { color: var(--text); background: var(--fill-hover); }
.chip[aria-current="true"] { color: var(--on-accent); background: var(--accent); }

.notice {
  margin-top: 16px;
  padding: 10px 14px;
  font-size: 0.9375rem;
  background: var(--fill);
  border-radius: var(--radius-field);
}

.notice a { color: var(--accent-ink); }

.decisions { margin-top: 16px; padding: 4px; border-radius: 20px; }
.decisions > .card { margin-top: 8px; }
.day-label { padding: 0 4px; }
.group { margin-top: 28px; border-radius: 20px; }
.group .section-title { margin-bottom: 12px; padding: 0 4px; }

/* ---------- Live activity ---------- */

.live-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.live-status { color: var(--text-secondary); font-size: 0.9375rem; }
.live-status.is-live { color: var(--text); font-weight: 600; }

.live-status.is-live::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1.4s ease-in-out infinite;
}

.live-raw-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-caption);
  color: var(--text-secondary);
  cursor: pointer;
}

.live-raw-toggle input { accent-color: var(--accent); }

.live-steps {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.live-steps > li { display: flex; gap: 14px; padding: 12px 20px; }
.live-steps > li + li { border-top: 1px solid var(--line); }
.live-steps .feed-time { flex: none; width: 4.6em; padding-top: 2px; font-size: var(--text-caption); font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.live-warn .feed-text, .live-error .feed-text { color: var(--red); }
.live-warn .bot-name, .live-error .bot-name { color: var(--text); }
.live-step.is-fresh { animation: rise 0.5s var(--ease-out); }
.live-link { margin-left: 4px; font-size: var(--text-caption); font-weight: 500; color: var(--accent-ink); text-decoration: none; white-space: nowrap; }
.live-link:hover { text-decoration: underline; }

.live-raw {
  display: none;
  margin-top: 6px;
  padding: 6px 8px;
  font: 0.75rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-secondary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--fill);
  border-radius: 8px;
}

.show-raw .live-raw { display: block; }

/* ---------- The highlight ring ---------- */

@keyframes ring-in {
  from { box-shadow: 0 0 0 0 var(--accent), 0 0 0 0 transparent; }
}

.is-ringed {
  position: relative;
  z-index: 2;
  border-radius: var(--radius-card);
  box-shadow: 0 0 0 3px var(--accent), 0 0 0 10px rgba(232, 106, 0, 0.18) !important;
  animation: ring-in 0.6s var(--ease-out);
  scroll-margin: 110px;
}

:root[data-theme="dark"] .is-ringed { box-shadow: 0 0 0 3px var(--accent), 0 0 0 10px rgba(255, 128, 0, 0.22) !important; }

.is-ringed[data-ring-note]::after {
  content: attr(data-ring-note);
  position: absolute;
  top: calc(100% + 14px);
  left: 12px;
  z-index: 6;
  max-width: min(360px, calc(100% - 24px));
  padding: 7px 12px;
  font-size: var(--text-caption);
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0;
  color: var(--on-accent);
  white-space: normal;
  background: var(--accent);
  border-radius: 12px;
  box-shadow: var(--shadow-float);
  animation: rise 0.4s var(--ease-out) 0.15s both;
}

/* Inside the Today list the ring cannot spill outside the card, so it is drawn inside the row and the
   caption sits in the row. */
.today-list > li.is-ringed { border-radius: 0; box-shadow: inset 0 0 0 3px var(--accent) !important; }
.today-list > li.is-ringed[data-ring-note]::after { position: static; display: block; max-width: none; margin: 0 20px 16px; box-shadow: none; }

/* ---------- Command bar ---------- */

.cmd {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 4px;
  width: min(580px, calc(100% - 32px));
  height: 54px;
  padding: 0 7px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-float);
  transform: translateX(-50%);
  transition: border-color var(--fast), box-shadow var(--fast);
}

.cmd:focus-within,
.cmd.is-listening { border-color: var(--accent); box-shadow: var(--shadow-float), 0 0 0 4px rgba(232, 106, 0, 0.16); }

.cmd input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 6px;
  font-size: 1rem;
  background: transparent;
  border: 0;
  outline: none;
}

.cmd input::placeholder { color: var(--text-secondary); opacity: 1; }

.cmd-mic,
.cmd-send {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  touch-action: none;
  transition: background var(--fast), color var(--fast), transform var(--fast);
}

.cmd-mic:hover, .cmd-send:hover { color: var(--text); background: var(--fill); }
.cmd-mic:active, .cmd-send:active { transform: scale(0.93); }
.cmd-mic:disabled { opacity: 0.35; cursor: default; }
.cmd-send { color: var(--on-accent); background: var(--accent); }
.cmd-send:hover { color: var(--on-accent); background: var(--accent-hover); }
.cmd.is-busy .cmd-send { opacity: 0.5; }

@keyframes mic-halo {
  from { box-shadow: 0 0 0 0 rgba(232, 106, 0, 0.5); }
  to { box-shadow: 0 0 0 12px rgba(232, 106, 0, 0); }
}

.cmd-mic.is-listening { color: var(--on-accent); background: var(--accent); animation: mic-halo 1.2s ease-out infinite; }

.cmd-key {
  flex: none;
  margin-right: 4px;
  padding: 2px 7px;
  font: 500 0.6875rem/1.5 var(--font);
  color: var(--text-secondary);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.cmd:focus-within .cmd-key { display: none; }

/* ---------- Step list (what the command is doing) ---------- */

.steps {
  position: fixed;
  right: 16px;
  bottom: 92px;
  z-index: 32;
  width: min(340px, calc(100% - 32px));
  max-height: min(62vh, 520px);
  padding: 14px 16px 14px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-float);
  animation: rise 0.3s var(--ease-out);
}

.steps-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.steps-close:hover { color: var(--text); background: var(--fill); }
.steps-heard { margin-right: 26px; font-size: var(--text-caption); color: var(--text-secondary); overflow-wrap: anywhere; }
.steps-heard:empty { display: none; }
.steps-list { margin-top: 8px; }
.steps-list:empty { display: none; }

.steps-list li {
  position: relative;
  padding: 3px 0 3px 22px;
  font-size: 0.9375rem;
  color: var(--text-secondary);
  animation: rise 0.3s var(--ease-out);
}

.steps-list li::before {
  content: "";
  position: absolute;
  top: 0.62em;
  left: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
}

.steps-list li.is-active { font-weight: 500; color: var(--text); }
.steps-list li.is-active::before { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.steps-list li.is-done::before { background: var(--accent); }
.steps-list li.is-missed { color: var(--red); }
.steps-list li.is-missed::before { background: var(--red); }

.steps-answer,
.steps-error { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.steps-error { color: var(--red); }
.steps-list:empty + .steps-extra > :first-child { margin-top: 6px; padding-top: 0; border-top: 0; }

.preview { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.preview .label + p { margin-top: 2px; }
.preview .label:not(:first-child) { margin-top: 10px; }
.preview-title { font-weight: 600; }
.preview-would { font-size: 0.9375rem; }

.preview-call {
  display: block;
  margin-top: 4px;
  padding: 8px 10px;
  font: 0.75rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
  background: var(--fill);
  border-radius: 8px;
}

.preview .btn { width: 100%; margin-top: 12px; }

@media (max-width: 520px) {
  .steps { right: 12px; bottom: 86px; width: calc(100% - 24px); max-height: 46vh; }
  .cmd-key { display: none; }
  .tabs { display: flex; }
  .tabs a { flex: 1; text-align: center; }
  .live-head { flex-direction: column; gap: 8px; }
  .live-steps > li { flex-direction: column; gap: 0; padding: 12px 18px; }
  .live-steps .feed-time { width: auto; }
}
