/* Minimal: black, white and grey, small monospace text, thin square borders, small
   icon buttons. Colour is kept for what it says: the code's syntax, danger, the
   line being explained. */
:root {
  --bg: #f7f7f5;
  --fg: #2e2f33;
  --muted: #6c6d72;
  --line: #dcdcd8;
  --panel: #eeeeea;
  --danger: #b42828;
  /* The tour's button: green, so the way to the films is easy to find. */
  --ok: #17784a;
  --ok-soft: #e3f4ea;
  --current: #f8eec4;
  --current-edge: #8a7a2e;
  --speaking: #e3d48f;
  /* The glow around a focused field. */
  --focus: #18a8c9;
  --tok-keyword: #7a1fa2;
  --tok-string: #1d6b35;
  --tok-number: #9a4a00;
  --tok-comment: #6b6b6b;
  --tok-builtin: #0b627a;
  --tok-definition: #1f47a8;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #1b1c1f;
  --fg: #d6d6d3;
  --muted: #8f9095;
  --line: #36383d;
  --panel: #25272b;
  --danger: #ec7a7a;
  --ok: #5fd39a;
  --ok-soft: #173427;
  --current: #33301c;
  --current-edge: #c9b45a;
  --speaking: #5a5124;
  --focus: #3fd2f0;
  --tok-keyword: #d49bf0;
  --tok-string: #8fd6a0;
  --tok-number: #f2b27a;
  --tok-comment: #8f8f8f;
  --tok-builtin: #7fd0e6;
  --tok-definition: #9db9ff;
  color-scheme: dark;
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.5 var(--mono);
  display: flex;
  flex-direction: column;
}

:focus-visible { outline: 1px solid var(--fg); outline-offset: 2px; }
/* A field shows focus by its own border, not a second frame around it. */
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 1px var(--focus), 0 0 8px var(--focus);
}

h1, h2, h3 { margin: 0; font-weight: 700; }
h1 { font-size: 13px; }
h2 {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 4px 0 10px;
}
h3 { font-size: 12px; font-weight: 400; color: var(--muted); }

p { margin: 0 0 8px; }
code, pre { font-family: var(--mono); }

.muted { color: var(--muted); }
.error { color: var(--danger); margin: 8px 0 0; }
.path { overflow-wrap: anywhere; }

/* --- buttons ------------------------------------------------------------------ */

button {
  font: inherit;
  font-size: 12px;
  min-height: 28px;
  padding: 2px 10px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--fg);
  border-radius: 0;
  cursor: pointer;
}
button:disabled { opacity: 0.35; cursor: default; }
button.is-primary { background: var(--fg); color: var(--bg); }
button.is-danger { color: var(--danger); border-color: var(--danger); }
button.link { border: 0; min-height: 0; padding: 0; text-decoration: underline; background: none; color: inherit; }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 28px;
  height: 28px;
  min-height: 0;
  padding: 0;
  border: 1px solid transparent;
  background: none;
  color: inherit;
}
.icon-button:hover:not(:disabled) { border-color: var(--line); background: var(--panel); }
.icon-button svg { width: 16px; height: 16px; }
.icon-button.is-primary { border-color: var(--fg); background: var(--fg); color: var(--bg); }
.icon-button.is-primary:hover:not(:disabled) { background: var(--fg); opacity: 0.8; }
.icon-button.is-danger { border-color: transparent; color: var(--danger); }
.icon-button[aria-pressed="true"] { border-color: var(--fg); }
.icon-button.needs-login { color: var(--danger); border-color: var(--danger); }
#mic-button[aria-pressed="true"] { color: var(--danger); border-color: var(--danger); }

/* --- fields ----------------------------------------------------------------- */

input[type="text"], input[type="password"], input[type="email"], textarea, select {
  font: inherit;
  width: 100%;
  padding: 6px 8px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--muted);
  border-radius: 0;
}
/* A fixed size: no grip to drag, the text scrolls inside. */
textarea { resize: none; }
label { font-size: 12px; }

/* --- frame ------------------------------------------------------------------------ */

.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.brand {
  font-weight: 700;
  letter-spacing: 0.06em;
  border: 0;
  padding: 0;
  font-size: 13px;
  background: none;
}
.version { color: var(--muted); font-size: 11px; }
.top-actions { display: flex; align-items: center; gap: 2px; margin-left: auto; }

