/* Profu' De Mate: remi tiles on a calm, bright ground (INTERACTIVE_PAGE_DESIGN.md §11). */

@font-face { font-family: 'Atkinson Next'; src: url('../fonts/atkinson-latin-400.woff2') format('woff2'); font-weight: 400; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+2215; }
@font-face { font-family: 'Atkinson Next'; src: url('../fonts/atkinson-latin-ext-400.woff2') format('woff2'); font-weight: 400; font-display: swap; unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113; }
@font-face { font-family: 'Atkinson Next'; src: url('../fonts/atkinson-latin-700.woff2') format('woff2'); font-weight: 700; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+2215; }
@font-face { font-family: 'Atkinson Next'; src: url('../fonts/atkinson-latin-ext-700.woff2') format('woff2'); font-weight: 700; font-display: swap; unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113; }
@font-face { font-family: 'Atkinson Next'; src: url('../fonts/atkinson-latin-800.woff2') format('woff2'); font-weight: 800; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+2215; }
@font-face { font-family: 'Atkinson Next'; src: url('../fonts/atkinson-latin-ext-800.woff2') format('woff2'); font-weight: 800; font-display: swap; unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113; }

:root {
  --font: 'Atkinson Next', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ground: #FAF9F6;
  --zone: #FFFFFF;
  --table: #F4F1EA;
  --paper: #FFFEFB;
  --rule: #E6E3DC;
  --ink: #1C2230;
  --ink-soft: #4A4F5C;
  --ink-faint: #62666F;
  --tile: #FFFDF6;
  --tile-edge: #E2DACA;
  --tile-side: #D3C7AE;
  --rack: #B98A5A;
  --dot: #CFC9BC;
  --note: #FFF6D9;
  --note-edge: #EBD9A0;
  /* Topic hues from §11 for fills; the -ink shades carry text at 4.5:1 or better. */
  --puteri: #1F6FD1; --puteri-ink: #1F6FD1;
  --factor: #1E9B5A; --factor-ink: #16794A;
  --gauss: #E8781E; --gauss-ink: #B4570C;
  --figurativa: #7B4FC9; --figurativa-ink: #7B4FC9;
  --accent: var(--puteri);
  --accent-ink: var(--puteri-ink);
  --radius: 12px;
  --tap: 56px;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  color-scheme: light;
}

