/* =========================================================================
   Echo
   A calm, quiet interface. Generous space, one accent colour, no decoration
   that does not carry meaning. Type and spacing are adjustable by the person
   using it rather than fixed to one assumption about what they need.
   ========================================================================= */

:root {
  --paper:        #f7f6f3;
  --surface:      #ffffff;
  --surface-sunk: #f1efeb;
  --ink:          #1e1f22;
  --ink-soft:     #55585f;
  --ink-faint:    #82868f;
  --line:         #e2dfd9;
  --line-strong:  #cfcbc3;

  --accent:       #1f6f5c;
  --accent-soft:  #e6f0ec;
  --accent-ink:   #14513f;

  --warn:         #8a5a12;
  --warn-soft:    #fbf1de;
  --danger:       #9a3025;
  --danger-soft:  #fbeae7;
  --mark:         #fdf0c2;
  /* Four highlighter colours. Chosen to stay readable with black text on top,
     which rules out anything saturated. */
  --hl-green:     #cfe9d8;
  --hl-blue:      #d4e4f5;
  --hl-pink:      #f6d9e5;

  --radius:       14px;
  --radius-sm:    9px;
  --radius-lg:    20px;

  --shadow-sm: 0 1px 2px rgba(24, 22, 18, .06);
  --shadow:    0 2px 10px rgba(24, 22, 18, .07);
  --shadow-lg: 0 12px 40px rgba(24, 22, 18, .16);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-reading: var(--font);
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --text:      1rem;
  --leading:   1.6;
  --tracking:  0;
  --measure:   68ch;
  --block-gap: 1rem;

  --nav-width: 232px;
  --topbar-h:  60px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:        #16171a;
    --surface:      #1d1f23;
    --surface-sunk: #232529;
    --ink:          #ecebe8;
    --ink-soft:     #b3b5ba;
    --ink-faint:    #878a91;
    --line:         #2e3138;
    --line-strong:  #3d414a;

    --accent:       #6fc0a6;
    --accent-soft:  #1b2f2a;
    --accent-ink:   #a5dbc9;

    --warn:         #e0b168;
    --warn-soft:    #2e2618;
    --danger:       #e58a7e;
    --danger-soft:  #2f1e1c;
    --mark:         #4a421f;
    --hl-green:     #23412f;
    --hl-blue:      #1f3450;
    --hl-pink:      #45243a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow:    0 2px 12px rgba(0, 0, 0, .45);
    --shadow-lg: 0 14px 44px rgba(0, 0, 0, .6);
  }
}

:root[data-theme="dark"] {
  --paper:        #16171a;
  --surface:      #1d1f23;
  --surface-sunk: #232529;
  --ink:          #ecebe8;
  --ink-soft:     #b3b5ba;
  --ink-faint:    #878a91;
  --line:         #2e3138;
  --line-strong:  #3d414a;
  --accent:       #6fc0a6;
  --accent-soft:  #1b2f2a;
  --accent-ink:   #a5dbc9;
  --warn:         #e0b168;
  --warn-soft:    #2e2618;
  --danger:       #e58a7e;
  --danger-soft:  #2f1e1c;
  --mark:         #4a421f;
  --hl-green:     #23412f;
  --hl-blue:      #1f3450;
  --hl-pink:      #45243a;
}

/* ---- Reading preferences -------------------------------------------------
   Set by the person in Settings. Echo does not decide these for her.        */
body.reading-larger   { --text: 1.14rem; --leading: 1.7; }
body.reading-spacious { --text: 1.14rem; --leading: 1.9; --tracking: .012em; --measure: 58ch; }
body.reading-relaxed  { --text: 1.22rem; --leading: 2.0; --tracking: .02em;  --measure: 52ch; }

body.density-compact     { --block-gap: .6rem; }
body.density-comfortable { --block-gap: 1rem; }
body.density-chunked     { --block-gap: 1.7rem; --measure: 58ch; }

body.font-serif    { --font-reading: Georgia, "Iowan Old Style", "Times New Roman", serif; }
body.font-mono     { --font-reading: var(--font-mono); }
body.font-readable { --font-reading: Verdana, Tahoma, "Trebuchet MS", sans-serif; --tracking: .02em; }

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

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

/* The browser's own [hidden] rule is in its user-agent stylesheet, which any
   author rule beats. So a panel styled with `display: flex` ignores hidden
   entirely and sits on screen forever, with its close button appearing to do
   nothing. Every overlay in Echo is a fixed flex container, so this line is
   what makes hidden mean hidden. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text);
  line-height: var(--leading);
  letter-spacing: var(--tracking);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; font-weight: 640; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.22rem; }
h3 { font-size: 1.03rem; }
h4 { font-size: .95rem; }

p { margin: 0 0 var(--block-gap); }
a { color: var(--accent-ink); text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 2px; }
a:hover { text-decoration-color: currentColor; }

mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 .12em; }

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

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.skip-link {
  position: absolute; left: -999px; top: .5rem; z-index: 100;
  background: var(--surface); padding: .7rem 1rem; border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.skip-link:focus { left: .5rem; }

/* ---- Shell --------------------------------------------------------------- */
.shell {
  display: grid;
  grid-template-columns: var(--nav-width) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas: "brand top" "nav main";
  min-height: 100vh;
}

.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1rem;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}

.brand {
  grid-area: brand;
  display: flex; align-items: center; gap: .55rem;
  padding: 0 1rem; text-decoration: none; color: var(--ink);
  font-weight: 680; letter-spacing: -.02em; font-size: 1.1rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  position: sticky; top: 0; height: var(--topbar-h); z-index: 31;
}
.brand-mark {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2.5px solid var(--accent);
  box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--accent) 16%, transparent);
  flex: none;
}

.topsearch { flex: 1; position: relative; max-width: 620px; }
.topsearch input {
  width: 100%; height: 40px; padding: 0 .95rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink); font-size: .96rem; font-family: inherit;
}
.topsearch input::placeholder { color: var(--ink-faint); }

