/* ==========================================================================
   Assignment Writer — paced writing for handwritten assignments
   Teal design language shared with the other Alok Systems tools.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --page: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;

  --brand: #14b8a6;
  --brand-deep: #0d9488;
  --brand-dark: #0f766e;
  --brand-soft: rgba(20, 184, 166, 0.1);
  --brand-ring: rgba(20, 184, 166, 0.22);

  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --success: #0d9488;

  --radius: 18px;
  --radius-sm: 12px;
  --radius-xs: 9px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 14px 34px -22px rgba(15, 23, 42, 0.28);
  --shadow-lg: 0 28px 70px -30px rgba(15, 23, 42, 0.35);

  /* Highlight + reader type (some values are set by script.js) */
  --hl-color: rgba(254, 231, 92, 0.55);
  --hl-radius: 6px;
  --hl-shade: rgba(15, 23, 42, 0.14);
  --write-size: 22px;
  --write-lh: 1.8;
  --write-ls: 0px;
  --write-width: 72ch;
  --write-family: var(--font-ui);

  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-write: Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

[data-theme="dark"] {
  --page: #0b1120;
  --surface: #101a2e;
  --surface-soft: #16233a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --line: #26354a;

  --brand: #2dd4bf;
  --brand-deep: #14b8a6;
  --brand-dark: #0d9488;
  --brand-soft: rgba(45, 212, 191, 0.12);
  --brand-ring: rgba(45, 212, 191, 0.28);

  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --success: #2dd4bf;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 16px 40px -24px rgba(0, 0, 0, 0.75);
  --shadow-lg: 0 30px 80px -34px rgba(0, 0, 0, 0.85);
  --hl-shade: rgba(0, 0, 0, 0.4);
}

/* ---------- Reset ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background:
    radial-gradient(900px 420px at 50% -160px, rgba(20, 184, 166, 0.09), transparent 70%),
    var(--page);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

[data-theme="dark"] body {
  background:
    radial-gradient(900px 420px at 50% -160px, rgba(45, 212, 191, 0.08), transparent 70%),
    var(--page);
}

h1, h2, h3, h4, p, dl, dd { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; flex: none; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--brand-ring);
  outline-offset: 2px;
  border-radius: 6px;
}

::selection { background: var(--brand); color: #fff; }

html { scroll-behavior: smooth; }

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

/* ---------- Views and page shell ---------- */
.view {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 44px 24px 72px;
}
.view[hidden] { display: none; }
.page-shell { width: 100%; }

/* ---------- Hero ---------- */
.hero {
  max-width: 780px;
  margin: 0 auto;
  padding: 4px 0 22px;
  text-align: center;
}
.eyebrow {
  margin: 0 0 12px;
  color: var(--brand-deep);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
[data-theme="dark"] .eyebrow { color: var(--brand); }

.hero h1 {
  margin: 0;
  font-size: clamp(1.75rem, 3.4vw, 2.4rem);
  line-height: 1.15;
  letter-spacing: -0.035em;
  text-wrap: balance;
  color: var(--text);
}

.hero-lead {
  max-width: 680px;
  margin: 10px auto 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.6;
  text-wrap: balance;
}

.privacy-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 14px auto 0;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}
.privacy-note svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--brand-deep);
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
[data-theme="dark"] .privacy-note svg { stroke: var(--brand); }

