/*
 * Visual explanations (docs/visuals-spec.md, public/js/visuals/). Phone first (360 px), both
 * themes, right-to-left page with left-to-right islands for code, lists and Latin terms.
 * Layouts that need width switch on the figure's own width (container queries, or a class set
 * by a ResizeObserver for trees and flows).
 */

:root {
  --t-blue: #0EA5E9; --t-blue-soft: #E0F4FE; --t-blue-ink: #0369A1;
  --t-green: #12B76A; --t-green-soft: #DFF8EB; --t-green-ink: #065F46;
  --t-orange: #F97316; --t-orange-soft: #FFEDD5; --t-orange-ink: #B4410C;
  --t-pink: #EC4899; --t-pink-soft: #FCE7F3; --t-pink-ink: #BE185D;
  --t-purple: #5B4BFF; --t-purple-soft: #EAE8FF; --t-purple-ink: #3D30C7;
  --t-gray: #8A91B4; --t-gray-soft: #EEF1FF; --t-gray-ink: #4A5275;
  --v-line: #B9C0E3;
  --term-bg: #161A33;
  --term-fg: #E8EBFF;
  --term-muted: #8E96C4;
  --g-bg: #EAE8FF;
  --g-hijab: #6D4AD8;
  --g-hijab-edge: #523AB0;
  --g-skin: #F6D3B8;
  --g-eye: #2B2340;
  --g-mouth: #8A3A4A;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --t-blue: #38BDF8; --t-blue-soft: #0F3247; --t-blue-ink: #7DD3FC;
    --t-green: #34D399; --t-green-soft: #103B2C; --t-green-ink: #6EE7B7;
    --t-orange: #FB923C; --t-orange-soft: #3F2412; --t-orange-ink: #FDBA74;
    --t-pink: #F472B6; --t-pink-soft: #43142E; --t-pink-ink: #F9A8D4;
    --t-purple: #8B80FF; --t-purple-soft: #2A2A66; --t-purple-ink: #C4B5FD;
    --t-gray: #A6ADD3; --t-gray-soft: #222852; --t-gray-ink: #C9CEEA;
    --v-line: #4A5290;
    --term-bg: #0B0E1F;
    --g-bg: #2A2A66;
    --g-hijab: #8B6CF0;
    --g-hijab-edge: #6D4AD8;
  }
}
:root[data-theme="dark"] {
  --t-blue: #38BDF8; --t-blue-soft: #0F3247; --t-blue-ink: #7DD3FC;
  --t-green: #34D399; --t-green-soft: #103B2C; --t-green-ink: #6EE7B7;
  --t-orange: #FB923C; --t-orange-soft: #3F2412; --t-orange-ink: #FDBA74;
  --t-pink: #F472B6; --t-pink-soft: #43142E; --t-pink-ink: #F9A8D4;
  --t-purple: #8B80FF; --t-purple-soft: #2A2A66; --t-purple-ink: #C4B5FD;
  --t-gray: #A6ADD3; --t-gray-soft: #222852; --t-gray-ink: #C9CEEA;
  --v-line: #4A5290;
  --term-bg: #0B0E1F;
  --g-bg: #2A2A66;
  --g-hijab: #8B6CF0;
  --g-hijab-edge: #6D4AD8;
}

.vis, .visuals { --tone: var(--unit, var(--primary)); --tone-soft: var(--primary-soft); --tone-ink: var(--unit-ink, var(--primary-edge)); }
.tone-blue { --tone: var(--t-blue); --tone-soft: var(--t-blue-soft); --tone-ink: var(--t-blue-ink); }
.tone-green { --tone: var(--t-green); --tone-soft: var(--t-green-soft); --tone-ink: var(--t-green-ink); }
.tone-orange { --tone: var(--t-orange); --tone-soft: var(--t-orange-soft); --tone-ink: var(--t-orange-ink); }
.tone-pink { --tone: var(--t-pink); --tone-soft: var(--t-pink-soft); --tone-ink: var(--t-pink-ink); }
.tone-purple { --tone: var(--t-purple); --tone-soft: var(--t-purple-soft); --tone-ink: var(--t-purple-ink); }
.tone-gray { --tone: var(--t-gray); --tone-soft: var(--t-gray-soft); --tone-ink: var(--t-gray-ink); }