.suggest-list {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  overflow: hidden; max-height: 60vh; overflow-y: auto;
}
.suggest-item {
  display: flex; justify-content: space-between; gap: .75rem; align-items: center;
  width: 100%; padding: .7rem .9rem; border: 0; background: none;
  font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.suggest-item:hover, .suggest-item:focus { background: var(--surface-sunk); }
.suggest-kind { color: var(--ink-faint); font-size: .8rem; }

/* ---- Navigation ---------------------------------------------------------- */
.sidenav {
  grid-area: nav;
  padding: 1rem .6rem 6rem;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 1.4rem;
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}
.nav-section { display: flex; flex-direction: column; gap: 1px; }
.nav-bottom { margin-top: auto; }
.nav-heading {
  margin: .3rem .7rem .35rem; font-size: .72rem; font-weight: 640;
  letter-spacing: .07em; text-transform: uppercase; color: var(--ink-faint);
}
.nav-item {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem .7rem; border-radius: var(--radius-sm);
  color: var(--ink-soft); text-decoration: none; font-size: .93rem; font-weight: 500;
}
.nav-item:hover { background: var(--surface-sunk); color: var(--ink); }
.nav-item.is-current { background: var(--accent-soft); color: var(--accent-ink); font-weight: 620; }
.nav-icon { width: 1.25rem; text-align: center; opacity: .85; font-size: .95rem; }
.nav-item.as-button { width: 100%; border: 0; background: none; font-family: inherit; cursor: pointer; }
.nav-logout { margin: 0; }

.main {
  grid-area: main;
  padding: 1.6rem clamp(1rem, 3vw, 2.4rem) 6rem;
  min-width: 0;
}

/* ---- Mobile -------------------------------------------------------------- */
.tabbar { display: none; }
.menu-toggle { display: none; }

@media (max-width: 880px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "top" "main";
    grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  }
  .brand { display: none; }
  .menu-toggle { display: inline-flex; }
  .topbar { gap: .5rem; padding: 0 .75rem; }

  .sidenav {
    position: fixed; inset: var(--topbar-h) auto 0 0;
    width: min(85vw, 300px); background: var(--surface);
    height: calc(100vh - var(--topbar-h));
    transform: translateX(-102%); transition: transform .22s ease;
    z-index: 45; box-shadow: var(--shadow-lg);
  }
  .sidenav.is-open { transform: none; }

  .main { padding: 1rem .95rem 6.5rem; }

  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(14px) saturate(160%);
    border-top: 1px solid var(--line);
    padding: .35rem .35rem calc(.35rem + env(safe-area-inset-bottom));
  }
  .tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: .45rem 0; font-size: .68rem; color: var(--ink-faint);
    text-decoration: none; border-radius: var(--radius-sm); min-height: 52px;
  }
  .tab span { font-size: 1.15rem; line-height: 1.1; }
  .tab.is-current { color: var(--accent-ink); }
  .tab-primary {
    background: var(--accent); color: #fff; max-width: 60px; justify-content: center;
    border-radius: 999px; margin: 0 .3rem; box-shadow: var(--shadow);
  }
  .tab-primary span { font-size: 1.5rem; }
}

/* ---- Buttons and controls ------------------------------------------------ */
.button, .ghost-button, .small-button, .icon-button, .danger-button {
  font-family: inherit; cursor: pointer; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  text-decoration: none; transition: background .12s ease, border-color .12s ease;
}
.button {
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  padding: .62rem 1.1rem; font-size: .95rem; font-weight: 580; min-height: 44px;
}
.button:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.ghost-button {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  padding: .55rem .9rem; font-size: .9rem; font-weight: 520; min-height: 42px;
}
.ghost-button:hover { background: var(--surface-sunk); border-color: var(--line-strong); }
.small-button {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  padding: .34rem .7rem; font-size: .84rem; min-height: 34px;
}
.small-button:hover { background: var(--surface-sunk); }
.danger-button {
  background: var(--surface); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line));
  padding: .5rem .9rem; font-size: .9rem; min-height: 42px;
}
.danger-button:hover { background: var(--danger-soft); }
.icon-button {
  background: none; border: 1px solid transparent; color: var(--ink-soft);
  width: 42px; height: 42px; font-size: 1.15rem; flex: none;
}
.icon-button:hover { background: var(--surface-sunk); color: var(--ink); }
button[disabled], .button[disabled] { opacity: .55; cursor: not-allowed; }

.button-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.inline-form { display: inline; margin: 0; }

/* ---- Forms --------------------------------------------------------------- */
label { display: block; font-size: .87rem; font-weight: 560; color: var(--ink-soft); margin-bottom: .32rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="date"], input[type="datetime-local"], input[type="number"], select, textarea {
  width: 100%; padding: .62rem .75rem; min-height: 44px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font-family: inherit; font-size: .96rem; line-height: 1.5;
}
textarea { min-height: 120px; resize: vertical; line-height: var(--leading); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-faint) 50%), linear-gradient(135deg, var(--ink-faint) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 2.2rem; }

.field { margin-bottom: 1rem; }
.field-hint { font-size: .82rem; color: var(--ink-faint); margin: .3rem 0 0; }
.field-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.checkbox, .radio { display: flex; align-items: flex-start; gap: .6rem; font-weight: 450; color: var(--ink); margin-bottom: .55rem; }
.checkbox input, .radio input { width: 20px; height: 20px; min-height: 0; flex: none; margin-top: .18rem; accent-color: var(--accent); }

