/* The course site's two typefaces, served from here: Assistant for text, Heebo for headings (both under the Open Font License). */
@font-face { font-family: 'Assistant'; font-style: normal; font-weight: 400 800; font-display: swap; src: url("vendor/fonts/assistant-hebrew.woff2") format('woff2'); unicode-range: U+0307-0308, U+0590-05FF, U+200C-2010, U+20AA, U+25CC, U+FB1D-FB4F; }
@font-face { font-family: 'Assistant'; font-style: normal; font-weight: 400 800; font-display: swap; src: url("vendor/fonts/assistant-latin.woff2") format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Heebo'; font-style: normal; font-weight: 400 700; font-display: swap; src: url("vendor/fonts/heebo-hebrew.woff2") format('woff2'); unicode-range: U+0307-0308, U+0590-05FF, U+200C-2010, U+20AA, U+25CC, U+FB1D-FB4F; }
@font-face { font-family: 'Heebo'; font-style: normal; font-weight: 400 700; font-display: swap; src: url("vendor/fonts/heebo-latin.woff2") format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
:root {
  color-scheme: light;
  /* Colours of the course site (site/assets/style.css): paper, ink and the terracotta accent. */
  --ink: #302b27;
  --muted: #70665c;
  --paper: #fffcf7;
  --line: #ded5c8;
  --green: #a94d31;
  --light: #f1ece3;
  --orange: #a94d31;
  --bg: #faf9f5;
  --shadow: 0 0.5rem 2rem #302b2708;
  --sans: 'Assistant', Arial, "Noto Sans Hebrew", sans-serif;
  --serif: 'Heebo', Arial, "Noto Sans Hebrew", sans-serif; /* the site's heading face */
  font-family: var(--sans);
  /* The app's one size knob (owner, 2026-11-25: "100% should look like 80%"). Every length below is in rem, so
     the whole app follows it: phones keep 16px, tablets 90%, laptops and desktops 80%. Hairlines stay 1px and
     touch-screen targets stay px (44px), so a finger always has room. */
  font-size: 16px;
  /* The conversation column and its composer: one width, about 1000 css px on a desktop. */
  --chat-w: 1000px;
}
@media (min-width: 600px) { :root { font-size: 14.4px; } }
@media (min-width: 900px) { :root { font-size: 12.8px; } }
/* Icons drawn with width/height attributes follow the same scale. */
svg[width="12"][height="12"] { width: 0.75rem; height: 0.75rem; }
svg[width="14"][height="14"] { width: 0.875rem; height: 0.875rem; }
svg[width="15"][height="15"] { width: 0.9375rem; height: 0.9375rem; }
svg[width="16"][height="16"] { width: 1rem; height: 1rem; }
svg[width="18"][height="18"] { width: 1.125rem; height: 1.125rem; }
svg[width="19"][height="19"] { width: 1.1875rem; height: 1.1875rem; }
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  height: var(--app-h, 100dvh); /* --app-h: the height above the on-screen keyboard (app.js) */
  overflow: hidden;
}
button,
input,
select,
textarea {
  font: inherit;
}
button,
a,
input,
textarea,
select {
  -webkit-tap-highlight-color: transparent;
}
button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 0.5625rem;
  background: var(--green);
  color: white;
  padding: 0.625rem 1.0625rem;
  transition:
    background 0.15s,
    box-shadow 0.15s;
}
button:hover {
  filter: brightness(0.96);
}
button:disabled {
  opacity: 0.48;
  cursor: wait;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 0.1875rem solid #c69b54;
  outline-offset: 0.125rem;
}
a {
  color: var(--green);
}
input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--paper);
  color: var(--ink);
  padding: 0.625rem;
}
textarea {
  resize: vertical;
  min-height: 5.5rem;
  max-height: 15rem;
  unicode-bidi: plaintext;
  line-height: 1.6;
}
input::placeholder,
textarea::placeholder {
  color: #8b8982;
}
.quiet {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
  padding: 0.5rem 0.75rem;
}
/* The settings button lives in the top bar (.top-actions) with the other header buttons. */
.workspace {
  height: var(--app-h, 100dvh);
  display: grid;
  grid-template-columns: minmax(0, 62fr) minmax(20rem, 38fr);
  min-height: 0;
  overflow: hidden;
}
.tutor-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  position: relative;
  padding-top: 4.25rem;
}
.eyebrow {
  font-size: 0.6875rem;
  letter-spacing: 0.03em;
  color: #70665c;
  margin-bottom: 0.5rem;
}
.catalog-filters h3 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
}
.filter-row label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
}
.filter-row input,
.filter-row select {
  min-width: 5.5rem;
}
.result-card {
  width: 100%;
  text-align: right;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0.75rem 0.875rem;
  margin-bottom: 0.4375rem;
  display: block;
}
.result-card:hover {
  border-color: #b9aca0;
  background: #f4f2ec;
}
.result-card strong {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  margin: 0.375rem 0;
  line-height: 1.5;
}
.card-meta {
  font-size: 0.6875rem;
  color: var(--muted);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.card-meta b {
  color: var(--green);
  font-weight: 500;
}
.learning-area {
  flex: 1;
  overflow: auto;
  padding: 1.25rem 1.875rem;
  scroll-behavior: smooth;
}
.welcome {
  max-width: 42.5rem;
  margin: 0 auto 1.75rem;
  text-align: center;
}
.welcome-prompt {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.6;
  margin: 1rem 0 0;
}
.stem {
  white-space: pre-wrap;
  font-size: 0.8125rem;
  line-height: 1.9;
  max-height: 11.875rem;
  overflow: auto;
  padding: 0 0 0.875rem;
}
.question-actions {
  display: flex;
  gap: 0.4375rem;
  flex-wrap: wrap;
  margin-top: 0.375rem;
}
.question-actions button {
  font-size: 0.6875rem;
  padding: 0.3125rem 0.5rem;
  background: #f4f2ec;
  border: 1px solid var(--line);
  color: var(--green);
}
.question-actions button:first-child {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.messages {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: var(--chat-w);
  margin: auto;
}
.message {
  display: flex;
  gap: 0.6875rem;
  align-items: flex-start;
}
.avatar {
  flex: 0 0 1.75rem;
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  background: #f0e6df;
  color: var(--green);
  font:
    1rem Georgia,
    serif;
  border-radius: 0.5rem;
}
.message.system {
  padding: 0.5rem 0;
  border-block: 1px solid var(--line);
}
.message.system .avatar {
  display: none;
}
.message.system .content {
  font-size: 0.75rem;
  color: var(--muted);
}
.catalog-text {
  font-size: 0.75rem;
  margin-block: 0.375rem;
}
.catalog-text summary {
  cursor: pointer;
}
.part-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3125rem;
}
.message.user .avatar {
  background: #eeece6;
  color: #6b6760;
  font: 0.75rem Arial;
}
.message-body {
  min-width: 0;
  flex: 1;
  font-size: 1rem;
  line-height: 1.85;
}
.message.user .content {
  background: #eeece6;
  padding: 0.625rem 0.875rem;
  border-radius: 0.625rem;
  white-space: pre-wrap;
  unicode-bidi: plaintext;
}
.message-label {
  font-size: 0.625rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
.content p {
  margin: 0.25rem 0 0.75rem;
}
.content pre,
.content code {
  direction: ltr;
  unicode-bidi: isolate;
  background: #eeece6;
  border-radius: 0.3125rem;
}
.content pre {
  padding: 0.75rem;
  overflow: auto;
}
.content table {
  border-collapse: collapse;
}
.content td,
.content th {
  padding: 0.375rem;
  border: 1px solid var(--line);
}
.content blockquote {
  border-right: 0.1875rem solid #cc9c88;
  margin: 0.625rem 0;
  padding-right: 0.75rem;
  color: var(--muted);
}
.content img {
  max-width: 100%;
}
.content .katex,
.composer-input .katex {
  direction: ltr;
  unicode-bidi: isolate;
}
.katex-display {
  overflow: auto hidden;
  padding: 0.3125rem 0;
  direction: ltr;
  unicode-bidi: isolate;
}
.source-chip {
  background: #f0eee8;
  color: #706a61;
  border: 1px solid #dedad1;
  border-radius: 1.25rem;
  font-size: 0.625rem;
  padding: 0.1875rem 0.5625rem;
}
.usage {
  font-size: 0.625rem;
  color: var(--muted);
  margin-top: 0.5rem;
  line-height: 1.6;
  direction: rtl;
}
.notice {
  color: #9b613b;
  font-size: 0.75rem;
}
.composer-area {
  background: #faf9f5;
  padding: 0.75rem 1.875rem 1.25rem;
  width: min(calc(var(--chat-w) + 3.75rem), 100%); /* the messages' width plus the same side padding */
  margin-inline: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.composer {
  background: var(--paper);
  border: 1px solid #d9d5cd;
  border-radius: 1.375rem;
  box-shadow: 0 0.1875rem 0.3125rem #302c2410, 0 0.75rem 2.1875rem #302c2405;
  padding: 1rem;
  order: 1;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer textarea {
  width: 100%;
  border: 0;
  padding: 0.375rem 0.25rem;
  background: transparent;
  outline-offset: 0;
  display: block;
  min-height: 4.25rem;
  height: 4.25rem;
  max-height: 11.25rem;
  resize: none;
  font-size: 1rem;
}
.composer-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.25rem;
}
.composer-tools > div {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.math-button {
  font-size: 0.6875rem;
  border: 0;
  padding: 0.3125rem;
}
.math-button span {
  font:
    italic 1rem Georgia,
    serif;
}
.composer-tools #send {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  font: 1.5rem Arial, sans-serif;
  border-radius: 0.625rem;
  display: grid;
  place-items: center;
}
.session-panel {
  display: grid;
  gap: 0.625rem;
  margin-bottom: 0.25rem;
}
.session-panel-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
  font-size: 0.8125rem;
}
.session-label {
  color: var(--muted);
  font-size: 0.75rem;
}
.session-panel #reset-session {
  justify-self: start;
  font-size: 0.75rem;
  padding: 0.4375rem 0.6875rem;
}
.key-notice {
  font-size: 0.6875rem;
  line-height: 1.7;
  background: #f3eddf;
  border: 1px solid #e8dfc8;
  border-radius: 0.4375rem;
  padding: 0.5rem 0.6875rem;
  margin-bottom: 0.5rem;
  color: #8c7551;
}
.image-pane {
  background: #eeece6;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1.25rem 0.75rem 0.75rem;
  position: relative;
}
.page-chrome {
  position: absolute;
  top: 0.875rem;
  inset-inline-start: 0.875rem;
  z-index: 2;
  display: flex;
  gap: 0.375rem;
  align-items: center;
  pointer-events: none;
}
.page-chrome > * {
  pointer-events: auto;
}
.page-open {
  display: grid;
  place-items: center;
  width: 1.875rem;
  height: 1.875rem;
  border-radius: 62.4375rem;
  background: #fffffff2;
  border: 1px solid #d5dbc8;
  color: var(--green);
  text-decoration: none;
  font-size: 0.875rem;
  box-shadow: 0 0.125rem 0.625rem #26302014;
}
.page-open:hover {
  background: #fff;
}
.page-stage {
  flex: 1;
  overflow: auto;
  text-align: center;
  min-height: 0;
  border: 1px solid #dcd8cf;
  border-radius: 0.5rem;
  background: #e8e5de;
}
.page-stage img {
  width: 100%;
  height: auto;
  display: block;
  background: white;
  box-shadow: 0 0.125rem 1.25rem #2630200a;
}
.page-empty {
  height: 100%;
  min-height: 17.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #70665c;
}
.page-empty > span {
  font-size: 3.125rem;
  font-weight: 100;
  color: #aaa298;
}
.page-empty p {
  font-size: 0.875rem;
  margin: 0.875rem 0 0.5rem;
}
.page-empty small {
  font-size: 0.6875rem;
}
.settings-dialog {
  border: 1px solid var(--line);
  border-radius: 0.9375rem;
  background: var(--paper);
  color: var(--ink);
  padding: 1.5625rem;
  box-shadow: 0 1.5625rem 6.25rem #18331d30;
  width: min(30rem, calc(100% - 1.75rem));
  max-height: 90dvh;
}
dialog::backdrop {
  background: #302b273b;
  backdrop-filter: blur(0.125rem);
}
.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}
.dialog-heading h2 {
  font-size: 1.3125rem;
  font-weight: 500;
  margin: 0;
}
.dialog-heading .quiet {
  border: 0;
}
.settings-fields {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  font-size: 0.75rem;
}
.settings-fields label {
  display: flex;
  flex-direction: column;
  gap: 0.4375rem;
}
.settings-fields select {
  width: 100%;
}
.settings-fields label[for="reasoning"] {
  flex-direction: row;
  justify-content: space-between;
  margin-top: 0.625rem;
}
.settings-fields input[type="range"] {
  padding: 0;
  accent-color: var(--green);
}
.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.625rem;
  color: var(--muted);
  margin-top: -0.5rem;
}
.mapping {
  font-family: monospace;
  font-size: 0.6875rem;
  line-height: 1.6;
  background: #f0eee8;
  border-radius: 0.4375rem;
  padding: 0.625rem;
}
.price-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem;
  margin-top: 0.5rem;
}
.price-grid > div {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.75rem;
  color: var(--muted);
}
.price-grid strong {
  font-size: 1.4375rem;
  font-weight: 500;
  color: var(--green);
  display: block;
  margin-top: 0.4375rem;
}
.muted {
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.7;
  margin: 0.375rem 0;
}
.settings-fields small {
  color: #70665c;
  line-height: 1.7;
}
.settings-help {
  font-size: 0.75rem;
  line-height: 1.8;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 0.875rem;
  margin-bottom: 0;
}
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.75rem 1.25rem;
  background: #302b27;
  color: white;
  border-radius: 0.5625rem;
  z-index: 100;
  font-size: 0.8125rem;
  max-width: 90vw;
  box-shadow: var(--shadow);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
[hidden] {
  display: none !important;
}
@media (max-width: 1000px) {
  .learning-area {
    padding: 0.875rem 1.25rem;
  }
  .composer-area {
    padding: 0.625rem 1.25rem;
  }
  .question-actions {
    gap: 0.3125rem;
  }
}
@media (max-width: 740px) {
  .learning-area {
    padding: 1rem;
  }
  .welcome {
    margin: 0.5rem auto 0.75rem;
  }
  .page-empty {
    min-height: 7.5rem;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    scroll-behavior: auto !important;
  }
}


.settings-divider {
  border: 0;
  border-top: 1px solid color-mix(in srgb, currentColor 16%, transparent);
  margin: 1rem 0;
}

.byok-block h3 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.byok-note {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  line-height: 1.45;
}

.byok-block label {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.65rem;
  font-size: 0.9rem;
}

.byok-block input[type="password"] {
  width: 100%;
  box-sizing: border-box;
  padding: 0.55rem 0.7rem;
  border-radius: 0.55rem;
  border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
  background: color-mix(in srgb, Canvas 92%, CanvasText 8%);
  color: inherit;
  font: inherit;
}

.byok-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.35rem;
}

.byok-actions #byok-status {
  font-size: 0.85rem;
}

/* The start screen stays focused on the conversation. The exam opens on selection. */
/* The mark is the letter π in the formulas' own italic (KaTeX's face, which the page already has). A small
   letter fills less of its line than the asterisk it replaced, so it is set larger on a shorter line: the mark
   looks the same size and takes the same room (58, 48 and 36 pixels high). */