/* ---------- frame ---------- */
.info-visual { gap: 14px; }
.info-lead {
  display: flex; flex-direction: column; gap: 8px;
  padding: 2px 4px;
}
.info-lead .body { font-size: 18px; font-weight: 500; }
.visuals { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.visuals.is-question { margin-bottom: 2px; }
.vis {
  container: vis / inline-size;
  margin: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.vis .vis { padding: 0; border: 0; box-shadow: none; background: transparent; border-radius: 0; }
.v-caption { font-size: 15px; color: var(--muted); font-weight: 700; text-align: center; }
.v-icon {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--tone-soft);
  color: var(--tone-ink);
}
.v-enter { animation: v-enter .28s ease-out; }
.v-flash { animation: v-flash .9s ease-out; }
@keyframes v-enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes v-flash { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--xp) 70%, transparent); } 100% { box-shadow: 0 0 0 10px transparent; } }

/* ---------- controls (story, code trace) ---------- */
.v-controls { display: flex; align-items: center; gap: 10px; }
.v-ctrl {
  width: 48px; height: 48px; flex: none;
  display: grid; place-items: center;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.v-ctrl:disabled { opacity: .35; cursor: default; }
.v-ctrl:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.v-progress { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.v-dots { display: flex; gap: 6px; }
.v-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--line); transition: width .2s, background .2s; }
.v-dot.is-past { background: color-mix(in srgb, var(--tone) 45%, var(--line)); }
.v-dot.is-on { width: 22px; background: var(--tone); }
.v-count { margin: 0; font-size: 14px; font-weight: 800; color: var(--muted); }

/* ---------- story ---------- */
.st-stage { min-width: 0; }
.st-frame { display: flex; flex-direction: column; gap: 10px; }
.st-text {
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--tone-soft);
  border-inline-start: 5px solid var(--tone);
}
.st-line { margin: 0; font-size: 19px; font-weight: 700; line-height: 1.6; }

/* ---------- diagram: shared node ---------- */
.dg { min-width: 0; transition: opacity .2s; }
.dg-node {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  text-align: center;
  padding: 8px 10px;
  min-width: 84px;
  max-width: 200px;
  border-radius: 16px;
  border: 2px solid var(--tone);
  background: var(--surface);
  transition: opacity .2s, transform .2s, box-shadow .2s;
}
.dg-words { display: flex; flex-direction: column; align-items: inherit; gap: 1px; min-width: 0; }
.dg-label { font-weight: 800; font-size: 16px; line-height: 1.35; }
.dg-en { font-size: 13px; font-weight: 700; color: var(--muted); line-height: 1.3; }
.dg-note { font-size: 14px; color: var(--muted); font-weight: 600; line-height: 1.35; }
.dg.has-focus [data-id]:not(.is-on) { opacity: .5; }
.dg [data-id].is-on { box-shadow: 0 0 0 4px var(--tone-soft), 0 8px 18px rgba(25, 29, 58, .12); background: var(--tone-soft); }
.dg-tree:not(.is-vertical) .dg-node.is-on { transform: scale(1.04); }