.toolbar { display: flex; align-items: center; gap: 4px; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }

.notice {
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 6px 10px;
  font-size: 12px;
}

.panel { border: 1px solid var(--line); padding: 10px 12px 12px; }

/* --- home ------------------------------------------------------------------------ */

.home {
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 14px 16px 40px;
  display: grid;
  gap: 14px;
}
.step-label { margin: 12px 0 6px; }
select { width: auto; padding: 5px 6px; }
#branch-select { width: 100%; }
.focus-row { display: flex; align-items: center; gap: 8px; }
.focus-file { flex: 1; min-width: 0; color: var(--muted); }
.focus-file.is-chosen { color: var(--fg); }
/* Signing in: one narrow panel. */
.signin { max-width: 32em; }
.signin .ask-row { margin: 4px 0 8px; }
/* Shortly before a review's session ends: a bubble offering another hour. */
.bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--fg);
  background: var(--panel);
  padding: 4px 4px 4px 8px;
  font-size: 12px;
}
#session-text { flex: 1; }
.bubble button { min-height: 22px; padding: 0 8px; font-size: 11px; }
/* The public key: fixed, sized for one key, nothing to scroll or drag. */
#ssh-key { font-size: 11px; word-break: break-all; resize: none; overflow: hidden; height: 5.2em; }
#ssh-replace { margin-top: 8px; }
.passkey, .people-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
  border-bottom: 1px solid var(--line);
}
.passkey span, .people-list .email { flex: 1; overflow-wrap: anywhere; }
.modal-body h3 { margin: 14px 0 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.known-repos { display: flex; align-items: baseline; gap: 8px; margin-top: 6px; font-size: 12px; }
.chip { font-size: 11px; min-height: 24px; padding: 0 8px; border-color: var(--line); }

.plain { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
.review-list button {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 6px 4px;
}
.review-list button:hover { background: var(--panel); }
.review-list .meta { display: block; color: var(--muted); font-size: 11px; }

/* --- review ------------------------------------------------------------------------ */

.review {
  --code-share: 60%;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(200px, var(--code-share)) 7px minmax(260px, 1fr);
}
.code-panel { display: flex; flex-direction: column; min-height: 0; }
/* The divider: a thin line inside a wider grab area. */
.splitter {
  cursor: col-resize;
  touch-action: none;
  background: linear-gradient(var(--line), var(--line)) center / 1px 100% no-repeat;
}
.splitter:hover, .splitter.dragging, .splitter:focus-visible {
  background: linear-gradient(var(--muted), var(--muted)) center / 3px 100% no-repeat;
  outline: none;
}
body.resizing { cursor: col-resize; user-select: none; }
body.resizing-row { cursor: row-resize; user-select: none; }
/* The right column: the explanation on top, the progress pile below, the divider
   between them moving the height they share. */
.side {
  --explain-share: 70%;
  display: grid;
  grid-template-rows: minmax(120px, var(--explain-share)) 7px minmax(60px, 1fr);
  min-height: 0;
  min-width: 0;
}
.splitter-row {
  cursor: row-resize;
  background: linear-gradient(var(--line), var(--line)) center / 100% 1px no-repeat;
}
.splitter-row:hover, .splitter-row.dragging, .splitter-row:focus-visible {
  background: linear-gradient(var(--muted), var(--muted)) center / 100% 3px no-repeat;
}
.progress-panel { display: flex; flex-direction: column; min-height: 0; padding: 4px 14px 8px; }
.code-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
#code-path { flex: 1; text-align: left; text-decoration: none; font-size: 12px; }
#code-path:hover { text-decoration: underline; }
.code-head .icon-button { width: 22px; height: 22px; }
.code-view {
  flex: 1;
  overflow: auto;
  font-size: 12px;
  line-height: 1.55;
  padding: 4px 0;
}
.line { display: flex; white-space: pre; border-left: 2px solid transparent; }
.line.current { background: var(--current); border-left-color: var(--current-edge); }
.ln {
  flex: none;
  width: 5ch;
  padding-right: 1.5ch;
  text-align: right;
  color: var(--muted);
  user-select: none;
}
.src { padding-right: 12px; }
.tok-keyword { color: var(--tok-keyword); font-weight: 700; }
.tok-string { color: var(--tok-string); }
.tok-number { color: var(--tok-number); }
.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-builtin { color: var(--tok-builtin); }
.tok-definition { color: var(--tok-definition); font-weight: 700; }
.code-empty { padding: 12px; color: var(--muted); }
/* Names that lead to their declaration: plain text until Ctrl or Cmd is held. */
.code-view .ref { color: inherit; text-decoration: none; cursor: text; }
.code-view.linking .ref { text-decoration: underline dotted; text-underline-offset: 2px; cursor: pointer; }
.code-view.linking .ref:hover { text-decoration: underline solid; }

.explain-panel {
  min-height: 0;
  overflow-y: auto;
  padding: 10px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.review-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.review-name { min-width: 0; }
.review-head p { margin: 2px 0 0; font-size: 11px; }
.trail { display: flex; flex-wrap: wrap; gap: 4px; font-size: 11px; }
.trail span { border: 1px solid var(--line); padding: 0 4px; }
.trail span.sep { border: 0; color: var(--muted); padding: 0; }
.step h2 { color: var(--fg); text-transform: none; letter-spacing: 0; font-size: 13px; margin: 0 0 6px; }
.explanation p { margin: 0 0 8px; }
.explanation code, .suggestion code { background: var(--panel); border: 1px solid var(--line); padding: 0 3px; }
.suggestion { border: 1px solid var(--fg); padding: 8px; }
.suggestion p { margin: 0 0 6px; }
.finished { border-left: 2px solid var(--fg); padding-left: 8px; }
.status { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; }
.spinner {
  width: 12px;
  height: 12px;
  border: 1px solid var(--line);
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.error-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  border: 1px solid var(--danger);
  padding: 6px 8px;
  color: var(--danger);
}
.error-box p { margin: 0; }
.speech-status {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 2px 2px 2px 8px;
  font-size: 12px;
}
#speech-text, #continue-text { flex: 1; }
.toolbar-gap { flex: 1; }
/* An on/off button: filled when on, faint and crossed out (its icon) when off. */
.icon-button.toggle[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.icon-button.toggle[aria-pressed="true"]:hover:not(:disabled) { background: var(--fg); opacity: 0.85; }
.icon-button.toggle[aria-pressed="false"] { color: var(--muted); }
/* Two choices side by side; the chosen one filled. */
.segmented { display: inline-flex; }
.segmented button { min-height: 24px; padding: 0 8px; font-size: 11px; border-color: var(--line); }
.segmented button + button { border-left: 0; }
.segmented button[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.to-visit { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; font-size: 11px; }
.to-visit ol { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; list-style: none; counter-reset: visit; }
.to-visit li { border: 1px solid var(--line); padding: 0 4px; counter-increment: visit; }
.to-visit li::before { content: counter(visit) ". "; color: var(--muted); }
/* While a part is read: its lines in the code, its words in the explanation. */
.line.speaking { background: var(--speaking); border-left-color: var(--fg); }
.part.speaking { background: var(--speaking); }
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.bars i { width: 2px; height: 100%; background: var(--fg); animation: bar 0.9s ease-in-out infinite; }
.bars i:nth-child(2) { animation-delay: -0.6s; }
.bars i:nth-child(3) { animation-delay: -0.3s; }
.bars i:nth-child(4) { animation-delay: -0.45s; }
@keyframes bar { 0%, 100% { transform: scaleY(0.3); } 50% { transform: scaleY(1); } }
.bars i { transform-origin: bottom; }
@media (prefers-reduced-motion: reduce) { .bars i { animation: none; } }
.controls { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px 0; }
.question label { display: block; margin-bottom: 4px; color: var(--muted); }
.ask-row { display: flex; gap: 4px; align-items: center; }
.ask-row button { white-space: nowrap; }
/* The progress pile: every step so far, indented by how deep in the calls it is,
   then the places still to visit, faint. A past step can be opened again. */
.progress-panel h3 { margin: 0 0 4px; }
.pile { flex: 1; min-height: 0; list-style: none; margin: 0; padding: 0; overflow-y: auto; border-left: 1px solid var(--line); }
.pile li { padding-left: calc(8px + var(--depth, 0) * 12px); }
.pile button {
  display: block;
  width: 100%;
  border: 0;
  min-height: 0;
  padding: 2px 4px;
  text-align: left;
  background: none;
  font-size: 12px;
}
.pile button:hover { background: var(--panel); }
.pile .number { color: var(--muted); margin-right: 6px; }
.pile button[aria-current="true"] { font-weight: 700; background: var(--panel); box-shadow: inset 2px 0 0 var(--fg); }
.pile .kind { color: var(--muted); font-weight: 400; }
.pile .upcoming { color: var(--muted); font-size: 11px; padding-top: 1px; padding-bottom: 1px; }
.pile .upcoming::before { content: "○ "; }
#revisit-text { flex: 1; }
#revisit-bar button { min-height: 22px; padding: 0 8px; font-size: 11px; }

/* --- modals: a fixed frame, the content scrolls inside (02-coding §2.13) ------- */

.modal-layer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.modal {
  width: min(480px, calc(100vw - 24px));
  height: min(460px, calc(100dvh - 24px));
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--fg);
}
.modal-small { height: min(180px, calc(100dvh - 24px)); }
/* Each dialog's own frame, sized for its content: nothing scrolls but a long list. */
#account-modal .modal { width: min(580px, calc(100vw - 24px)); height: min(500px, calc(100dvh - 24px)); }
#passkey-list { max-height: 66px; overflow-y: auto; }
#people-modal .modal { width: min(580px, calc(100vw - 24px)); height: min(500px, calc(100dvh - 24px)); }
#login-modal .modal { width: min(540px, calc(100vw - 24px)); height: min(500px, calc(100dvh - 24px)); }
/* Nearly the whole screen: a topic's words and its whole film fit in view together. */
#tour-modal .modal { width: min(1240px, calc(100vw - 24px)); height: calc(100dvh - 24px); }
.tour-body { scroll-snap-type: y proximity; }
.tour-body section { scroll-snap-align: start; }
#help-button, #help-button:hover:not(:disabled) { background: var(--ok-soft); color: var(--ok); }
#help-button:hover:not(:disabled) { box-shadow: inset 0 0 0 1px var(--ok); }
.tour-body section { padding-top: 6px; }
.tour-body p, .tour-body li { line-height: 1.55; }
.tour-topics { margin: 4px 0 8px; padding-left: 22px; }
.tour-topics a { color: inherit; text-decoration: underline; }
/* As wide as the dialog allows, never taller than the screen leaves once the topic's
   words, the title bar and the Close bar are shown: its ratio is kept either way. */
.tour-film { display: block; width: auto; max-width: 100%; height: auto; max-height: calc(100dvh - 300px);
  margin: 8px auto 14px; border: 1px solid var(--line); background: #000; }
#files-modal .modal { width: min(640px, calc(100vw - 24px)); height: min(560px, calc(100dvh - 24px)); }
/* The picker's frame stays put: only the list scrolls, whatever the filter leaves. */
.files-body { display: flex; flex-direction: column; gap: 4px; overflow: hidden; }
.files-body p { margin: 2px 0; }
.files-list { flex: 1; min-height: 0; overflow-y: auto; border: 1px solid var(--line); }
.files-list button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  min-height: 0;
  padding: 3px 8px;
  background: none;
  font-size: 12px;
  overflow-wrap: anywhere;
}
.files-list button:hover, .files-list button:focus-visible { background: var(--panel); }
.files-list .folder { color: var(--muted); }
#commit-modal .modal { height: min(200px, calc(100dvh - 24px)); }
.people-list { max-height: 200px; overflow-y: auto; }
.modal-frame { display: flex; flex-direction: column; height: 100%; }
.modal-frame h2 { margin: 0; padding: 8px 12px; border-bottom: 1px solid var(--line); color: var(--fg); }
.modal-body { flex: 1 1 auto; overflow-y: auto; padding: 10px 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--line); }
.modal-actions .left { margin-right: auto; }
.command { border: 1px solid var(--line); background: var(--panel); padding: 4px 8px; margin: 0 0 8px; }
.status-line { font-weight: 700; }

@media (max-width: 860px) {
  .review { grid-template-columns: 1fr; grid-template-rows: minmax(220px, 45vh) auto; }
  .code-panel { border-bottom: 1px solid var(--line); }
  .splitter { display: none; }
  .side { grid-template-rows: auto auto; }
  .pile { max-height: 40vh; }
  .version { display: none; }
}