/* ---------- Panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 24px;
}
.panel + .panel { margin-top: 18px; }

.panel-heading {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 20px;
}
.panel-heading-copy { min-width: 0; flex: 1; }
.panel-heading h2 {
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}
.panel-heading p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.5;
}

.step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  border: 1px solid var(--brand-ring);
  border-radius: 11px;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}
[data-theme="dark"] .step-number { color: var(--brand); }

.panel-tool { margin-left: auto; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.87rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  transition:
    background-color 0.18s var(--ease),
    border-color 0.18s var(--ease),
    color 0.18s var(--ease),
    box-shadow 0.18s var(--ease),
    transform 0.08s linear;
  user-select: none;
}
.btn:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-dark);
}
[data-theme="dark"] .btn:hover { color: var(--brand); }
.btn:active { transform: translateY(1px); }

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 11px;
  color: var(--muted);
}
.btn-icon:hover { color: var(--brand-deep); }

.btn-sm {
  padding: 7px 12px;
  border-radius: var(--radius-xs);
  font-size: 0.8rem;
  background: var(--surface-soft);
  border-color: transparent;
}
.btn-sm:hover { background: var(--brand-soft); border-color: transparent; }

.btn-primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--brand-deep), var(--brand));
  color: #ffffff;
  box-shadow: 0 10px 24px -12px rgba(13, 148, 136, 0.7);
}
.btn-primary:hover {
  border-color: transparent;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #ffffff;
  box-shadow: 0 14px 28px -12px rgba(13, 148, 136, 0.8);
}
.btn-primary:active { transform: translateY(1px); }

.btn-danger {
  border-color: transparent;
  background: var(--danger);
  color: #ffffff;
  box-shadow: 0 10px 24px -14px rgba(220, 38, 38, 0.65);
}
.btn-danger:hover {
  border-color: transparent;
  background: #b91c1c;
  color: #ffffff;
}

.btn-block { width: 100%; margin-top: 20px; }

.btn-start {
  width: 100%;
  margin-top: 18px;
  padding: 15px 20px;
  border-radius: 14px;
  font-size: 0.96rem;
  letter-spacing: 0.01em;
}

/* ---------- Setup layout ---------- */
.setup-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  gap: 22px;
  align-items: start;
}
.setup-input-col,
.setup-side-col { min-width: 0; }
.setup-side-col { position: sticky; top: 24px; }

/* ---------- Text input ---------- */
.textarea-wrap { position: relative; }

.text-input {
  display: block;
  width: 100%;
  min-height: 272px;
  max-height: 54vh;
  resize: vertical;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--page);
  color: var(--text);
  font-size: 0.96rem;
  line-height: 1.7;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease), background-color 0.18s var(--ease);
}
.text-input::placeholder { color: var(--muted); opacity: 0.75; }
.text-input:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--brand-soft);
}

.stats-row {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  padding-top: 12px;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
.stat-dot { color: var(--line); }

.input-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.tool-spacer { flex: 1; }
.recent-wrap { position: relative; }

/* ---------- Form fields ---------- */
.field { margin-bottom: 20px; }
.field:last-child { margin-bottom: 0; }
.field-label {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.71rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.field-hint { margin-top: 8px; line-height: 1.5; }

.micro { font-size: 0.72rem; }
.small { font-size: 0.78rem; }
.muted { color: var(--muted); }
.muted-inline { color: var(--muted); font-weight: 400; }

/* Segmented control */
.segmented {
  display: flex;
  width: 100%;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
}
.seg-btn {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 600;
  transition: background-color 0.16s var(--ease), color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-active {
  background: var(--surface);
  color: var(--brand-dark);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}
[data-theme="dark"] .seg-btn.is-active { color: var(--brand); background: var(--surface); }

/* Chips */
.chips-row { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.79rem;
  font-weight: 600;
  transition: background-color 0.16s var(--ease), border-color 0.16s var(--ease), color 0.16s var(--ease);
}
.chip:hover { border-color: var(--brand); color: var(--brand-dark); background: var(--brand-soft); }
[data-theme="dark"] .chip:hover { color: var(--brand); }
.chip.is-active {
  border-color: var(--brand-ring);
  background: var(--brand-soft);
  color: var(--brand-dark);
}
[data-theme="dark"] .chip.is-active { color: var(--brand); }
.chip-readout {
  min-width: 56px;
  border-color: var(--line);
  background: var(--surface-soft);
  color: var(--text);
  text-align: center;
  cursor: default;
  font-variant-numeric: tabular-nums;
}
.chip-readout:hover { border-color: var(--line); background: var(--surface-soft); color: var(--text); }

/* Sliders */
.slider-row {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-top: 12px;
}
.slider-min,
.slider-max {
  flex: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.range {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0;
  height: 20px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  accent-color: var(--brand-deep);
}
.range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-soft);
  box-shadow: inset 0 0 0 1px var(--line);
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border: 2px solid var(--brand-deep);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.2);
  transition: transform 0.14s var(--ease);
}
.range:active::-webkit-slider-thumb { transform: scale(1.14); }
.range::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-soft);
  box-shadow: inset 0 0 0 1px var(--line);
}
.range::-moz-range-progress {
  height: 6px;
  border-radius: 999px;
  background: var(--brand-deep);
}
.range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid var(--brand-deep);
  border-radius: 50%;
  background: var(--surface);
}
[data-theme="dark"] .range::-webkit-slider-thumb { background: var(--surface); border-color: var(--brand); }
[data-theme="dark"] .range::-moz-range-thumb { background: var(--surface); border-color: var(--brand); }
[data-theme="dark"] .range::-moz-range-progress { background: var(--brand); }