/* ---------- diagram: tree (an org chart; an indented list on narrow figures) ---------- */
.dg-tree ul { list-style: none; margin: 0; padding: 0; display: flex; justify-content: center; }
.dg-tree li { display: flex; flex-direction: column; align-items: center; position: relative; min-width: 0; }
.dg-tree .dg-kids { position: relative; padding-top: 18px; width: 100%; }
.dg-tree .dg-kids::before {
  content: ""; position: absolute; top: 0; inset-inline-start: 50%;
  height: 18px; border-inline-start: 2px solid var(--v-line);
}
.dg-tree .dg-kids > li { padding: 18px 4px 0; flex: 1 1 0; }
.dg-tree .dg-kids > li::before,
.dg-tree .dg-kids > li::after {
  content: ""; position: absolute; top: 0; width: 50%; height: 18px;
  border-top: 2px solid var(--v-line);
}
.dg-tree .dg-kids > li::before { inset-inline-start: 0; }
.dg-tree .dg-kids > li::after { inset-inline-end: 0; border-inline-start: 2px solid var(--v-line); }
.dg-tree .dg-kids > li:first-child::before { border-top: 0; }
.dg-tree .dg-kids > li:last-child::after { border-top: 0; }
.dg-tree .dg-kids > li:only-child::before { border-top: 0; }

.dg-tree.is-vertical ul { flex-direction: column; align-items: stretch; }
.dg-tree.is-vertical li { align-items: flex-start; }
.dg-tree.is-vertical .dg-kids { padding-top: 0; padding-inline-start: 30px; }
.dg-tree.is-vertical .dg-kids::before { display: none; }
.dg-tree.is-vertical .dg-kids > li { padding: 10px 0 0; flex: none; }
.dg-tree.is-vertical .dg-kids > li::before,
.dg-tree.is-vertical .dg-kids > li:first-child::before,
.dg-tree.is-vertical .dg-kids > li:only-child::before {
  top: 0; bottom: 0; height: auto; width: 0;
  inset-inline-start: -16px;
  border-top: 0;
  border-inline-start: 2px solid var(--v-line);
}
.dg-tree.is-vertical .dg-kids > li:last-child::before { bottom: auto; height: 36px; }
.dg-tree.is-vertical .dg-kids > li::after,
.dg-tree.is-vertical .dg-kids > li:last-child::after {
  top: 36px; height: 0; width: 14px;
  inset-inline-start: -16px; inset-inline-end: auto;
  border-inline-start: 0;
  border-top: 2px solid var(--v-line);
}
.dg-tree.is-vertical .dg-node {
  flex-direction: row; text-align: start; align-items: center;
  max-width: none; min-height: 52px; width: fit-content;
}
.dg-tree.is-vertical .dg-words { align-items: flex-start; }
.dg-tree.is-vertical .v-icon { width: 34px; height: 34px; }