.choice-grid { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.choice {
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .7rem .8rem;
  background: var(--surface); cursor: pointer; display: block;
}
.choice input { position: absolute; opacity: 0; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice-title { font-weight: 600; color: var(--ink); display: block; }
.choice-note { font-size: .82rem; color: var(--ink-faint); display: block; margin-top: .15rem; }

/* ---- Page furniture ------------------------------------------------------ */
.page-head {
  display: flex; flex-wrap: wrap; gap: .9rem; align-items: flex-start;
  justify-content: space-between; margin-bottom: 1.5rem;
}
.page-head h1 { margin: 0; }
.page-sub { color: var(--ink-soft); margin: .3rem 0 0; font-size: .93rem; }
.section { margin-bottom: 2.2rem; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: .75rem; margin-bottom: .8rem;
}
.section-head h2 { margin: 0; }
.section-more { font-size: .87rem; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: .8rem; }
.card-quiet { background: var(--surface-sunk); border-color: transparent; box-shadow: none; }

.grid { display: grid; gap: .8rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.empty {
  text-align: center; padding: 3rem 1.5rem; color: var(--ink-soft);
  border: 1px dashed var(--line-strong); border-radius: var(--radius-lg); background: var(--surface);
}
.empty h2 { color: var(--ink); }
.empty p { max-width: 42ch; margin-inline: auto; }

.readable { max-width: var(--measure); font-family: var(--font-reading); }
.readable h2 { margin-top: 1.6em; }
.readable h3 { margin-top: 1.4em; }
.readable ul, .readable ol { padding-left: 1.3em; margin: 0 0 var(--block-gap); }
.readable li { margin-bottom: .45em; }
.readable strong { font-weight: 660; }

.meta { color: var(--ink-faint); font-size: .84rem; }
.meta-row { display: flex; flex-wrap: wrap; gap: .5rem 1rem; color: var(--ink-faint); font-size: .85rem; }

/* ---- Chips --------------------------------------------------------------- */
.chip-row { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .6rem; }
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .22rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 520;
  background: var(--surface-sunk); color: var(--ink-soft); text-decoration: none;
  border: 1px solid transparent;
}
.chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip-species { background: var(--accent-soft); color: var(--accent-ink); }
.chip-ai::after { content: "auto"; font-size: .65rem; opacity: .65; }

/* ---- Home ---------------------------------------------------------------- */
.greeting { font-size: clamp(1.5rem, 4vw, 2rem); margin-bottom: .2rem; }
.greeting-sub { color: var(--ink-soft); margin-bottom: 1.8rem; }

.action-grid { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.action {
  display: flex; flex-direction: column; align-items: flex-start; gap: .45rem;
  padding: 1.1rem; border-radius: var(--radius); text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  min-height: 108px; box-shadow: var(--shadow-sm);
}
.action:hover { border-color: var(--accent); background: var(--accent-soft); }
.action-icon { font-size: 1.5rem; line-height: 1; }
.action-label { font-weight: 620; }
.action-note { font-size: .8rem; color: var(--ink-faint); }

.recent-list { display: grid; gap: .55rem; }
.recent-item {
  display: flex; align-items: center; gap: .8rem; padding: .75rem .9rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: inherit;
}
.recent-item:hover { border-color: var(--line-strong); }
.recent-kind { font-size: 1.2rem; flex: none; width: 1.6rem; text-align: center; }
.recent-body { min-width: 0; }
.recent-title { display: block; font-weight: 580; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-meta { display: block; font-size: .8rem; color: var(--ink-faint); }

/* ---- Source cards -------------------------------------------------------- */
.source-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow-sm);
}
.source-card.is-failed { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.source-card.needs-review { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.source-card-main { display: flex; gap: .8rem; text-decoration: none; color: inherit; align-items: flex-start; }
.source-kind { font-size: 1.25rem; flex: none; line-height: 1.4; }
.source-body { min-width: 0; flex: 1; }
.source-title { display: block; font-weight: 600; margin-bottom: .15rem; }
.source-meta { display: flex; flex-wrap: wrap; gap: .3rem .8rem; font-size: .82rem; color: var(--ink-faint); }
.source-lesson { color: var(--accent-ink); }
.source-summary { display: block; margin-top: .45rem; color: var(--ink-soft); font-size: .88rem; }
.source-status { margin-top: .7rem; display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.status-label { margin: 0; font-size: .84rem; color: var(--ink-soft); }

.progress { flex: 1; min-width: 120px; height: 6px; background: var(--surface-sunk); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s ease; }

/* ---- Lessons and detail pages -------------------------------------------- */
.detail-layout { display: grid; gap: 1.5rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) {
  .detail-layout { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
  .context-panel { position: sticky; top: calc(var(--topbar-h) + 1.2rem); }
}
.context-panel { display: grid; gap: .9rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.panel h3 { margin: 0 0 .6rem; font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); }
.panel ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.panel li a { text-decoration: none; color: var(--ink); font-size: .9rem; }
.panel li a:hover { color: var(--accent-ink); }

.timeline { display: grid; gap: .6rem; }

/* ---- Audio player and transcript ----------------------------------------- */
.player {
  position: sticky; top: calc(var(--topbar-h) + .5rem); z-index: 20;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow);
  margin-bottom: 1.2rem;
}
.player audio { width: 100%; height: 40px; }
.player-tools { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; align-items: center; }
.player-time { font-variant-numeric: tabular-nums; color: var(--ink-faint); font-size: .85rem; }

.transcript { display: grid; gap: .15rem; }
.transcript-section {
  margin-top: 1.4rem; padding-top: .9rem; border-top: 1px solid var(--line);
}
.transcript-section:first-child { margin-top: 0; border-top: 0; padding-top: 0; }
.transcript-section h3 { font-size: .95rem; color: var(--ink); margin-bottom: .1rem; }
.transcript-section .meta { margin-bottom: .6rem; display: block; }

.segment {
  display: grid; grid-template-columns: 62px minmax(0, 1fr); gap: .8rem;
  padding: .42rem .5rem; border-radius: var(--radius-sm);
  scroll-margin-top: calc(var(--topbar-h) + 120px);
}
.segment:hover { background: var(--surface-sunk); }
.segment.is-active { background: var(--accent-soft); }
.segment-time {
  font-variant-numeric: tabular-nums; font-size: .82rem; color: var(--accent-ink);
  background: none; border: 0; padding: .1rem .2rem; cursor: pointer; text-align: left;
  font-family: var(--font-mono); align-self: start; border-radius: 4px; min-height: 0;
}
.segment-time:hover { background: var(--accent-soft); }
.segment-text { font-family: var(--font-reading); }
.segment-note {
  grid-column: 2; margin-top: .3rem; padding: .5rem .7rem; font-size: .88rem;
  background: var(--warn-soft); border-left: 3px solid var(--warn); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* ---- Pages and slides ---------------------------------------------------- */
.page-block {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.15rem; margin-bottom: .8rem; scroll-margin-top: calc(var(--topbar-h) + 20px);
}
.page-block.is-target { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.page-number {
  display: inline-block; font-size: .74rem; font-weight: 640; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: .35rem;
}
.page-body { white-space: pre-wrap; font-family: var(--font-reading); }
.speaker-notes {
  margin-top: .8rem; padding-top: .7rem; border-top: 1px dashed var(--line);
  font-size: .9rem; color: var(--ink-soft);
}

.review-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); align-items: start; }
.review-image img { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); }

/* ---- Search -------------------------------------------------------------- */
.search-form { display: grid; gap: .6rem; margin-bottom: 1.2rem; }
.search-bar { display: flex; gap: .5rem; }
.search-bar input[type="search"] { flex: 1; height: 50px; font-size: 1.05rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filters select, .filters input { min-height: 40px; width: auto; min-width: 140px; }

.expansion-note {
  background: var(--accent-soft); color: var(--accent-ink);
  border-radius: var(--radius-sm); padding: .6rem .8rem; font-size: .88rem; margin-bottom: 1rem;
}

.result-group { margin-bottom: 1.3rem; }
.result-group-head { display: flex; flex-wrap: wrap; gap: .4rem .8rem; align-items: baseline; margin-bottom: .45rem; }
.result-group-title { font-weight: 620; }
.result {
  display: block; padding: .7rem .85rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface);
  text-decoration: none; color: inherit; margin-bottom: .4rem;
}
.result:hover { border-color: var(--accent); }
.result-locator { font-size: .8rem; color: var(--accent-ink); font-family: var(--font-mono); }
.result-snippet { margin: .3rem 0 0; font-size: .92rem; color: var(--ink-soft); font-family: var(--font-reading); }
.match-tags { display: inline-flex; gap: .3rem; margin-left: .4rem; }
.match-tag { font-size: .68rem; padding: .05rem .4rem; border-radius: 999px; background: var(--surface-sunk); color: var(--ink-faint); }

/* ---- Ask Echo ------------------------------------------------------------ */
.chat { display: grid; gap: 1.1rem; margin-bottom: 1.5rem; }
.turn { display: grid; gap: .5rem; }
.turn-question {
  justify-self: end; max-width: min(90%, 46ch);
  background: var(--accent); color: #fff; padding: .7rem 1rem;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
}
.answer { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.grounding-banner {
  display: flex; align-items: center; gap: .5rem; padding: .55rem .9rem;
  font-size: .82rem; font-weight: 620; letter-spacing: .02em;
}
.grounding-grounded { background: var(--accent-soft); color: var(--accent-ink); }
.grounding-partial  { background: var(--warn-soft);   color: var(--warn); }
.grounding-general  { background: var(--surface-sunk); color: var(--ink-soft); }
.grounding-none     { background: var(--danger-soft); color: var(--danger); }
.answer-body { padding: 1rem 1.1rem; }
.answer-general {
  border-top: 1px solid var(--line); background: var(--surface-sunk);
  padding: 1rem 1.1rem;
}
.answer-tools { display: flex; flex-wrap: wrap; gap: .4rem; padding: 0 1.1rem 1rem; }

.citations { border-top: 1px solid var(--line); padding: .9rem 1.1rem 1rem; }
.citations-heading { font-size: .76rem; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-faint); margin-bottom: .5rem; }
.citation-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.citation a { display: flex; gap: .6rem; align-items: flex-start; text-decoration: none; color: inherit; padding: .4rem .5rem; border-radius: var(--radius-sm); }
.citation a:hover { background: var(--surface-sunk); }
.citation-number {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-ink);
  display: grid; place-items: center; font-size: .74rem; font-weight: 680;
}
.citation-label { display: block; font-size: .9rem; }
.citation-action { display: block; font-size: .8rem; color: var(--accent-ink); }

.composer {
  position: sticky; bottom: 0; background: var(--paper);
  padding: .8rem 0 1rem; border-top: 1px solid var(--line);
}
.composer-inner { display: flex; gap: .5rem; align-items: flex-end; }
.composer textarea { min-height: 52px; max-height: 180px; }
.starter-row { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .8rem; }
.starter {
  padding: .45rem .8rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: .86rem; cursor: pointer; font-family: inherit; color: var(--ink-soft);
}
.starter:hover { border-color: var(--accent); color: var(--accent-ink); }

.mic-button { width: 46px; height: 46px; border-radius: 50%; flex: none; }
.mic-button.is-listening { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 45%, transparent); } 50% { box-shadow: 0 0 0 10px transparent; } }

/* ---- Teach Me ------------------------------------------------------------ */
.stage { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: .8rem; overflow: hidden; }
.stage-head {
  display: flex; align-items: center; gap: .7rem; width: 100%;
  padding: .95rem 1.1rem; background: none; border: 0; cursor: pointer;
  font-family: inherit; font-size: 1.02rem; font-weight: 620; color: var(--ink); text-align: left;
}
.stage-head:hover { background: var(--surface-sunk); }
.stage-number {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-ink);
  display: grid; place-items: center; font-size: .8rem; font-weight: 700;
}
.stage-body { padding: 0 1.1rem 1.1rem; }
.stage-chunk { padding: .8rem 0; border-top: 1px solid var(--line); }
.stage-chunk:first-child { border-top: 0; padding-top: .2rem; }
.stage-chunk h4 { margin-bottom: .3rem; color: var(--accent-ink); }
.stage-toggle-icon { margin-left: auto; color: var(--ink-faint); }