/* Phrase stepper */
.stepper {
  display: flex;
  align-items: center;
  gap: 10px;
}
.stepper .btn-icon {
  width: 38px;
  height: 38px;
  background: var(--surface-soft);
  border-color: transparent;
  color: var(--text);
  font-size: 1.05rem;
}
.stepper .btn-icon:hover { background: var(--brand-soft); color: var(--brand-dark); }
[data-theme="dark"] .stepper .btn-icon:hover { color: var(--brand); }
.stepper-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 38px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.phrase-range { flex: 1; }

/* Switches */
.field-switches {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 0;
  cursor: pointer;
  user-select: none;
}
.switch-row input[type="checkbox"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.switch-label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 6px;
  color: var(--text);
  font-size: 0.87rem;
  font-weight: 500;
}
.switch {
  position: relative;
  width: 46px;
  height: 26px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.28);
  transition: transform 0.2s var(--ease);
}
input:checked + .switch {
  border-color: transparent;
  background: linear-gradient(135deg, var(--brand-deep), var(--brand));
}
input:checked + .switch::after { transform: translateX(20px); }
input:focus-visible + .switch {
  outline: 3px solid var(--brand-ring);
  outline-offset: 3px;
}

.field-back {
  margin: 4px 0 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

/* ---------- Reader preview panel ---------- */
.reader-panel { padding: 22px; }
.reader-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.reader-label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.ready-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--brand-ring);
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 0.7rem;
  font-weight: 700;
}
[data-theme="dark"] .ready-pill { color: var(--brand); }
.ready-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
}

.preview-canvas {
  position: relative;
  padding: 18px;
  min-height: 128px;
  max-height: 178px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--page);
}
.preview-canvas::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 44px;
  background: linear-gradient(transparent, var(--page));
  pointer-events: none;
}
.preview-text {
  max-width: 100%;
  color: var(--text);
  font-family: var(--write-family);
  font-size: calc(var(--write-size) * 0.86);
  line-height: var(--write-lh);
  letter-spacing: var(--write-ls);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.preview-mark {
  padding: 1px 4px;
  margin: 0 -4px;
  border-radius: var(--hl-radius);
  background: var(--hl-color);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.summary-list {
  display: flex;
  flex-direction: column;
  margin-top: 14px;
}
.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 0.83rem;
}
.summary-row:last-child { border-bottom: 0; padding-bottom: 2px; }
.summary-row dt { color: var(--muted); }
.summary-row dd { color: var(--text); font-weight: 600; text-align: right; }

.start-hint {
  margin-top: 12px;
  text-align: center;
  line-height: 1.6;
}

/* ---------- Shortcuts panel ---------- */
.shortcuts-panel { padding: 18px 22px; }
.mini-title {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.shortcut-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px 12px;
}
.shortcut-grid span {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  min-width: 0;
}
.shortcut-grid span:first-child { grid-column: 1 / -1; }
kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
}

/* ---------- Marketing content ---------- */
.content-section { margin-top: 64px; }
.section-heading {
  max-width: 660px;
  margin: 0 auto 28px;
  text-align: center;
}
.section-heading h2 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.section-heading > p:last-child {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.65;
}

.steps-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}
.info-card {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease), transform 0.18s var(--ease);
}
.info-card:hover {
  border-color: var(--brand-ring);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-bottom: 14px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-size: 0.82rem;
  font-weight: 800;
}
[data-theme="dark"] .step-badge { color: var(--brand); }
.info-card h3 { font-size: 0.98rem; font-weight: 700; margin-bottom: 6px; }
.info-card p { color: var(--muted); font-size: 0.85rem; line-height: 1.65; }