/* ---------- diagram: flow (a row of steps; a column on narrow figures) ---------- */
.dg-flow { display: flex; align-items: center; justify-content: center; gap: 2px; }
.dg-flow .dg-node { flex: 1 1 0; }
.dg-arrow { flex: none; min-width: 46px; max-width: 96px; padding: 0 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); }
.dg-arrow-svg { width: 40px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.dg-arrow-label { font-size: 13px; font-weight: 800; text-align: center; line-height: 1.25; }
.dg-flow.is-vertical { flex-direction: column; align-items: stretch; gap: 0; }
.dg-flow.is-vertical .dg-node { flex-direction: row; text-align: start; max-width: none; width: 100%; }
.dg-flow.is-vertical .dg-words { align-items: flex-start; }
.dg-flow.is-vertical .dg-arrow { width: 100%; max-width: none; flex-direction: row; justify-content: center; gap: 8px; min-height: 34px; }
.dg-flow.is-vertical .dg-arrow-svg { transform: rotate(-90deg); width: 30px; }

/* ---------- diagram: network ---------- */
.dg-net { position: relative; width: 100%; max-width: 440px; margin-inline: auto; aspect-ratio: 5 / 4; }
.dg-net-lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.dg-net-lines line { stroke: var(--v-line); stroke-width: 2.5; stroke-linecap: round; transition: stroke .2s; }
.dg-net-lines line.is-on { stroke: var(--tone); stroke-width: 3.5; }
.dg-net-node {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  max-width: 112px; text-align: center;
  transition: opacity .2s, transform .2s;
}
.dg-net-node .v-icon { width: 40px; height: 40px; border-radius: 999px; border: 2px solid var(--tone); background: var(--surface); }
.dg-net-node .dg-label { font-size: 14px; background: var(--surface); padding: 0 4px; border-radius: 6px; }
.dg-dot::after { content: ""; width: 12px; height: 12px; border-radius: 999px; background: var(--tone); }
.dg-net.has-focus .dg-net-node.is-on { transform: translate(-50%, -50%) scale(1.08); }

/* ---------- compare ---------- */
.cmp-cards { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
@container vis (min-width: 420px) { .cmp-2 .cmp-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@container vis (min-width: 620px) { .cmp-3 .cmp-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.cmp-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px;
  border-radius: 16px;
  border: 2px solid color-mix(in srgb, var(--tone) 45%, var(--line));
  border-top: 6px solid var(--tone);
  background: color-mix(in srgb, var(--tone-soft) 55%, var(--surface));
  min-width: 0;
}
.cmp-head { display: flex; align-items: center; gap: 10px; }
.cmp-names { display: flex; flex-direction: column; min-width: 0; }
.cmp-title { margin: 0; font-size: 19px; font-weight: 800; line-height: 1.3; }
.cmp-en { font-size: 13px; color: var(--muted); font-weight: 700; }
.cmp-text { margin: 0; font-size: 17px; line-height: 1.55; }
.cmp-examples { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.cmp-ex {
  padding: 3px 10px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line);
  font-weight: 700; font-size: 15px;
}
.cmp-ex code.ic { background: transparent; border: 0; padding: 0; margin: 0; }

/* ---------- points ---------- */
.pt-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.pt-row { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 14px; background: color-mix(in srgb, var(--tone-soft) 45%, var(--surface)); }
.pt-text { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.5; }

/* ---------- analogy ---------- */
.an-scene { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 12px; padding: 4px 0; }
.an-item { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 64px; }
.an-pic {
  position: relative;
  width: 64px; height: 64px;
  display: grid; place-items: center;
  border-radius: 18px;
  background: var(--tone-soft);
  color: var(--tone-ink);
  border: 2px solid color-mix(in srgb, var(--tone) 40%, transparent);
}
.an-tag {
  position: absolute; bottom: -8px; inset-inline-end: -8px;
  min-width: 26px; height: 26px; padding: 0 6px;
  display: grid; place-items: center;
  border-radius: 999px;
  background: var(--xp); color: var(--on-xp);
  font-family: var(--mono); font-weight: 800; font-size: 14px;
}
.an-label { font-size: 14px; font-weight: 700; color: var(--muted); text-align: center; max-width: 96px; line-height: 1.3; }
.an-say { display: flex; align-items: flex-start; gap: 10px; padding: 12px; border-radius: 16px; background: var(--xp-soft); }
.an-text { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.6; }
.an-pairs { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.an-pair {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 12px; background: var(--surface-2);
}
.an-pair dt, .an-pair dd { margin: 0; font-weight: 800; font-size: 16px; }
.an-pair dt { color: var(--muted); }
.an-pair dd { text-align: end; }
.an-eq { color: var(--tone-ink); display: grid; place-items: center; }

/* ---------- array (a Python list: always left to right, like the code) ---------- */
/* The scroller is left-to-right too, so a long list starts at its name, not at its last cell. */
.arr-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 4px 0; direction: ltr; }
.arr { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; width: max-content; margin-inline: auto; direction: ltr; }
.arr-name { font-family: var(--mono); font-weight: 800; font-size: 15px; color: var(--muted); padding-left: 2px; }
.arr-track { display: flex; gap: 6px; align-items: stretch; }
.arr-col { display: flex; flex-direction: column; align-items: center; gap: 4px; transition: opacity .2s, transform .2s; }
.arr-cell {
  min-width: 58px; padding: 10px 10px;
  text-align: center;
  font-family: var(--mono); font-size: 16px; font-weight: 700;
  border: 2px solid color-mix(in srgb, var(--tone) 55%, var(--line));
  border-radius: 12px;
  background: var(--code-bg, var(--surface-2));
  color: var(--text);
  white-space: pre;
}
.arr-ix { font-family: var(--mono); font-size: 14px; font-weight: 800; color: var(--muted); min-height: 1.2em; }
.arr-ix.is-neg { color: var(--t-pink-ink); }
.arr.has-focus .arr-col:not(.is-on) { opacity: .4; }
.arr-col.is-on { transform: translateY(-3px); }
.arr-col.is-on .arr-cell { border-color: var(--tone); background: var(--tone-soft); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tone) 25%, transparent); }
.arr-col.is-on .arr-ix { color: var(--tone-ink); }
.arr-col.is-on .arr-ix.is-neg { color: var(--t-pink-ink); }

/* ---------- table ---------- */
.vt-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.vt { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 16px; }
.vt th, .vt td { padding: 8px 10px; text-align: start; border-bottom: 1px solid var(--line); transition: background .2s, color .2s; }
.vt thead tr:last-child th { background: var(--surface-2); font-weight: 800; }
.vt thead tr:last-child th:nth-child(2) { border-start-start-radius: 12px; }
.vt thead tr:last-child th:last-child { border-start-end-radius: 12px; }
.vt thead tr:last-child th.is-on { background: var(--tone); color: var(--on-primary); }
.vt td.is-on { background: var(--tone-soft); font-weight: 800; }
.vt.has-focus tbody td:not(.is-on):not(.vt-rowtag) { color: var(--muted); }
.vt-tags { display: none; }
.vt-tags.is-shown { display: table-row; }
.vt-tags td { border: 0; padding: 0 10px 6px; }
.vt-rowtag { display: none; }
.vt.has-rowtag .vt-rowtag { display: table-cell; width: 1%; padding-inline: 0 6px; border-bottom-color: transparent; background: transparent; }
.vt-pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  background: var(--tone); color: var(--on-primary);
  font-size: 14px; font-weight: 800; white-space: nowrap;
}
.accent-a2 .vt thead tr:last-child th.is-on, .accent-a2 .vt-pill,
.accent-a3 .vt thead tr:last-child th.is-on, .accent-a3 .vt-pill,
.accent-a4 .vt thead tr:last-child th.is-on, .accent-a4 .vt-pill { color: var(--on-unit); }