.welcome-mark { color: #c37356; font-family: KaTeX_Math, "Times New Roman", serif; font-style: italic; font-size: 4.8125rem; line-height: 0.75; margin-bottom: 1.375rem; }
.welcome h1 {
  font-family: var(--serif);
  font-size: clamp(2.125rem, 4vw, 3rem);
  font-weight: 500;
  letter-spacing: -0.4px;
  line-height: 1.2;
  margin: 0;
}
.workspace:not(.page-expanded) { grid-template-columns: minmax(0, 1fr); }
.tutor-pane:has(#welcome:not([hidden])) { justify-content: center; padding-bottom: 8dvh; }
.tutor-pane:has(#welcome:not([hidden])) .learning-area { flex: 0 0 auto; padding-bottom: 0; }
.tutor-pane:has(#welcome:not([hidden])) .messages:empty { display: none; }
.key-notice { order: 4; background: transparent; border: 0; text-align: center; color: var(--muted); margin: 0.75rem 0 0; padding: 0; }
.composer:focus-within { border-color: #b7afa1; box-shadow: 0 0.1875rem 0.3125rem #302c2410, 0 0 0 0.125rem #b7afa115; }
.composer textarea:focus-visible { outline: none; }
.composer-tools > div { gap: 0.5rem; min-width: 0; flex: 1; margin-inline-end: 0.75rem; }
.math-button { border: 1px solid var(--line); border-radius: 0.5rem; padding: 0.375rem 0.5625rem; color: #68645e; white-space: nowrap; }
.model-button { display: flex; align-items: center; gap: 0.5rem; border: 0; color: #68645e; font-size: 0.75rem; padding: 0.375rem 0.5rem; min-width: 0; }
.model-button bdi { min-width: 0; max-width: 11.25rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message.user { margin-inline-start: 2.125rem; }
.message.user .avatar, .message.user .message-label { display: none; }
.message.user .content { padding: 0.875rem 1.125rem; border-radius: 1rem; }
.message:not(.user) .avatar { background: transparent; color: var(--green); font-size: 1.5rem; }
.message.system { padding: 0.875rem; border: 1px solid var(--line); border-radius: 0.75rem; background: #f2f0ea; }
.source-chip { color: #706a61; }
.settings-dialog { box-shadow: 0 1.5625rem 6.25rem #302c2429; }
dialog::backdrop { background: #302c243b; }
@media (max-width: 740px) {
  .tutor-pane { padding-top: 3.75rem; }
  .tutor-pane:has(#welcome:not([hidden])) { padding-bottom: 8dvh; }
  .welcome { margin-bottom: 1rem; }
  .welcome-mark { font-size: 4rem; margin-bottom: 1.125rem; }
  .welcome-prompt { font-size: 0.875rem; }
  .composer-area { padding: 0.75rem 1rem 1rem; }
  .composer { padding: 0.75rem; border-radius: 1.125rem; }
  .composer-tools > div { gap: 0.25rem; }
  .model-button bdi { max-width: 7.5rem; }
  .message-body { font-size: 0.9375rem; }
}
@media (max-height: 620px) {
  .tutor-pane:has(#welcome:not([hidden])) { justify-content: flex-start; padding-bottom: 0; overflow: auto; }
  .tutor-pane:has(#welcome:not([hidden])) .learning-area { overflow: visible; padding-top: 1rem; }
  .welcome-mark { font-size: 3rem; margin-bottom: 0.75rem; }
  .welcome h1 { font-size: 2rem; }
}

.panel-toggle {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 5;
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0 0 0.1875rem;
  border: 1px solid var(--line);
  border-radius: 0.625rem;
  background: var(--paper);
  color: var(--muted);
  font: 1.75rem Arial, sans-serif;
  box-shadow: 0 0.125rem 0.375rem #302c2408;
}
.panel-toggle:hover, .quiet:hover { background: #eeece6; filter: none; }
.page-chrome:has(.page-open[hidden]) { display: none; }
@media (max-width: 740px) {
  .panel-toggle { top: 0.75rem; left: 0.75rem; }
}

.reply-waiting {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0 0.375rem 0.75rem;
  color: var(--muted);
  font-size: 0.8125rem;
}
.waiting-dots { display: flex; align-items: center; gap: 0.25rem; }
.waiting-dots i {
  width: 0.3125rem;
  height: 0.3125rem;
  border-radius: 50%;
  background: var(--green);
  animation: waiting-pulse 1.2s ease-in-out infinite;
}
.waiting-dots i:nth-child(2) { animation-delay: 0.15s; }
.waiting-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes waiting-pulse {
  0%, 70%, 100% { opacity: 0.3; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-0.1875rem); }
}
@media (prefers-reduced-motion: reduce) {
  .waiting-dots i { animation: none; opacity: 0.7; }
}

/* MathPaster formula editor overlay (vendor/mathpaster). */
.mp-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
.mp-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.mp-overlay iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  color-scheme: normal;
}
.mp-exit {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 0.9375rem;
  cursor: pointer;
  box-shadow: 0 0.25rem 1.125rem #0003;
  z-index: 2;
}

/* Scope pickers (subject, material) sit in the composer toolbar like the other quiet controls. */
.composer-tools > div { flex-wrap: wrap; }
.scope-select {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 0.75rem;
  color: #68645e;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none' stroke='%2368645e' stroke-width='1.5'%3E%3Cpath d='m1 1 4 4 4-4'/%3E%3C/svg%3E") no-repeat left 0.5rem center;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.375rem 0.5625rem 0.375rem 1.5rem;
  cursor: pointer;
  width: auto;
  max-width: 8.125rem;
}
.scope-select:hover { background-color: #eeece6; }
.scope-select:focus-visible { outline: 0.125rem solid #b7afa180; outline-offset: 1px; }
/* Live preview of $...$ typed in the message box. */
.message.user .content { white-space: pre-wrap; }

/* ── Polish ─────────────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: #d2cdc3 transparent; }
::-webkit-scrollbar { width: 0.5rem; height: 0.5rem; }
::-webkit-scrollbar-thumb { background: #d2cdc3; border-radius: 0.5rem; border: 0.125rem solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b7afa1; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* One calm focus ring everywhere (replaces the double ring). */
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 0.125rem solid #a94d31;
  outline-offset: 0.125rem;
  box-shadow: none;
}

button { transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s, opacity 0.15s; }
button:not(:disabled):active { transform: scale(0.97); }
.composer-tools #send { background: var(--green); color: #fff; }
.composer-tools #send:not(:disabled):hover { background: #94422a; }
.composer-tools #send:disabled { opacity: 0.55; cursor: progress; }

/* Starter prompts on the empty screen. */
.starters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.375rem;
  max-width: 35rem;
  margin-inline: auto;
}
.starter {
  font-size: 0.8125rem;
  color: #68645e;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 62.4375rem;
  padding: 0.4375rem 0.875rem;
  cursor: pointer;
}
.starter:hover { background: #eeece6; border-color: #cfc9bd; color: var(--ink); }

/* Composer controls share one height. */
.composer-tools .math-button, .scope-select, .model-button { height: 2rem; }
.composer-tools .math-button { display: inline-flex; align-items: center; gap: 0.375rem; }
.model-button { border-radius: 0.5rem; }
.model-button:hover { background: #eeece6; }

/* Messages. */
.message { animation: message-in 0.22s ease-out both; }
@keyframes message-in { from { opacity: 0; transform: translateY(0.375rem); } to { opacity: 1; transform: none; } }
.message.user .content { width: fit-content; max-width: 100%; background: #efede7; }
.content ol, .content ul { margin: 0.375rem 0 0.75rem; padding-inline-start: 1.5em; }
.content li { margin: 0.1875rem 0; }
.content li > p { margin: 0; }
.content h1, .content h2, .content h3 { line-height: 1.4; margin: 1rem 0 0.375rem; }
.content h1 { font-size: 1.25em; } .content h2 { font-size: 1.15em; } .content h3 { font-size: 1.05em; }
.content hr { border: 0; border-top: 1px solid var(--line); margin: 0.875rem 0; }
.usage { color: #9a968e; font-size: 0.6875rem; margin-top: 0.375rem; }
.notice:not(:empty) { color: #9a4a35; background: #fbeeea; border-radius: 0.5rem; padding: 0.375rem 0.625rem; margin-top: 0.5rem; font-size: 0.8125rem; }

/* Catalog note: quiet and compact. */
.message.system { padding: 0.625rem 0.875rem; gap: 0.625rem; }
.message.system .message-label { font-size: 0.6875rem; letter-spacing: 0.02em; }
.message.system .content { font-size: 0.8125rem; color: #5d5a54; }
.catalog-text summary { color: var(--green); list-style-position: inside; padding: 0.125rem 0; }
.catalog-text[open] summary { margin-bottom: 0.375rem; }
.catalog-text .stem { background: #fbfaf7; border: 1px solid var(--line); border-radius: 0.625rem; padding: 0.75rem 0.875rem; }

/* Settings dialog. */
.settings-dialog { border: 0; border-radius: 1.125rem; }
.settings-dialog select, .settings-dialog input { border-radius: 0.625rem; }

/* Phones: the toolbar scrolls sideways instead of wrapping into rows. */
@media (max-width: 740px) {
  .composer-tools { align-items: flex-end; }
  .composer-tools > div {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 0.125rem;
    scrollbar-width: none;
    margin-inline-end: 0.5rem;
  }
  .composer-tools > div::-webkit-scrollbar { display: none; }
  .composer-tools > div { -webkit-mask-image: linear-gradient(to right, transparent 0, #000 1.375rem); mask-image: linear-gradient(to right, transparent 0, #000 1.375rem); }
  .composer-tools > div > * { flex: none; }
  .starters { margin-top: 1rem; }
  .starter { font-size: 0.7812rem; padding: 0.375rem 0.75rem; }
}
@media (prefers-reduced-motion: reduce) { .message { animation: none; } button { transition: none; } }

/* ── Dialogs and overlays ───────────────────────────────── */
.settings-dialog {
  padding: 0;
  width: min(32.5rem, calc(100% - 1.5rem));
  max-height: min(86dvh, 47.5rem);
  overflow: hidden;
  display: none;
  flex-direction: column;
  background: #faf9f6;
  border-radius: 1.25rem;
  box-shadow: 0 1.875rem 5.625rem #302c2440, 0 0.125rem 0.5rem #302c2410;
}
.settings-dialog[open] { display: flex; animation: dialog-in 0.2s cubic-bezier(0.2, 0.8, 0.3, 1); }
.settings-dialog[open]::backdrop { animation: fade-in 0.2s ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(0.625rem) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.sd-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.125rem 1.375rem 0.875rem;
  border-bottom: 1px solid var(--line);
  background: #faf9f6;
  flex: none;
}
.sd-head h2 { font-size: 1.25rem; font-weight: 500; margin: 0.125rem 0 0; }
.sd-close {
  width: 2.125rem; height: 2.125rem; padding: 0;
  display: grid; place-items: center;
  border: 0; border-radius: 0.625rem;
  background: transparent; color: var(--muted); font-size: 0.9375rem; cursor: pointer;
}
.sd-close:hover { background: #eeece6; color: var(--ink); }
.sd-body {
  overflow-y: auto;
  padding: 1rem 1.375rem 1.375rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}
.sd-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0.875rem;
  padding: 1rem 1rem 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.sd-card h3 { margin: 0; font-size: 0.875rem; font-weight: 600; color: var(--ink); }
.sd-card .muted { margin: 0; }
.sd-field { display: flex; flex-direction: column; gap: 0.375rem; font-size: 0.7812rem; color: #5d5a54; }
.sd-field select, .sd-field input[type="password"], .sd-field input[type="number"], .settings-dialog .filter-row input {
  width: 100%;
  font: inherit;
  font-size: 0.875rem;
  color: var(--ink);
  background: #fbfaf7;
  border: 1px solid var(--line);
  border-radius: 0.625rem;
  padding: 0.5625rem 0.6875rem;
}
.sd-field select:hover, .sd-field input:hover { border-color: #cfc9bd; }
.sd-field select:focus, .sd-field input:focus { border-color: #a94d31; outline: none; box-shadow: 0 0 0 0.1875rem #a94d3126; }
.sd-row { display: flex; justify-content: space-between; align-items: baseline; }
.sd-row output { color: var(--green); font-weight: 600; }
.settings-dialog .filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.settings-dialog .slider-labels { margin-top: -0.25rem; font-size: 0.6875rem; }
.settings-dialog .mapping { margin: 0.125rem 0 0; font-size: 0.6875rem; color: #6b6760; background: #f4f2ec; border-radius: 0.5rem; }
.settings-dialog .price-grid { margin-top: 0; }
.settings-dialog .price-grid > div { border-radius: 0.625rem; padding: 0.625rem 0.75rem; font-size: 0.75rem; background: #fbfaf7; }
.settings-dialog .price-grid strong { font-size: 1.25rem; margin-top: 0.25rem; text-align: start; }
.sd-fine { color: #8d8a83; font-size: 0.7188rem; line-height: 1.7; }
.settings-dialog .session-panel-row { font-size: 0.8125rem; }
.settings-dialog .session-label { color: var(--muted); }
.settings-dialog #reset-session { align-self: flex-start; }
.settings-dialog .byok-actions { margin-top: 0.125rem; gap: 0.5rem; }
.sd-primary {
  background: var(--green); color: #fff; border: 0; border-radius: 0.625rem;
  padding: 0.5625rem 1rem; font: inherit; font-size: 0.8125rem; cursor: pointer;
}
.sd-primary:hover { background: #94422a; }
.settings-dialog .quiet { border: 1px solid var(--line); border-radius: 0.625rem; font-size: 0.8125rem; padding: 0.5rem 0.8125rem; }
.settings-dialog .byok-actions #byok-status { color: #4f7a4a; font-size: 0.75rem; }

/* Formula editor overlay: same dim and blur as the dialogs. */
.mp-overlay { background: #302c2400; transition: opacity 0.22s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.22s; }
.mp-overlay.open { background: #302c243b; backdrop-filter: blur(0.125rem); }
.mp-exit { transition: opacity 0.15s, background-color 0.15s; }
.mp-exit:hover { background: #eeece6; }

/* Toast. */
.toast {
  background: #302b27;
  border-radius: 0.75rem;
  box-shadow: 0 0.625rem 2.125rem #302c2438;
  font-size: 0.8125rem;
  line-height: 1.5;
  padding: 0.6875rem 1.125rem;
  text-align: center;
}
.toast:not([hidden]) { animation: toast-in 0.22s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 0.625rem); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (max-width: 740px) {
  .settings-dialog { width: calc(100% - 1rem); max-height: 92dvh; border-radius: 1.125rem; }
  .sd-head { padding: 0.875rem 1rem 0.75rem; }
  .sd-body { padding: 0.75rem 0.875rem 1.125rem; }
}
@media (prefers-reduced-motion: reduce) {
  .settings-dialog[open], .settings-dialog[open]::backdrop, .toast:not([hidden]) { animation: none; }
}

.settings-dialog input[type="range"] { width: 100%; accent-color: #a94d31; padding: 0; margin: 0.125rem 0; }
/* Opening the dialog focuses its first control; do not paint a ring on the close button for that. */
.sd-close:focus:not(:focus-visible) { outline: none; }
.sd-close:focus-visible { outline: 0.125rem solid #a94d31; outline-offset: 1px; }
.settings-dialog:focus, .sd-body:focus { outline: none; }

/* ── Exam-pane toggle ───────────────────────────────────── */
.panel-toggle {
  padding: 0;
  font-size: 0;
  border-radius: 0.75rem;
  color: #6f6a62;
  background: #fffffff2;
  backdrop-filter: blur(0.375rem);
  box-shadow: 0 1px 0.125rem #302c240d, 0 0.25rem 0.875rem #302c2410;
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.3, 1.4, 0.5, 1), box-shadow 0.2s, color 0.2s, border-color 0.2s, background-color 0.2s;
}
.panel-toggle .chev {
  display: block;
  /* Points right when the pane is closed (open it), left when open (tuck it away). */
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.panel-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.panel-toggle:hover {
  color: var(--green);
  border-color: #dcb7a8;
  background: #fff;
  box-shadow: 0 0.125rem 0.25rem #a94d311a, 0 0.5rem 1.375rem #a94d3126;
  transform: translateY(-1px);
}
.panel-toggle:hover .chev { transform: translateX(0.125rem); }
.panel-toggle[aria-expanded="true"]:hover .chev { transform: rotate(180deg) translateX(0.125rem); }
.panel-toggle:active { transform: scale(0.93); transition-duration: 0.08s; }
.panel-toggle:focus-visible { outline: 0.125rem solid #a94d3199; outline-offset: 0.1875rem; }
/* The word in the toggle belongs to sheet mode (narrow or short screens). On a wide screen it is taken out, so
   the chevron is the button's only child and sits exactly in its middle. */
#page-toggle .toggle-text { display: none; }
/* Wide screens: the toggle rides on the pane's edge. Closed, it waits at the screen's corner; open, it sits just
   outside the pane's inner edge and travels there together with the pane (same curve and time as the grid). */
@media (min-width: 1001px) and (min-height: 521px) {
  #page-toggle {
    transition: left 0.5s cubic-bezier(0.22, 0.9, 0.3, 1), transform 0.18s cubic-bezier(0.3, 1.4, 0.5, 1),
      box-shadow 0.2s, color 0.2s, border-color 0.2s, background-color 0.2s;
  }
  #page-toggle[aria-expanded="true"] { left: calc(38% + 0.625rem); }
}
/* A soft ring pulses once when the pane opens by itself (a question just loaded). */
.panel-toggle.ping::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 0.75rem;
  border: 0.125rem solid #a94d31;
  animation: toggle-ping 0.9s ease-out;
  pointer-events: none;
}
@keyframes toggle-ping { from { opacity: 0.7; transform: scale(1); } to { opacity: 0; transform: scale(1.7); } }

/* Desktop: the exam pane slides open and shut instead of popping. */
@media (min-width: 1001px) {
  .workspace {
    grid-template-columns: minmax(0, 62fr) minmax(0, 38fr);
    transition: grid-template-columns 0.5s cubic-bezier(0.22, 0.9, 0.3, 1);
  }
  .workspace:not(.page-expanded) { grid-template-columns: minmax(0, 1fr) minmax(0, 0fr); }
  .image-pane {
    min-width: 0;
    overflow: hidden;
    transition: opacity 0.35s ease, visibility 0s linear 0s;
  }
  .image-pane[hidden] {
    display: flex !important;
    visibility: hidden;
    opacity: 0;
    padding-inline: 0;
    border-width: 0;
    transition: opacity 0.2s ease, visibility 0s linear 0.5s;
  }
}
@media (prefers-reduced-motion: reduce) {
  .panel-toggle, .panel-toggle .chev, .workspace, .image-pane { transition: none !important; }
  .panel-toggle.ping::after { animation: none; }
}

/* ── Custom dropdowns (composer pickers) ────────────────── */
.dd { position: relative; display: inline-flex; flex: none; }
.dd-native { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dd-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 2rem;
  padding: 0 0.625rem 0 0.75rem;
  font: inherit;
  font-size: 0.75rem;
  color: #68645e;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.dd-btn:hover { background: #f1efe9; border-color: #d3cdc1; }
.dd-btn[aria-expanded="true"] { background: #fbf1ed; border-color: #dcb7a8; color: var(--green); box-shadow: 0 0 0 0.1875rem #b8634218; }
.dd-btn:focus-visible { outline: 0.125rem solid #a94d3199; outline-offset: 0.125rem; }
.dd-chev { flex: none; transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1); }
.dd-btn[aria-expanded="true"] .dd-chev { transform: rotate(180deg); }
.dd-list {
  position: fixed;
  z-index: 70;
  margin: 0;
  padding: 0.3125rem;
  list-style: none;
  overflow-y: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0.875rem;
  box-shadow: 0 0.875rem 2.5rem #302c2426, 0 0.125rem 0.5rem #302c240d;
  font-size: 0.8125rem;
  outline: none;
  animation: dd-in-down 0.16s cubic-bezier(0.2, 0.8, 0.3, 1);
  transform-origin: top;
}
.dd-list[data-dir="up"] { animation-name: dd-in-up; transform-origin: bottom; }
.dd-list[hidden] { display: none; }
@keyframes dd-in-down { from { opacity: 0; transform: translateY(-0.375rem) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes dd-in-up { from { opacity: 0; transform: translateY(0.375rem) scale(0.97); } to { opacity: 1; transform: none; } }
.dd-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.875rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5625rem;
  color: #4a4742;
  cursor: pointer;
  white-space: nowrap;
}
.dd-item.active { background: #f3f1eb; }
.dd-item[aria-selected="true"] { color: var(--green); font-weight: 600; }
.dd-item[aria-selected="true"]::after {
  content: "";
  width: 0.75rem;
  height: 0.75rem;
  flex: none;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 5 5 9-10'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 5 5 9-10'/%3E%3C/svg%3E") center / contain no-repeat;
}
@media (prefers-reduced-motion: reduce) { .dd-list { animation: none; } .dd-chev { transition: none; } }

/* ── Chat history ───────────────────────────────────────── */
.top-actions { position: fixed; top: 1rem; right: 1rem; z-index: 5; display: flex; gap: 0.5rem; }
.top-actions .panel-toggle { position: static; }
.history-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: #302c2400; transition: background-color 0.3s;
}
.history-backdrop.open { background: #302c243b; backdrop-filter: blur(0.125rem); }
.history-drawer {
  position: fixed; top: 0; bottom: 0; right: 0; z-index: 41;
  width: min(21.25rem, 88vw);
  display: flex; flex-direction: column; gap: 0.625rem;
  padding: 1rem 0.875rem 0.75rem;
  background: #faf9f6;
  border-left: 1px solid var(--line);
  box-shadow: -1.25rem 0 3.75rem #302c2426;
  transform: translateX(100%);
  transition: transform 0.32s cubic-bezier(0.22, 0.9, 0.3, 1);
}
.history-drawer.open { transform: none; }
.history-head { display: flex; align-items: center; justify-content: space-between; padding: 0.125rem 0.25rem 0.125rem 0.125rem; }
.history-head h2 { margin: 0; font-size: 1.125rem; font-weight: 500; }
.history-new {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.625rem 0.875rem; border: 0; border-radius: 0.75rem;
  background: var(--green); color: #fff; font: inherit; font-size: 0.875rem; cursor: pointer;
}
.history-new:hover { background: #94422a; }
.history-search {
  display: flex; align-items: center; gap: 0.5rem; padding: 0 0.75rem; height: 2.375rem;
  border: 1px solid var(--line); border-radius: 0.75rem; background: #fff; color: var(--muted);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.history-search:focus-within { border-color: #a94d31; box-shadow: 0 0 0 0.1875rem #b8634226; }
.history-search input {
  flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font: inherit; font-size: 0.875rem; color: var(--ink);
  appearance: none; -webkit-appearance: none;
}
.history-search input::-webkit-search-cancel-button { display: none; }
.history-list { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -0.375rem; padding: 0 0.375rem 0.5rem; }
.history-group { margin: 0.875rem 0.5rem 0.375rem; font-size: 0.6875rem; font-weight: 600; color: #9a968e; letter-spacing: 0.02em; }
.history-empty { margin: 1.75rem 0.75rem; text-align: center; color: var(--muted); font-size: 0.8125rem; line-height: 1.8; }
.chat-row {
  position: relative; display: flex; align-items: center; gap: 0.125rem;
  border-radius: 0.6875rem; transition: background-color 0.15s;
}
.chat-row:hover, .chat-row:focus-within { background: #f0eee8; }
.chat-row.current { background: #f8ece7; }
.chat-row.current .chat-title { color: var(--green); font-weight: 600; }
.chat-main {
  flex: 1; min-width: 0; display: flex; align-items: baseline; justify-content: space-between; gap: 0.625rem;
  padding: 0.5625rem 0.75rem; border: 0; background: transparent; font: inherit; font-size: 0.8438rem; text-align: start; cursor: pointer; color: var(--ink);
  border-radius: 0.6875rem;
}
.chat-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-when { flex: none; font-size: 0.6875rem; color: #a09b92; }
.chat-actions { display: none; flex: none; gap: 0.125rem; padding-inline-end: 0.25rem; }
.chat-row:hover .chat-actions, .chat-row:focus-within .chat-actions { display: flex; }
.chat-row:hover .chat-when, .chat-row:focus-within .chat-when { display: none; }
.chat-act {
  width: 1.75rem; height: 1.75rem; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 0.5rem; background: transparent; color: #8d8a83; cursor: pointer;
}
.chat-act:hover { background: #e4e0d7; color: var(--ink); }
.chat-act.danger:hover { background: #f7dfd8; color: #a3402a; }
.chat-rename {
  flex: 1; margin: 0.25rem 0.375rem; padding: 0.375rem 0.625rem; font: inherit; font-size: 0.8438rem;
  border: 1px solid #a94d31; border-radius: 0.5625rem; outline: none; box-shadow: 0 0 0 0.1875rem #b8634226; background: #fff;
}
.chat-row.confirming { flex-wrap: wrap; padding: 0.5rem 0.75rem; gap: 0.5rem; background: #fbeeea; }
.chat-confirm-text { flex: 1 1 100%; font-size: 0.8125rem; color: #7a3524; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-confirm { padding: 0.375rem 0.875rem; border-radius: 0.5625rem; border: 1px solid var(--line); background: #fff; font: inherit; font-size: 0.7812rem; cursor: pointer; }
.chat-confirm.yes { background: #b3402a; border-color: #b3402a; color: #fff; }
.chat-confirm.yes:hover { background: #9a3623; }
.history-drawer :focus-visible { outline: 0.125rem solid #a94d3199; outline-offset: 1px; }
@media (max-width: 740px) {
  .top-actions { top: 0.75rem; right: 0.75rem; }
  .history-drawer { width: min(21.25rem, 92vw); }
}
@media (prefers-reduced-motion: reduce) { .history-drawer, .history-backdrop { transition: none; } }
.history-search input:focus-visible { outline: none; }
.chat-confirm { color: var(--ink); }
.chat-confirm.yes { color: #fff; }
.chat-confirm:hover { background: #f3f1eb; }
.chat-confirm.yes:hover { background: #9a3623; }

/* ── Exam page navigator ────────────────────────────────── */
.page-stage { outline: none; scroll-behavior: smooth; padding-bottom: 4rem; }
.page-stage:focus-visible { box-shadow: inset 0 0 0 0.125rem #a94d3166; }
.page-stage img { transition: opacity 0.2s ease; }
.page-stage img.turning { opacity: 0.35; }
/* A question image shorter than the pane sits in its middle; a taller one starts at the top and scrolls.
   The top padding keeps the corner buttons off the question. */
.page-stage { display: flex; flex-direction: column; padding-top: 3.25rem; }
.page-stage > img { margin-block: auto; flex: none; }
.page-stage > .page-empty { flex: 1; height: auto; }
.page-nav {
  position: absolute;
  inset-inline: 0;
  bottom: 1.375rem;
  margin-inline: auto;
  width: max-content;
  max-width: calc(100% - 1.5rem);
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 0.125rem;
  padding: 0.25rem;
  background: #fffffff0;
  backdrop-filter: blur(0.625rem);
  border: 1px solid var(--line);
  border-radius: 62.4375rem;
  box-shadow: 0 0.375rem 1.375rem #302c2420, 0 1px 0.1875rem #302c240d;
  animation: nav-in 0.3s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.page-nav[hidden] { display: none; }
@keyframes nav-in { from { opacity: 0; transform: translateY(0.5rem); } to { opacity: 1; transform: none; } }
.pn-btn {
  width: 2.125rem; height: 2.125rem; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: #5d5a54; cursor: pointer;
}
.pn-btn:hover:not(:disabled) { background: #f3ebe7; color: var(--green); }
.pn-btn:disabled { opacity: 0.3; cursor: default; }
.pn-pos { min-width: 6rem; text-align: center; font-size: 0.8125rem; color: #4a4742; font-variant-numeric: tabular-nums; padding: 0 0.375rem; user-select: none; }
.pn-sep { width: 1px; height: 1.125rem; background: var(--line); margin: 0 0.25rem; }
.pn-chip {
  border: 0; border-radius: 62.4375rem; padding: 0.375rem 0.75rem; margin-inline: 0.125rem;
  background: #f8ece7; color: var(--green); font: inherit; font-size: 0.75rem; cursor: pointer; white-space: nowrap;
}
.pn-chip:hover { background: #f3dcd2; }
.pn-chip[hidden], .pn-btn[hidden] { display: none; }
.page-log {
  position: absolute; bottom: calc(100% + 0.625rem); inset-inline-start: 0;
  margin: 0; padding: 0.3125rem; list-style: none; min-width: 15rem; max-height: 16.25rem; overflow-y: auto;
  background: var(--paper); border: 1px solid var(--line); border-radius: 0.875rem;
  box-shadow: 0 0.875rem 2.5rem #302c2426; animation: dd-in-up 0.16s cubic-bezier(0.2, 0.8, 0.3, 1); transform-origin: bottom;
}
.page-log[hidden] { display: none; }
.pl-item {
  width: 100%; display: flex; justify-content: space-between; gap: 0.875rem; align-items: baseline;
  padding: 0.5rem 0.75rem; border: 0; border-radius: 0.5625rem; background: transparent; font: inherit; font-size: 0.8125rem;
  color: #4a4742; text-align: start; cursor: pointer; white-space: nowrap;
}
.pl-item:hover { background: #f3f1eb; }
.pl-item[aria-current="true"] { color: var(--green); font-weight: 600; }
.pl-page { color: #9a968e; font-size: 0.75rem; font-weight: 400; }
.pn-btn:focus-visible, .pn-chip:focus-visible, .pl-item:focus-visible { outline: 0.125rem solid #a94d3199; outline-offset: 1px; }
@media (max-width: 740px) {
  .page-nav { bottom: 0.875rem; }
  .pn-pos { min-width: 5.25rem; font-size: 0.75rem; }
  .pn-chip { padding: 0.375rem 0.625rem; }
}
@media (prefers-reduced-motion: reduce) { .page-nav, .page-log { animation: none; } .page-stage { scroll-behavior: auto; } .page-stage img { transition: none; } }

/* ── Collection view: every question of a type, in the side pane ── */
.collection { flex: 1; min-height: 0; display: flex; flex-direction: column; border: 1px solid #dcd8cf; border-radius: 0.5rem; background: #e8e5de; overflow: hidden; animation: co-in 0.28s cubic-bezier(0.2, 0.8, 0.3, 1); }
.collection[hidden] { display: none; }
@keyframes co-in { from { opacity: 0; transform: translateY(0.5rem); } to { opacity: 1; transform: none; } }
.image-pane.show-collection .page-stage,
.image-pane.show-collection .page-nav,
.image-pane.show-collection .page-chrome { display: none; }

/* ── Figure view: what the tutor drew (graphs, geometry), in the side pane ── */
.figure {
  --fg-surface: #ffffff; --fg-ink: #302b27; --fg-soft: #66635d; --fg-grid: #ebe8e1; --fg-axis: #55524c;
  --fg-accent: #94422a; --fg-s1: #2a78d6; --fg-s2: #d95926; --fg-s3: #12906a; --fg-s4: #b07a00; --fg-s5: #d55181;
  flex: 1; min-height: 0; display: flex; flex-direction: column; border: 1px solid #dcd8cf; border-radius: 0.5rem;
  background: var(--fg-surface); overflow: hidden; animation: co-in 0.28s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.figure[hidden] { display: none; }
.image-pane.show-figure .page-stage,
.image-pane.show-figure .page-nav,
.image-pane.show-figure .page-chrome { display: none; }
.fg-body { flex: 1; min-height: 0; overflow: auto; padding: 0.75rem 0.75rem 1.125rem; display: flex; flex-direction: column; justify-content: safe center; gap: 0.625rem; outline: none; }
.fg-body:focus-visible { box-shadow: inset 0 0 0 0.125rem var(--focus); }
.fg-canvas { position: relative; flex: none; min-width: 0; direction: ltr; }
.fg-svg { display: block; margin-inline: auto; max-width: 100%; height: auto; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.fg-grid { stroke: var(--fg-grid); stroke-width: 1; }
.fg-axis { stroke: var(--fg-axis); stroke-width: 1.2; }
.fg-arrow { fill: var(--fg-axis); }
.fg-tick, .fg-name, .fg-label { font-family: KaTeX_Main, "Times New Roman", "Noto Sans Hebrew", serif; fill: var(--fg-soft); font-size: 0.7812rem;
  paint-order: stroke; stroke: var(--fg-surface); stroke-width: 0.2188rem; stroke-linejoin: round; }
.fg-name { font-style: italic; font-size: 0.875rem; fill: var(--fg-axis); }
.fg-label { fill: var(--fg-ink); font-size: 0.9688rem; }
.fg-label.small { font-size: 0.8438rem; }
.fg-label.free { font-size: 0.875rem; }
.fg-curve { fill: none; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }
.fg-curve.dashed, .fg-shape.dashed { stroke-dasharray: 7 5; }
.fg-s1 { stroke: var(--fg-s1); } .fg-s2 { stroke: var(--fg-s2); } .fg-s3 { stroke: var(--fg-s3); }
.fg-s4 { stroke: var(--fg-s4); } .fg-s5 { stroke: var(--fg-s5); }
.fg-shape { fill: none; stroke: var(--fg-ink); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.fg-shape.fill { fill: color-mix(in srgb, var(--fg-accent) 13%, transparent); }
.fg-area { fill: color-mix(in srgb, var(--fg-accent) 22%, transparent); stroke: none; }
.fg-head { fill: var(--fg-ink); }
.fg-angle { fill: none; stroke: var(--fg-accent); stroke-width: 1.5; }
.fg-point { fill: var(--fg-ink); stroke: var(--fg-surface); stroke-width: 2; }
.fg-hair { stroke: var(--fg-soft); stroke-width: 1; stroke-dasharray: 3 4; opacity: 0.7; }
.fg-probe { fill: var(--fg-surface); stroke: var(--fg-soft); stroke-width: 2; }
.fg-probe.fg-s1 { stroke: var(--fg-s1); } .fg-probe.fg-s2 { stroke: var(--fg-s2); } .fg-probe.fg-s3 { stroke: var(--fg-s3); }
.fg-probe.fg-s4 { stroke: var(--fg-s4); } .fg-probe.fg-s5 { stroke: var(--fg-s5); }
.fg-read { position: absolute; top: 0.125rem; right: 0.25rem; padding: 0.1875rem 0.5625rem; border-radius: 62.4375rem; background: var(--fg-surface);
  border: 1px solid var(--line); color: var(--fg-ink); font-size: 0.7812rem; font-variant-numeric: tabular-nums; direction: ltr; pointer-events: none; }
.fg-read[hidden] { display: none; }
.fg-legend { list-style: none; margin: 0; padding: 0 0.25rem; display: flex; flex-wrap: wrap; gap: 0.375rem 1.125rem; justify-content: center; direction: ltr; }
.fg-legend[hidden], .fg-note[hidden] { display: none; }
.fg-legend li { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--fg-ink); font-size: 0.875rem; }
.fg-legend svg { flex: none; }
.fg-legend .fg-curve { stroke-width: 2.6; }
.fg-legend code { font-size: 0.8125rem; }
.fg-note { margin: 0; text-align: center; color: var(--fg-soft); font-size: 0.8125rem; line-height: 1.5; }
/* The formula sheet in the figure's place: the printed page, and a loop around each formula the tutor named. */
/* Left to right, so that a pane narrower than the page scrolls sideways to all of it. */
.figure.is-sheet .fg-body { justify-content: flex-start; direction: ltr; }
.figure.is-sheet .fg-canvas { width: max-content; align-self: safe center; }
.fg-sheet { position: relative; flex: none; }
.fg-sheet img, .fg-marks { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.fg-sheet img { user-select: none; -webkit-user-select: none; }
.fg-marks { overflow: visible; pointer-events: none; }
.fg-mark { fill: color-mix(in srgb, var(--fg-accent) 11%, transparent); stroke: var(--fg-accent); stroke-width: 2.4;
  vector-effect: non-scaling-stroke; stroke-linejoin: round; animation: fg-mark-in 0.9s ease-out 0.15s both; }
@keyframes fg-mark-in { from { opacity: 0; stroke-width: 7; } to { opacity: 1; stroke-width: 2.4; } }
@media (prefers-reduced-motion: reduce) { .fg-mark { animation: none; } }
@media (prefers-reduced-motion: reduce) { .figure { animation: none; } }
.co-head { display: flex; align-items: center; justify-content: space-between; gap: 0.625rem; padding: 0.625rem 0.75rem; padding-inline-end: 3.75rem; background: #fffffff2; border-bottom: 1px solid var(--line); flex: none; }
.co-titles { display: flex; flex-direction: column; min-width: 0; }
.co-titles strong { font-size: 0.9375rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.co-titles small { color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.co-actions { display: flex; gap: 0.375rem; flex: none; }
.co-btn { border: 1px solid var(--line); background: #fff; color: #4a4742; border-radius: 62.4375rem; padding: 0.375rem 0.75rem; font: inherit; font-size: 0.7812rem; cursor: pointer; transition: background 0.15s, color 0.15s, border-color 0.15s; }
.co-btn:hover { background: #f8ece7; color: var(--green); border-color: #e7c9bd; }
.co-btn[hidden] { display: none; }
.co-list { flex: 1; min-height: 0; overflow: auto; padding: 0.75rem 0.75rem 4.375rem; display: flex; flex-direction: column; gap: 0.875rem; outline: none; scroll-behavior: smooth; }
.co-list:focus-visible { box-shadow: inset 0 0 0 0.125rem #a94d3166; }
.co-card { background: #fff; border-radius: 0.5rem; box-shadow: 0 0.125rem 0.875rem #2630200d; overflow: hidden; flex: none; }
.co-card-head { display: flex; align-items: center; gap: 0.625rem; padding: 0.5625rem 0.75rem; border-bottom: 1px solid #f0ede7; }
.co-num { width: 1.625rem; height: 1.625rem; flex: none; border-radius: 50%; background: #f8ece7; color: var(--green); display: grid; place-items: center; font-size: 0.75rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.co-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.co-info strong { font-size: 0.8438rem; }
.co-chips { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.co-chip { font-size: 0.6875rem; line-height: 1; padding: 0.1875rem 0.4375rem; border-radius: 62.4375rem; background: #f0ede7; color: #5d5a54; }
.co-chip.accent { background: #f8ece7; color: var(--green); }
.co-open { flex: none; border: 0; border-radius: 62.4375rem; padding: 0.4375rem 0.75rem; background: var(--green); color: #fff; font: inherit; font-size: 0.7812rem; cursor: pointer; transition: filter 0.15s, transform 0.1s; }
.co-open:hover { filter: brightness(1.08); }
.co-open:active { transform: scale(0.97); }
.co-card img { display: block; width: 100%; height: auto; min-height: 10rem; background: #fafaf8; }
.co-more { align-self: center; border: 1px dashed #cfc9bd; background: #fffffff0; color: var(--green); border-radius: 62.4375rem; padding: 0.5625rem 1.125rem; font: inherit; font-size: 0.8125rem; cursor: pointer; }
.co-more:hover { background: #f8ece7; }
.co-note { margin: 0.25rem 0.5rem 0; text-align: center; font-size: 0.7812rem; color: var(--muted); }
.co-btn:focus-visible, .co-open:focus-visible, .co-more:focus-visible { outline: 0.125rem solid #a94d3199; outline-offset: 0.125rem; }
@media (max-width: 700px) { .co-card-head { flex-wrap: wrap; } .co-open { margin-inline-start: auto; } }
@media (prefers-reduced-motion: reduce) { .collection { animation: none; } .co-list { scroll-behavior: auto; } }
.co-section { margin: 0.5rem 0.25rem 0; font-size: 0.8125rem; font-weight: 600; color: var(--green); display: flex; align-items: center; gap: 0.5rem; }
.co-section::after { content: ""; flex: 1; height: 1px; background: #d9d3c7; }
.co-section:first-child { margin-top: 0; }

/* ── Chat history additions (owned by chats.js: second line, touch actions, export/import, reset confirm) ── */
.chat-main { align-items: center; }
.chat-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.125rem; }
.chat-sub { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.7188rem; color: #8d8a83; }
.chat-sub.match { color: #7a5a4c; }
.history-tools { display: flex; gap: 0.25rem; padding-top: 0.5rem; border-top: 1px solid var(--line); }
.history-tool {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 0.4375rem;
  padding: 0.5625rem 0.625rem; border: 0; border-radius: 0.625rem; background: transparent;
  font: inherit; font-size: 0.8125rem; color: var(--muted); cursor: pointer;
}
.history-tool::before {
  content: ""; width: 0.9375rem; height: 0.9375rem; flex: none; background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat;
}
.history-tool:first-child { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 4v11M7 11l5 5 5-5M5 20h14'/%3E%3C/svg%3E"); }
.history-tool:nth-child(2) { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 16V5M7 9l5-5 5 5M5 20h14'/%3E%3C/svg%3E"); }
.history-tool:hover { background: var(--light); color: var(--ink); }
.history-list { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.history-list::-webkit-scrollbar { width: 0.5rem; }
.history-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 0.5rem; }
.history-list::-webkit-scrollbar-button { display: none; }
@media (hover: none), (pointer: coarse) {
  /* No hover on touch screens: keep rename and delete visible, with finger-sized targets. */
  .chat-actions { display: flex; }
  .chat-row .chat-when { display: none; }
  .chat-act { width: 44px; height: 44px; }
  .history-tool { padding: 12px 10px; }
  .history-search input, .chat-rename { font-size: 16px; } /* 16px keeps iOS from zooming in on focus */
}
.reset-confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.625rem; padding: 0.625rem 0.75rem; border-radius: 0.6875rem; background: color-mix(in srgb, var(--green) 14%, transparent); }
.reset-confirm .chat-confirm-text { white-space: normal; }

/* ══ Stream D: layout, page viewer, collection, a11y, dark mode, print ══════════════════════════════ */
:root {
  --green: #94422a; /* the accent, a touch darker: 5:1 on white, so it passes as text and under white text */
  --orange: #94422a;
  --muted: #66635d; /* secondary text, 5.6:1 on the page background */
  --bg: #faf9f5;
  --top-h: 4rem; /* room for the fixed top bar */
  --focus: #94422a;
}
body { background: var(--bg); }

/* Top bar: history, new chat and settings sit together (top right in RTL); the exam toggle top left. */
.top-actions .settings-btn { position: static; }

/* Focus rings: one solid ring, visible on every surface. */
.panel-toggle:focus-visible, .dd-btn:focus-visible, .pn-btn:focus-visible, .pn-chip:focus-visible, .pl-item:focus-visible,
.co-btn:focus-visible, .co-open:focus-visible, .co-more:focus-visible, .history-drawer :focus-visible, .sd-close:focus-visible,
.scope-select:focus-visible, .starter:focus-visible, .zm-btn:focus-visible, .co-remove:focus-visible, .co-link:focus-visible {
  outline: 0.125rem solid var(--focus);
  outline-offset: 0.125rem;
}
.page-stage:focus-visible, .co-list:focus-visible { box-shadow: inset 0 0 0 0.125rem var(--focus); }
.composer:focus-within { border-color: #9d958a; }

/* Readable small text (WCAG AA): nothing under 12px, secondary gray at >= 4.5:1. */
.eyebrow, .message-label, .source-chip, .slider-labels, .mapping, .card-meta, .page-empty small, .co-chip,
.history-group, .chat-when, .settings-dialog .slider-labels, .settings-dialog .mapping { font-size: 0.75rem; }
.usage { color: var(--muted); font-size: 0.75rem; }
.eyebrow, .settings-fields small, .page-empty, .history-group, .chat-when, .pl-page, .sd-fine, input::placeholder,
textarea::placeholder { color: var(--muted); }
.sd-fine { font-size: 0.75rem; }
.key-notice { font-size: 0.75rem; }
.math-button, .model-button, .scope-select, .dd-btn, .starter { color: #57544e; }

/* Wide display equations scroll sideways; a soft shadow at the edge says there is more. */
.content .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.375rem 0.125rem;
  background:
    linear-gradient(to right, var(--bg) 30%, transparent) left center / 1.75rem 100% no-repeat local,
    linear-gradient(to left, var(--bg) 30%, transparent) right center / 1.75rem 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, #302c2430, transparent) left center / 0.75rem 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, #302c2430, transparent) right center / 0.75rem 100% no-repeat scroll;
}
/* Hebrew words inside math (a numerator like "דרך", a unit like קמ"ש) are taller than KaTeX's Latin metrics. */
.content .katex { line-height: 1.35; }
.content .katex .vlist-t2 > .vlist-r:first-child, .content .katex .vlist { overflow: visible; }

/* Page viewer: the page is clickable (opens the zoom view). */
#exam-page { cursor: zoom-in; }
.page-chrome { gap: 0.5rem; }
.page-zoom { padding: 0; border: 1px solid #d5dbc8; cursor: pointer; }
.page-zoom:hover { filter: none; background: #fff; }
.toggle-text { white-space: nowrap; }

/* Collection cards: clear label, every page, done and remove. */
.co-card-head { align-items: flex-start; }
.co-info strong { font-size: 0.875rem; line-height: 1.45; }
.co-subject { font-size: 0.7812rem; color: var(--muted); line-height: 1.4; }
.co-chip { line-height: 1.2; padding: 0.1875rem 0.5rem; color: #4f4c46; }
.co-card-actions { display: flex; align-items: center; gap: 0.375rem; flex: none; }
.co-done { display: inline-flex; align-items: center; gap: 0.375rem; font-size: 0.7812rem; color: #4f4c46; cursor: pointer; padding: 0.375rem 0.5rem; border-radius: 62.4375rem; user-select: none; }
.co-done:hover { background: #f3f1eb; }
.co-done input { width: 1.0625rem; height: 1.0625rem; margin: 0; accent-color: var(--green); cursor: pointer; }
.co-remove { width: 2rem; height: 2rem; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: var(--muted); }
.co-remove:hover { background: #f7dfd8; color: #9a3623; filter: none; }
.co-card img { cursor: zoom-in; }
.co-card img.co-cont { border-top: 0.125rem dashed #e3ddd2; }
.co-card.done .co-num { background: #e6efe3; color: #3f6b3a; }
.co-card.done .co-num::before { content: "✓"; }
.co-card.done .co-num { font-size: 0; }
.co-card.done .co-num::before { font-size: 0.875rem; }
.co-card.done img { opacity: 0.55; }
.co-card.done .co-info strong { color: var(--muted); }
.co-bar { display: flex; flex-direction: column; gap: 0.25rem; padding: 0.4375rem 0.75rem; background: #fbf4ef; border-bottom: 1px solid #ecd9cf; font-size: 0.8125rem; color: #4f4c46; flex: none; }
.co-bar-row { display: flex; align-items: center; justify-content: space-between; gap: 0.625rem; min-width: 0; }
.co-bar-row > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.co-link { flex: none; background: transparent; border: 0; padding: 0.25rem 0.375rem; color: var(--green); font: inherit; font-size: 0.8125rem; font-weight: 600; text-decoration: underline; text-underline-offset: 0.1875rem; }
.co-link:hover { filter: none; color: #8a4530; }
@media (max-width: 700px) {
  .co-card-head { flex-wrap: wrap; }
  .co-card-actions { width: 100%; justify-content: flex-end; }
  .co-open { margin-inline-start: 0; }
}

/* ── Zoom view (a page, large) ─────────────────────────── */
.zoom {
  position: fixed; inset: 0; width: 100vw; height: 100dvh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: #1d1c1af2; color: #f3f1ec;
  display: none; flex-direction: column; overflow: hidden;
}
.zoom[open] { display: flex; animation: fade-in 0.18s ease-out; }
.zoom::backdrop { background: transparent; }
html.zoom-open, html.zoom-open body { overflow: hidden; }
.zm-top {
  flex: none; display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  padding: max(0.625rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.5rem max(1rem, env(safe-area-inset-left));
}
.zm-title { font-size: 0.9375rem; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zm-hint { font-size: 0.7812rem; color: #c9c5bd; white-space: nowrap; }
.zm-stage { flex: 1; min-height: 0; position: relative; overflow: hidden; touch-action: none; cursor: grab; user-select: none; }
.zm-stage:active { cursor: grabbing; }
.zm-img { position: absolute; top: 0; left: 0; transform-origin: 0 0; max-width: none; background: #fff; box-shadow: 0 0.625rem 2.5rem #0006; border-radius: 0.125rem; }
.zm-bar {
  flex: none; align-self: center; display: flex; align-items: center; gap: 0.25rem; flex-wrap: wrap; justify-content: center;
  margin: 0.5rem 0.75rem max(0.75rem, env(safe-area-inset-bottom)); padding: 0.3125rem;
  background: #fffffff2; color: #302b27; border-radius: 62.4375rem; box-shadow: 0 0.5rem 1.875rem #0005;
}
.zm-btn {
  width: 2.75rem; height: 2.75rem; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%;
  background: transparent; color: #4a4742; text-decoration: none; cursor: pointer;
}
.zm-btn:hover:not(:disabled) { background: #f3ebe7; color: var(--green); filter: none; }
.zm-btn:disabled { opacity: 0.3; cursor: default; }
.zm-btn[hidden], .zm-pos[hidden], .zm-sep[hidden] { display: none; }
.zm-fit { width: auto; min-width: 4rem; padding: 0 0.625rem; border-radius: 62.4375rem; font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.zm-close { background: var(--green); color: #fff; }
.zm-close:hover:not(:disabled) { background: #8a4530; color: #fff; }
.zm-pos { min-width: 5.75rem; text-align: center; font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.zm-sep { width: 1px; height: 1.375rem; background: #ddd8cf; margin: 0 0.25rem; }
@media (max-width: 560px) {
  .zm-hint, .zm-link, .zm-sep { display: none !important; }
  .zm-bar { flex-wrap: nowrap; gap: 0; margin-inline: 0.5rem; }
  .zm-pos { min-width: 0; padding: 0 0.25rem; font-size: 0.7812rem; white-space: nowrap; }
  .zm-fit { min-width: 3.25rem; padding: 0 0.375rem; }
}
@media (prefers-reduced-motion: reduce) { .zoom[open] { animation: none; } }

/* ── Sheet mode: phones, small tablets, short or zoomed-in windows ──────────────────────────────
   The conversation and the message box get the whole screen. The exam pane, when open, is a sheet that
   covers the conversation only: it sits between the top bar and the message box, which stays usable
   (its height comes from pageview.js as --composer-h). Nothing ever covers the message box. */
@media (max-width: 1000px), (max-height: 520px) {
  .workspace, .workspace:not(.page-expanded) { display: flex; flex-direction: column; height: var(--app-h, 100dvh); }
  .tutor-pane { flex: 1; min-height: 0; padding-top: var(--top-h); }
  .learning-area { min-height: 0; }
  .composer-area { padding-bottom: max(0.75rem, env(safe-area-inset-bottom)); }
  .image-pane {
    position: fixed; z-index: 4; top: 0; inset-inline: 0;
    bottom: calc(var(--composer-h, 0px) + var(--keyboard-h, 0px));
    max-height: none; min-height: 0;
    padding: var(--top-h) max(0.625rem, env(safe-area-inset-right)) 0.375rem max(0.625rem, env(safe-area-inset-left));
    border: 0; border-bottom: 1px solid var(--line);
    box-shadow: 0 0.375rem 1.125rem #302c2414;
    animation: sheet-in 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
  }
  .image-pane .page-stage { display: flex; flex: 1; min-height: 0; max-height: none; padding-bottom: 3.75rem; }
  .page-chrome { position: absolute; top: calc(var(--top-h) + 0.5rem); inset-inline-start: 1.125rem; margin: 0; }
  .page-nav { bottom: 0.875rem; }
  /* The exam toggle says what it does, and appears only once there is a page or a worksheet to open. */
  html:not(.has-exam) #page-toggle { display: none; }
  #page-toggle { width: auto; display: inline-flex; align-items: center; gap: 0.25rem; padding: 0 0.75rem 0 0.5rem; }
  #page-toggle .toggle-text { display: inline; font-size: 0.875rem; color: var(--ink); }
  #page-toggle[aria-expanded="true"] { background: var(--green); border-color: var(--green); color: #fff; }
  #page-toggle[aria-expanded="true"] .toggle-text { color: #fff; }
  #page-toggle:hover .chev, #page-toggle[aria-expanded="true"]:hover .chev { transform: none; }
  #page-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
  .co-head { padding-inline-end: 0.75rem; flex-wrap: wrap; }
  .co-actions { flex-wrap: wrap; }
}
@keyframes sheet-in { from { opacity: 0; transform: translateY(-0.625rem); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .image-pane { animation: none !important; } }
@media (max-width: 740px) {
  :root { --top-h: 3.875rem; }
  .page-chrome { inset-inline-start: 0.875rem; }
  .composer textarea { min-height: 2.875rem; height: 2.875rem; padding: 0.375rem 0.25rem; }
  .pn-pos { min-width: 0; }
}
/* Short screens (landscape phone, on-screen keyboard up, 200% zoom): a slimmer top bar and message box. */
@media (max-height: 600px) and (max-width: 740px) { .pv-home .welcome-mark { display: none; } }
@media (max-height: 520px) {
  :root { --top-h: 3.25rem; }
  .top-actions, .panel-toggle { top: 0.5rem; }
  #page-toggle { top: 0.5rem; left: 0.75rem; }
  .top-actions { right: 0.75rem; }
  .composer-area { padding: 0.375rem 1rem max(0.5rem, env(safe-area-inset-bottom)); }
  .composer { padding: 0.5rem 0.75rem; border-radius: 1rem; }
  .composer textarea { min-height: 2.5rem; height: 2.5rem; padding: 0.25rem; --pad-top: 0.25rem; }
  .key-notice { margin-top: 0.375rem; }
  .reply-waiting { padding-bottom: 0.375rem; }
  .page-nav { bottom: 0.5rem; }
  .image-pane .page-stage { padding-bottom: 3.25rem; }
}

/* The on-screen keyboard is up (html.keyboard-up, app.js): the page is only as tall as what is visible above it,
   and the message box with what is being written gets the room. Safari on iPhone and iPad does not shorten the
   screen for the keyboard, so the short-screen rules above do not reach it: the ones that matter are repeated. */
html.keyboard-up { --top-h: 3.25rem; }
html.keyboard-up .top-actions, html.keyboard-up .panel-toggle { top: 0.5rem; }
html.keyboard-up #page-toggle { top: 0.5rem; left: 0.75rem; }
html.keyboard-up .top-actions { right: 0.75rem; }
html.keyboard-up .tutor-pane { padding-top: var(--top-h); }
html.keyboard-up .tutor-pane:has(#welcome:not([hidden])) { justify-content: flex-end; padding-bottom: 0; }
html.keyboard-up .tutor-pane:has(#welcome:not([hidden])) .learning-area { display: none; } /* back when it closes */
html.keyboard-up .composer-area { padding: 0.375rem 0.75rem 0.375rem; }
html.keyboard-up .composer { padding: 0.5rem 0.75rem; border-radius: 1rem; }
html.keyboard-up .composer-input { --min-h: 2.5rem; --pad-top: 0.25rem; }
html.keyboard-up .key-notice { margin-top: 0.375rem; }
html.keyboard-up .learning-area { padding-block: 0.25rem; }
html.keyboard-up .fx { gap: 0.375rem; padding-top: 0.375rem; }
html.keyboard-up .fx-keys { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; max-height: none; }
html.keyboard-up .fx-key { flex: none; }

/* Message box toolbar on narrow screens: one row that scrolls sideways, with a fade at the far edge as a cue. */
@media (max-width: 740px), (max-height: 520px) {
  .composer-tools > div {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain;
    padding-inline-end: 1.75rem; margin-inline-end: 0.5rem;
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 2.25rem);
    mask-image: linear-gradient(to right, transparent 0, #000 2.25rem);
  }
  .composer-tools > div::-webkit-scrollbar { display: none; }
  .composer-tools > div > * { flex: none; }
  /* The formula button shows just ƒx here; its name stays for screen readers and in the tooltip. */
  .composer-tools .math-button { font-size: 0; gap: 0; padding: 0 0.625rem; }
  .composer-tools .math-button span { font-size: 1.0625rem; }
}

/* Touch screens: every control at least 44px. */
@media (pointer: coarse) {
  .panel-toggle { width: 44px; height: 44px; }
  .composer-tools #send { width: 44px; height: 44px; }
  .composer-tools .math-button, .scope-select, .model-button, .dd-btn { height: 44px; min-width: 44px; }
  .composer-tools > div { gap: 6px; }
  .pn-btn, .sd-close, .chat-act, .co-remove, .page-open { width: 44px; height: 44px; }
  .pn-chip, .co-btn, .co-open, .co-more, .co-link, .starter { min-height: 44px; }
  .co-done { min-height: 44px; }
  .co-done input { width: 22px; height: 22px; }
  .dd-item, .pl-item { min-height: 44px; }
  .chat-main { min-height: 44px; }
  .zm-bar { gap: 2px; }
}
/* Chat rename / delete: with no hover (touch), always shown. */
@media (hover: none) {
  .chat-actions { display: flex; }
  .chat-row .chat-when { display: none; }
}

/* ── Print the conversation (the worksheet has its own print view) ── */
@media print {
  html, body { height: auto !important; overflow: visible !important; background: #fff !important; color: #000; }
  .workspace { display: block !important; height: auto !important; overflow: visible !important; }
  .tutor-pane { display: block !important; padding: 0 !important; overflow: visible !important; }
  .learning-area { overflow: visible !important; height: auto !important; padding: 0 !important; }
  .messages { max-width: none; }
  .message { animation: none !important; break-inside: avoid-page; }
  .composer-area, .image-pane, .top-actions, .panel-toggle, .history-drawer, .history-backdrop, .toast,
  .welcome, .reply-waiting, .zoom, .mp-overlay, dialog, .message button { display: none !important; }
  .content .katex-display { background: none; overflow: visible; }
}

/* ── Dark mode ─────────────────────────────────────────── */
/* dark theme */
:root[data-theme='dark'] {

    color-scheme: dark;
    --ink: #f3ece2;
    --muted: #c2b5a7;
    --paper: #2d2824;
    --line: #50453c;
    --green: #e59c7e;
    --orange: #e59c7e;
    --light: #302b27;
    --bg: #262320;
    --focus: #e59c7e;
}
:where(:root[data-theme='dark']) body, :where(:root[data-theme='dark']) .composer-area { background: var(--bg); }
:where(:root[data-theme='dark']) button { color: #fff; }
:where(:root[data-theme='dark']) button { background-color: #a94d31; } /* class rules (quiet, chips, icons) still win */
:where(:root[data-theme='dark']) .composer-tools #send, :where(:root[data-theme='dark']) .sd-primary, :where(:root[data-theme='dark']) .history-new, :where(:root[data-theme='dark']) .co-open { background: #a94d31; color: #fff; }
:where(:root[data-theme='dark']) .composer-tools #send:not(:disabled):hover, :where(:root[data-theme='dark']) .sd-primary:hover, :where(:root[data-theme='dark']) .history-new:hover { background: #b85c3e; }
:where(:root[data-theme='dark']) .composer, :where(:root[data-theme='dark']) .settings-dialog, :where(:root[data-theme='dark']) .sd-head, :where(:root[data-theme='dark']) .history-drawer, :where(:root[data-theme='dark']) .dd-list, :where(:root[data-theme='dark']) .page-log, :where(:root[data-theme='dark']) .sd-card { background: var(--paper); border-color: var(--line); }
:where(:root[data-theme='dark']) .settings-dialog, :where(:root[data-theme='dark']) .sd-head, :where(:root[data-theme='dark']) .history-drawer { background: #2a2622; }
:where(:root[data-theme='dark']) .composer:focus-within { border-color: #6a655c; }
:where(:root[data-theme='dark']) .message.user .content { background: #2e2c28; }
:where(:root[data-theme='dark']) .message.system, :where(:root[data-theme='dark']) .catalog-text .stem, :where(:root[data-theme='dark']) .mapping, :where(:root[data-theme='dark']) .settings-dialog .mapping, :where(:root[data-theme='dark']) .settings-dialog .price-grid > div, :where(:root[data-theme='dark']) .sd-field select, :where(:root[data-theme='dark']) .sd-field input[type="password"], :where(:root[data-theme='dark']) .sd-field input[type="number"], :where(:root[data-theme='dark']) .settings-dialog .filter-row input, :where(:root[data-theme='dark']) .history-search { background: #302b27; border-color: var(--line); color: var(--ink); }
:where(:root[data-theme='dark']) .message.system .content, :where(:root[data-theme='dark']) .sd-field, :where(:root[data-theme='dark']) .co-chip, :where(:root[data-theme='dark']) .co-done, :where(:root[data-theme='dark']) .co-bar, :where(:root[data-theme='dark']) .dd-item, :where(:root[data-theme='dark']) .pl-item, :where(:root[data-theme='dark']) .pn-pos { color: #d3cfc7; }
:where(:root[data-theme='dark']) .content pre, :where(:root[data-theme='dark']) .content code { background: #2e2c28; }
:where(:root[data-theme='dark']) .math-button, :where(:root[data-theme='dark']) .model-button, :where(:root[data-theme='dark']) .scope-select, :where(:root[data-theme='dark']) .dd-btn, :where(:root[data-theme='dark']) .starter, :where(:root[data-theme='dark']) .chat-act, :where(:root[data-theme='dark']) .pn-btn, :where(:root[data-theme='dark']) .sd-close { color: #cfcac1; }
:where(:root[data-theme='dark']) .quiet:hover, :where(:root[data-theme='dark']) .model-button:hover, :where(:root[data-theme='dark']) .scope-select:hover, :where(:root[data-theme='dark']) .starter:hover, :where(:root[data-theme='dark']) .dd-btn:hover, :where(:root[data-theme='dark']) .dd-item.active, :where(:root[data-theme='dark']) .pl-item:hover, :where(:root[data-theme='dark']) .chat-row:hover, :where(:root[data-theme='dark']) .chat-row:focus-within, :where(:root[data-theme='dark']) .chat-act:hover, :where(:root[data-theme='dark']) .sd-close:hover, :where(:root[data-theme='dark']) .pn-btn:hover:not(:disabled), :where(:root[data-theme='dark']) .co-done:hover { background: #3a332d; color: var(--ink); }
:where(:root[data-theme='dark']) .dd-btn[aria-expanded="true"], :where(:root[data-theme='dark']) .chat-row.current, :where(:root[data-theme='dark']) .pn-chip, :where(:root[data-theme='dark']) .co-num, :where(:root[data-theme='dark']) .co-chip.accent { background: #493129; color: #eaa98c; border-color: #7a4a36; }
:where(:root[data-theme='dark']) .panel-toggle, :where(:root[data-theme='dark']) .page-open, :where(:root[data-theme='dark']) .page-nav, :where(:root[data-theme='dark']) .co-head, :where(:root[data-theme='dark']) .co-btn { background: #302b27f2; border-color: var(--line); color: #d3cfc7; }
:where(:root[data-theme='dark']) .panel-toggle:hover { background: #3a332d; border-color: #7a4a36; }
:where(:root[data-theme='dark']) .toast { background: #ebe8e2; color: #1c1b19; }
:where(:root[data-theme='dark']) .image-pane { background: #2a2622; }
:where(:root[data-theme='dark']) .page-stage, :where(:root[data-theme='dark']) .collection { background: #231f1c; border-color: var(--line); }
:where(:root[data-theme='dark']) .figure {

    --fg-surface: #231f1c; --fg-ink: #ebe8e2; --fg-soft: #b2ada4; --fg-grid: #2c2b27; --fg-axis: #bdb8ae;
    --fg-accent: #e59c7e; --fg-s1: #3987e5; --fg-s2: #d95926; --fg-s3: #199e70; --fg-s4: #c98500; --fg-s5: #d55181;
    border-color: var(--line);
}
/* The formula sheet is black line art on nothing: in the dark it turns to light ink on the pane's own surface. */
:where(:root[data-theme='dark']) .fg-sheet img { filter: invert(1) brightness(0.92); }
/* Exam pages stay paper-white (they are scans) but a little dimmer, so they do not glare at night. */
:where(:root[data-theme='dark']) .page-stage img, :where(:root[data-theme='dark']) .co-card img { filter: brightness(0.86) contrast(1.05); }
:where(:root[data-theme='dark']) .co-card { background: #2d2824; box-shadow: none; }
:where(:root[data-theme='dark']) .co-card-head { border-bottom-color: var(--line); }
:where(:root[data-theme='dark']) .co-chip { background: #3a332d; }
:where(:root[data-theme='dark']) .co-card.done .co-num { background: #26382a; color: #9fd09a; }
:where(:root[data-theme='dark']) .co-bar { background: #2f2622; border-color: #5a3a2e; }
:where(:root[data-theme='dark']) .co-link { color: #eaa98c; }
:where(:root[data-theme='dark']) .co-more { background: #2d2824; border-color: #55524b; }
:where(:root[data-theme='dark']) .co-section::after { background: var(--line); }
:where(:root[data-theme='dark']) .notice:not(:empty) { background: #3a2520; color: #f0b3a3; }
:where(:root[data-theme='dark']) .history-backdrop.open, :where(:root[data-theme='dark']) dialog::backdrop, :where(:root[data-theme='dark']) .mp-overlay.open { background: #0008; }
:where(:root[data-theme='dark']) .chat-confirm { background: #302b27; color: var(--ink); }
:where(:root[data-theme='dark']) .chat-row.confirming { background: #3a2520; }
:where(:root[data-theme='dark']) .chat-confirm-text { color: #f0b3a3; }
:where(:root[data-theme='dark']) ::-webkit-scrollbar-thumb { background: #4a4740; background-clip: content-box; }
:where(:root[data-theme='dark']) * { scrollbar-color: #4a4740 transparent; }
:where(:root[data-theme='dark']) .waiting-dots i { background: var(--green); }
:where(:root[data-theme='dark']) .zm-bar { background: #302b27f2; color: var(--ink); }
:where(:root[data-theme='dark']) .zm-btn { color: #d3cfc7; }
:where(:root[data-theme='dark']) .zm-btn:hover:not(:disabled) { background: #3a332d; color: #eaa98c; }
:where(:root[data-theme='dark']) .zm-close { background: #a94d31; color: #fff; }
:where(:root[data-theme='dark']) .zm-sep { background: var(--line); }
:where(:root[data-theme='dark']) .welcome-mark { color: #e59c7e; }
:where(:root[data-theme='dark']) .katex { color: var(--ink); }
@media (max-width: 1000px), (max-height: 520px) {
  :where(:root[data-theme='dark']) #page-toggle[aria-expanded="true"] { background: #a94d31; border-color: #a94d31; }
}
/* ══ end of Stream D ════════════════════════════════════════════════════════════════════════════ */

/* ══ Stream C: composer and messages (stop button, counter, message actions) ═══════════════════════ */
.composer-tools #send { user-select: none; -webkit-user-select: none; }
.composer-tools #send.stop { background: var(--ink); color: var(--paper); cursor: pointer; }
.composer-tools #send.stop:hover { background: #000; }
.char-count { margin: 0 0.375rem 0.25rem; font-size: 0.75rem; color: var(--muted); }
.char-count.over { color: #9a4a35; font-weight: 600; }
.message-actions { display: flex; gap: 0.375rem; margin-top: 0.375rem; }
.message-actions:empty { display: none; }
.msg-act {
  font: inherit; font-size: 0.75rem; line-height: 1.4; padding: 0.1875rem 0.625rem; border-radius: 62.4375rem;
  border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer;
}
.msg-act:hover { color: var(--ink); border-color: #cfcac0; }
.msg-act:focus-visible { outline: 0.125rem solid #b7afa1; outline-offset: 1px; }
.msg-act.retry { color: var(--green); border-color: currentColor; font-weight: 600; }
.msg-act.retry:hover { background: #fbf1ed; color: var(--green); }
.message .content .math-inline, .message .content .ltr-run { unicode-bidi: isolate; }
.usage-toggle { display: flex; align-items: center; gap: 0.5rem; font-size: 0.7812rem; color: var(--muted); margin: 0.5rem 0; cursor: pointer; }
/* dark theme */
:where(:root[data-theme='dark']) .composer-tools #send.stop { background: #e9e5dc; color: #1f1e1b; }
:where(:root[data-theme='dark']) .composer-tools #send.stop:hover { background: #fff; }
:where(:root[data-theme='dark']) .msg-act:hover { border-color: #5a564e; }
:where(:root[data-theme='dark']) .msg-act.retry:hover { background: #3a2520; }
:where(:root[data-theme='dark']) .char-count.over { color: #eaa98c; }
/* ══ end of Stream C ═══════════════════════════════════════════════════════════════════════════════ */

/* ══ Settings dialog: flat sections with dividers; owner options collapsed under "הגדרות מתקדמות" ══════════ */
.settings-dialog { width: min(30rem, calc(100% - 1.5rem)); }
.sd-head { padding: 1rem 1.375rem 0.875rem; }
.sd-head h2 { margin: 0; font-size: 1.125rem; font-weight: 600; }
.sd-body { padding: 0 1.375rem 0.875rem; gap: 0; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.sd-body::-webkit-scrollbar { width: 0.5rem; }
.sd-body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 0.5rem; }
.sd-body::-webkit-scrollbar-button { display: none; }
.sd-sec { display: flex; flex-direction: column; gap: 0.75rem; padding: 1.25rem 0; border-bottom: 1px solid var(--line); }
.sd-sec h3 { margin: 0; font-size: 0.9375rem; font-weight: 600; color: var(--ink); }
.sd-hint { margin: 0; font-size: 0.8125rem; line-height: 1.65; color: var(--muted); }
.settings-dialog .sd-field { gap: 0.4375rem; font-size: 0.8438rem; color: var(--ink); }
.settings-dialog .sd-row { align-items: center; }
.settings-dialog .sd-row output {
  font-size: 0.7812rem; font-weight: 600; color: var(--green);
  background: color-mix(in srgb, var(--green) 13%, transparent); border-radius: 62.4375rem; padding: 0.1875rem 0.6875rem;
}
.settings-dialog input[type="range"] { accent-color: var(--green); margin: 0.25rem 0 0; }
.settings-dialog .slider-labels { margin-top: 0; font-size: 0.7812rem; color: var(--muted); }
.sd-advanced > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 1rem 0 0.75rem; font-size: 0.875rem; color: var(--muted); cursor: pointer; list-style: none; border-radius: 0.5rem;
}
.sd-advanced > summary::-webkit-details-marker { display: none; }
.sd-advanced > summary::after {
  content: ""; width: 0.4375rem; height: 0.4375rem; margin-inline-end: 0.25rem;
  border: solid currentColor; border-width: 0 0.1125rem 0.1125rem 0; transform: rotate(45deg); transition: transform 0.15s;
}
.sd-advanced[open] > summary::after { transform: rotate(-135deg); }
.sd-advanced > summary:hover { color: var(--ink); }
.sd-advanced > summary:focus-visible { outline: 0.125rem solid var(--green); outline-offset: 0.125rem; }
.sd-adv-body { display: flex; flex-direction: column; gap: 1.625rem; padding: 0.375rem 0 0.5rem; }
.sd-group { display: flex; flex-direction: column; gap: 0.6875rem; }
.sd-group h4 { margin: 0; font-size: 0.7812rem; font-weight: 600; color: var(--muted); }
.settings-dialog .mapping { margin: 0; padding: 0.5rem 0.6875rem; font-size: 0.75rem; background: var(--light); color: var(--muted); border-radius: 0.5rem; overflow-wrap: anywhere; }
.settings-dialog .price-grid { gap: 0.5rem; }
.settings-dialog .price-grid > div { border: 0; background: var(--light); padding: 0.625rem 0.75rem; font-size: 0.7812rem; }
.settings-dialog .price-grid strong { margin-top: 0.1875rem; font-size: 1rem; font-weight: 600; color: var(--ink); }
.settings-dialog .session-panel-row { font-size: 0.8438rem; }
.settings-dialog .usage-toggle { margin: 0.125rem 0; font-size: 0.8438rem; color: var(--ink); }
@media (max-width: 560px) { .sd-body { padding: 0 1rem 0.75rem; } .sd-head { padding: 0.875rem 1rem 0.75rem; } }
@media (prefers-reduced-motion: reduce) { .sd-advanced > summary::after { transition: none; } }
/* ══ end of settings dialog ═════════════════════════════════════════════════════════════════════════ */

/* ══ Formula panel inside the message box: field, symbol tabs, symbol keys ════════════════════════════ */
.fx { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.25rem; padding: 0.625rem 0 0.125rem; border-top: 1px solid var(--line); }
.fx[hidden] { display: none; }
.fx-field {
  display: flex; align-items: center; gap: 0.75rem; min-height: 2.875rem; padding: 0.25rem 0.875rem 0.25rem 0.3125rem;
  border: 1px solid var(--line); border-radius: 0.75rem; background: color-mix(in srgb, var(--ink) 3%, transparent);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.fx-field:focus-within { border-color: color-mix(in srgb, var(--green) 60%, var(--line)); box-shadow: 0 0 0 0.1875rem color-mix(in srgb, var(--green) 14%, transparent); }
.fx-input {
  order: 1; flex: 1; min-width: 0; display: block; padding: 0.25rem 0; border: 0; outline: 0; background: transparent; color: var(--ink);
  font-size: 1.1875rem; --caret-color: var(--green); --selection-background-color: color-mix(in srgb, var(--green) 24%, transparent);
  --selection-color: var(--ink); --contains-highlight-background-color: transparent; --placeholder-color: var(--muted);
  --smart-fence-color: var(--ink);
}
.fx-input:focus, .fx-input:focus-within { outline: 0; }
.fx-input::part(virtual-keyboard-toggle), .fx-input::part(menu-toggle) { display: none; }
.fx-insert {
  order: 0; flex: none; height: 2.125rem; padding: 0 1rem; border: 0; border-radius: 0.5625rem; cursor: pointer;
  background: var(--green); color: #fff; font: inherit; font-size: 0.8438rem;
}
.fx-insert:hover { filter: brightness(1.07); }
.fx-bar { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.fx-tabs { display: flex; gap: 0.125rem; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.fx-tabs::-webkit-scrollbar { display: none; }
.fx-tab {
  flex: none; padding: 0.3125rem 0.6875rem; border: 0; border-radius: 62.4375rem; background: transparent; cursor: pointer;
  font: inherit; font-size: 0.8125rem; color: var(--muted);
}
.fx-tab:hover { color: var(--ink); }
.fx-tab[aria-selected="true"] { background: var(--light); color: var(--ink); }
.fx-close {
  flex: none; width: 1.75rem; height: 1.75rem; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); font-size: 0.8125rem; cursor: pointer;
}
.fx-close:hover { background: var(--light); color: var(--ink); }
.fx-keys { display: flex; flex-wrap: wrap; gap: 0.375rem; max-height: 5.125rem; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.fx-key {
  flex: none; min-width: 2.5rem; height: 2.375rem; padding: 0 0.5625rem; display: grid; place-items: center; direction: ltr;
  border: 1px solid var(--line); border-radius: 0.625rem; background: transparent; color: var(--ink); cursor: pointer;
  font-size: 0.9375rem; line-height: 1; transition: background-color 0.12s, border-color 0.12s, transform 0.08s;
}
.fx-key:hover { background: var(--light); border-color: color-mix(in srgb, var(--ink) 22%, var(--line)); }
.fx-key:active { transform: scale(0.95); }
.fx-key .katex { font-size: 1em; }
.fx-key .amsrm { opacity: 0.55; font-size: 0.82em; } /* the empty-slot squares */
.fx-key:has(.mfrac) .katex { font-size: 0.74em; } /* fractions and binomials are two lines tall */
.fx-tab:focus-visible, .fx-key:focus-visible, .fx-close:focus-visible, .fx-insert:focus-visible { outline: 0.125rem solid var(--green); outline-offset: 1px; }
.math-button[aria-expanded="true"] { background: var(--light); color: var(--ink); }
@media (hover: none), (pointer: coarse) {
  .fx-key { min-width: 44px; height: 44px; } .fx-keys { max-height: 94px; } .fx-close { width: 40px; height: 40px; }
  .fx-insert { height: 40px; } .fx-tab { padding: 9px 12px; }
}
@media (prefers-reduced-motion: reduce) { .fx-key, .fx-field { transition: none; } }
@media (hover: none) { .fx-key:hover { background: transparent; border-color: var(--line); } } /* no stuck hover after a tap */
/* dark theme */
:where(:root[data-theme='dark']) .fx-insert { background: #a94d31; }
@media print { .fx { display: none !important; } }
/* ══ end of formula panel ═════════════════════════════════════════════════════════════════════ */
.toast { cursor: pointer; } /* a click dismisses it */

/* ── Guide ──────────────────────────────────────────────── */
.guide-dialog { width: min(47.5rem, calc(100% - 1.5rem)); max-height: min(88dvh, 53.75rem); }
.guide-dialog .sd-body { padding: 1.125rem 1.375rem 1.375rem; gap: 0; }
.gd-lead { margin: 0 0 1rem; font-size: 0.9062rem; line-height: 1.7; color: var(--ink); }
.gd-sec { border-top: 1px solid var(--line); padding: 0.25rem 0 0.125rem; }
.gd-sec > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.75rem 0; cursor: pointer; list-style: none;
  font-size: 0.9375rem; font-weight: 600; color: var(--ink);
}
.gd-sec > summary::-webkit-details-marker { display: none; }
.gd-sec > summary::after {
  content: ""; width: 0.4375rem; height: 0.4375rem; flex: none; margin-inline-end: 0.25rem;
  border-right: 0.125rem solid var(--muted); border-bottom: 0.125rem solid var(--muted);
  transform: rotate(45deg); transition: transform 0.15s ease;
}
.gd-sec[open] > summary::after { transform: rotate(-135deg); }
.gd-sec > summary:focus-visible { outline: 0.125rem solid var(--green); outline-offset: 0.125rem; border-radius: 0.375rem; }
.gd-sec > :not(summary) { margin-bottom: 0.875rem; }
.gd-asks { margin: 0; display: grid; grid-template-columns: minmax(7.5rem, max-content) 1fr; gap: 0.625rem 1rem; align-items: start; }
.gd-asks dt { font-size: 0.8125rem; color: var(--muted); padding-top: 0.4375rem; }
.gd-asks dd { margin: 0; display: flex; flex-wrap: wrap; gap: 0.375rem 0.5rem; align-items: center; min-width: 0; }
.gd-asks .starter, .gd-tags .starter { text-align: start; }
.gd-note { font-size: 0.7812rem; color: var(--muted); flex-basis: 100%; }
.gd-list { margin: 0; padding-inline-start: 1.125rem; display: flex; flex-direction: column; gap: 0.5rem; font-size: 0.8438rem; line-height: 1.7; color: var(--ink); }
.gd-search { margin: 0 0 0.75rem; }
.gd-tags { display: flex; flex-direction: column; gap: 0.875rem; }
.gd-subject { display: flex; flex-direction: column; gap: 0.5rem; padding-bottom: 0.875rem; border-bottom: 1px dashed var(--line); }
.gd-subject:last-of-type { border-bottom: 0; padding-bottom: 0; }
.gd-subject h3 { margin: 0; }
.gd-subject h3 .starter { font-size: 0.875rem; font-weight: 600; color: var(--ink); border-color: #cfc9bd; }
.gd-row { display: flex; flex-wrap: wrap; gap: 0.375rem; align-items: center; }
.gd-kind { font-size: 0.75rem; color: var(--muted); min-width: 3.875rem; }
.gd-tag { display: inline-flex; align-items: baseline; gap: 0.375rem; padding: 0.3125rem 0.6875rem; font-size: 0.7812rem; }
.gd-count { font-size: 0.6875rem; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (max-width: 560px) {
  .gd-asks { grid-template-columns: 1fr; gap: 0.25rem; }
  .gd-asks dt { padding-top: 0.5rem; }
  .gd-kind { min-width: 0; flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) { .gd-sec > summary::after { transition: none; } }
@media print { .guide-dialog { display: none !important; } }

/* ── Scrollbars on the right ────────────────────────────── */
/* In a right-to-left page a scrolling box puts its scrollbar on the left. The chat, the dialogs and the chat list
   scroll as left-to-right boxes so the bar is on the right, and their content is turned back to right-to-left. */
.learning-area, .sd-body, .history-list { direction: ltr; }
.learning-area > *, .sd-body > *, .history-list > * { direction: rtl; }

/* ── The caret of the message box ───────────────────────── */
/* An empty box used to take its direction from its (missing) text, which put the caret on the left. While the
   placeholder shows, the box follows the page, so the caret waits on the right where Hebrew starts. */
.composer textarea:placeholder-shown { unicode-bidi: normal; }
/* The caret is the accent colour and breathes (a slow fade) instead of blinking on and off. */
@property --caret-a { syntax: "<number>"; inherits: false; initial-value: 1; }
input, textarea { caret-color: var(--green); }
.composer textarea { caret-animation: manual; animation: caret-breathe 1.3s ease-in-out infinite; }
@keyframes caret-breathe {
  0%, 100% { --caret-a: 1; caret-color: var(--green); }
  50% { --caret-a: 0.28; caret-color: color-mix(in srgb, var(--green) 35%, transparent); }
}
/* Empty and focused: instead of the browser's hairline, a tapered stroke with a soft glow stands where the first
   letter will go. It is drawn as the box's background, so nothing has to follow the caret; once there is text,
   the browser's own caret (same colour, same breathing) takes over. */
.composer textarea:focus:placeholder-shown {
  caret-color: transparent !important;
  background-image:
    linear-gradient(to bottom, transparent, rgb(from var(--green) r g b / var(--caret-a)) 24%,
      rgb(from var(--green) r g b / var(--caret-a)) 76%, transparent),
    radial-gradient(closest-side, rgb(from var(--green) r g b / calc(var(--caret-a) * 0.4)), transparent);
  background-repeat: no-repeat;
  background-size: 0.1562rem 1.625rem, 1.125rem 2.25rem;
  background-position: right 0 top calc(var(--pad-top, 0.375rem) - 0.5px), right -0.4844rem top calc(var(--pad-top, 0.375rem) - 0.3438rem);
}
@media (prefers-reduced-motion: reduce) {
  .composer textarea { animation: none; caret-animation: auto; }
}

/* ── Accounts (hosted app) ──────────────────────────────── */
/* Signing in is a dialog that opens when it is needed: on the first message, or from the button at the top. */
.signin-dialog {
  border: 1px solid var(--line); border-radius: 1.125rem; background: var(--paper); color: var(--ink);
  padding: 2.125rem 1.75rem 1.625rem; width: min(26.875rem, calc(100% - 1.75rem)); box-shadow: 0 1.5625rem 6.25rem #302c2429;
}
.signin-dialog .sd-close { position: absolute; top: 0.75rem; inset-inline-end: 0.75rem; }
.signin-dialog .welcome-mark { margin-bottom: 0; }
.signin-card { max-width: 26.25rem; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 0.875rem; }
.signin-card h2 { margin: 0; font-size: 1.5rem; font-weight: 500; letter-spacing: -0.4px; color: var(--ink); }
.signin-card p { margin: 0; font-size: 0.9375rem; line-height: 1.7; color: var(--muted); }
.signin-card small { font-size: 0.7812rem; color: var(--muted); }
.signin-google {
  display: inline-flex; align-items: center; gap: 0.625rem; margin-top: 0.375rem; padding: 0.6875rem 1.375rem;
  border: 1px solid var(--line); border-radius: 62.4375rem; background: var(--paper); color: var(--ink);
  font-size: 0.9375rem; font-weight: 500; cursor: pointer; box-shadow: 0 0.125rem 0.625rem #302c2412;
}
.signin-google:hover { border-color: #cfc9bd; filter: none; }
.signin-google:disabled { opacity: 0.6; cursor: progress; }
.signin-status { min-height: 1.4em; font-size: 0.8438rem; }
/* The account at the top: "כניסה עם Google" for a visitor, the account's picture for a student. It is the last
   button of the row (its left end); the site tree is the first, in the corner. */
.top-signin {
  display: inline-flex; align-items: center; gap: 0.5rem; height: 2.25rem; padding: 0 0.875rem; border: 1px solid var(--line);
  border-radius: 0.75rem; background: var(--paper); color: var(--ink); font: inherit; font-size: 0.875rem; font-weight: 500;
  cursor: pointer; white-space: nowrap; box-shadow: 0 1px 0.125rem #302c240d, 0 0.25rem 0.875rem #302c2410;
}
.top-signin:hover { border-color: color-mix(in srgb, var(--ink) 30%, var(--line)); filter: none; }
.top-signin:disabled { opacity: 0.6; cursor: progress; }
.top-signin svg { flex: none; }
.ts-short { display: none; }
@media (max-width: 620px) {
  .top-signin { padding: 0 0.6875rem; }
  .ts-long { display: none; }
  .ts-short { display: inline; }
}
/* On a touch screen the row's buttons are 44px tall (.panel-toggle): the sign-in button keeps their height. */
@media (pointer: coarse) {
  .top-signin { height: 44px; padding: 0 13px; }
  .top-actions .avatar-btn .avatar { width: 30px; height: 30px; }
}
/* A narrow phone with the whole row showing (a visitor in the free tutor): keep it clear of the left edge. */
@media (max-width: 400px) {
  .top-actions { gap: 0.375rem; }
  .top-signin { padding: 0 0.625rem; gap: 0.375rem; }
}
@media (max-width: 340px) {
  .top-signin { width: 2.75rem; padding: 0; justify-content: center; }
  .top-signin .ts-short { display: none; }
}
.avatar {
  display: grid; place-items: center; width: 1.625rem; height: 1.625rem; border-radius: 50%; overflow: hidden; flex: none;
  background: color-mix(in srgb, var(--green) 18%, var(--paper)); color: var(--green);
  font: 600 0.8125rem/1 system-ui, sans-serif;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.big { width: 4rem; height: 4rem; font-size: 1.625rem; }
.top-actions .avatar-btn { border-radius: 50%; }
.account-menu {
  position: fixed; z-index: 40; min-width: 14.375rem; max-width: calc(100vw - 1rem); padding: 0.375rem; display: flex;
  flex-direction: column; border: 1px solid var(--line); border-radius: 0.875rem; background: var(--paper);
  color: var(--ink); box-shadow: 0 0.875rem 2.75rem #302c2426;
}
.account-menu[hidden] { display: none; }
/* The site as a tree, under the top button. Branch lines come from each nested list's border and a short tick
   before each row; the last row's ::after hides the line below its tick. */
.nav-menu {
  position: fixed; z-index: 40; width: min(23.125rem, calc(100vw - 1rem)); max-height: calc(100dvh - 4.75rem); overflow-y: auto;
  padding: 0.5rem; border: 1px solid var(--line); border-radius: 0.875rem; background: var(--paper); color: var(--ink);
  box-shadow: 0 0.875rem 2.75rem #302c2426; overscroll-behavior: contain;
  --nt-line: color-mix(in srgb, var(--ink) 30%, var(--paper));
}
.nt, .nt ul { list-style: none; margin: 0; padding: 0; }
.nt ul { margin-inline-start: 1.0625rem; padding-inline-start: 0.75rem; border-inline-start: 0.0938rem solid var(--nt-line); }
.nt ul > li { position: relative; }
.nt ul > li::before { content: ""; position: absolute; inset-inline-start: -0.75rem; top: 1.125rem; width: 0.5625rem; border-top: 0.0938rem solid var(--nt-line); }
.nt ul > li:last-child::after { content: ""; position: absolute; inset-inline-start: -0.875rem; top: 1.2188rem; bottom: 0; width: 0.1875rem; background: var(--paper); }
.nt-row { display: flex; align-items: center; gap: 0.125rem; }
.nt-link {
  flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 0.5rem; min-height: 2.25rem; padding: 0.4375rem 0.625rem; border-radius: 0.5625rem;
  color: var(--ink); text-decoration: none; font-size: 0.9062rem; line-height: 1.4;
}
.nt > li > .nt-row .nt-link, .nt > li > ul > li > .nt-row .nt-link { font-weight: 600; }
.nt ul ul ul .nt-link { font-size: 0.8438rem; }
.nt-label { flex: 1; min-width: 0; }
.nt-link.quiet .nt-label { color: var(--muted); }
.nt-num { flex: none; font-size: 0.75rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.nt-done { flex: none; color: var(--green); font-size: 0.8125rem; font-weight: 700; }
.nt-here { flex: none; align-self: center; padding: 1px 0.5rem; border-radius: 6.1875rem; font-size: 0.7188rem; font-weight: 600; background: var(--green); color: var(--paper); }
.nt-link:hover, .nt-link:focus-visible { background: color-mix(in srgb, var(--ink) 7%, transparent); outline: none; }
.nt-link[aria-current] { background: color-mix(in srgb, var(--green) 14%, transparent); font-weight: 600; }
.nt-link:focus-visible, .nt-toggle:focus-visible { outline: 0.125rem solid var(--focus); outline-offset: -0.125rem; }
.nt-toggle {
  flex: none; width: 2.125rem; height: 2.125rem; display: grid; place-items: center; border-radius: 0.5625rem; background: transparent;
  color: var(--muted); font-size: 1.25rem; line-height: 1;
}
.nt-toggle:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); filter: none; }
.nt-chev { display: block; transition: transform 0.15s; }
.nt-toggle[aria-expanded="true"] .nt-chev { transform: rotate(-90deg); }
@media (pointer: coarse) {
  .nt-link { min-height: 42px; padding-block: 9px; }
  .nt ul > li::before { top: 21px; }
  .nt ul > li:last-child::after { top: 22.5px; }
  .nt-toggle { width: 42px; height: 42px; }
}
.am-who { display: flex; flex-direction: column; gap: 0.125rem; padding: 0.5625rem 0.75rem 0.625rem; margin-bottom: 0.25rem; border-bottom: 1px solid var(--line); }
.am-who strong { font-size: 0.9062rem; font-weight: 600; overflow-wrap: anywhere; }
.am-who bdi { font-size: 0.7812rem; color: var(--muted); overflow-wrap: anywhere; align-self: flex-start; }
.account-menu a, .account-menu button {
  display: block; width: 100%; padding: 0.5625rem 0.75rem; border: 0; border-radius: 0.5625rem; background: none; color: var(--ink);
  font: inherit; font-size: 0.9062rem; text-align: start; text-decoration: none; cursor: pointer;
}
.account-menu a:hover, .account-menu button:hover, .account-menu a:focus-visible, .account-menu button:focus-visible {
  background: color-mix(in srgb, var(--ink) 7%, transparent); filter: none; outline: none;
}
/* The personal area (#me, plans.js renderMe). */
.pv-me { display: flex; flex-direction: column; gap: 1rem; }
.pv-me[hidden] { display: none; }
.pv-me .pv-back { align-self: flex-start; margin-bottom: 0; }
.me-head { display: flex; align-items: center; gap: 1rem; margin: 0.25rem 0 0.375rem; }
.me-head h1 { font-size: 1.75rem; }
.me-head bdi { color: var(--muted); font-size: 0.9062rem; overflow-wrap: anywhere; }
.me-head > div { min-width: 0; }
.me-card { border: 1px solid var(--line); border-radius: 1rem; background: var(--paper); padding: 1.125rem 1.25rem; display: flex; flex-direction: column; gap: 0.625rem; }
.me-card h2 { margin: 0; font-size: 1.0312rem; font-weight: 600; }
.me-card p { margin: 0; color: var(--muted); font-size: 0.9375rem; line-height: 1.7; }
.me-plans { display: flex; flex-direction: column; gap: 0.625rem; }
.me-plan { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.75rem 0.875rem; border: 1px solid var(--line); border-radius: 0.75rem; color: var(--ink); text-decoration: none; }
.me-plan:hover { border-color: color-mix(in srgb, var(--green) 55%, var(--line)); }
.me-plan-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }
.me-plan-head strong { font-size: 0.9375rem; font-weight: 600; }
.me-plan-goal, .me-plan-meta { color: var(--muted); font-size: 0.8125rem; }
.me-meter { height: 0.375rem; border-radius: 6.1875rem; background: color-mix(in srgb, var(--ink) 9%, transparent); overflow: hidden; }
.me-meter span { display: block; height: 100%; border-radius: 6.1875rem; background: var(--green); }
.me-link { color: var(--green); font-size: 0.9062rem; text-decoration: none; align-self: flex-start; }
.me-link:hover { text-decoration: underline; }
.me-note { margin: 0; color: var(--muted); font-size: 0.8125rem; line-height: 1.7; }
.me-signout { border: 1px solid var(--line); border-radius: 0.625rem; font-size: 0.875rem; padding: 0.5625rem 1rem; }
/* Online the tutor uses the service's own key, so the bring-your-own-key and model settings are not shown. */
.hosted .sd-advanced { display: none; }
/* Nor which model answers: the button beside the message box would only name it (settings open from the header). */
.hosted .model-button { display: none; }
/* One model online: nothing to choose, so the message box does not name it. */
.hosted #composer-model { display: none; }

/* ── Entry page and study plans (plans.js) ──────────────── */
.portal {
  position: fixed; inset: 0; z-index: 4; overflow-y: auto; background: var(--bg);
  padding: 4.75rem max(1.25rem, env(safe-area-inset-right, 0px)) 3.5rem max(1.25rem, env(safe-area-inset-left, 0px));
}
body.portal-open .workspace { visibility: hidden; }
body.portal-open #page-toggle, body.portal-open #history-open, body.portal-open #new-chat { display: none; }
/* A chapter of a study plan is not a chat of the free tutor: its list of chats and "new chat" do not belong here.
   The bar under the buttons leads back to the plan and to the chapter's lessons. */
body.in-plan #history-open, body.in-plan #new-chat { display: none; }
.pv { max-width: 53.75rem; margin: 0 auto; }
.pv[hidden] { display: none; }
.pv h1 {
  font-family: var(--serif); font-weight: 500; letter-spacing: -0.3px;
  font-size: clamp(1.75rem, 3.4vw, 2.5rem); line-height: 1.2; margin: 0; text-wrap: balance;
}
.pv-sub { color: var(--muted); font-size: 1rem; line-height: 1.7; margin: 0.75rem 0 0; max-width: 60ch; }
.pv-back { display: inline-flex; gap: 0.375rem; align-items: center; margin-bottom: 1.125rem; color: var(--muted); font-size: 0.875rem; text-decoration: none; border-radius: 0.5rem; padding: 0.25rem 0.375rem; margin-inline-start: -0.375rem; }
.pv-back:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.pv-home { min-height: calc(100dvh - 8.25rem); display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
.pv-home .welcome-mark { margin-bottom: 1.125rem; }
.pv-home .pv-sub { margin-inline: auto; }
.pv-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.125rem; margin-top: 2.125rem; width: 100%; text-align: start; }
.pv-card {
  display: flex; flex-direction: column; gap: 0.625rem; padding: 1.625rem 1.625rem 1.375rem; border: 1px solid var(--line); border-radius: 1.25rem;
  background: var(--paper); color: var(--ink); text-decoration: none; box-shadow: 0 0.125rem 0.625rem #302c240a;
  transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
}
.pv-card:hover { transform: translateY(-0.125rem); border-color: color-mix(in srgb, var(--green) 55%, var(--line)); box-shadow: 0 0.625rem 1.875rem #302c2416; }
.pv-card h2 { margin: 0.375rem 0 0; font-size: 1.375rem; font-weight: 600; letter-spacing: -0.3px; }
.pv-card p { margin: 0; color: var(--muted); font-size: 0.9375rem; line-height: 1.7; flex: 1; }
.pv-icon { width: 2.75rem; height: 2.75rem; color: var(--green); }
.pv-go { margin-top: 0.5rem; font-weight: 600; font-size: 0.9375rem; color: var(--green); }
.pv-card-plans { border-color: color-mix(in srgb, var(--green) 45%, var(--line)); background: color-mix(in srgb, var(--green) 7%, var(--paper)); }
.pv-short { display: none; }
/* The plan page: a side panel (goal, progress, where to continue) beside a dense list of chapters. */
.pv-plan { max-width: 73.75rem; }
.pv-plan h1 { font-size: clamp(1.5rem, 2.4vw, 1.875rem); letter-spacing: -0.5px; }
.pv-plan .pv-back { margin-bottom: 0.625rem; }
.pp-layout { margin-top: 1.25rem; display: grid; gap: 1.125rem; align-items: start; }
.pp-side { display: grid; gap: 0.75rem; min-width: 0; }
.pp-card { display: grid; gap: 1rem; padding: 1.125rem; border: 1px solid var(--line); border-radius: 1.125rem; background: var(--paper); }
.pp-goal-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.pp-goal-label { font-weight: 600; }
.pp-goal-swap { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.8125rem; line-height: 1.5; }
.seg { display: inline-flex; padding: 0.1875rem; border: 1px solid var(--line); border-radius: 0.6875rem; background: var(--bg); gap: 0.125rem; }
.seg-btn { background: transparent; color: var(--muted); border: 0; border-radius: 0.5rem; padding: 0.375rem 1.125rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.seg-btn:hover { filter: none; color: var(--ink); }
.seg-btn[aria-pressed="true"] { background: var(--green); color: #fff; }
.pp-progress { display: grid; gap: 0.5rem; }
.pp-big { display: flex; align-items: baseline; gap: 0.5rem; color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.pp-big strong { font-family: var(--serif); font-weight: 500; font-size: 2.375rem; line-height: 1; color: var(--ink); }
.pp-left { font-size: 0.8438rem; color: var(--muted); }
.pp-continue {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 0.875rem; border-radius: 0.8125rem; text-decoration: none;
  background: var(--green); color: #fff; transition: filter 0.15s;
}
.pp-continue:hover { filter: brightness(1.07); }
.pp-continue-text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.pp-continue small { font-size: 0.75rem; opacity: 0.85; }
.pp-continue strong { font-size: 0.9062rem; font-weight: 600; line-height: 1.4; }
.pp-continue-arrow { font-size: 1.125rem; }
.pp-mores { display: grid; border: 1px solid var(--line); border-radius: 0.875rem; padding: 0.125rem 0.875rem; }
.pp-more { font-size: 0.8438rem; line-height: 1.75; color: var(--muted); }
.pp-more + .pp-more { border-top: 1px solid var(--line); }
.pp-more summary { cursor: pointer; color: var(--ink); padding: 0.625rem 0; border-radius: 0.375rem; }
.pp-more > div { padding-bottom: 0.75rem; }
.pp-more p { margin: 0 0 0.375rem; }
.pp-note { margin: 0; font-size: 0.7812rem; color: var(--muted); }
/* The plan-and-tracking chat: not a chapter, a small card of its own at the bottom of the panel. */
.pp-ov {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.6875rem 0.875rem; border: 1px solid var(--line); border-radius: 0.875rem;
  background: var(--paper); color: var(--ink); text-decoration: none; transition: border-color 0.15s;
}
.pp-ov:hover { border-color: color-mix(in srgb, var(--green) 55%, var(--line)); }
.pp-ov:focus-visible { outline: 0.125rem solid var(--focus); outline-offset: 0.125rem; }
.pp-ov-text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.pp-ov-head { display: flex; align-items: center; flex-wrap: wrap; gap: 0.25rem 0.5rem; }
.pp-ov-head strong { font-size: 0.9062rem; font-weight: 600; }
.pp-ov-sub { font-size: 0.7812rem; color: var(--muted); }
.pp-ov-go { font-weight: 600; font-size: 0.8438rem; color: var(--green); white-space: nowrap; }
.meter { height: 0.375rem; border-radius: 6.1875rem; background: color-mix(in srgb, var(--ink) 10%, transparent); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 6.1875rem; background: var(--green); transition: width 0.4s; }

.pp-about p { margin: 0; }

.pp-chats { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.375rem; min-width: 0; }
/* A chapter: a row that opens the chat, a toggle, and (opened) its description and lessons. */
.pp-chat {
  border: 1px solid var(--line); border-radius: 0.875rem; background: var(--paper);
  transition: border-color 0.18s, box-shadow 0.18s;
}
.pp-chat:hover { border-color: color-mix(in srgb, var(--green) 55%, var(--line)); box-shadow: 0 0.375rem 1.375rem #302c2412; }
.pp-chat-row { display: flex; align-items: stretch; }
.pp-chat-link {
  flex: 1; min-width: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) 11rem auto; grid-template-areas: "num body stats go";
  column-gap: 0.875rem; align-items: center; padding: 0.5625rem 0.875rem; padding-inline-end: 0.375rem;
  border-radius: 0.8125rem; color: var(--ink); text-decoration: none;
}
.pp-toggle {
  flex-shrink: 0; width: 2.5rem; display: grid; place-items: center; padding: 0; border: 0; border-radius: 0.8125rem;
  background: transparent; color: var(--muted);
}
.pp-toggle:hover { filter: none; color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.pp-toggle svg { transition: transform 0.15s; }
.pp-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.pp-chat-more { padding: 0.625rem 0.875rem 0.625rem; padding-inline-start: 3.5rem; border-top: 1px solid var(--line); }
.pp-chat-more .pp-about { font-size: 0.8438rem; line-height: 1.7; max-width: 80ch; }
.pp-chat-more .pp-about p { white-space: normal; display: block; overflow: visible; }
.pp-lessons { margin-top: 0.375rem; margin-inline-start: -0.625rem; }
.pp-num {
  grid-area: num; width: 1.875rem; height: 1.875rem; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 0.8438rem;
  background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--muted); font-variant-numeric: tabular-nums;
}
.pp-chat.next { border-color: var(--green); }
.pp-chat.next .pp-num, .pp-chat.done .pp-num { background: var(--green); color: #fff; }
.pp-chat.optional { background: transparent; border-style: dashed; }
.pp-chat-body { grid-area: body; min-width: 0; }
.pp-chat-head { display: flex; flex-wrap: wrap; align-items: center; column-gap: 0.5rem; row-gap: 0.125rem; }
.pp-chat-head strong { font-size: 0.9375rem; font-weight: 600; line-height: 1.45; }
.pp-badge { font-size: 0.6875rem; padding: 1px 0.5rem; border-radius: 6.1875rem; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pp-badge.now, .pp-badge.full { border-color: color-mix(in srgb, var(--green) 50%, var(--line)); color: var(--green); }
.pp-about { color: var(--muted); font-size: 0.8125rem; line-height: 1.55; }
.pp-about p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pp-stats { grid-area: stats; display: grid; gap: 0.3125rem; min-width: 0; }
.pp-meta { font-size: 0.7812rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pp-go { grid-area: go; min-width: 2.75rem; text-align: end; font-weight: 600; font-size: 0.8438rem; color: var(--green); white-space: nowrap; }
@media (min-width: 1000px) {
  /* Right-to-left: the chapters take the first (right) column, the panel stays in view on the left. */
  .pp-layout { grid-template-columns: minmax(0, 1fr) 20rem; column-gap: 1.5rem; }
  .pp-chats { grid-column: 1; grid-row: 1; }
  .pp-side { grid-column: 2; grid-row: 1; position: sticky; top: 1.25rem; }
  /* The title and the way back share a line, and every chapter is one line, so the whole road fits a screen.
     Only the chapter that is next keeps its description; the others show it as a tooltip. */
  .pv-plan .pp-top { display: flex; flex-direction: row-reverse; align-items: baseline; justify-content: space-between; gap: 1rem; }
  .pv-plan .pp-top .pv-back { margin: 0; }
  .pp-layout { margin-top: 1rem; }
  .pp-chats { gap: 0.3125rem; }
  .pp-chat-link { padding-block: 0.4375rem; }
  .pp-num { width: 1.75rem; height: 1.75rem; }
  .pp-chat:not(.next) .pp-chat-link .pp-about { display: none; }
  .pp-chat.next .pp-chat-link .pp-about p { white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
}
@media (min-width: 741px) and (max-width: 999px) {
  .pp-card { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; column-gap: 1.5rem; }
  .pp-continue { grid-column: 1 / -1; }
}

.plan-bar {
  position: relative; flex-shrink: 0; display: flex; align-items: center; gap: 0.75rem; width: min(var(--chat-w), 100% - 2.5rem);
  margin: 0 auto 0.125rem; padding: 0.5rem 0.75rem; border: 1px solid var(--line); border-radius: 0.875rem; background: var(--paper);
}
.pb-back { color: var(--muted); text-decoration: none; font-size: 0.8438rem; white-space: nowrap; padding: 0.3125rem 0.5rem; border-radius: 0.5rem; }
.pb-back:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.pb-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.pb-titles strong, .pb-titles small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pb-titles strong { font-size: 0.875rem; font-weight: 600; }
.pb-titles small { font-size: 0.75rem; color: var(--muted); }
.pb-titles small:empty { display: none; }
.pb-meter { width: 5.25rem; height: 0.375rem; border-radius: 6.1875rem; background: color-mix(in srgb, var(--ink) 10%, transparent); overflow: hidden; flex-shrink: 0; }
.pb-meter i { display: block; height: 100%; border-radius: 6.1875rem; background: var(--green); transition: width 0.4s; }
.pb-count { font-size: 0.7812rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.pb-lessons-open {
  display: inline-flex; align-items: center; gap: 0.375rem; background: transparent; color: var(--ink); border: 1px solid var(--line);
  border-radius: 0.5625rem; padding: 0.375rem 0.625rem; font-size: 0.8125rem; white-space: nowrap;
}
.pb-lessons-open:hover { filter: none; background: color-mix(in srgb, var(--ink) 6%, transparent); }
.pb-lessons-open[aria-expanded="true"] svg { transform: rotate(180deg); }
.plan-lessons {
  position: absolute; z-index: 6; top: calc(100% + 0.375rem); inset-inline: 0; max-height: min(60dvh, 28.75rem); overflow-y: auto;
  padding: 0.5rem; border: 1px solid var(--line); border-radius: 0.875rem; background: var(--paper); box-shadow: 0 0.875rem 2.75rem #302c2426;
}
.ls-title { padding: 0.5rem 0.625rem 0.25rem; font-size: 0.75rem; color: var(--muted); }
.ls-list { list-style: none; margin: 0; padding: 0; }
.ls-row { display: flex; align-items: center; gap: 0.25rem; border-radius: 0.625rem; }
.ls-row:hover, .ls-item.current > .ls-row { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.ls-main {
  flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 0.625rem; text-align: start; background: transparent;
  color: var(--ink); border: 0; padding: 0.5625rem 0.5rem; border-radius: 0.625rem; font-size: 0.875rem;
}
.ls-main:hover { filter: none; }
.ls-name { flex: 1; min-width: 0; line-height: 1.5; }
.ls-item.current .ls-name { font-weight: 600; }
.ls-item.done .ls-name { color: var(--muted); }
.ls-arrow { align-self: center; display: grid; color: var(--muted); transition: transform 0.15s; }
.ls-main[aria-expanded="true"] .ls-arrow { transform: rotate(180deg); }
.ls-steps { list-style: none; margin: 0.125rem 0 0.375rem; padding: 0; padding-inline-start: 2.75rem; padding-inline-end: 0.625rem; }
.ls-step { display: flex; align-items: center; gap: 0.5625rem; padding: 0.25rem 0; font-size: 0.8125rem; color: var(--ink); }
.ls-step.done .ls-step-name, .ls-step.off .ls-step-name { color: var(--muted); }
.ls-mark {
  flex-shrink: 0; width: 0.9375rem; height: 0.9375rem; border-radius: 50%; display: grid; place-items: center; font-size: 0.5625rem; line-height: 1;
  color: transparent; border: 0.0938rem solid color-mix(in srgb, var(--ink) 26%, transparent); user-select: none;
}
.ls-step.done .ls-mark { background: var(--green); border-color: var(--green); color: #fff; }
.ls-step.next .ls-mark { border-color: var(--green); }
.ls-step.next .ls-step-name { font-weight: 600; }
.ls-step.off .ls-mark { border-style: dashed; }
.ls-tag { font-size: 0.6875rem; padding: 1px 0.4375rem; border-radius: 6.1875rem; color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.ls-tag.now { color: var(--green); border-color: color-mix(in srgb, var(--green) 45%, transparent); }
.ls-jump {
  margin: 0 0 0.625rem; margin-inline-start: 2.75rem; padding: 0.3125rem 0.75rem; border-radius: 6.1875rem; font-size: 0.7812rem;
  background: transparent; color: var(--ink); border: 1px solid var(--line);
}
.ls-jump:hover { filter: none; background: color-mix(in srgb, var(--ink) 6%, transparent); }
/* Every lesson is a chat of its own: its link at the end of its row (plans.js lessonList) */
.ls-open {
  flex-shrink: 0; display: inline-flex; align-items: center; min-height: 2rem; padding: 0.25rem 0.75rem; border-radius: 6.1875rem;
  font-size: 0.8125rem; font-weight: 600; color: var(--green); text-decoration: none; white-space: nowrap;
  border: 1px solid color-mix(in srgb, var(--green) 45%, var(--line));
}
.ls-open:hover { background: color-mix(in srgb, var(--green) 10%, transparent); }
.ls-item.done .ls-open { color: var(--muted); border-color: var(--line); font-weight: 500; }
@media (pointer: coarse) { .ls-open { min-height: 44px; } }
/* A lesson's chat, finished: on to the next lesson (plans.js paintBar) */
.pb-next {
  display: inline-flex; align-items: center; min-height: 2rem; padding: 0.3125rem 0.75rem; border-radius: 0.5625rem; white-space: nowrap;
  font-size: 0.8125rem; font-weight: 600; text-decoration: none; color: #fff; background: var(--green);
}
.pb-next[hidden] { display: none; }
.pb-next:hover { filter: brightness(1.08); }
@media (pointer: coarse) { .pb-next { min-height: 44px; } }
.ls-meta { font-size: 0.75rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.ls-check {
  flex-shrink: 0; width: 1.5rem; height: 1.5rem; margin-inline-start: 0.5rem; border-radius: 50%; font-size: 0.8125rem; line-height: 1;
  display: grid; place-items: center; user-select: none;
  background: transparent; color: transparent; border: 0.0938rem solid color-mix(in srgb, var(--ink) 28%, transparent);
}
.ls-item.done .ls-check { background: var(--green); border-color: var(--green); color: #fff; }
.in-plan .composer-tools .dd { display: none; }
.pv-card:focus-visible, .pv-track:focus-visible, .pp-chat-link:focus-visible, .pp-toggle:focus-visible, .pv-back:focus-visible, .pb-back:focus-visible,
.seg-btn:focus-visible, .pb-lessons-open:focus-visible, .ls-main:focus-visible, .ls-jump:focus-visible,
.ls-open:focus-visible, .pb-next:focus-visible,
.pp-more summary:focus-visible, .pp-continue:focus-visible { outline: 0.125rem solid var(--focus); outline-offset: 0.125rem; }
@media (max-width: 740px) {
  .portal { padding-top: 4.25rem; padding-bottom: 2.5rem; }
  .pv-choices { grid-template-columns: minmax(0, 1fr); }
  /* The entry page on a phone fits the screen, with nothing to scroll: shorter texts, the icon beside the title,
     and the whole of it centred in the height the screen has. (A very short screen still scrolls.) */
  .portal.at-home { display: flex; flex-direction: column; padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px)); }
  .pv-home { flex: 1 0 auto; width: 100%; min-height: 0; }
  .pv-home .welcome-mark { margin-bottom: 0.5rem; }
  .pv-home .pv-sub { margin-top: 0.375rem; font-size: 0.9375rem; }
  .pv-long { display: none; }
  .pv-short { display: inline; }
  .pv-choices { margin-top: 1.25rem; gap: 0.75rem; }
  .pv-card { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 0.375rem 0.75rem; padding: 1rem 1.125rem; }
  .pv-card .pv-icon { width: 2.125rem; height: 2.125rem; }
  .pv-card h2 { margin: 0; font-size: 1.25rem; }
  .pv-card p, .pv-card .pv-go { grid-column: 1 / -1; }
  .pv-card p { font-size: 0.9062rem; line-height: 1.55; text-wrap: pretty; }
  .pv-card .pv-go { margin-top: 0.125rem; }
  .pv-track-row { grid-template-columns: minmax(0, 1fr); gap: 0.625rem; }
  .pv-track { min-height: 0; }
  .pp-chat-link { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "num body go" "num stats go"; column-gap: 0.75rem; row-gap: 0.375rem; padding: 0.75rem; padding-inline-end: 0.25rem; }
  .pp-about p { white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  .pp-toggle { width: 2.25rem; }
  .pp-chat-more { padding-inline-start: 0.875rem; }
  .pp-lessons { margin-inline-start: -0.5rem; }
  .plan-bar { flex-wrap: wrap; row-gap: 0.375rem; width: calc(100% - 1.5rem); padding: 0.375rem 0.5rem; }
  .pb-titles { flex: 1 1 40%; }
  .pb-meter { order: 5; flex: 1 1 40%; width: auto; }
  .pb-count { order: 6; }
  .pb-next { order: 7; }
}
/* dark theme */
:where(:root[data-theme='dark']) .pv-card, :where(:root[data-theme='dark']) .pv-track, :where(:root[data-theme='dark']) .pp-chat { box-shadow: none; }
:where(:root[data-theme='dark']) .pp-toggle { background-color: transparent; color: var(--muted); }
:where(:root[data-theme='dark']) .seg-btn, :where(:root[data-theme='dark']) .pb-lessons-open, :where(:root[data-theme='dark']) .ls-main { background-color: transparent; }
:where(:root[data-theme='dark']) .seg-btn { color: var(--muted); }
:where(:root[data-theme='dark']) .pb-lessons-open, :where(:root[data-theme='dark']) .ls-main { color: var(--ink); }
:where(:root[data-theme='dark']) .seg-btn[aria-pressed="true"] { background-color: #a94d31; color: #fff; }
:where(:root[data-theme='dark']) .ls-item.done .ls-check, :where(:root[data-theme='dark']) .ls-step.done .ls-mark { background-color: #a94d31; border-color: #a94d31; }
:where(:root[data-theme='dark']) .ls-jump { background-color: transparent; color: var(--ink); }
:where(:root[data-theme='dark']) .pb-next { background-color: #a94d31; color: #fff; }
:where(:root[data-theme='dark']) .pp-chat.next .pp-num, :where(:root[data-theme='dark']) .pp-chat.done .pp-num, :where(:root[data-theme='dark']) .pp-continue { background: #a94d31; }
@media (prefers-reduced-motion: reduce) { .pv-card, .pv-track, .pp-chat, .pp-toggle svg, .ls-arrow, .meter i, .pb-meter i { transition: none; } }


/* ══ Course additions ══════════════════════════════════════════════════════════════════════════ */
/* A link from the entry page back to the course site (the landing at /). */
.pv-site { margin-top: 1.375rem; color: var(--muted); font-size: 0.875rem; text-decoration: none; border-bottom: 1px solid var(--line); }
.pv-site:hover { color: var(--ink); border-color: var(--green); }
/* Short points instead of paragraphs (settings, guide lead, personal area). */
.sd-points, ul.gd-lead, ul.me-note { margin: 0; padding-inline-start: 1.125rem; }
ul.gd-lead { margin-bottom: 1rem; }
ul.gd-lead li + li, ul.me-note li + li { margin-top: 0.125rem; }
/* The topics that are not examined this year. */
.pp-out { margin: 0; padding: 0 0 0.75rem; padding-inline-start: 1.125rem; display: grid; gap: 0.1875rem; }
.pp-out p { margin: 0; }
/* A chapter's video: a row at the head of its lessons, and the card above the chapter's conversation. */
a.ls-main { text-decoration: none; }
.ls-play { align-self: center; color: var(--green); font-size: 0.625rem; width: 0.75rem; text-align: center; }
.plan-video { max-width: 46.25rem; margin: 0 auto 1.25rem; display: grid; gap: 0.75rem; }
.cv { border: 1px solid var(--line); border-radius: 1rem; background: var(--paper); overflow: hidden; }
.cv-head {
  width: 100%; display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 0.875rem; background: transparent; color: var(--ink);
  border: 0; border-radius: 0; text-align: start;
}
.cv-head:hover { filter: none; background: color-mix(in srgb, var(--ink) 4%, transparent); }
.cv-head:not(:disabled):active { transform: none; }
.cv-check {
  flex-shrink: 0; width: 1.5rem; height: 1.5rem; border-radius: 50%; display: grid; place-items: center; font-size: 0.8125rem; line-height: 1;
  color: transparent; border: 0.0938rem solid color-mix(in srgb, var(--ink) 28%, transparent); user-select: none;
}
.cv.done .cv-check { background: var(--green); border-color: var(--green); color: #fff; }
.cv-titles { flex: 1; min-width: 0; display: grid; gap: 1px; }
.cv-titles small { font-size: 0.7812rem; color: var(--muted); }
.cv-titles strong { font-size: 1rem; line-height: 1.4; }
.cv-arrow { display: grid; color: var(--muted); transition: transform 0.15s; }
.cv.open .cv-arrow { transform: rotate(180deg); }
.cv-body { display: none; padding: 0 0.875rem 0.875rem; }
.cv.open .cv-body { display: block; }
.cv-frame { position: relative; aspect-ratio: 16 / 9; border-radius: 0.75rem; overflow: hidden; background: #1c1917; }
.cv-poster, .cv-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }
.cv-poster img { width: 100%; height: 100%; object-fit: cover; display: block; transition: filter 0.2s; }
.cv-poster:hover img { filter: brightness(0.9); }
.cv-play {
  position: absolute; top: 50%; left: 50%; width: 4rem; height: 4rem; margin: -2rem 0 0 -2rem; display: grid; place-items: center;
  border-radius: 50%; background: var(--green); box-shadow: 0 0.625rem 1.875rem -0.5rem #0009; transition: transform 0.15s;
}
.cv-play svg { width: 1.6875rem; height: 1.6875rem; fill: #fff; margin-left: 0.1875rem; }
.cv-poster:hover .cv-play { transform: scale(1.07); }
.cv-foot { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.75rem; }
.cv-hint { flex: 1; min-width: 0; margin: 0; color: var(--muted); font-size: 0.8438rem; line-height: 1.5; }
.cv-mark { flex-shrink: 0; padding: 0.5rem 0.875rem; border-radius: 6.1875rem; font-size: 0.8438rem; background: var(--green); color: #fff; border: 1px solid var(--green); }
.cv-mark.quiet { background: transparent; color: var(--muted); border-color: var(--line); }
.cv-mark.quiet:hover { filter: none; color: var(--ink); border-color: var(--muted); }
.cv-head:focus-visible, .cv-poster:focus-visible, .cv-mark:focus-visible { outline: 0.125rem solid var(--focus); outline-offset: -0.125rem; }
.cv-mark:focus-visible { outline-offset: 0.125rem; }
:where(:root[data-theme='dark']) .cv.done .cv-check, :where(:root[data-theme='dark']) .cv-play { background-color: #a94d31; border-color: #a94d31; }
:where(:root[data-theme='dark']) .cv-mark { background-color: #a94d31; border-color: #a94d31; color: #fff; }
:where(:root[data-theme='dark']) .cv-mark.quiet { background-color: transparent; border-color: var(--line); color: var(--muted); }
:where(:root[data-theme='dark']) .cv-head { background-color: transparent; color: var(--ink); }
@media (max-width: 560px) {
  .cv-foot { flex-direction: column; align-items: stretch; }
  .cv-mark { align-self: flex-start; }
  .cv-play { width: 3.375rem; height: 3.375rem; margin: -1.6875rem 0 0 -1.6875rem; }
}
@media print { .plan-video { display: none; } }
/* Start a lesson's conversation over (the lessons menu in a lesson; in an older chapter chat, the chapter's). */
.ls-clear { margin: 0.625rem 0.25rem 0.125rem; padding: 0.375rem 0.625rem; background: none; border: 1px solid var(--line); color: var(--muted); font-size: 0.8125rem; border-radius: 0.5625rem; }
.ls-clear:hover { color: var(--ink); border-color: var(--muted); }
/* A question with parts outside this year's material. */
.co-chip.out { background: color-mix(in srgb, var(--ink) 8%, transparent); color: var(--muted); }
/* The open question as typed text, under its image. */
.page-text { margin: 0.625rem 0.75rem 1rem; border: 1px solid var(--line); border-radius: 0.75rem; background: var(--paper); color: var(--ink); font-size: 0.9062rem; line-height: 1.7; }
.page-text summary { cursor: pointer; padding: 0.5625rem 0.875rem; font-weight: 600; }
.page-text-body { padding: 0 0.875rem; }
.page-text-body p { margin: 0 0 0.5rem; }
.page-text small { display: block; padding: 0 0.875rem 0.625rem; color: var(--muted); font-size: 0.7812rem; }
.page-stage > .page-text { flex: none; text-align: start; }
.pp-why { color: var(--muted); font-size: 0.8438rem; }
.gd-out { margin-inline-start: 0.375rem; font-size: 0.6875rem; color: var(--muted); border: 1px dashed var(--line); border-radius: 6.1875rem; padding: 0 0.375rem; }

/* Light or dark, in the settings: the same choice as the course site. */
.sd-theme { display: inline-flex; width: fit-content; align-self: flex-start; }

/* ── The message box as an editor (composer.js) ─────────── */
/* A formula between $ signs shows rendered inside the box; under the caret it is its LaTeX source. The sizes
   repeat the old text box: it starts 68px tall and grows with the text up to 180px, then scrolls. */
.composer-input { --pad-top: 0.375rem; --min-h: 4.25rem; width: 100%; font-size: 1rem; line-height: 1.6; cursor: text; }
.composer .composer-input .cm-editor { max-height: 11.25rem; background: transparent; }
.composer .composer-input .cm-editor.cm-focused { outline: none; }
.composer .composer-input .cm-scroller { font-family: inherit; line-height: inherit; overflow: auto; }
.composer .composer-input .cm-content {
  min-height: var(--min-h); padding: var(--pad-top) 0.25rem 0.375rem; color: var(--ink);
  caret-color: var(--green); caret-animation: manual; animation: caret-breathe 1.3s ease-in-out infinite;
}
.composer .composer-input .cm-line { padding: 0; }
.composer .composer-input .cm-placeholder { color: var(--muted); }
.composer-input .cm-math { display: inline-block; padding: 0 0.125rem; border-radius: 0.375rem; cursor: text; vertical-align: baseline; }
.composer-input .cm-math:hover { background: var(--light); }
.composer-input .cm-math-src {
  unicode-bidi: isolate; direction: ltr; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em; color: var(--green); background: var(--light); border-radius: 0.3125rem; padding: 1px 0.1875rem;
}
/* Empty and focused: the tapered stroke stands where the first letter will go (as it did in the old text box). */
.composer .composer-input.is-empty .cm-editor.cm-focused .cm-content {
  caret-color: transparent !important;
  background-image:
    linear-gradient(to bottom, transparent, rgb(from var(--green) r g b / var(--caret-a)) 24%,
      rgb(from var(--green) r g b / var(--caret-a)) 76%, transparent),
    radial-gradient(closest-side, rgb(from var(--green) r g b / calc(var(--caret-a) * 0.4)), transparent);
  background-repeat: no-repeat;
  background-size: 0.1562rem 1.625rem, 1.125rem 2.25rem;
  background-position: right 0 top calc(var(--pad-top) - 0.5px), right -0.4844rem top calc(var(--pad-top) - 0.3438rem);
}
@media (max-width: 740px) { .composer-input { --min-h: 2.875rem; } }
@media (max-height: 520px) { .composer-input { --min-h: 2.5rem; --pad-top: 0.25rem; } }
@media (prefers-reduced-motion: reduce) {
  .composer .composer-input .cm-content { animation: none; caret-animation: auto; }
}

/* Attached images (attach.js, a laptop only). Colours come from the theme's tokens, so both themes are covered. */
.attachments { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0 0.125rem 0.625rem; }
.attachments[hidden] { display: none; }
.att {
  position: relative;
  width: 4.5rem;
  height: 4.5rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--light);
  overflow: hidden;
}
.att img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att.sending img { opacity: 0.45; }
.att.sending::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 1.25rem;
  height: 1.25rem;
  border: 0.125rem solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: att-spin 0.8s linear infinite;
}
@keyframes att-spin { to { transform: rotate(360deg); } }
.att-x {
  position: absolute;
  top: 0.1875rem;
  inset-inline-end: 0.1875rem;
  width: 1.375rem;
  height: 1.375rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #1f1c19cc;
  color: #fff;
  font-size: 0.9375rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.att-x:hover { background: #1f1c19; }
.message-images { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0.5rem; margin-bottom: 0.5rem; }
.message-images a {
  display: block;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  overflow: hidden;
  background: var(--light);
  line-height: 0;
}
/* Sizes in fixed units, so the frame closes on the picture whatever its shape. */
.message-images img { display: block; max-width: min(16.25rem, 64vw); max-height: 13.75rem; width: auto; height: auto; }
.att-gone {
  border: 1px dashed var(--line);
  border-radius: 0.75rem;
  padding: 0.625rem 0.875rem;
  color: var(--muted);
  font-size: 0.8125rem;
}
.drop-veil {
  position: fixed;
  inset: 0;
  z-index: 400;
  pointer-events: none;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
}
.drop-veil[hidden] { display: none; }
.drop-veil > div {
  border: 0.125rem dashed var(--green);
  border-radius: 1.25rem;
  padding: 2.125rem 2.75rem;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.1875rem;
  text-align: center;
}
@media (prefers-reduced-motion: reduce) {
  .att.sending::after { animation: none; }
}

/* ===================================================================== Python: the code side
   The chat on top and the student's editor under it (.tutor-pane); the question or the tutor's code on top and the
   results under them (.image-pane). Code always sits on the dark editor surface of the course site, in both themes,
   in JetBrains Mono with ligatures off (so == looks like two characters). */
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 400 700; font-display: swap; src: url("vendor/fonts/jetbrains-mono-latin.woff2") format('woff2'); }
:root {
  --mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  --code-bg: #2a2522; --code-bar: #221e1b; --code-line: #3d3530; --code-ink: #ece4d9; --code-muted: #9a8d80;
  --syn-keyword: #ec9a78; --syn-func: #e8c57e; --syn-string: #a9c78d; --syn-builtin: #82c0b6; --syn-number: #d6a9cb;
  --syn-operator: #cdbfb1; --ok: #2f7d4f; --bad: #b3412e;
}
:root[data-theme='dark'] { --code-bg: #1c1917; --code-bar: #171413; --code-line: #3a322c; --ok: #7fc79a; --bad: #f08a72; }
.welcome-mark { font-family: var(--mono); letter-spacing: -0.04em; }
code, pre, .cm-editor { font-variant-ligatures: none !important; }
.content code, .content pre { font-family: var(--mono); }
.content pre { direction: ltr; text-align: left; background: var(--code-bg) !important; color: var(--code-ink); border-radius: 0.625rem; padding: 0.625rem 0.75rem; overflow-x: auto; font-size: 0.8438rem; line-height: 1.6; }
.content pre code { background: none !important; color: inherit; padding: 0; }
.content :not(pre) > code { direction: ltr; unicode-bidi: isolate; padding: 0 0.25rem; border-radius: 0.25rem; font-size: 0.92em; }

/* --- the two halves of the tutor pane */
.chat-half { flex: 0 0 var(--split, 58%); min-height: 0; display: flex; flex-direction: column; }
.tutor-pane.code-collapsed .chat-half { flex: 1 1 auto; }
.tutor-pane:has(#welcome:not([hidden])) { justify-content: flex-start; padding-bottom: 0; }
.tutor-pane:has(#welcome:not([hidden])) .chat-half { justify-content: center; }
.split-handle { flex: none; height: 0.5625rem; cursor: row-resize; position: relative; touch-action: none; }
.split-handle::after { content: ""; position: absolute; inset-inline: 42%; top: 0.1875rem; height: 0.1875rem; border-radius: 0.1875rem; background: var(--line); }
.split-handle:hover::after, .split-handle:focus-visible::after { background: var(--green); }
.split-handle:focus-visible { outline: none; }
.tutor-pane.code-collapsed #code-split { display: none; }

.code-area { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; width: min(var(--chat-w), calc(100% - 2rem)); margin: 0 auto 0.75rem; border: 1px solid var(--code-line); border-radius: 0.75rem; background: var(--code-bg); overflow: hidden; box-shadow: 0 1.125rem 2.5rem -1.875rem #302b2799; }
.code-area.collapsed { flex: none; }
.code-area.collapsed .ca-editor, .code-area.collapsed .ca-results { display: none; }
.ca-head { display: flex; align-items: center; gap: 0.5rem; padding: 0.375rem 0.5rem 0.375rem 0.625rem; background: var(--code-bar); border-bottom: 1px solid var(--code-line); color: var(--code-ink); flex-wrap: wrap; }
.ca-toggle { display: inline-flex; align-items: center; gap: 0.375rem; background: none !important; border: 0; color: var(--code-ink) !important; font: 600 0.875rem var(--sans); padding: 0.25rem 0.375rem; cursor: pointer; border-radius: 0.375rem; }
.ca-toggle .chev { transition: transform 0.15s; }
.code-area.collapsed .ca-toggle .chev { transform: rotate(180deg); }
.ca-task { color: var(--code-muted); font-size: 0.7812rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 0 1 auto; }
.ca-link { background: none !important; border: 0; color: var(--code-muted) !important; font: 0.7812rem var(--sans); text-decoration: underline; cursor: pointer; padding: 0.125rem 0.25rem; }
.ca-actions { margin-inline-start: auto; display: flex; gap: 0.375rem; align-items: center; }
.ca-btn { font: 600 0.8125rem var(--sans); border-radius: 0.5rem; padding: 0.375rem 0.75rem; border: 1px solid var(--code-line); background: #3a322c !important; color: var(--code-ink) !important; cursor: pointer; min-height: 2rem; }
.ca-btn:hover:not(:disabled) { background: #4a4039 !important; }
.ca-btn.quiet { background: transparent !important; color: var(--code-muted) !important; }
.ca-btn.primary { background: #a94d31 !important; border-color: #a94d31; color: #fff !important; }
.ca-btn.primary:hover:not(:disabled) { background: #b85c3e !important; }
.ca-btn:disabled { opacity: 0.55; cursor: progress; }
.ca-btn:focus-visible, .ca-toggle:focus-visible, .ca-link:focus-visible { outline: 0.125rem solid #e59c7e; outline-offset: 1px; }
.ca-editor { flex: 1; min-height: 0; overflow: hidden; text-align: left; }
.code-area.running .ca-editor { opacity: 0.85; }

/* CodeMirror on the dark surface (the student's editor and the tutor's code) */
.ca-editor .cm-editor, .tc-code .cm-editor { height: 100%; background: var(--code-bg); color: var(--code-ink); font: max(13px, 0.875rem)/1.6 var(--mono); }
/* Code and the testers' output keep a floor under the app's 80% scale: code is read character by character. */
.cm-editor.cm-focused { outline: none; }
.cm-editor .cm-scroller { font-family: var(--mono); }
.cm-editor .cm-gutters { background: var(--code-bg); color: color-mix(in srgb, var(--code-muted) 70%, transparent); border-right: 1px solid var(--code-line); }
.cm-editor .cm-activeLine { background: #ffffff08; }
.cm-editor .cm-activeLineGutter { background: #ffffff0c; color: var(--code-ink); }
.cm-editor .cm-cursor { border-left-color: #f0c9b6; }
.cm-editor .cm-selectionBackground, .cm-editor.cm-focused .cm-selectionBackground, .cm-editor ::selection { background: #a94d3155 !important; }
.cm-editor .cm-matchingBracket { background: #ffffff18; outline: 1px solid #ffffff30; }
.cm-editor .cm-placeholder { color: var(--code-muted); font-family: var(--sans); direction: rtl; }
.cm-editor .cm-content { padding: 0.5rem 0; caret-color: #f0c9b6; }
.tk-kw { color: var(--syn-keyword); } .tk-str { color: var(--syn-string); } .tk-num { color: var(--syn-number); }
.tk-com { color: var(--code-muted); font-style: italic; } .tk-fn { color: var(--syn-func); } .tk-def { color: var(--syn-func); }
.tk-bi { color: var(--syn-builtin); } .tk-op { color: var(--syn-operator); }
.code-area[data-kind="trace"] .cm-content { font-family: var(--mono); }

/* --- the side pane: the question or the tutor's code on top, the results below */
.image-pane { padding: 0.875rem 0.75rem 0.625rem; }
.pane-top { flex: 0 0 var(--split, 56%); min-height: 0; display: flex; flex-direction: column; position: relative; }
.image-pane .pane-top .page-stage { flex: 1; }
.tutor-code { flex: 1; min-height: 0; display: flex; flex-direction: column; border: 1px solid var(--code-line); border-radius: 0.625rem; background: var(--code-bg); overflow: hidden; }
.tutor-code[hidden] { display: none; }
.tutor-code .co-head { background: var(--code-bar) !important; color: var(--code-ink); border-color: var(--code-line) !important; }
.tutor-code .co-titles small { color: var(--code-muted); }
.tutor-code .co-btn { background: #3a322c !important; color: var(--code-ink) !important; border-color: var(--code-line) !important; }
.tutor-code .co-btn.primary { background: #a94d31 !important; border-color: #a94d31 !important; color: #fff !important; }
.tc-note { margin: 0; padding: 0.5rem 0.75rem; color: var(--code-ink); font-size: 0.8438rem; border-bottom: 1px solid var(--code-line); }
.tc-code { flex: 1; min-height: 0; overflow: auto; text-align: left; }
.tc-code pre { margin: 0; padding: 0.625rem; color: var(--code-ink); font: max(13px, 0.8438rem)/1.6 var(--mono); }
.image-pane.show-tutor-code .page-stage, .image-pane.show-tutor-code .page-nav, .image-pane.show-tutor-code .page-chrome,
.image-pane.show-tutor-code .collection, .image-pane.show-tutor-code .figure { display: none !important; }

.results { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 0.625rem; background: var(--paper); overflow: hidden; }
.rs-head { display: flex; align-items: baseline; gap: 0.625rem; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--line); }
.rs-head strong { font: 600 0.875rem var(--serif); }
.rs-status { font-size: max(11.5px, 0.8125rem); color: var(--muted); }
.rs-status.ok { color: var(--ok); font-weight: 600; }
.rs-status.bad { color: var(--bad); font-weight: 600; }
.rs-body, .ca-results { flex: 1; min-height: 0; overflow: auto; padding: 0.625rem 0.75rem; font-size: max(13px, 0.875rem); }
.rs-empty { color: var(--muted); margin: 0; font-size: max(12.5px, 0.8438rem); }
.rs-fail { color: var(--bad); margin: 0 0 0.5rem; }
.rs-hint { color: var(--muted); font-size: max(11.5px, 0.8125rem); margin: 0.5rem 0 0; }
.rs-label { display: block; color: var(--muted); font-size: max(11.5px, 0.75rem); margin-bottom: 0.25rem; }
.rs-out pre, .rs-lines, .rs-case-grid code, .rs-call { font-family: var(--mono); font-variant-ligatures: none; }
.rs-out pre { margin: 0 0 0.5rem; background: var(--code-bg); color: var(--code-ink); padding: 0.5rem 0.625rem; border-radius: 0.5rem; white-space: pre-wrap; word-break: break-word; font-size: max(12.5px, 0.8125rem); text-align: left; max-height: 40vh; overflow: auto; }
.rs-error { border: 1px solid color-mix(in srgb, var(--bad) 45%, transparent); background: color-mix(in srgb, var(--bad) 8%, transparent); border-radius: 0.5rem; padding: 0.5rem 0.625rem; margin-bottom: 0.5rem; }
.rs-error-head code { font-size: 0.7812rem; }
.rs-error small { display: block; margin-top: 0.25rem; color: var(--muted); direction: ltr; text-align: right; font-family: var(--mono); }
.rs-cases, .rs-lines { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.375rem; }
.rs-cases li { border: 1px solid var(--line); border-radius: 0.5rem; padding: 0.375rem 0.5rem; }
.rs-cases li.bad { border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.rs-case-top { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.rs-mark { font-weight: 700; width: 1em; flex: none; }
li.ok > .rs-case-top .rs-mark, .rs-lines li.ok .rs-mark { color: var(--ok); }
li.bad > .rs-case-top .rs-mark, .rs-lines li.bad .rs-mark { color: var(--bad); }
.rs-call { font-size: 0.8125rem; word-break: break-all; }
.rs-note { color: var(--muted); font-size: 0.75rem; }
.rs-case-grid { display: grid; grid-template-columns: auto 1fr; gap: 0.125rem 0.625rem; margin-top: 0.25rem; font-size: max(12px, 0.7812rem); text-align: left; }
.rs-k { color: var(--muted); }
.rs-lines li { display: flex; gap: 0.5rem; text-align: left; font-size: 0.8125rem; }
.rs-rules { margin-top: 0.625rem; border-top: 1px dashed var(--line); padding-top: 0.5rem; font-size: 0.8125rem; }
.rs-rules ul { margin: 0.25rem 0; padding-inline-start: 1.125rem; }
.rs-rules small { color: var(--muted); }
.rs-figure { display: block; max-width: 100%; margin-top: 0.5rem; border-radius: 0.5rem; background: #fff; }

/* --- phones: the pane is a sheet over the chat; the results show inside the code area, under the editor */
@media (max-width: 1000px), (max-height: 520px) {
  .chat-half { flex: 1 1 auto; }
  .tutor-pane:not(.code-collapsed) .chat-half { flex: 0 0 var(--split, 50%); }
  .code-area { width: auto; margin: 0 0.5rem max(0.5rem, env(safe-area-inset-bottom)); border-radius: 0.625rem; }
  .ca-head { gap: 0.25rem; padding: 0.25rem 0.375rem; }
  .ca-task { order: 9; flex-basis: 100%; padding-inline-start: 0.5rem; }
  .ca-btn { padding: 0.375rem 0.625rem; min-height: 2.5rem; }
  .ca-results { flex: 0 1 auto; max-height: 38%; background: var(--paper); color: var(--ink); border-top: 1px solid var(--code-line); }
  .ca-results[hidden] { display: none; }
  .results, #pane-split { display: none; }
  .pane-top { flex: 1 1 auto; }
}
.message:not(.user):not(.system) .avatar { font-family: var(--mono); font-size: 0.75rem; letter-spacing: -0.04em; font-variant-ligatures: none; }

/* Full screen (fullscreen.js): the button in the top row, highlighted for a few seconds on entering a chat page. */
.fs-toggle { position: relative !important; inset: auto !important; }
.fs-toggle .fs-off, .fs-toggle.on .fs-on { display: none; }
.fs-toggle.on .fs-off { display: block; }
.fs-toggle.attention { border-color: #e59c7e !important; color: #e59c7e !important; animation: fs-glow 1.4s ease-in-out infinite; }
.fs-toggle.attention::after { content: "מסך מלא"; position: absolute; top: calc(100% + 0.5rem); left: 50%; transform: translateX(-50%); white-space: nowrap; padding: 0.25rem 0.625rem; border-radius: 0.5rem; background: #a94d31; color: #fff; font: 600 0.7812rem var(--sans); pointer-events: none; box-shadow: 0 0.375rem 1rem -0.375rem #302b2799; }
.fs-toggle.attention::before { content: ""; position: absolute; top: calc(100% + 0.1875rem); left: 50%; transform: translateX(-50%); border: 0.3125rem solid transparent; border-bottom-color: #a94d31; border-top: 0; pointer-events: none; }
@keyframes fs-glow { 0%, 100% { box-shadow: 0 0 0 0 #e59c7e66; } 50% { box-shadow: 0 0 0 0.375rem #e59c7e00, 0 0 0.875rem 0.125rem #e59c7e88; } }
@media (prefers-reduced-motion: reduce) { .fs-toggle.attention { animation: none; box-shadow: 0 0 0 0.1875rem #e59c7e66; } }

/* Phones: the top row keeps the everyday buttons (history, new chat, the account) and puts the site map, fullscreen,
   the guide and settings in the "עוד" menu (app.js), so the row fits a 320px screen beside the exam toggle.
   With an exam open the sign-in button and, on the narrowest screens, the toggle show only their icons. */
.top-actions .more-btn { display: none; }
.more-menu button { display: flex; align-items: center; gap: 0.625rem; min-height: 2.75rem; }
.more-menu svg { flex: none; color: var(--muted); }
@media (max-width: 740px) {
  .top-actions .more-btn { display: grid; }
  .top-actions #nav-open, .top-actions #fullscreen-toggle, .top-actions #guide-open, .top-actions #settings-open { display: none !important; }
  html.has-exam .top-signin { width: 2.75rem; padding: 0; justify-content: center; }
  html.has-exam .top-signin .ts-long, html.has-exam .top-signin .ts-short { display: none; }
}
@media (max-width: 440px) { html.has-exam .top-actions { gap: 0.25rem; } }
@media (max-width: 380px) {
  html.has-exam #page-toggle { width: 2.75rem; padding: 0; justify-content: center; }
  html.has-exam #page-toggle .toggle-text { display: none; }
}
/* The zoom bar on a narrow touch screen: two fingers zoom, so its + and − give their room to the page flip and the
   close button (on a 320px screen the full bar was 372px wide and close was off the edge). */
@media (max-width: 380px) and (pointer: coarse) {
  .zm-bar .zm-out, .zm-bar .zm-in { display: none; }
}
/* The message box toolbar on a phone: the filters wrap onto a second line rather than hide past the edge (on a 320px
   screen half of them were out of sight). With the on-screen keyboard up it stays one row that scrolls sideways. */
@media (max-width: 740px) {
  html:not(.keyboard-up) .composer-tools > div {
    flex-wrap: wrap; overflow: visible; row-gap: 0.375rem; padding-inline-end: 0; -webkit-mask-image: none; mask-image: none;
  }
  html:not(.keyboard-up) .composer-tools { align-items: flex-end; }
}
/* A small phone with the keyboard up (under 420px left): the top row steps aside while the student types, so the
   message box with the formula panel fits (on a 320x568 screen it was 20px taller than the room). */
html.keyboard-tight { --top-h: 0.375rem; }
html.keyboard-tight .top-actions, html.keyboard-tight #page-toggle { display: none !important; }
html.keyboard-tight .composer-area { padding: 0.25rem 0.5rem; }
html.keyboard-tight .composer { padding: 0.375rem 0.625rem; }
html.keyboard-tight .fx { gap: 0.25rem; padding-top: 0.25rem; margin-top: 0.125rem; }
/* The formula panel on a touch screen: its tabs scroll sideways (a fade at the far edge says so) and every control
   is 44px; the close mark is drawn in the text colour, not as a faint glyph. */
.fx-tabs { -webkit-mask-image: linear-gradient(to right, transparent 0, #000 1.75rem); mask-image: linear-gradient(to right, transparent 0, #000 1.75rem); padding-inline-end: 1.25rem; }
.fx-close { color: var(--ink); font-size: 1.125rem; font-weight: 600; }
@media (hover: none), (pointer: coarse) {
  .fx-tab { min-height: 44px; }
  .fx-insert { height: 44px; }
  .fx-close { width: 44px; height: 44px; }
}
html.keyboard-tight .fx-field { min-height: 0; padding-block: 0.125rem; }
html.keyboard-tight .fx-insert { height: 2.25rem; }
html.keyboard-tight .composer:has(.fx:not([hidden])) .composer-input { --min-h: 1.875rem; --pad-top: 0.125rem; }
html.keyboard-tight .composer:has(.fx:not([hidden])) .composer-input .cm-editor { max-height: 2.125rem; }
/* The first screen on a phone: centred while it fits; taller (the formula panel open, the filters on two rows), it
   starts at the top and scrolls, so the message box is never pushed past the bottom edge. */
@media (max-width: 740px) {
  .tutor-pane:has(#welcome:not([hidden])) { justify-content: safe center; overflow-y: auto; }
}
html.keyboard-tight .learning-area { padding-block: 0; }
/* Touch screens: the plan's and the settings' small controls get a finger's room (44px), as the rest already do. */
@media (pointer: coarse) {
  .ls-step { padding: 0; }
  .ls-step button.ls-step-name { min-height: 44px; display: inline-flex; align-items: center; text-align: start; }
  .ls-jump, .pb-back, .pv-back, .pb-lessons-open, .seg-btn, .history-new { min-height: 44px; }
  .pb-back, .pv-back { display: inline-flex; align-items: center; }
  .sd-theme button, #settings input[type="number"] { min-height: 44px; }
}
/* Phones: the top row floats over the page; a band of the page colour behind it keeps scrolled text from showing
   between its buttons. */
@media (max-width: 740px) {
  body::before {
    content: ""; position: fixed; top: 0; left: 0; right: 0; z-index: 5; pointer-events: none;
    height: calc(var(--top-h, 3.75rem) + 0.25rem); background: linear-gradient(var(--bg) 78%, transparent);
  }
  html.keyboard-tight body::before { display: none; }
}

/* Any step of a lesson opens from the lesson list (plans.js goTo). */
.ls-go { font: inherit; background: none; margin: 0; cursor: pointer; border: 0; padding: 0; color: inherit; text-align: start; min-width: 0; }
.ls-go:hover { text-decoration: underline; text-underline-offset: 0.1875rem; }
.ls-go:focus-visible { outline: 0.125rem solid var(--green); outline-offset: 0.125rem; border-radius: 0.25rem; }
.ls-hint { margin: 0.125rem 0.75rem 0.5rem; font-size: 0.75rem; color: var(--muted); }
/* The code panel open beside the chat: the chat's half keeps its message box whole and scrolls what is above it (the
   welcome or the conversation), so the box never slides under the panel (its filters were drawn over the panel's
   "הקוד שלי" bar, which could not be tapped). */
.tutor-pane:not(.code-collapsed) .chat-half { overflow: hidden; }
.tutor-pane:not(.code-collapsed) .chat-half > .learning-area { flex: 1 1 auto !important; min-height: 0; overflow-y: auto; }
.tutor-pane:not(.code-collapsed) .chat-half .composer-area { flex: none; }
.tutor-pane:not(.code-collapsed):has(#welcome:not([hidden])) .chat-half { justify-content: flex-end; }