.faq-section { margin-top: 56px; }
.faq-list {
  max-width: 840px;
  margin: 0 auto;
  padding: 2px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.faq-list details { border-bottom: 1px solid var(--line); }
.faq-list details:last-child { border-bottom: 0; }
.faq-list summary {
  position: relative;
  padding: 17px 34px 17px 0;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.faq-list summary::-webkit-details-marker { display: none; }
.faq-list summary::after {
  content: "+";
  position: absolute;
  top: 50%;
  right: 2px;
  transform: translateY(-50%);
  color: var(--brand-deep);
  font-size: 1.25rem;
  font-weight: 400;
  line-height: 1;
}
[data-theme="dark"] .faq-list summary::after { color: var(--brand); }
.faq-list details[open] summary::after { content: "−"; }
.faq-list details p {
  max-width: 72ch;
  margin: -4px 0 18px;
  color: var(--muted);
  font-size: 0.87rem;
  line-height: 1.7;
}

/* ==========================================================================
   SESSION VIEW
   ========================================================================== */
.session-view {
  max-width: none;
  padding: 24px clamp(16px, 4vw, 40px);
}

.session-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, 1100px);
  height: calc(100dvh - 120px);
  min-height: 540px;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.session-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: none;
  padding: 13px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.session-ident {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.session-eyebrow {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}
.session-mode-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border: 1px solid var(--brand-ring);
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
[data-theme="dark"] .session-mode-chip { color: var(--brand); }

.session-topbar-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
}
.session-topbar-actions .btn-icon {
  width: 38px;
  height: 38px;
  border-color: transparent;
  background: var(--surface-soft);
  color: var(--muted);
}
.session-topbar-actions .btn-icon:hover { color: var(--brand-deep); background: var(--brand-soft); }
[data-theme="dark"] .session-topbar-actions .btn-icon:hover { color: var(--brand); }

.session-progress-top {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-right: 8px;
  font-size: 1.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.session-progress-top .micro { color: var(--muted); font-weight: 500; letter-spacing: 0; }

/* Reading stage */
.write-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
  overflow-y: auto;
  padding: clamp(28px, 5vh, 62px) clamp(20px, 5vw, 56px) clamp(36px, 6vh, 64px);
  background:
    radial-gradient(700px 260px at 50% 0, var(--brand-soft), transparent 70%),
    var(--surface);
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.write-stage::-webkit-scrollbar { width: 10px; }
.write-stage::-webkit-scrollbar-track { background: transparent; }
.write-stage::-webkit-scrollbar-thumb {
  border: 3px solid var(--surface);
  border-radius: 999px;
  background: var(--line);
}

.text-output {
  width: 100%;
  max-width: var(--write-width);
  padding: 6px 8px;
  color: var(--text);
  font-family: var(--write-family);
  font-size: var(--write-size);
  line-height: var(--write-lh);
  letter-spacing: var(--write-ls);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  transition: color 0.2s var(--ease);
}

.chunk {
  padding: 1px 4px;
  margin: 0 -4px;
  border-radius: var(--hl-radius);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  transition:
    background-color 0.32s var(--ease),
    box-shadow 0.32s var(--ease),
    color 0.32s var(--ease);
}
.chunk.is-active {
  background: var(--hl-color);
  box-shadow:
    0 0 0 1.5px var(--hl-shade),
    0 6px 22px -8px rgba(15, 23, 42, 0.35);
  color: var(--text);
}
[data-theme="dark"] .chunk.is-active {
  color: #f8fafc;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
  box-shadow:
    0 0 0 1.5px rgba(255, 255, 255, 0.24),
    0 8px 24px -10px rgba(0, 0, 0, 0.7);
}
body.no-highlight-anim .chunk { transition: none; }

/* Session controls */
.session-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: none;
  padding: 11px 22px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.btn-control {
  height: 42px;
  padding: 0 13px;
  border-color: transparent;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.82rem;
}
.btn-control:hover { color: var(--brand-deep); background: var(--brand-soft); border-color: transparent; }
[data-theme="dark"] .btn-control:hover { color: var(--brand); }

.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.btn-nav {
  width: 46px;
  height: 46px;
  padding: 0;
  border-color: transparent;
  background: var(--surface-soft);
  color: var(--text);
}
.btn-nav:hover { border-color: transparent; background: var(--brand-soft); color: var(--brand-deep); }
[data-theme="dark"] .btn-nav:hover { color: var(--brand); }
.btn-nav:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-nav:disabled:hover { background: var(--surface-soft); color: var(--text); }

.btn-play {
  width: 60px;
  height: 60px;
  padding: 0;
  border-radius: 50%;
  box-shadow: 0 12px 26px -12px rgba(13, 148, 136, 0.85);
}
.btn-play .icon-pause,
.btn-play .icon-play { display: none; }
.btn-play[data-playing="true"] .icon-pause { display: block; }
.btn-play[data-playing="false"] .icon-play { display: block; }

.session-view[data-manual="true"] .btn-play { display: none; }
.session-view[data-manual="true"] .btn-nav.is-done {
  width: auto;
  padding: 0 18px;
  border-color: transparent;
  background: linear-gradient(135deg, var(--brand-deep), var(--brand));
  color: #ffffff;
}
.session-view[data-manual="true"] .btn-nav.is-done::after {
  content: "Done";
  margin-left: 8px;
  font-size: 0.82rem;
  font-weight: 700;
}
.session-view[data-manual="true"] .btn-nav.is-done:hover { color: #ffffff; }

/* Progress */
.session-progress {
  flex: none;
  padding: 0 22px 13px;
  background: var(--surface);
}
.progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
  box-shadow: inset 0 0 0 1px var(--line);
}
.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-deep), var(--brand));
  transition: width 0.45s var(--ease);
}
.progress-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.77rem;
  font-variant-numeric: tabular-nums;
}
.progress-label { color: var(--text); font-weight: 700; }
#progressPct { color: var(--brand-deep); font-weight: 800; }
[data-theme="dark"] #progressPct { color: var(--brand); }
.progress-dots { flex: 1; min-width: 16px; }