/* ---- Terminology --------------------------------------------------------- */
.term-panel {
  position: fixed; right: 0; top: 0; bottom: 0; width: min(430px, 100vw);
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg); z-index: 60; display: flex; flex-direction: column;
}
.term-panel-head { display: flex; justify-content: space-between; gap: 1rem; padding: 1.1rem 1.2rem .6rem; }
.term-word { margin: 0 0 .25rem; font-size: 1.35rem; }
.term-panel-body { flex: 1; overflow-y: auto; padding: .5rem 1.2rem 1.2rem; }
.term-panel-foot { display: flex; gap: .5rem; padding: .8rem 1.2rem calc(.8rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.term-block { margin-bottom: 1.1rem; }
.term-block h3 { font-size: .76rem; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-faint); margin-bottom: .3rem; }
.term-block p { margin: 0; font-family: var(--font-reading); }
.pronounce {
  display: inline-flex; align-items: center; gap: .4rem; background: var(--accent-soft);
  border: 0; border-radius: 999px; padding: .35rem .8rem; color: var(--accent-ink);
  font-family: inherit; font-size: .88rem; cursor: pointer;
}
.pronounce-guide { font-family: var(--font-mono); font-size: .85rem; }
.term-seen { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.term-seen a { display: block; font-size: .88rem; text-decoration: none; color: var(--ink); }
.term-seen .meta { display: block; }
.term-warning { color: var(--warn); font-size: .88rem; }

.glossary-list { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.glossary-item {
  display: block; padding: .8rem .9rem; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface); text-decoration: none; color: inherit;
}
.glossary-item:hover { border-color: var(--accent); }
.glossary-term { font-weight: 640; }
.glossary-meaning { font-size: .86rem; color: var(--ink-soft); margin: .2rem 0 0; }
.alphabet { display: flex; flex-wrap: wrap; gap: .25rem; margin-bottom: 1.2rem; }
.alphabet a, .alphabet span {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--radius-sm);
  font-size: .85rem; text-decoration: none; color: var(--ink-soft); border: 1px solid var(--line); background: var(--surface);
}
.alphabet span { opacity: .35; }
.alphabet a.is-current { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- Capture ------------------------------------------------------------- */
.capture-tabs { display: flex; gap: .4rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.capture-tab {
  padding: .6rem 1rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-family: inherit; font-size: .93rem; color: var(--ink-soft);
  display: inline-flex; gap: .4rem; align-items: center; min-height: 44px;
}
.capture-tab.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }

.record-stage { text-align: center; padding: 1.5rem 1rem 2rem; }
.record-button {
  width: 132px; height: 132px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 2.6rem;
  box-shadow: 0 8px 30px color-mix(in srgb, var(--accent) 35%, transparent);
  display: grid; place-items: center; margin: 0 auto;
}
.record-button.is-recording { background: var(--danger); animation: pulse 2s infinite; }
.record-button.is-paused { background: var(--warn); }
.record-timer { font-size: 2.1rem; font-variant-numeric: tabular-nums; margin: 1.1rem 0 .3rem; font-family: var(--font-mono); }
.record-hint { color: var(--ink-faint); font-size: .9rem; }
.record-controls { display: flex; justify-content: center; gap: .6rem; margin-top: 1.3rem; flex-wrap: wrap; }
.level-meter { height: 6px; width: min(260px, 70vw); margin: 1rem auto 0; background: var(--surface-sunk); border-radius: 999px; overflow: hidden; }
.level-fill { height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }

.dropzone {
  border: 2px dashed var(--line-strong); border-radius: var(--radius-lg);
  padding: 2.5rem 1.5rem; text-align: center; background: var(--surface); cursor: pointer;
}
.dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.upload-list { display: grid; gap: .5rem; margin-top: 1rem; }
.upload-row { display: flex; align-items: center; gap: .7rem; padding: .6rem .8rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.upload-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.upload-state { font-size: .82rem; color: var(--ink-faint); }
.upload-row.is-done .upload-state { color: var(--accent-ink); }
.upload-row.is-error .upload-state { color: var(--danger); }

.scan-preview { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--line); display: block; margin: 1rem auto; }
.scan-canvas-wrap { position: relative; display: inline-block; max-width: 100%; }

/* ---- Duplicate and review prompts ---------------------------------------- */
.notice {
  border-radius: var(--radius); padding: .9rem 1.1rem; margin-bottom: 1rem;
  border: 1px solid var(--line); background: var(--surface);
}
.notice-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.notice-error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.notice-info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.notice h3 { margin: 0 0 .3rem; font-size: 1rem; }
.notice p { margin: 0 0 .6rem; font-size: .92rem; }

/* ---- Flash --------------------------------------------------------------- */
.flash-stack { display: grid; gap: .5rem; margin-bottom: 1.2rem; }
.flash {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem 1rem; border-radius: var(--radius); font-size: .93rem;
  background: var(--accent-soft); color: var(--accent-ink);
}
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-close { background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: inherit; }

/* ---- Reader bar ---------------------------------------------------------- */
.reader-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 55;
  width: min(560px, calc(100vw - 1.5rem));
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; box-shadow: var(--shadow-lg);
}
@media (max-width: 880px) { .reader-bar { bottom: calc(76px + env(safe-area-inset-bottom)); } }
.reader-inner { display: flex; align-items: center; gap: .3rem; padding: .4rem .6rem; }
.reader-button {
  background: none; border: 0; cursor: pointer; color: var(--ink-soft);
  width: 40px; height: 40px; border-radius: 50%; font-size: .95rem; flex: none;
}
.reader-button:hover { background: var(--surface-sunk); color: var(--ink); }
.reader-play { background: var(--accent); color: #fff; }
.reader-play:hover { background: var(--accent-ink); color: #fff; }
.reader-progress { flex: 1; min-width: 0; padding: 0 .4rem; }
.reader-title { display: block; font-size: .85rem; font-weight: 580; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-position { display: block; font-size: .74rem; color: var(--ink-faint); }
.reader-speed select { min-height: 34px; padding: .1rem 1.6rem .1rem .5rem; font-size: .8rem; width: auto; }

.reading-now { background: var(--mark); border-radius: 4px; box-shadow: 0 0 0 3px var(--mark); }

/* ---- Selection menu and side sheet --------------------------------------- */
.selection-menu {
  position: absolute; z-index: 65; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden; min-width: 210px;
}
.selection-menu button {
  display: flex; align-items: center; gap: .6rem; padding: .62rem .9rem;
  background: none; border: 0; font: inherit; color: var(--ink); cursor: pointer; text-align: left;
}
.selection-menu button:hover { background: var(--accent-soft); color: var(--accent-ink); }
.selection-colours {
  display: flex; gap: .45rem; padding: .6rem .9rem;
  border-top: 1px solid var(--line); background: var(--surface-sunk);
}
.selection-colours button { padding: 0; }
.selection-colours button:hover { background: inherit; }
.selection-colours .swatch-yellow:hover, .selection-colours .swatch-yellow { background: var(--mark); }
.selection-colours .swatch-green:hover,  .selection-colours .swatch-green  { background: var(--hl-green); }
.selection-colours .swatch-blue:hover,   .selection-colours .swatch-blue   { background: var(--hl-blue); }
.selection-colours .swatch-pink:hover,   .selection-colours .swatch-pink   { background: var(--hl-pink); }

.side-sheet {
  position: fixed; right: 0; top: 0; bottom: 0; width: min(460px, 100vw); z-index: 60;
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
}
.side-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); }
.side-sheet-title { margin: 0; font-size: 1.05rem; }
.side-sheet-tools { display: flex; gap: .4rem; align-items: center; }
.side-sheet-body { flex: 1; overflow-y: auto; padding: 1.1rem 1.2rem calc(2rem + env(safe-area-inset-bottom)); }

/* ---- Tables (admin) ------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-faint); font-weight: 620; }
.stat-grid { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; }
.stat-value { font-size: 1.5rem; font-weight: 660; line-height: 1.2; }
.stat-label { font-size: .82rem; color: var(--ink-faint); }
.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 600; }
.pill-ok { background: var(--accent-soft); color: var(--accent-ink); }
.pill-off { background: var(--surface-sunk); color: var(--ink-faint); }
.pill-bad { background: var(--danger-soft); color: var(--danger); }

/* ---- Plain pages --------------------------------------------------------- */
.plain-page { display: grid; place-items: center; min-height: 100vh; padding: 2rem 1rem; }
.plain-main { width: 100%; max-width: 460px; }
.plain-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 2rem 1.8rem; box-shadow: var(--shadow); }
.plain-brand { display: flex; align-items: center; gap: .6rem; font-size: 1.3rem; font-weight: 680; margin-bottom: 1.5rem; }
.plain-footnote { text-align: center; color: var(--ink-faint); font-size: .85rem; margin-top: 1.2rem; }

/* ---- Pagination ---------------------------------------------------------- */
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1.6rem; }
.page-link { padding: .5rem .9rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); text-decoration: none; color: var(--ink); }
.page-link.is-disabled { opacity: .45; }
.page-status { font-size: .87rem; color: var(--ink-faint); }