[data-topic='factor'] { --accent: var(--factor); --accent-ink: var(--factor-ink); }
[data-topic='gauss'] { --accent: var(--gauss); --accent-ink: var(--gauss-ink); }
[data-topic='figurativa'] { --accent: var(--figurativa); --accent-ink: var(--figurativa-ink); }
[data-topic='puzzle'] { --accent: var(--ink); --accent-ink: var(--ink); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--ground);
  color: var(--ink);
  font: 400 20px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
  caret-color: var(--accent-ink);
}
::selection { background: color-mix(in srgb, var(--accent) 22%, white); color: var(--ink); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
* { scrollbar-width: thin; scrollbar-color: var(--tile-side) transparent; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }
sup { font-size: .58em; line-height: 0; vertical-align: .85em; font-weight: 700; }
.muted { color: var(--ink-soft); }
.strong { font-weight: 700; }
.visually-hidden { position: absolute; top: 0; left: 0; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.icon { display: inline-grid; width: 24px; height: 24px; flex: none; }
.icon svg { width: 100%; height: 100%; }

/* ---------- maths ---------- */
.m { white-space: nowrap; font-variant-numeric: lining-nums; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; line-height: 1.05; font-size: .82em; margin: 0 .1em; }
.frac > span:first-child { border-bottom: 2px solid currentColor; padding: 0 .15em .05em; }
.frac > span:last-child { padding: .05em .15em 0; }
.box { display: inline-block; width: 1.4em; height: 1.1em; border: 2px solid currentColor; border-radius: 4px; vertical-align: -.15em; }

/* ---------- buttons ---------- */
.primary, .secondary, .choice, .hint-button, .tool, .back, .trap-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: var(--tap); border-radius: var(--radius); cursor: pointer; touch-action: manipulation;
  transition: transform 120ms var(--ease-out), background-color 160ms;
}
.primary { padding: 0 30px; border: 0; background: var(--accent-ink); color: #fff; font-weight: 800; font-size: 22px; box-shadow: 0 4px 10px color-mix(in srgb, var(--accent-ink) 28%, transparent); }
.primary:active { transform: translateY(2px); }
.primary:disabled { background: var(--tile-side); color: var(--ink-soft); box-shadow: none; cursor: not-allowed; }
.primary.big { min-height: 72px; padding: 0 44px; font-size: 26px; border-radius: 16px; }
.secondary { padding: 0 22px; border: 2px solid var(--ink); background: var(--zone); font-weight: 700; text-decoration: none; color: var(--ink); }
.secondary:active { transform: translateY(2px); }
.secondary:disabled { border-color: var(--rule); color: var(--ink-faint); }
.back { padding: 0 16px; border: 2px solid var(--rule); background: var(--zone); font-weight: 700; }
.hint-button { align-self: flex-start; padding: 0 18px; border: 2px dashed var(--tile-side); background: transparent; color: var(--ink-soft); font-weight: 700; }
.answer-actions { display: flex; gap: 12px; margin-top: 16px; }

/* ---------- the remi tile ---------- */
.tile {
  position: relative; display: inline-grid; place-items: center;
  min-width: var(--tap); height: 72px; padding: 0 10px;
  background: var(--tile); color: var(--accent-ink);
  border: 2px solid var(--tile-edge); border-bottom: 7px solid var(--tile-side); border-radius: 10px;
  font: 800 34px/1 var(--font);
  box-shadow: 0 3px 8px rgba(28, 34, 48, .10);
  user-select: none; -webkit-user-select: none;
}
.tile .face { display: inline-block; white-space: nowrap; }
.tile sup { color: var(--ink); }
button.tile { cursor: pointer; touch-action: manipulation; }
button.tile:active { transform: translateY(3px); border-bottom-width: 4px; margin-top: 3px; }
.tile-power { min-width: 92px; }
.tile-big { min-width: 92px; font-size: 40px; }
.tile-paren { min-width: 120px; color: var(--accent-ink); }
.tile-common { border-color: var(--accent); border-bottom-color: color-mix(in srgb, var(--accent) 70%, var(--tile-side)); }
.tile-counted { background: color-mix(in srgb, var(--accent) 12%, var(--tile)); }
.tile-counted::after {
  content: attr(data-count); position: absolute; top: -12px; right: -10px;
  min-width: 26px; height: 26px; padding: 0 6px; border-radius: 13px;
  background: var(--ink); color: #fff; font-size: 15px; display: grid; place-items: center;
}
.tile-cancelled { color: var(--ink-faint); background: var(--table); }
.tile-cancelled::before { content: ''; position: absolute; inset: 10px 6px; background: linear-gradient(to top right, transparent calc(50% - 2px), #C8322D calc(50% - 2px), #C8322D calc(50% + 2px), transparent calc(50% + 2px)); }
.tile-one, .tile-new { border-color: var(--accent); animation: tile-pulse 700ms var(--ease-out) 2; }
.tile-digit { min-width: 64px; }
@keyframes tile-pulse { 50% { transform: translateY(-6px) scale(1.06); } }

.rack {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px;
  padding: 16px 18px 12px; background: var(--zone);
  border-radius: 12px 12px 6px 6px; border-bottom: 16px solid var(--rack);
  box-shadow: 0 6px 14px rgba(28, 34, 48, .08);
}
.rack-op { align-self: center; min-width: 22px; text-align: center; font: 800 32px/1 var(--font); color: var(--ink); }
.term { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.paren { align-self: center; font: 400 54px/1 var(--font); color: var(--ink-soft); }
.outer-exp { font-size: 26px; color: var(--ink); align-self: flex-start; }
.rewrite { display: inline-flex; align-items: flex-end; gap: 6px; }

/* ---------- start screen ---------- */
.start { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 26px; padding: 32px 16px; text-align: center; }
.brand { font-size: 22px; font-weight: 800; letter-spacing: .02em; color: var(--ink-soft); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.rack-start { justify-content: center; }
.greeting { font-size: clamp(30px, 4.6vw, 46px); font-weight: 700; line-height: 1.15; max-width: 18ch; }
.greeting strong { color: var(--accent-ink); }
.start-note { max-width: 34ch; padding: 12px 18px; border-radius: var(--radius); background: var(--note); border: 1px solid var(--note-edge); color: var(--ink); font-size: 19px; }
.puzzle-link { margin-top: 12px; }

/* ---------- session shell ---------- */
.session { min-height: 100dvh; display: flex; flex-direction: column; }
.session-header {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 18px;
  min-height: 88px; padding: 12px max(16px, env(safe-area-inset-left)) 12px max(16px, env(safe-area-inset-right));
  background: var(--zone); border-bottom: 2px solid var(--rule);
}
.session-title { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 4px 8px; border: 0; background: none; text-align: left; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.topic-name { font-size: 22px; font-weight: 800; color: var(--accent-ink); }
.step-label { font-size: 16px; color: var(--ink-soft); }
.progress-tiles { display: flex; gap: 8px; margin: 0 auto; padding: 0; list-style: none; }
.progress-tile { width: 26px; height: 36px; border-radius: 6px; background: var(--table); border: 2px solid var(--tile-edge); border-bottom-width: 5px; }
.progress-tile.is-done { background: var(--accent); border-color: var(--accent); border-bottom-color: color-mix(in srgb, var(--accent) 70%, black); }
.progress-tile.is-current { border-color: var(--accent); background: var(--tile); }
.trap-button { padding: 0 16px; border: 2px solid var(--rule); background: var(--table); font-weight: 800; }
.trap-popover { margin: 96px 16px auto auto; width: min(380px, calc(100vw - 32px)); padding: 20px 22px; border: 2px solid var(--rule); border-radius: 16px; background: var(--zone); color: var(--ink); box-shadow: 0 18px 40px rgba(28, 34, 48, .18); }
.trap-popover h2 { font-size: 22px; margin-bottom: 8px; }
.trap-popover h3 { font-size: 16px; color: var(--ink-soft); margin: 14px 0 8px; }
.trap-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.trap-chip { padding: 6px 12px; border-radius: 999px; background: var(--table); border: 1px solid var(--tile-edge); font-size: 17px; }

/* Five zones, always in the same place. Mobile first: stacked. */
.zones {
  flex: 1; display: grid; gap: 0;
  grid-template-columns: 1fr;
  grid-template-areas: 'q' 'm' 'a' 'd';
  grid-template-rows: auto auto auto minmax(46vh, auto);
}
.zone { padding: 22px 20px; min-width: 0; }
.zone-question { grid-area: q; background: var(--zone); display: flex; flex-direction: column; gap: 14px; }
.zone-answer { grid-area: a; background: var(--zone); border-top: 2px solid var(--rule); }
.zone-model { grid-area: m; background: var(--table); display: flex; flex-direction: column; justify-content: space-between; gap: 16px; min-height: 280px; border-top: 2px solid var(--rule); }
.zone-ciorna { grid-area: d; display: flex; flex-direction: column; padding: 0; border-top: 2px solid var(--rule); background: var(--paper); }

@media (min-width: 700px) {
  .zones { grid-template-columns: 1fr 1fr; grid-template-areas: 'q q' 'm m' 'a d'; grid-template-rows: auto auto minmax(420px, 1fr); }
  .zone-ciorna { border-left: 2px solid var(--rule); }
}
@media (min-width: 1000px) and (orientation: landscape) {
  .session { height: 100dvh; }
  /* Fixed 2×2: the zones keep their place and size whatever the step asks for. */
  .zones {
    min-height: 0;
    grid-template-columns: minmax(380px, 470px) 1fr;
    grid-template-areas: 'q m' 'a d';
    grid-template-rows: minmax(0, 1fr) clamp(370px, 46dvh, 440px);
  }
  .zone-question, .zone-answer { border-right: 2px solid var(--rule); overflow-y: auto; }
  .zone-answer { padding-block: 16px; }
  .zone-model { border-top: 0; overflow: auto; }
  .zone-ciorna { border-left: 0; min-height: 0; }
  .ciorna-paper { min-height: 0; }
  .tile { height: 64px; font-size: 30px; }
}

/* ---------- zone A: one question ---------- */
.item-title { font-size: clamp(30px, 3.4vw, 42px); font-weight: 800; line-height: 1.15; }
.ask { font-size: clamp(22px, 2.2vw, 27px); font-weight: 700; line-height: 1.32; max-width: 30ch; text-wrap: balance; }
.ask.ask-title { font-size: clamp(30px, 3.4vw, 42px); font-weight: 800; }
.ask .m { font-size: 1.08em; }
.stage-label { font-size: 17px; font-weight: 700; color: var(--accent-ink); }
.feedback strong { display: block; margin-bottom: 2px; }
.feedback { padding: 14px 16px; border-radius: var(--radius); background: var(--note); border: 1px solid var(--note-edge); font-size: 20px; max-width: 34ch; }
.hint { display: flex; gap: 12px; align-items: baseline; font-size: 20px; color: var(--ink-soft); max-width: 34ch; }
.hint-index { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--table); border: 1px solid var(--tile-edge); font-size: 15px; font-weight: 800; color: var(--ink); }
.praise { font-size: 19px; font-weight: 700; color: var(--accent-ink); }
.example-lines { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; counter-reset: line; }
.example-lines li { display: flex; flex-direction: column; gap: 4px; padding-left: 40px; position: relative; counter-increment: line; }
.example-lines li::before { content: counter(line); position: absolute; left: 0; top: 2px; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--table); border: 1px solid var(--tile-edge); font-size: 15px; font-weight: 800; }
.example-lines .say { font-size: 21px; font-weight: 700; }
.example-lines .show { font-size: 21px; color: var(--accent-ink); }
.example-lines .is-asking .say::after { content: ' …'; color: var(--ink-faint); }
.trap-reveal-label { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; color: var(--accent-ink); }
.trap-outcome { font-size: 22px; font-weight: 700; }
.trap-why { font-size: 20px; color: var(--ink-soft); max-width: 34ch; }
.summary { font-size: clamp(28px, 3vw, 36px); }
.streak { font-size: 22px; font-weight: 700; color: var(--accent-ink); }

/* ---------- zone B: the answer ---------- */
.keypad { display: flex; flex-direction: column; gap: 12px; max-width: 460px; }
.keypad-top { display: flex; gap: 12px; align-items: stretch; }
.keypad-top .keypad-display { flex: 1; min-width: 0; }
.keypad-display {
  display: flex; align-items: center; min-height: 68px; padding: 8px 18px;
  border: 3px solid var(--ink); border-radius: 14px; background: var(--zone);
  font: 800 32px/1.2 var(--font); overflow-x: auto; white-space: nowrap;
}
.caret { display: inline-block; width: 3px; height: 1.05em; margin-left: 3px; background: var(--accent-ink); animation: blink 1.1s steps(1) infinite; }
.caret-up { height: .6em; transform: translateY(-.55em); }
@keyframes blink { 50% { opacity: 0; } }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keys-wide { grid-template-columns: repeat(5, 1fr); }
.key {
  min-height: var(--tap); border-radius: 10px; cursor: pointer; touch-action: manipulation;
  background: var(--tile); border: 2px solid var(--tile-edge); border-bottom: 5px solid var(--tile-side);
  font: 800 26px/1 var(--font); color: var(--ink);
}
.key:active { transform: translateY(2px); border-bottom-width: 3px; }
.key-power[aria-pressed='true'] { background: var(--accent-ink); color: #fff; border-color: var(--accent-ink); }
.key-letter { font-style: italic; color: var(--accent-ink); }
.key-erase { display: grid; place-items: center; }
.draw-gate { padding: 10px 14px; border-radius: 10px; background: var(--note); border: 1px solid var(--note-edge); font-size: 18px; }
.choices { display: flex; flex-wrap: wrap; gap: 12px; }
.choice {
  padding: 10px 24px; min-width: 110px;
  background: var(--tile); border: 2px solid var(--tile-edge); border-bottom: 6px solid var(--tile-side);
  font-weight: 800; font-size: 24px; color: var(--ink);
}
.choice:active { transform: translateY(3px); border-bottom-width: 3px; }
.text-answer { display: flex; flex-direction: column; gap: 10px; max-width: 520px; }
.free-text { width: 100%; padding: 14px 16px; border: 3px solid var(--ink); border-radius: 14px; font: 400 21px/1.4 var(--font); resize: vertical; background: var(--zone); color: var(--ink); }
.answer-hint { font-size: 20px; color: var(--ink-soft); }

/* ---------- zone C: the model ---------- */
.model-body { display: flex; flex-direction: column; gap: 16px; align-items: flex-start; }
.model-note { font-size: 19px; color: var(--ink); }
.model-note.muted { color: var(--ink-soft); }
.model-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.model-title-big { font-size: clamp(40px, 5vw, 64px); font-weight: 800; color: var(--accent-ink); }
.equation { min-height: 1.4em; font-size: clamp(22px, 2.3vw, 28px); font-weight: 700; color: var(--ink); overflow-x: auto; }
.equation .m { white-space: normal; }
.stacked { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; min-width: 0; }
.rack-stacked { flex-wrap: nowrap; align-items: stretch; }
.stack-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.group-brace { align-self: stretch; display: flex; align-items: center; gap: 10px; margin-left: 6px; max-width: 3em; font-size: 22px; line-height: 1.1; font-weight: 800; color: var(--accent-ink); }
.group-brace::before { content: ''; align-self: stretch; width: 14px; border: 4px solid var(--accent); border-left: 0; border-radius: 0 10px 10px 0; }
.fraction-stack { display: flex; flex-direction: column; gap: 10px; }
.fraction-bar { height: 5px; border-radius: 3px; background: var(--ink); }

.balance { --tilt: 0deg; position: relative; width: min(100%, 560px); padding-bottom: 70px; }
.beam { display: flex; justify-content: space-between; align-items: flex-end; padding: 0 0 12px; border-bottom: 8px solid var(--rack); border-radius: 4px; transform: rotate(var(--tilt)); transition: transform 280ms var(--ease-out); }
.pan { padding: 10px; border-radius: 0 0 40px 40px; background: var(--zone); border: 3px solid var(--tile-side); border-top: 0; }
.fulcrum { position: absolute; left: 50%; bottom: 10px; width: 0; height: 0; transform: translateX(-50%); border-left: 34px solid transparent; border-right: 34px solid transparent; border-bottom: 56px solid var(--ink); }

.rack-wheel { gap: 14px; }
.wheel-cell { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 4px; border-radius: 12px; }
.wheel-cell.is-repeat { outline: 3px solid var(--accent); outline-offset: 2px; }
.wheel-power { font-size: 20px; font-weight: 700; }

.rects { display: grid; grid-template-columns: auto auto; grid-template-areas: 'h pair' '. widths' '. total'; gap: 6px 10px; align-items: center; }
.side-height { grid-area: h; font-size: 24px; font-weight: 800; }
.rect-pair { grid-area: pair; display: flex; gap: 22px; transition: gap 260ms var(--ease-out); }
.rects.is-joined .rect-pair { gap: 0; }
.area-rect { display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 14%, var(--zone)); border: 3px solid var(--accent-ink); border-radius: 6px; transition: border-radius 260ms; }
.rects.is-joined .area-rect:first-child { border-radius: 6px 0 0 6px; border-right-width: 1.5px; }
.rects.is-joined .area-rect:last-child { border-radius: 0 6px 6px 0; border-left-width: 1.5px; }
.area-label { font-size: 22px; font-weight: 800; }
.width-labels { grid-area: widths; display: flex; gap: 22px; }
.rects.is-joined .width-labels { gap: 0; }
.side-label { text-align: center; font-size: 22px; font-weight: 800; }
.side-total { grid-area: total; padding-top: 6px; border-top: 3px solid var(--accent-ink); color: var(--accent-ink); }

.rack-gauss { gap: 6px; }
.gauss-col { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.gauss-col .tile { min-width: 48px; height: 60px; font-size: 26px; }
.gauss-col.is-open .tile { background: color-mix(in srgb, var(--accent) 16%, var(--tile)); border-color: var(--accent); }
.col-sum { min-height: 28px; font-size: 20px; font-weight: 800; color: var(--accent-ink); }
.gauss-col.gap { justify-content: flex-end; }
.slider-box { width: min(100%, 560px); display: flex; flex-direction: column; gap: 14px; }
.slider-count { font-size: 24px; font-weight: 800; color: var(--accent-ink); }
.term-slider { width: 100%; height: var(--tap); accent-color: var(--accent-ink); }
.slider-ends { display: flex; justify-content: space-between; }
.school-bar { width: min(100%, 620px); display: flex; flex-direction: column; gap: 10px; }
.bar-track { display: flex; gap: 3px; height: 56px; border: 3px solid var(--ink); border-radius: 8px; overflow: hidden; background: var(--ink); }
.bar-piece { transition: background-color 200ms, opacity 200ms; }
.bar-start { background: color-mix(in srgb, var(--accent) 40%, var(--zone)); }
.bar-rest { background: var(--zone); }
.is-all .bar-start, .is-all .bar-rest { background: color-mix(in srgb, var(--accent) 26%, var(--zone)); }
.is-start .bar-start { background: repeating-linear-gradient(-45deg, var(--accent), var(--accent) 6px, var(--zone) 6px, var(--zone) 12px); }
.is-rest .bar-start { opacity: .25; }
.is-rest .bar-rest { background: color-mix(in srgb, var(--accent) 30%, var(--zone)); }
.bar-labels { display: flex; gap: 8px; }
.bar-label { font-size: 19px; font-weight: 700; }
.bar-label-rest { flex: 1; text-align: right; }

.bar-empty { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.bar-model { width: min(100%, 640px); display: flex; flex-direction: column; gap: 8px; }
.bar { display: flex; gap: 3px; height: 64px; border: 3px solid var(--ink); border-radius: 8px; overflow: hidden; background: var(--ink); }
.bar-part { flex: 1; display: grid; place-items: center; border: 0; background: var(--zone); font: 800 22px/1 var(--font); color: var(--ink); }
button.bar-part { cursor: pointer; }
.bar-part.is-shaded { background: color-mix(in srgb, var(--accent) 34%, var(--zone)); }
.brace { display: flex; justify-content: center; font-size: 22px; font-weight: 800; color: var(--accent-ink); }
.brace-top { padding-bottom: 6px; border-bottom: 3px solid var(--accent-ink); border-radius: 0 0 4px 4px; }
.brace-bottom { padding-top: 6px; border-top: 3px solid var(--accent-ink); }
.compare-model { width: min(100%, 680px); display: flex; flex-direction: column; gap: 14px; }
.compare-row { display: grid; grid-template-columns: 96px 1fr auto; align-items: center; gap: 12px; }
.compare-name { font-weight: 800; font-size: 20px; }
.compare-bar { display: flex; gap: 3px; height: 52px; border: 3px solid var(--ink); border-radius: 8px; overflow: hidden; background: var(--ink); }
.bar-extra { display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 34%, var(--zone)); transition: opacity 200ms; }
.bar-extra.is-removed { opacity: .3; background: repeating-linear-gradient(-45deg, var(--tile-side), var(--tile-side) 5px, var(--zone) 5px, var(--zone) 10px); }
.part-value { font-size: 20px; font-weight: 800; }
.compare-total { font-size: 22px; font-weight: 800; color: var(--accent-ink); }

.number-line { position: relative; width: min(100%, 640px); height: 140px; margin: 0 24px; }
.number-line .line { position: absolute; left: 0; right: 0; top: 66px; height: 4px; background: var(--ink); border-radius: 2px; }
.tick { position: absolute; top: 0; bottom: 0; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; }
.tick-above { height: 46px; display: grid; place-items: end center; font-size: 24px; font-weight: 800; color: var(--accent-ink); }
.tick-mark { width: 4px; height: 30px; margin-top: 4px; background: var(--ink); border-radius: 2px; }
.tick.is-given .tick-mark, .tick.is-known .tick-mark { background: var(--accent-ink); height: 36px; }
.tick-below { margin-top: 8px; font-size: 19px; font-weight: 700; }

.dot-array { display: flex; flex-direction: column; gap: 8px; }
.dot-row { display: flex; gap: 8px; }
.dot { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); }

.star-tile { display: grid; place-items: center; width: 120px; height: 140px; background: var(--tile); border: 2px solid var(--tile-edge); border-bottom: 10px solid var(--tile-side); border-radius: 16px; color: var(--accent-ink); animation: star-drop 420ms var(--ease-out); }
.star-tile .icon { width: 72px; height: 72px; }
.star-tile svg { fill: color-mix(in srgb, var(--accent) 30%, transparent); }
@keyframes star-drop { from { transform: translateY(-40px); opacity: 0; } }

/* ---------- zone D: the ciornă ---------- */
.ciorna-tools { display: flex; align-items: center; gap: 10px; padding: 6px 14px; border-bottom: 1px solid var(--rule); background: var(--zone); }
.ciorna-name { margin-right: auto; font-weight: 800; color: var(--ink-soft); }
.swatch { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--zone); background: var(--swatch); box-shadow: 0 0 0 2px var(--tile-edge); cursor: pointer; }
.swatch[aria-pressed='true'] { box-shadow: 0 0 0 3px var(--ink); }
.tool { padding: 0 14px; border: 2px solid var(--rule); background: var(--zone); font-weight: 700; font-size: 17px; }
.ciorna-paper { position: relative; flex: 1; min-height: 240px; background-color: var(--paper); background-image: radial-gradient(var(--dot) 1.4px, transparent 1.7px); background-size: 28px 28px; }
.ciorna-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

/* ---------- puzzle ---------- */
.puzzle-board { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.slot-number { display: inline-flex; gap: 6px; }
.slot { width: 64px; height: 80px; border: 3px dashed var(--tile-side); border-radius: 12px; background: var(--zone); font: 800 38px/1 var(--font); color: var(--ink); cursor: pointer; }
.slot.is-filled { border-style: solid; border-color: var(--tile-edge); border-bottom: 7px solid var(--tile-side); background: var(--tile); }
.slot.is-selected { outline: 3px solid var(--ink); outline-offset: 3px; }
.digit-tray { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; background: var(--zone); border-radius: 12px; border-bottom: 16px solid var(--rack); }
.digit-tray .tile { color: var(--ink); }
.rule-list { margin: 0; padding-left: 28px; display: flex; flex-direction: column; gap: 8px; font-size: 22px; font-weight: 700; }
.rule-list .is-new { color: var(--ink); }
.rule-list li:not(.is-new) { color: var(--ink-soft); font-weight: 400; }
.found-list { display: flex; flex-direction: column; gap: 4px; }
.found-row { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- parent view ---------- */
.parent { max-width: 1040px; margin: 0 auto; padding: 16px 16px 48px; display: flex; flex-direction: column; gap: 18px; }
.parent-header { display: flex; align-items: center; gap: 18px; padding: 8px 0; }
.parent-header h1 { font-size: 28px; }
.parent-card { display: flex; flex-direction: column; gap: 12px; padding: 22px; background: var(--zone); border: 1px solid var(--rule); border-radius: 16px; }
.parent-card h2 { font-size: 22px; }
.parent-card label { font-weight: 700; font-size: 17px; }
.field { min-height: var(--tap); padding: 0 14px; border: 2px solid var(--ink-faint); border-radius: 10px; font: 400 20px var(--font); background: var(--zone); color: var(--ink); }
.parent-card .primary { align-self: flex-start; }
.parent-table { width: 100%; border-collapse: collapse; font-size: 17px; font-variant-numeric: tabular-nums; }
.parent-table th { text-align: left; font-weight: 700; color: var(--ink-soft); border-bottom: 2px solid var(--rule); padding: 8px; }
.parent-table td { border-bottom: 1px solid var(--rule); padding: 8px; vertical-align: top; }
.parent-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.flags { margin: 0; padding: 12px 16px 12px 34px; border-radius: 10px; background: var(--note); border: 1px solid var(--note-edge); }
.reflection, .parent blockquote { margin: 0; padding: 12px 16px; border-radius: 10px; background: var(--table); }
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, 132px); gap: 12px; }
.thumb { position: relative; margin: 0; display: flex; flex-direction: column; gap: 4px; font-size: 15px; }
.thumb-canvas { width: 120px; height: 120px; border-radius: 10px; background-color: var(--paper); background-image: radial-gradient(var(--dot) 1px, transparent 1.3px); background-size: 12px 12px; border: 1px solid var(--rule); }
.thumb.is-circled::after { content: ''; position: absolute; left: -6px; top: -6px; width: 132px; height: 132px; border: 3px solid #C8322D; border-radius: 48% 52% 50% 46% / 52% 46% 54% 48%; transform: rotate(-4deg); pointer-events: none; }
.parent details summary { cursor: pointer; padding: 8px 0; font-weight: 700; }

@media (max-width: 699px) {
  body { font-size: 19px; }
  .session-header { gap: 10px; flex-wrap: wrap; min-height: 72px; }
  .back span:last-child { display: none; }
  .progress-tiles { order: 3; width: 100%; justify-content: flex-start; margin: 0; }
  .progress-tile { width: 22px; height: 30px; }
  .trap-button { margin-left: auto; }
  .tile { height: 62px; font-size: 28px; min-width: 48px; }
  .keys-wide { grid-template-columns: repeat(5, 1fr); }
  .compare-row { grid-template-columns: 70px 1fr auto; }
  .rack-stacked { flex-wrap: wrap; }
  .rack-stacked .group-brace { max-width: none; min-height: 44px; }
}

@media (max-width: 999px) {
  .tool-label { display: none; }
  .swatch { width: 40px; height: 40px; }
  .ciorna-tools { gap: 8px; padding-inline: 10px; }
  .tool { padding: 0 12px; }
}

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