/* Paused banner */
.paused-banner {
  position: fixed;
  top: 88px;
  left: 50%;
  z-index: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--surface);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  box-shadow: var(--shadow-md);
  transform: translateX(-50%);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Help popover */
.help-popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 60;
  width: 280px;
  max-width: calc(100vw - 32px);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: popIn 0.18s var(--ease);
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
.pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 700;
}
.kbd-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  color: var(--muted);
  font-size: 0.78rem;
}
.kbd-list span { display: flex; align-items: center; gap: 6px; }

/* Focus mode */
.focus-exit {
  display: none;
  position: fixed;
  top: 88px;
  left: 50%;
  z-index: 600;
  border-color: var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  transform: translateX(-50%);
}

body.focus-mode .session-topbar { display: none; }
body.focus-mode .session-shell {
  height: calc(100dvh - 120px);
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}
body.focus-mode .write-stage {
  background: transparent;
  padding-top: clamp(56px, 10vh, 100px);
}
body.focus-mode .session-controls {
  border-top: 0;
  background: transparent;
  justify-content: center;
}
body.focus-mode .session-controls > .btn-control { display: none; }
body.focus-mode .session-progress { display: none; }
body.focus-mode .focus-exit { display: inline-flex; }

/* ==========================================================================
   COMPLETION VIEW
   ========================================================================== */