/* ---------- code and code trace ---------- */
.vc-code { border: 1.5px solid var(--code-edge); border-radius: 12px; background: var(--code-bg); overflow: hidden; direction: ltr; text-align: left; }
.vc-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.vc-lines { display: block; width: max-content; min-width: 100%; padding: 8px 0; font-family: var(--mono); font-size: 15.5px; line-height: 1.65; color: var(--text); }
.vc-line { display: flex; padding: 0 12px 0 0; border-left: 4px solid transparent; transition: background .2s; }
.vc-num { flex: none; width: 2.6ch; padding-left: 6px; margin-right: 12px; text-align: right; color: var(--code-num); user-select: none; -webkit-user-select: none; }
.vc-text { white-space: pre; }
.vc-line.is-on { background: color-mix(in srgb, var(--tone) 16%, transparent); border-left-color: var(--tone); }
.vc-code.has-focus .vc-line:not(.is-on) .vc-text { opacity: .55; }
.vc-line.is-now { background: color-mix(in srgb, var(--xp) 26%, transparent); border-left-color: var(--xp); }
.vc-line.is-now .vc-num { color: var(--xp-ink); font-weight: 800; }
.vc-out-title { margin: 0 0 4px; font-size: 14px; font-weight: 800; color: var(--muted); }
.vc-screen {
  margin: 0; padding: 10px 12px; min-height: 2.4em;
  border-radius: 12px;
  background: var(--term-bg); color: var(--term-fg);
  font-family: var(--mono); font-size: 15px; line-height: 1.55;
  direction: ltr; text-align: left;
  overflow-x: auto; white-space: pre;
}
.vc-out-line { display: block; }
.vc-out-line.is-error { color: #FF8FA3; font-weight: 700; }
.vc-out-line.is-empty { color: var(--term-muted); }
/* Phones: a smaller font and gutter so about 32 characters fit without scrolling sideways. */
@container vis (max-width: 420px) {
  .vc-lines { font-size: 14px; }
  .vc-num { width: 2ch; padding-left: 4px; margin-right: 8px; }
  .vc-line { padding-right: 8px; }
  .vc-screen { font-size: 14px; }
  .arr-cell { min-width: 50px; padding: 9px 8px; font-size: 15px; }
  .dg-node { padding: 6px 8px; min-width: 76px; }
  .dg-node .v-icon { width: 32px; height: 32px; border-radius: 10px; }
  .dg-label { font-size: 15px; }
  .dg-note { font-size: 13px; }
}
.vc-layout { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
@container vis (min-width: 600px) { .vc-layout { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: start; } }
.vt-state { display: grid; gap: 10px; min-width: 0; }
.vc-var-grid { display: flex; flex-wrap: wrap; gap: 8px; direction: ltr; }
.vc-var { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); min-width: 0; max-width: 100%; }
.vc-var-name { font-family: var(--mono); font-size: 13px; font-weight: 800; color: var(--muted); }
.vc-var-value { font-family: var(--mono); font-size: 15.5px; font-weight: 700; white-space: pre-wrap; overflow-wrap: anywhere; }
.vc-var.is-new { border-color: var(--xp); background: var(--xp-soft); }
.vc-var-empty { color: var(--muted); font-weight: 800; }
.vc-note { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: 14px; background: var(--xp-soft); }
.vc-note-tag { flex: none; padding: 2px 10px; border-radius: 999px; background: var(--xp); color: var(--on-xp); font-weight: 800; font-size: 14px; margin-top: 2px; }
.vc-note-text { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.55; }

/* ---------- quick tries: flip cards and pick ---------- */
.try-hint { margin: 0; display: flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 800; color: var(--xp-ink); }
.flip-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(136px, 1fr)); grid-auto-rows: 1fr; }
.flip-card {
  padding: 0; border: 0; background: transparent; color: inherit; font: inherit;
  perspective: 900px; cursor: pointer; text-align: center; min-height: 112px;
  border-radius: 16px;
}
.flip-card:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
.flip-inner { display: grid; height: 100%; transition: transform .45s ease; transform-style: preserve-3d; }
.flip-card.is-flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  grid-area: 1 / 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 10px;
  border-radius: 16px;
  border: 2px solid var(--line);
  box-shadow: 0 4px 0 var(--line);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.flip-face.is-front { background: var(--surface); }