/* ---- Utilities ----------------------------------------------------------- */
.stack > * + * { margin-top: var(--block-gap); }
.muted { color: var(--ink-faint); }
.right { margin-left: auto; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* =========================================================================
   Study support
   Assignments, the to-do and questions list, the focus timer, highlighting,
   the writing check, word parts, the map and the offline outbox.
   Same quiet vocabulary as everything else: one accent, no badges to collect,
   nothing that scores her.
   ========================================================================= */

/* ---- Ticking things off -------------------------------------------------- */
/* Deliberately large. This is tapped on a phone, often in a corridor. */
.task-tick {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border: 2px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  display: grid; place-items: center;
  font-size: .95rem; line-height: 1;
  color: var(--surface);
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.task-tick:hover { border-color: var(--accent); }
.task-tick.is-done { background: var(--accent); border-color: var(--accent); color: #fff; }
.task-tick:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.step-card { transition: opacity .2s ease; }
.step-card.is-done { opacity: .55; }
.step-card.is-done h3 { text-decoration: line-through; text-decoration-thickness: 1px; }

/* ---- Focus timer --------------------------------------------------------- */
.focus-card {
  display: grid; gap: 1.2rem; justify-items: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 2rem 1.4rem; box-shadow: var(--shadow-sm);
}
.focus-dial { width: min(260px, 70vw); height: auto; display: block; }
.focus-track { fill: none; stroke: var(--surface-sunk); stroke-width: 8; }
.focus-progress {
  fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round;
  transform: rotate(-90deg); transform-origin: 50% 50%;
  transition: stroke-dashoffset .9s linear, stroke .3s ease;
}
.focus-card.is-break .focus-progress { stroke: var(--warn); }
.focus-readout { text-align: center; }
.focus-time {
  font-size: clamp(2.4rem, 11vw, 3.4rem); font-weight: 300;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1;
}
.focus-phase { color: var(--ink-faint); margin-top: .4rem; font-size: .95rem; }
.focus-card.is-working .focus-phase { color: var(--accent-ink); }
.focus-lengths { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; }

/* ---- Highlights ---------------------------------------------------------- */
.is-highlighted {
  border-radius: 3px;
  padding: .05em .12em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  cursor: pointer;
}
.highlight-yellow, .is-highlighted.highlight-yellow { background: var(--mark); }
.highlight-green,  .is-highlighted.highlight-green  { background: var(--hl-green); }
.highlight-blue,   .is-highlighted.highlight-blue   { background: var(--hl-blue); }
.highlight-pink,   .is-highlighted.highlight-pink   { background: var(--hl-pink); }

.highlight-card { border-left: 4px solid var(--line-strong); }
.highlight-card.highlight-yellow { border-left-color: #d9b93c; background: none; }
.highlight-card.highlight-green  { border-left-color: #4b9a72; background: none; }
.highlight-card.highlight-blue   { border-left-color: #4a83b8; background: none; }
.highlight-card.highlight-pink   { border-left-color: #b8688f; background: none; }
.highlight-quote { font-family: var(--font-reading); font-size: 1.02rem; font-style: normal; margin: 0 0 .5rem; }
.highlight-note {
  color: var(--ink-soft); font-size: .92rem; margin: 0 0 .5rem;
  padding-left: .8rem; border-left: 3px solid var(--line-strong);
}

.swatch {
  width: 22px; height: 22px; border-radius: 7px;
  border: 1px solid var(--line-strong); cursor: pointer; padding: 0;
}
.swatch.is-chosen { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch-yellow { background: var(--mark); }
.swatch-green  { background: var(--hl-green); }
.swatch-blue   { background: var(--hl-blue); }
.swatch-pink   { background: var(--hl-pink); }

/* ---- Writing check ------------------------------------------------------- */
/* Before and after, side by side, so the change is visible rather than
   described. The point is that she can see the pattern, not just the fix. */
.change-card { display: grid; gap: .45rem; padding: .8rem .9rem; }
.change-before, .change-after {
  font-family: var(--font-reading); padding: .25rem .5rem;
  border-radius: var(--radius-sm); display: inline-block;
}
.change-before { background: var(--danger-soft); color: var(--ink); text-decoration: line-through; text-decoration-color: var(--danger); }
.change-after { background: var(--accent-soft); color: var(--accent-ink); font-weight: 560; }
.change-why { color: var(--ink-soft); font-size: .9rem; margin: 0; }
.change-type {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-faint); font-weight: 620;
}

/* ---- Word parts ---------------------------------------------------------- */
.breakdown { display: flex; flex-wrap: wrap; align-items: stretch; gap: .35rem; }
.breakdown-part {
  padding: .45rem .7rem; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--accent-ink);
  text-decoration: none; text-align: center; min-width: 74px;
}
.breakdown-part small { display: block; font-size: .74rem; opacity: .8; font-weight: 500; }
.breakdown-literal { font-family: var(--font-reading); margin: .8rem 0 0; }

/* ---- Concept map --------------------------------------------------------- */
.map-holder {
  position: relative; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; touch-action: none; cursor: grab;
  min-height: 420px;
}
.map-holder.is-panning { cursor: grabbing; }
.map-edge { stroke: var(--line-strong); stroke-width: 1.4; opacity: .7; }
.map-node { cursor: pointer; }
.map-node:hover .map-dot { stroke: var(--accent); stroke-width: 3; }
.map-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.map-node-lesson .map-dot { fill: var(--ink-faint); }
.map-node-species .map-dot { fill: var(--warn); }
.map-label { font-size: 11px; fill: var(--ink); paint-order: stroke; stroke: var(--paper); stroke-width: 3px; }
.map-legend { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: .7rem; font-size: .85rem; color: var(--ink-faint); }
.map-key { display: inline-flex; align-items: center; gap: .35rem; }
.map-key::before { content: ""; width: 10px; height: 10px; border-radius: 999px; background: var(--accent); }
.map-key-lesson::before { background: var(--ink-faint); }
.map-key-species::before { background: var(--warn); }

/* ---- Offline outbox ------------------------------------------------------ */
/* Sits above the tab bar on a phone. It only appears when something really is
   still waiting, so it can afford to be noticed. */
.outbox-banner {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 74px);
  z-index: 60; max-width: min(560px, calc(100vw - 1.6rem));
  display: flex; align-items: center; gap: .7rem;
  padding: .7rem .9rem;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 999px; box-shadow: var(--shadow-lg);
  font-size: .88rem;
}
.outbox-dot {
  flex: 0 0 auto; width: 9px; height: 9px; border-radius: 999px;
  background: var(--warn); animation: outbox-pulse 2.4s ease-in-out infinite;
}
@keyframes outbox-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.outbox-text { min-width: 0; }
.outbox-warn { display: block; color: var(--danger); }
@media (min-width: 900px) { .outbox-banner { bottom: 1.2rem; } }

/* ---- Nav count ----------------------------------------------------------- */
.nav-count {
  margin-left: auto; min-width: 20px; padding: 0 .35rem;
  background: var(--accent-soft); color: var(--accent-ink);
  border-radius: 999px; font-size: .74rem; font-weight: 660; text-align: center;
}

/* ---- Reading focus ------------------------------------------------------- */
/* Not a "quiet room": Echo cannot give her one. What it can do is take
   everything else off the screen, which is the part of distraction it is
   actually able to remove. */
body.is-reading-focus .topbar,
body.is-reading-focus .sidenav,
body.is-reading-focus .tabbar,
body.is-reading-focus .context-panel,
body.is-reading-focus .section-head .button-row,
body.is-reading-focus .page-head .button-row { display: none !important; }
body.is-reading-focus .shell { grid-template-columns: 1fr; grid-template-areas: "main"; }
body.is-reading-focus .main { padding-top: 2.4rem; padding-bottom: 6rem; }
body.is-reading-focus .detail-layout { display: block; }
body.is-reading-focus .readable, body.is-reading-focus .segment-text { max-width: var(--measure); }
.focus-exit {
  position: fixed; top: 1rem; right: 1rem; z-index: 70;
  display: none;
}
body.is-reading-focus .focus-exit { display: inline-flex; }

@media print {
  .topbar, .sidenav, .tabbar, .reader-bar, .selection-menu, .composer,
  .outbox-banner, .focus-exit { display: none !important; }
  .shell { grid-template-columns: 1fr; grid-template-areas: "main"; }
  body { background: #fff; }
}

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

/* ---- Mind maps ------------------------------------------------------------
   A canvas she draws on herself. Two things drive the choices here: it has to
   work with a finger as well as a mouse, so every target is at least 44px; and
   the bubbles are HTML over an SVG layer rather than SVG shapes, because text
   in SVG does not wrap and a mind map is mostly text.
   ------------------------------------------------------------------------- */
.map-card .card-title { margin-bottom: .2rem; }
.map-card form { margin-top: .6rem; }
.quiet-details summary { cursor: pointer; color: var(--ink-soft); font-size: .9rem; }

.mindmap-bar {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .55rem .2rem .8rem;
}
.mindmap-title {
  flex: 1 1 200px; min-width: 140px; font-size: 1.15rem; font-weight: 650;
  border: 1px solid transparent; background: transparent; color: var(--ink);
  padding: .35rem .5rem; border-radius: var(--radius-sm);
}
.mindmap-title:hover { border-color: var(--line); }
.mindmap-title:focus { border-color: var(--accent); background: var(--surface); outline: none; }
.mindmap-status { font-size: .82rem; color: var(--ink-faint); min-width: 5.5rem; }
.mindmap-status.is-warn { color: var(--warn); font-weight: 600; }
.mindmap-bar-actions { display: flex; gap: .4rem; }

.mindmap-help { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1.1rem; margin-bottom: .7rem; }
.mindmap-help ul { margin: 0; padding-left: 1.1rem; display: grid; gap: .35rem; font-size: .9rem; color: var(--ink-soft); }
.mindmap-help kbd {
  font: inherit; font-size: .82rem; background: var(--surface-sunk);
  border: 1px solid var(--line-strong); border-radius: 5px; padding: 0 .3rem;
}

.mindmap-stage {
  position: relative;
  /* `clip` rather than `hidden`, and this matters. `hidden` still makes a
     scroll container, so focusing a bubble that sits off to the left scrolls
     the canvas sideways behind her back, and because it is hidden there is no
     scrollbar to put it back. The map looks permanently stuck off-centre and
     the toolbar lands off the screen. `clip` does not scroll at all.
     `hidden` stays first as the fallback for older browsers, where the
     JavaScript guard catches it instead. */
  overflow: hidden;
  overflow: clip;
  height: min(72vh, 780px); min-height: 380px;
  background: var(--surface-sunk);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  /* Without this the browser claims every drag as a scroll and nothing on the
     canvas can be moved with a finger. */
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  cursor: grab;
}
.mindmap-stage.is-connecting { cursor: crosshair; }

.mindmap-edges, .mindmap-nodes {
  position: absolute; inset: 0; transform-origin: 0 0;
}
.mindmap-edges { width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.mindmap-nodes { pointer-events: none; }

.map-edge { fill: none; stroke: var(--line-strong); stroke-width: 2; }
.map-edge-cross { stroke: var(--accent); stroke-dasharray: 5 4; stroke-width: 2; opacity: .75; }
.map-edge-ghost { stroke: var(--accent); stroke-dasharray: 3 3; }

.map-node {
  position: absolute; top: 0; left: 0; pointer-events: auto;
  width: 168px; min-height: 52px;
  display: flex; align-items: center; gap: .35rem;
  padding: .55rem .7rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  box-shadow: var(--shadow); font-size: .92rem; line-height: 1.3;
  cursor: grab; word-break: break-word;
}
.map-node:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.map-node.is-root { font-weight: 650; border-width: 2px; }
.map-node.is-selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.map-node.is-drop-target { border-color: var(--accent); background: var(--accent-soft); }

.map-node.colour-yellow { background: var(--mark); }
.map-node.colour-green  { background: var(--hl-green); }
.map-node.colour-blue   { background: var(--hl-blue); }
.map-node.colour-pink   { background: var(--hl-pink); }

.map-node-text { flex: 1; }
.map-node-text.is-empty { color: var(--ink-faint); font-style: italic; }
.map-node-badges { display: flex; gap: .25rem; align-items: center; font-size: .85rem; }
.map-node-link { text-decoration: none; color: var(--accent); }
.map-node-note { color: var(--ink-faint); }

/* The dot you drag from to connect two bubbles.
   It appears only on the bubble you are pointing at or have chosen. When
   every bubble carried one, the finger-sized pad around each dot reached
   outside its own bubble and swallowed taps meant for the bubble next door,
   which on a busy map means bubbles that simply cannot be selected. A map
   covered in dots was also a good deal noisier to look at. */
.map-node-handle {
  position: absolute; right: -9px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent);
  cursor: crosshair; opacity: 0; pointer-events: none;
  transition: opacity .12s ease;
}
.map-node:hover .map-node-handle,
.map-node.is-selected .map-node-handle { opacity: 1; pointer-events: auto; }
/* The pad stays inside the bubble's own footprint on the left and right, so
   it can never cover a neighbour. */
.map-node-handle::after { content: ''; position: absolute; inset: -13px -9px; }

.map-node-input {
  position: absolute; top: 0; left: 0; transform-origin: 0 0;
  width: 168px; min-height: 52px; padding: .55rem .7rem;
  font: inherit; font-size: .92rem; color: var(--ink);
  background: var(--surface); border: 2px solid var(--accent);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  pointer-events: auto; z-index: 5;
}

/* One toolbar for whichever bubble is selected, rather than controls on every
   bubble: the same target every time, and it never covers what she tapped. */
.mindmap-tools {
  position: absolute; z-index: 20;
  display: flex; gap: .15rem; padding: .25rem;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 999px; box-shadow: var(--shadow-lg);
}
.map-tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .1rem; min-width: 52px; min-height: 48px; padding: .3rem .4rem;
  border: none; border-radius: 999px; background: transparent;
  color: var(--ink-soft); font: inherit; font-size: 1rem; cursor: pointer;
}
.map-tool:hover { background: var(--surface-sunk); color: var(--ink); }
.map-tool-label { font-size: .64rem; letter-spacing: .01em; }
.map-tool-danger:hover { background: var(--danger-soft); color: var(--danger); }

.mindmap-fab {
  position: absolute; right: 1rem; bottom: 1rem; z-index: 15;
  width: 56px; height: 56px; border-radius: 50%;
  border: none; background: var(--accent); color: #fff;
  font-size: 1.5rem; line-height: 1; cursor: pointer;
  box-shadow: var(--shadow-lg);
}

.attach-results { display: grid; gap: .4rem; margin: .8rem 0; }
.attach-result {
  display: grid; gap: .1rem; text-align: left; width: 100%;
  padding: .6rem .7rem; min-height: 48px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); cursor: pointer; font: inherit; color: var(--ink);
}
.attach-result:hover { border-color: var(--accent); background: var(--accent-soft); }
.attach-kind { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-faint); }
.attach-label { font-weight: 600; }
.attach-context { font-size: .8rem; color: var(--ink-faint); }

/* On a phone the toolbar labels are what make the icons legible, so they stay;
   the canvas takes the height instead. */
@media (max-width: 640px) {
  .mindmap-stage { height: min(66vh, 560px); }
  .mindmap-bar-actions { width: 100%; }
  .mindmap-bar-actions .ghost-button { flex: 1; }
  .map-node { width: 148px; }
  .map-node-input { width: 148px; }
  /* The toolbar is placed and clamped in JavaScript, which already keeps it
     inside the canvas. An !important rule here centring it as well meant two
     mechanisms fighting, and the toolbar ended up half off the screen. */
  .mindmap-tools { max-width: calc(100vw - 16px); }
  .map-tool { min-width: 46px; }
}

/* ---- Pictures on mind map bubbles ---------------------------------------- */
.map-node.has-image { flex-direction: column; align-items: stretch; gap: .4rem; }
.map-node-image {
  display: block; width: 100%; max-height: 110px;
  object-fit: cover; border-radius: var(--radius-sm);
  background: var(--surface-sunk); cursor: zoom-in;
}
.map-node.has-image .map-node-text { text-align: left; }

.picture-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: .5rem; }
.picture-choice {
  display: grid; gap: .25rem; padding: .3rem; text-align: left;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); cursor: pointer; font: inherit; color: var(--ink);
}
.picture-choice img { width: 100%; height: 72px; object-fit: cover; border-radius: 6px; background: var(--surface-sunk); }
.picture-choice span { font-size: .72rem; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picture-choice:hover { border-color: var(--accent); background: var(--accent-soft); }

/* Full size. A thumbnail on a bubble is a reminder; this is the thing. */
.picture-viewer {
  position: fixed; inset: 0; z-index: 120;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .8rem; padding: 2rem 1rem; background: rgba(12, 13, 15, .92);
}
.picture-viewer img { max-width: min(96vw, 1100px); max-height: 82vh; object-fit: contain; border-radius: var(--radius); }
.picture-viewer-caption { color: #f2f1ee; font-size: .92rem; text-align: center; margin: 0; max-width: 60ch; }
.picture-viewer-close { position: absolute; top: 1rem; right: 1rem; color: #f2f1ee; }

/* ---- Recently deleted ---------------------------------------------------- */
.bin-item { display: flex; gap: 1rem; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.bin-item-main { flex: 1 1 260px; min-width: 0; }
.bin-kind {
  margin: 0 0 .15rem; font-size: .7rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--ink-faint); font-weight: 650;
}
.bin-title { margin: 0 0 .3rem; font-size: 1.02rem; overflow-wrap: anywhere; }
.bin-soon { color: var(--warn); }
.bin-item-action { flex: 0 0 auto; }