.complete-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 72px);
  padding: 48px 24px 72px;
}
.complete-card {
  width: 100%;
  max-width: 520px;
  padding: 42px 38px 34px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: rise 0.4s var(--ease);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
.complete-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  border-radius: 20px;
  background: var(--brand-soft);
  color: var(--brand-deep);
}
[data-theme="dark"] .complete-badge { color: var(--brand); }
.complete-title {
  margin: 2px 0 8px;
  font-size: clamp(1.8rem, 4vw, 2.25rem);
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.complete-sub { font-size: 0.92rem; line-height: 1.65; }
.complete-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 28px 0;
  padding: 20px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.complete-stats dt {
  color: var(--brand-deep);
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
[data-theme="dark"] .complete-stats dt { color: var(--brand); }
.complete-stats dd {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.4;
}
.complete-actions { display: flex; flex-direction: column; gap: 9px; }
.complete-actions .btn { width: 100%; padding: 12px 16px; }

/* ==========================================================================
   SETTINGS DRAWER
   ========================================================================== */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(3px);
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  width: min(420px, 100%);
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.26s var(--ease);
}
@keyframes slideIn {
  from { transform: translateX(28px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex: none;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { font-size: 1.15rem; letter-spacing: -0.02em; }
.drawer-head .small { margin-top: 2px; }
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 24px 28px;
}
.settings-group {
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
}
.settings-group h3 {
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Swatches */
.swatches { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 2px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line);
  transition: transform 0.14s var(--ease), box-shadow 0.14s var(--ease);
}
.swatch:hover { transform: scale(1.1); }
.swatch.is-active {
  box-shadow: 0 0 0 2px var(--brand-deep);
  transform: scale(1.08);
}
[data-theme="dark"] .swatch.is-active { box-shadow: 0 0 0 2px var(--brand); }
.swatch-custom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  margin-left: 2px;
}
.swatch-custom input[type="color"] {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  cursor: pointer;
}
.swatch-custom .micro { font-size: 0.62rem; }

/* Select */
.select-wrap { position: relative; }
.select {
  width: 100%;
  padding: 10px 36px 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  color: var(--text);
  font-size: 0.86rem;
  appearance: none;
  -webkit-appearance: none;
}
[data-theme="dark"] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
.select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-soft);
}

/* ==========================================================================
   MODAL
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10010;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  animation: fade 0.2s ease;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 10011;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-card {
  width: 100%;
  max-width: 420px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: rise 0.24s var(--ease);
}
.modal-card h3 { font-size: 1.08rem; letter-spacing: -0.01em; margin-bottom: 8px; }
.modal-card p { color: var(--muted); font-size: 0.87rem; line-height: 1.6; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 22px;
}

/* ==========================================================================
   RECENT TEXTS POPOVER
   ========================================================================== */
.popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 80;
  width: min(320px, calc(100vw - 64px));
  max-height: 330px;
  overflow-y: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: rise 0.2s var(--ease);
}
.pop-empty { padding: 8px 2px; font-size: 0.8rem; line-height: 1.55; }
.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 9px 9px;
  margin-bottom: 3px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.recent-item:hover { background: var(--surface-soft); border-color: var(--line); }
.recent-item:last-child { margin-bottom: 0; }
.recent-item .recent-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent-item .recent-del {
  width: 26px;
  height: 26px;
  flex: none;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1;
}
.recent-item .recent-del:hover { background: var(--danger-soft); color: var(--danger); }

/* ==========================================================================
   TOAST
   ========================================================================== */
.toast-wrap {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 10020;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  max-width: min(88vw, 460px);
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.24s var(--ease);
}
.toast.is-info {
  border-color: transparent;
  background: linear-gradient(135deg, var(--brand-deep), var(--brand));
  color: #ffffff;
}
.toast.is-error {
  border-color: transparent;
  background: var(--danger);
  color: #ffffff;
}
.toast.is-hide {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 900px) {
  .view { padding: 32px 20px 56px; }
  .setup-layout { grid-template-columns: minmax(0, 1fr); }
  .setup-side-col { position: static; }
  .reader-panel .summary-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
  .reader-panel .summary-row:nth-last-child(2) { border-bottom: 1px dashed var(--line); }
  .session-view { padding: 20px 20px 24px; }
  .session-shell { height: calc(100dvh - 116px); }
  body.focus-mode .session-shell { height: calc(100dvh - 116px); }
  .complete-view { min-height: calc(100dvh - 72px); padding: 40px 20px 56px; }
}