.flip-face.is-back { background: var(--tone-soft); border-color: var(--tone); transform: rotateY(180deg); }
.flip-front-text { font-weight: 800; font-size: 17px; line-height: 1.4; }
.flip-back-text { font-weight: 700; font-size: 16px; line-height: 1.5; }
.flip-back-title { font-size: 13px; font-weight: 800; color: var(--tone-ink); }
.flip-turn { color: var(--muted); }
@media (prefers-reduced-motion: reduce) {
  .flip-inner { transform: none !important; }
  .flip-face { backface-visibility: visible; transform: none !important; }
  .flip-card .flip-face.is-back { visibility: hidden; }
  .flip-card.is-flipped .flip-face.is-back { visibility: visible; }
  .flip-card.is-flipped .flip-face.is-front { visibility: hidden; }
}

.pick-prompt { margin: 0; font-size: 18px; font-weight: 800; }
.pick-stage { display: flex; flex-direction: column; gap: 10px; }
.pick-count { margin: 0; font-size: 14px; font-weight: 800; color: var(--muted); text-align: center; }
.pick-card {
  margin: 0; padding: 16px; text-align: center;
  font-size: 19px; font-weight: 800; line-height: 1.5;
  border-radius: 16px; background: var(--surface-2); border: 2px dashed var(--line);
}
.pick-buckets { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pick-buckets.n3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.pick-bucket {
  min-height: 56px; padding: 8px 10px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 14px; border: 2px solid var(--line); box-shadow: 0 4px 0 var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 800; cursor: pointer;
}
.pick-bucket:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.pick-bucket .v-icon { width: 30px; height: 30px; }
.pick-bucket:disabled { cursor: default; opacity: .6; }
.pick-bucket.is-right { opacity: 1; border-color: var(--good); background: var(--good-soft); box-shadow: 0 4px 0 var(--good-edge); }
.pick-bucket.is-wrong { opacity: 1; border-color: var(--xp); background: var(--xp-soft); box-shadow: 0 4px 0 var(--xp); }
.pick-feedback:empty { display: none; }
.pick-feedback { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: 14px; }
.pick-feedback.is-good { background: var(--good-soft); }
.pick-feedback.is-bad { background: var(--xp-soft); }
.pick-verdict { margin: 0; display: flex; align-items: center; gap: 6px; font-weight: 800; }
.pick-feedback.is-good .pick-verdict { color: var(--good-ink); }
.pick-feedback.is-bad .pick-verdict { color: var(--xp-ink); }
.pick-why { margin: 0; font-size: 16px; }
.pick-next, .pick-again { align-self: flex-start; min-height: 48px; }
.pick-done { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; font-weight: 800; }
.pick-done p { margin: 0; font-size: 18px; }

/* ---------- the guide (Lama) ---------- */
.guide { display: flex; align-items: flex-end; gap: 10px; }
.guide-who { position: relative; flex: none; width: 56px; height: 56px; }
.guide-face { display: block; }
.guide-face .g-bg { fill: var(--g-bg); }
.guide-face .g-hijab { fill: var(--g-hijab); }
.guide-face .g-skin { fill: var(--g-skin); }
.guide-face .g-band, .guide-face .g-fold { fill: none; stroke: var(--g-hijab-edge); stroke-width: 1.6; stroke-linecap: round; }
.guide-face .g-cheek { fill: #F59BB0; opacity: .55; }
.guide-face .g-eye { fill: var(--g-eye); }
.guide-face .g-glint { fill: #FFFFFF; }
.guide-face .g-mouth { fill: none; stroke: var(--g-mouth); stroke-width: 1.7; stroke-linecap: round; }
.guide-face .g-mouth-fill { fill: var(--g-mouth); }
.guide-badge {
  position: absolute; top: -4px; inset-inline-end: -6px;
  width: 24px; height: 24px; display: grid; place-items: center;
  border-radius: 999px; background: var(--xp); color: var(--on-xp);
  border: 2px solid var(--bg);
}
.guide-bubble {
  position: relative; flex: 1; min-width: 0;
  padding: 10px 14px 12px;
  border-radius: 18px;
  border-end-start-radius: 6px;
  background: var(--surface);
  border: 2px solid color-mix(in srgb, var(--g-hijab) 35%, var(--line));
  box-shadow: var(--shadow);
}
.guide-name { margin: 0; font-size: 14px; font-weight: 800; color: var(--g-hijab-edge); }
:root[data-theme="dark"] .guide-name { color: var(--t-purple-ink); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .guide-name { color: var(--t-purple-ink); } }
.guide-say { margin: 2px 0 0; font-size: 17px; font-weight: 600; line-height: 1.6; }

@media (max-height: 520px) {
  .st-line { font-size: 17px; }
  .an-pic { width: 52px; height: 52px; }
}