@media (max-width: 700px) {
  .view { padding: 24px 16px 48px; }
  .hero { padding: 2px 0 22px; }
  .hero-lead { font-size: 0.96rem; margin-top: 8px; }
  .panel { padding: 20px; }
  .text-input { min-height: 220px; padding: 16px; }
  .tool-spacer { display: none; }
  .steps-grid { grid-template-columns: 1fr; gap: 12px; }
  .content-section { margin-top: 44px; }
  .faq-list { padding: 2px 18px; }
  .section-heading { margin-bottom: 22px; }

  .session-view { padding: 12px 12px 20px; }
  .session-shell {
    height: calc(100dvh - 96px);
    min-height: 480px;
    border-radius: 16px;
  }
  .session-topbar { padding: 10px 14px; gap: 10px; }
  .session-eyebrow { display: none; }
  .session-topbar-actions { gap: 5px; }
  .session-topbar-actions .btn-icon { width: 36px; height: 36px; }
  .session-progress-top { margin-right: 4px; font-size: 0.98rem; }
  .write-stage { padding: 24px 16px 32px; }
  .text-output { padding: 4px; }
  .session-controls { padding: 9px 12px; gap: 8px; }
  .btn-control { width: 40px; height: 40px; padding: 0; }
  .btn-control .btn-label { display: none; }
  .transport { gap: 10px; }
  .btn-nav { width: 42px; height: 42px; }
  .btn-play { width: 54px; height: 54px; }
  .session-progress { padding: 0 14px 11px; }
  .progress-meta { gap: 4px 10px; font-size: 0.72rem; }
  .progress-dots { display: none; }
  .paused-banner,
  .focus-exit { top: 78px; }
  body.focus-mode .session-shell { height: calc(100dvh - 96px); }
  .complete-card { padding: 34px 24px 28px; }
  .complete-view { padding: 28px 16px 44px; }
  .complete-stats { margin: 22px 0; padding: 16px 0; }
  .drawer { width: 100%; }
  .drawer-head { padding: 18px 20px 14px; }
  .drawer-body { padding: 2px 20px 24px; }
}

@media (max-width: 440px) {
  body { font-size: 14.5px; }
  .hero-lead { font-size: 0.93rem; }
  .privacy-note { font-size: 0.76rem; padding: 7px 12px; }
  .panel { padding: 16px; }
  .panel-heading { gap: 11px; margin-bottom: 16px; }
  .step-number { width: 30px; height: 30px; border-radius: 9px; font-size: 0.66rem; }
  .panel-heading h2 { font-size: 1rem; }
  .panel-heading p { font-size: 0.78rem; }
  .panel-tool { width: 36px; height: 36px; }
  .text-input { font-size: 0.92rem; }
  .stats-row { gap: 6px; font-size: 0.74rem; }
  .input-tools { display: grid; grid-template-columns: 1fr 1fr; }
  .input-tools > .btn-sm,
  .input-tools .recent-wrap > .btn-sm { width: 100%; }
  .stats-row .stat-dot { display: none; }
  .chip { padding: 6px 10px; font-size: 0.75rem; }
  .chip-readout { min-width: 50px; }
  .slider-row { gap: 8px; }
  .slider-min, .slider-max { font-size: 0.68rem; }
  .shortcut-grid { grid-template-columns: 1fr; gap: 8px; }
  .shortcut-grid span:first-child { grid-column: auto; }
  .reader-panel { padding: 18px; }
  .reader-panel .summary-list { grid-template-columns: 1fr; }
  .reader-panel .summary-row:nth-last-child(2) { border-bottom: 1px dashed var(--line); }
  .shortcuts-panel { padding: 16px 18px; }
  .complete-stats { grid-template-columns: 1fr; gap: 14px; }
  .complete-stats div { display: flex; align-items: baseline; justify-content: center; gap: 8px; }
  .complete-stats dd { margin-top: 0; }
  .session-shell { min-height: 460px; }
  .session-mode-chip { font-size: 0.64rem; padding: 3px 8px; }
  .session-progress-top { font-size: 0.9rem; }
  .session-progress-top .micro { font-size: 0.65rem; }
  .session-topbar-actions .btn-icon { width: 34px; height: 34px; }
  .write-stage { padding: 22px 12px 28px; }
  .progress-meta > #etaLabel { display: none; }
  .modal { padding: 16px; }
  .modal-card { padding: 22px; }
  .toast-wrap { bottom: 16px; width: calc(100% - 32px); }
  .toast { max-width: 100%; text-align: center; }
}
