/* The notebook look: blue ballpoint on lined paper.
   Right-to-left in Hebrew, left-to-right in English (html[dir] is set by game.js). */

:root {
  --bg: #ebe5d6;
  --paper: #f3eee2;
  --ink: #1f2c55;
  --dim: #5f6789;
  --faint: rgba(31, 44, 85, 0.2);
  --danger: #8b3a1e;
  --acid: #66722a;
  --acid-bg: rgba(160, 178, 74, 0.38);
  --poison: #6d3a86;
  --tree: #3b6d11;
  --tree-bg: #b5d08a;
  --poison-bg: rgba(109, 58, 134, 0.2);
  --trail: rgba(31, 44, 85, 0.5);
  --active: rgba(31, 44, 85, 0.08);
  --veil: rgba(235, 229, 214, 0.55);
  --font: 'Playpen Sans Hebrew', 'Varela Round', system-ui, sans-serif;
  --font-title: 'Amatic SC', 'Playpen Sans Hebrew', sans-serif;
  --border: 2px solid var(--ink);
  --radius: 14px 9px 16px 8px / 8px 15px 9px 14px;
  --chip-border: 1.5px solid rgba(31, 44, 85, 0.35);
  /* the paper: faint blue rules and a red margin line on the side where writing starts */
  --rules: repeating-linear-gradient(to bottom, transparent 0 31px, rgba(60, 90, 150, 0.15) 31px 32px);
  --margin-line: transparent 38px, rgba(170, 60, 60, 0.28) 38px 40px, transparent 40px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html:not(.ready) .screen { visibility: hidden; } /* until game.js has put in the texts of the chosen language */
body:not([data-screen="home"]) .home, body:not([data-screen="play"]) .app, body:not([data-screen="journey"]) .journey-screen, body:not([data-screen="map"]) .map-screen,
body:not([data-screen="editor"]) .editor-screen { display: none; }
body {
  background-color: var(--bg);
  background-image: linear-gradient(to left, var(--margin-line)), var(--rules);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}
html[dir="ltr"] body { background-image: linear-gradient(to right, var(--margin-line)), var(--rules); }
/* Narrower windows: the page reaches the window's side (the header buttons are 16px from it), so the margin
   line moves out to the edge, where it crosses nothing. From 1280px on the game screen is wide enough to clear it. */
@media (max-width: 1279px) {
  :root { --margin-line: transparent 7px, rgba(170, 60, 60, 0.28) 7px 9px, transparent 9px; }
}
button, input { font: inherit; color: inherit; }

.screen {
  max-width: 520px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.main { display: flex; flex-direction: column; gap: 8px; }

/* Header: the menu on the left and the settings button on the right in both languages,
   so neither one jumps when the language changes. Each part has its place, because in Hebrew game.js puts
   them in the page right to left, so that Tab goes the way Hebrew reads (the left buttons are then reversed too). */
.top { display: grid; grid-template-columns: 96px 1fr 96px; align-items: center; gap: 8px; direction: ltr; min-height: 48px; }
.top > .top-start { grid-area: 1 / 1; }
.top > .title { grid-area: 1 / 2; }
.top > .top-end { grid-area: 1 / 3; }
.top-start, .top-end { display: flex; gap: 8px; }
html[dir="rtl"] .top-start { flex-direction: row-reverse; justify-content: flex-end; }
.top-end { justify-content: flex-end; }
.title { min-width: 0; text-align: center; }
html[dir="rtl"] .title { direction: rtl; }
.level-num { font-size: 0.8rem; color: var(--dim); }
h1 { margin: 0; font-family: var(--font-title); font-size: 2.1rem; line-height: 1.15; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  min-height: 40px;
  padding: 4px;
  font-size: 1.2rem;
  color: var(--ink);
  background: transparent;
  border: var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
/* the icons inside them (icons.js): one size, one line weight, in the middle */
.icon { display: block; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:disabled { opacity: 0.45; cursor: default; }

/* Board */
.board-wrap { position: relative; width: min(100%, 50vh); min-width: min(100%, 260px); margin: 0 auto; }
#board, #ed-board { display: block; width: 100%; height: auto; overflow: visible; }

/* Status */
.status { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 14px; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.goals { color: var(--dim); }
.hint { margin: 0; min-height: 1.35em; text-align: center; font-size: 0.95rem; color: var(--dim); }

/* Pads */
.pads { display: flex; flex-direction: column; gap: 10px; }
.pad {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border: var(--border);
  border-radius: var(--radius);
  transition: transform 0.08s, background-color 0.15s, opacity 0.15s;
}
.pad-row { display: flex; align-items: center; gap: 10px; }
.pad-key {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-family: var(--font-title);
  font-size: 2rem;
  font-weight: 700;
  border: var(--border);
  border-radius: var(--radius);
}
.pad-input {
  flex: 1;
  min-width: 0;
  padding: 6px 2px;
  font-size: 1.1rem;
  text-align: start;
  background: transparent;
  border: 0;
  border-bottom: 1.5px dashed var(--faint);
  outline: none;
  caret-color: var(--ink);
}
.pad-input:focus { border-bottom-color: var(--ink); }
.pad-input::placeholder { color: var(--dim); opacity: 0.7; }
.pad-input[readonly] { border-bottom-color: transparent; }
.pad-count.over { color: var(--danger); }
.pad-count { flex: none; font-size: 0.8rem; color: var(--dim); direction: ltr; font-variant-numeric: tabular-nums; }
.pad-preview { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; min-height: 28px; }
.pad-note { color: var(--dim); font-size: 0.9rem; }
.pad-msg { color: var(--danger); font-size: 0.95rem; }
.pad-source { margin-inline-start: auto; font-size: 0.75rem; color: var(--dim); }
.pad.error { border-color: var(--danger); }
.chip, .chip-group { direction: ltr; display: inline-flex; align-items: center; gap: 3px; }
.chip { min-height: 26px; padding: 0 8px; font-size: 1.05rem; border: var(--chip-border); border-radius: var(--radius); }
.chip small { font-size: 0.75rem; }
.chip-hop { font-size: 0.8rem; margin-inline-end: -2px; transform: translateY(-5px); }
.chip.jump { border-style: dashed; }
.chip-crawl { font-size: 0.8rem; margin-inline-end: -2px; transform: translateY(5px); }
.chip.crawl { border-style: dotted; }
.chip-inf { font-size: 1.05rem; }
.chip-group { padding: 2px 4px; border: 1.5px dashed var(--faint); border-radius: var(--radius); }
.chip-times { padding: 0 3px; font-weight: 700; }

.pad-press { display: none; position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; opacity: 0; border: 0; cursor: pointer; }
.app:is([data-phase="play"], [data-phase="busy"]) .pad.ok .pad-press { display: block; }
.app[data-phase="play"] .pad.ok:hover { background: var(--active); }
.app:not([data-phase="edit"]) .pad:not(.ok) { opacity: 0.4; }
.pad.running { background: var(--active); transform: translateY(2px); }
.pad:has(.pad-press:focus-visible) { outline: 3px solid var(--ink); outline-offset: 3px; }

/* Actions */
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.btn {
  min-height: 44px;
  padding: 8px 18px;
  font-size: 1.05rem;
  background: transparent;
  border: var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
.btn.primary { background: var(--ink); color: var(--paper); }
.btn:active:not(:disabled) { transform: translateY(2px); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn[hidden] { display: none; }
.app[data-phase="edit"] :is(#restart-btn, #edit-btn) { display: none; }
.app:not([data-phase="edit"]) #start-btn { display: none; }

/* Result card over the board */
.result { position: absolute; inset: 0; display: grid; place-items: center; padding: 12px; background: var(--veil); }
.result[hidden] { display: none; }
.result-card { width: min(100%, 320px); padding: 16px 18px; text-align: center; background: var(--paper); border: var(--border); border-radius: var(--radius); }
.result-card h2 { margin: 0 0 4px; font-family: var(--font-title); font-size: 2.2rem; }
.result-card p { margin: 6px 0 12px; }
.stars { font-size: 2rem; letter-spacing: 6px; }
.star { color: var(--faint); }
.star.on { color: var(--ink); }
.result-legend { font-size: 0.8rem; color: var(--dim); }
.result-new { display: block; margin-top: 8px; font-weight: 600; } /* a new character opened */
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

/* Levels dialog */
.levels-dialog { width: min(92vw, 380px); padding: 16px; color: var(--ink); background: var(--paper); border: var(--border); border-radius: var(--radius); }
.levels-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
/* The title and the close button stay put; only the middle scrolls. */
.levels-dialog[open] { display: flex; flex-direction: column; max-height: 86vh; overflow: hidden; }
/* the settings are taller than a small window: their body scrolls as one, and the close button stays in view */
#settings-dialog[open] { overflow: hidden; }
#settings-dialog > * { flex: none; }
.levels-dialog > :not(h2, .dialog-foot) { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.levels-dialog h2 { margin: 0 0 10px; font-family: var(--font-title); font-size: 2rem; }
.worlds { display: flex; flex-direction: column; gap: 14px; padding: 2px; }
.worlds { gap: 8px; }
.worlds:focus { outline: none; }
/* the open world's title stays in view while its levels scroll under it */
.world-head[aria-expanded="true"] { position: sticky; top: 0; z-index: 1; background: var(--paper); }
.world-head { width: 100%; display: flex; align-items: center; gap: 8px; padding: 6px 12px; text-align: start; background: transparent; border: 1.5px solid var(--faint); border-radius: var(--radius); cursor: pointer; }
.world-head::before { content: '▸'; color: var(--dim); }
html[dir="rtl"] .world-head::before { content: '◂'; }
html .world-head[aria-expanded="true"]::before { content: '▾'; }
.world-head:disabled { cursor: default; color: var(--dim); }
.world-head:disabled::before { visibility: hidden; }
.world-title { flex: 1; font-family: var(--font-title); font-size: 1.55rem; font-weight: 700; }
.world-meta { color: var(--dim); font-size: 0.85rem; font-variant-numeric: tabular-nums; direction: ltr; }
.world-here { padding: 1px 8px; font-size: 0.75rem; color: var(--paper); background: var(--ink); border-radius: var(--radius); }
.world.current .world-head { border: 2px solid var(--ink); }
.world-note { margin: 4px 6px 0; color: var(--dim); font-size: 0.85rem; }
.world .levels-list { margin-top: 6px; }
.level-item[aria-current] { border-color: var(--ink); background: var(--active); }
.levels-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.level-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; text-align: start; background: transparent; border: 1.5px solid var(--faint); border-radius: var(--radius); cursor: pointer; }
.level-item:hover:not(:disabled) { border-color: var(--ink); }
.level-item:disabled { cursor: default; color: var(--dim); border-style: dashed; }
.level-index { width: 1.6em; color: var(--dim); }
.level-title { flex: 1; }
.level-stars { direction: ltr; letter-spacing: 2px; }
.setting-title { margin: 0 0 8px; font-size: 1rem; font-weight: 600; }
.setting + .setting { margin-top: 18px; }
.setting-sub { margin: 10px 0 6px; color: var(--dim); font-size: 0.9rem; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices .btn { flex: 1; }
.choices .btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
/* the settings scroll on their own, so "close" stays in view */
#settings-dialog > .settings-body { flex: 1 1 auto; }
.dialog-foot { flex: none; display: flex; justify-content: center; padding-top: 12px; border-top: 1.5px dashed var(--faint); margin-top: 8px; }

/* Board pieces (drawn by js/art.js) */
/* The characters (art.js): outlined bodies with their own fill, ink lines, dot eyes. Walking swaps two leg poses. */
.char-body { stroke: var(--ink); stroke-linejoin: round; }
.char-line { fill: none; stroke: var(--ink); stroke-linecap: round; stroke-linejoin: round; }
.char-eye { fill: var(--ink); }
.char-extra { fill: none; stroke-linecap: round; }
.char-ink { fill: #22357a; opacity: 0.75; } /* the puddle Nib stands in */
.legs-b, .player[data-stride="1"] .legs-a { display: none; }
.player[data-stride="1"] .legs-b { display: inline; }
.trail { fill: none; stroke: var(--trail); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 0.1 17; }
.nb-grid { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; opacity: 0.85; }
.nb-hatch { fill: none; stroke: var(--ink); stroke-width: 4; stroke-linecap: round; }
.nb-acid-wash { fill: var(--acid-bg); }
.nb-acid { fill: none; stroke: var(--acid); stroke-width: 3.5; stroke-linecap: round; }
.nb-low { fill: none; stroke: var(--ink); stroke-width: 4; stroke-linecap: round; }
.nb-enemy circle, .nb-enemy path { fill: none; stroke: var(--danger); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
.nb-enemy circle { fill: rgba(139, 58, 30, 0.12); }
.nb-dog ellipse { fill: rgba(139, 58, 30, 0.2); stroke: var(--danger); stroke-width: 4; }
.nb-dog .nb-dog-nose { fill: var(--danger); stroke-width: 2; }
.nb-dog .nb-dog-eye { fill: var(--danger); stroke: none; }
.nb-block.nb-gate rect { fill: #ecd6a8; stroke: #7a4f24; stroke-width: 4.5; }
.nb-block.nb-gate .nb-gate-wood { fill: none; stroke: #7a4f24; stroke-width: 3; stroke-linecap: round; }
.nb-gate > path:last-child { stroke: var(--ink); }
/* the mimic: the player's character in red, frowning */
.nb-mimic :is(.char-body, .char-line) { stroke: var(--danger); }
.nb-mimic .char-body { fill: rgba(139, 58, 30, 0.14); }
.nb-mimic .char-eye { fill: var(--danger); }
.nb-mimic .char-extra { display: none; }
.nb-mimic .char-ink { fill: var(--danger); opacity: 0.5; }
.nb-mimic .nb-mimic-brows { fill: none; stroke: var(--danger); stroke-width: 3; stroke-linecap: round; }
.nb-tree circle { fill: var(--tree-bg); stroke: var(--tree); stroke-width: 3; }
.nb-tree path { fill: none; stroke: var(--tree); stroke-width: 2.5; stroke-linecap: round; }
.tree-cell.growing { transform-box: fill-box; transform-origin: center; animation: grow 0.35s ease-out; }
@keyframes grow { from { transform: scale(0.2); opacity: 0; } }
.nb-ceiling-area { fill: rgba(31, 44, 85, 0.06); stroke: var(--ink); stroke-width: 2; stroke-dasharray: 9 7; opacity: 0.6; }
.nb-ceiling-beam { fill: rgba(31, 44, 85, 0.35); stroke: var(--ink); stroke-width: 3; }
.nb-spikes { fill: rgba(31, 44, 85, 0.3); stroke: var(--ink); stroke-width: 2.5; stroke-linejoin: round; }
.nb-poison path { fill: var(--poison-bg); stroke: var(--poison); stroke-width: 3.5; stroke-linejoin: round; }
.nb-poison circle { fill: none; stroke: var(--poison); stroke-width: 3; }
.nb-archer circle, .nb-archer path { fill: none; stroke: var(--danger); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
.nb-archer circle { fill: rgba(139, 58, 30, 0.12); }
.nb-archer .nb-archer-bow { stroke-width: 5; }
.arrow-shot { fill: none; stroke: var(--danger); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 22 200; stroke-dashoffset: 22; opacity: 0; } /* pathLength 100: the arrow flies the whole line */
.arrow-shot.flying { opacity: 1; animation: fly 0.3s linear forwards; }
@keyframes fly { to { stroke-dashoffset: -100; } }
.nb-block rect { fill: var(--paper); stroke: var(--ink); stroke-width: 4.5; }
.nb-block path { fill: none; stroke: var(--ink); stroke-width: 3.5; stroke-linecap: round; }
.nb-block .nb-block-hatch { stroke-width: 2.5; opacity: 0.7; }
.nb-goal ellipse { fill: none; stroke: var(--ink); stroke-width: 3.5; }
.nb-goal-text { font-family: 'Amatic SC', sans-serif; font-size: 38px; font-weight: 700; fill: var(--ink); text-anchor: middle; }
/* the goal: a treasure chest */
.nb-treasure :is(rect, path) { stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; }
.nb-treasure .nb-treasure-glow { fill: rgba(239, 159, 39, 0.18); }
.nb-treasure-coins { fill: #fac775; }
.nb-treasure-box { fill: #c98a4b; }
.nb-treasure-lid { fill: #d99a55; }
.nb-treasure-band { fill: none; stroke: #ba7517 !important; stroke-width: 5 !important; }
.nb-treasure-lock { fill: #fac775; }
.nb-treasure .nb-sparkle { fill: #ef9f27; stroke: none; }
.nb-coord { font-family: var(--font); font-size: 18px; fill: var(--dim); text-anchor: middle; dominant-baseline: central; direction: ltr; }

/* Animations */
.player-body, .goal-mark { transform-box: fill-box; }
.player-body { transform-origin: 50% 100%; }
.goal-mark { transform-origin: 50% 50%; }
.player-body.dying { animation: sink 0.6s ease-in forwards; }
.player-body.crawling { transform: scaleY(0.6); }
.player-body.hurt :is(.char-body, .char-line) { stroke: var(--poison); } /* poisoned once */
.player-body.hurt .char-eye { fill: var(--poison); }
.mover.gone .nb-mimic { transform-box: fill-box; transform-origin: 50% 100%; animation: sink 0.6s ease-in forwards; }
.player-body.cheering { animation: hop 0.36s ease-out 2; }
.goal.reached .goal-mark { animation: pulse 0.5s ease-out 2; }
@keyframes sink { to { transform: scale(0.3, 0.05); opacity: 0; } }
@keyframes hop { 50% { transform: translateY(-28%); } }
@keyframes pulse { 50% { transform: scale(1.15); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* Home */
.home { min-height: 100vh; min-height: 100dvh; }
.home-hero { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 4vh; text-align: center; }
.home-art { width: min(100%, 300px); height: auto; overflow: visible; }
.figure-wrap[data-stride="1"] .legs-a { display: none; }
.figure-wrap[data-stride="1"] .legs-b { display: inline; }
.home-arrow { transition: opacity 0.3s; }
.home-arrow.away { opacity: 0; }
.home-arrow { fill: none; stroke: var(--dim); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 2 9; }
html[dir="rtl"] .home-art { transform: scaleX(-1); }
html[dir="rtl"] .home-art text { transform: scaleX(-1); transform-box: fill-box; transform-origin: center; }
/* Amatic SC draws small letters as small capitals: all capitals, so N, I and B are the same size */
.home-title { font-size: 5rem; line-height: 0.9; text-transform: uppercase; }
.home-slogan { margin: 0 0 6px; font-family: var(--font-title); font-size: 1.55rem; letter-spacing: 0.08em; }
.home-tagline { margin: 0 0 8px; max-width: 30ch; color: var(--dim); font-size: 1.05rem; }
.home-actions { display: flex; flex-direction: column; gap: 12px; width: min(100%, 320px); margin: 18px auto 0; }
.home-play { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 18px; font-size: 1.4rem; }
.home-play small { font-size: 0.85rem; opacity: 0.85; }
.home-count { display: block; color: var(--dim); font-size: 0.8rem; }

/* My obstacles */
.obstacle-worlds { display: flex; flex-direction: column; gap: 20px; margin-top: 8px; }
.obstacle-world-title { margin: 0; padding-bottom: 2px; border-bottom: 2px solid currentColor; font-family: var(--font-title); font-size: 1.45rem; line-height: 1.2; }
.obstacles-list { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 0; padding: 0; list-style: none; }
.obstacle { display: flex; align-items: flex-start; gap: 14px; padding: 10px 12px; border: var(--border); border-radius: var(--radius); }
.obstacle-art { flex: none; width: 76px; height: 76px; overflow: visible; }
.obstacle.unknown { border-style: dashed; border-color: var(--dim); background: rgba(31, 44, 85, 0.09); }
.obstacle.unknown .obstacle-art { filter: brightness(0); opacity: 0.55; }
.obstacle.unknown .obstacle-name { color: var(--dim); letter-spacing: 0.1em; }
.obstacle-info { flex: 1; min-width: 0; }
.obstacle-name { margin: 0; font-family: var(--font-title); font-size: 1.7rem; line-height: 1.1; }
.obstacle-text { margin: 2px 0 4px; font-size: 0.95rem; }
.obstacle.unknown .obstacle-text { color: var(--dim); }
.obstacle-first { color: var(--dim); font-size: 0.8rem; }
.obstacle-soon { display: inline-block; margin-inline-start: 10px; padding: 1px 9px; border: 1.5px dashed var(--dim); border-radius: 999px; font-family: var(--font); font-size: 0.75rem; letter-spacing: 0; vertical-align: middle; }
.obstacle.soon { opacity: 0.8; }
.intro-list { display: flex; flex-direction: column; gap: 10px; }
.intro-list .obstacle { border: 0; padding: 0; }
.home-open { font-size: 1.6rem; line-height: 1; }

/* Wide screens (a computer): the buttons, with the status and hint above them, sit to the left of
   the board, in both languages, centered on the board's height (the empty rows above and below them
   share the space left over). The board takes the rest of the width, as tall as the window allows. */
@media (min-width: 900px) {
  .screen.app { max-width: 1200px; }
  .app .main {
    display: grid;
    grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
    grid-template-rows: 1fr auto auto auto auto 1fr;
    grid-template-areas: ". board" "status board" "hint board" "pads board" "actions board" ". board";
    gap: 10px 40px;
    align-items: start;
  }
  /* in a right-to-left grid the first column is on the right */
  html[dir="rtl"] .app .main {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
    grid-template-areas: "board ." "board status" "board hint" "board pads" "board actions" "board .";
  }
  .app .board-wrap { grid-area: board; width: 100%; margin: 0; }
  .app #board { max-height: calc(100vh - 110px); max-height: calc(100dvh - 110px); }
  .app .status { grid-area: status; }
  .app .hint { grid-area: hint; }
  .app .pads { grid-area: pads; }
  .app .actions { grid-area: actions; }
}

/* Level editor (developer mode) */
.screen.editor-screen { max-width: 640px; }
.editor { display: flex; flex-direction: column; gap: 12px; }
.editor-bar, .editor-size { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.editor-bar .ed-select { flex: 1; min-width: 0; }
.editor-size label { display: flex; align-items: center; gap: 6px; font-size: 0.95rem; }
.ed-select { min-height: 40px; padding: 4px 8px; font: inherit; color: var(--ink); background: var(--paper); border: var(--border); border-radius: var(--radius); }
.editor-tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ed-group { grid-column: 1 / -1; margin: 6px 0 0; color: var(--dim); font-size: 0.85rem; font-weight: 600; }
.editor-tools .ed-tool { min-height: 38px; padding: 4px 8px; font-size: 0.95rem; line-height: 1.15; }
.editor-help { margin: 0; color: var(--dim); font-size: 0.85rem; }
.editor-board { width: min(100%, 62vh); touch-action: none; cursor: crosshair; }
.ed-arrow { font-family: var(--font); font-size: 30px; font-weight: 700; fill: var(--danger); text-anchor: middle; dominant-baseline: central; direction: ltr; }
.editor-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.editor-fields label { display: flex; flex-direction: column; gap: 2px; font-size: 0.85rem; color: var(--dim); }
.ed-input { padding: 6px 2px; font-size: 1rem; color: var(--ink); background: transparent; border: 0; border-bottom: 1.5px dashed var(--faint); outline: none; }
.ed-input:focus { border-bottom-color: var(--ink); }
.editor-section { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; border-top: 1.5px dashed var(--faint); }
.editor-heading { margin: 0; font-family: var(--font-title); font-size: 1.8rem; }
.ed-wins-lang + .ed-wins-lang { margin-top: 8px; }
.ed-win-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.ed-win { display: flex; align-items: center; gap: 10px; padding: 4px 8px; border: var(--chip-border); border-radius: var(--radius); }
.ed-win-text { flex: 1; min-width: 0; }
.ed-win-score { color: var(--dim); font-size: 0.85rem; white-space: nowrap; }
.ed-win-remove { width: 34px; min-height: 32px; }
.ed-win-remove .icon { width: 18px; height: 18px; }
.editor-targets { margin: 0; font-weight: 600; }
.editor-problems { margin: 0; padding-inline-start: 20px; }
.ed-problem { color: var(--danger); }
.ed-ready { color: var(--ink); list-style: none; margin-inline-start: -20px; }
.editor-code { width: 100%; padding: 8px; font: 0.8rem/1.4 ui-monospace, Consolas, monospace; color: var(--ink); background: var(--paper); border: var(--chip-border); border-radius: 8px; resize: vertical; }
@media (max-width: 520px) { .editor-fields { grid-template-columns: 1fr; } }

/* Choosing a character (settings) */
.character-choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.character-choice { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 0; padding: 6px 4px; font-size: 0.9rem; line-height: 1.2; }
.character-choice[aria-pressed="true"] { background: var(--active); box-shadow: inset 0 0 0 2px var(--ink); }
.character-art { width: 54px; height: 54px; overflow: visible; }
.character-choice:disabled { opacity: 1; }
.character-choice:disabled .character-art { filter: grayscale(1); opacity: 0.35; }
.character-lock { font-size: 0.72rem; color: var(--dim); }

/* My journey: tabs for the obstacles, the achievements and the statistics */
.tabs { display: flex; gap: 4px; border-bottom: 1.5px dashed var(--faint); }
.tab { flex: 1 1 auto; min-height: 44px; padding: 6px 8px; font: inherit; font-size: 1rem; color: var(--dim); background: transparent; border: 0; border-bottom: 3px solid transparent; cursor: pointer; }
.tab[aria-selected="true"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--ink); }
.tab:focus-visible { outline: 3px solid var(--ink); outline-offset: -3px; }
@media (max-width: 480px) { .journey-screen .tabs { flex-wrap: nowrap; gap: 2px; } .tab { padding: 6px 2px; font-size: 0.85rem; } } /* four tabs side by side on a phone */
.journey-count { margin: 10px 0 0; text-align: center; color: var(--dim); font-size: 0.9rem; }
.character-status { color: var(--dim); font-size: 0.85rem; }

/* Worlds 3-9: the castle, lab, glacier, factory, cave, haunted house and machine */
.nb-portcullis rect { fill: rgba(31, 44, 85, 0.05); stroke: #5f5e5a; stroke-width: 3; stroke-dasharray: 8 6; }
.nb-portcullis path { fill: none; stroke: #5f5e5a; stroke-width: 5; stroke-linecap: round; }
.nb-portcullis.closed rect { fill: rgba(31, 44, 85, 0.18); stroke-dasharray: none; stroke: var(--ink); }
.nb-portcullis.closed path { stroke: var(--ink); }
.nb-plate rect { fill: #d3d1c7; stroke: var(--ink); stroke-width: 3; }
.nb-plate .nb-plate-top { fill: #f1efe8; }
.nb-plate.pressed .nb-plate-top { fill: #888780; }
.nb-door rect { fill: #c99a5b; stroke: #6b4220; stroke-width: 4.5; }
.nb-door path { fill: none; stroke: #6b4220; stroke-width: 3; }
.nb-door circle { fill: #3b2410; }
.nb-door.open rect { fill: none; stroke: #6b4220; stroke-width: 3; stroke-dasharray: 9 7; }
/* the switch and its walls: red ones (a triangle) are up at first, blue ones (a circle) down */
.nb-switch-base { fill: #d3d1c7; stroke: var(--ink); stroke-width: 3; }
.nb-switch-arm { fill: none; stroke: var(--ink); stroke-width: 6; stroke-linecap: round; }
.nb-switch-knob { fill: #e0675f; stroke: var(--ink); stroke-width: 3; }
.nb-switch.flipped .nb-switch-knob { fill: #5b8ddf; }
.nb-switch-red { fill: #c2463d; }
.nb-switch-blue { fill: #2f62b8; }
.nb-cwall rect { stroke-width: 4; }
.nb-cwall.red rect { fill: #e0675f; stroke: #8f2a22; }
.nb-cwall.blue rect { fill: #5b8ddf; stroke: #1f4a94; }
.nb-cwall .nb-cwall-mark { fill: #fff; stroke: none; }
.nb-cwall.down rect { fill: none; stroke-width: 3; stroke-dasharray: 9 7; }
.nb-cwall.down .nb-cwall-mark { fill: none; stroke-width: 3; }
.nb-cwall.down.red .nb-cwall-mark { stroke: #8f2a22; }
.nb-cwall.down.blue .nb-cwall-mark { stroke: #1f4a94; }
.nb-portal ellipse { fill: none; stroke-width: 3.5; }
.nb-portal.p1 ellipse { stroke: #534ab7; } .nb-portal.p1 ellipse:first-child { fill: rgba(83, 74, 183, 0.12); }
.nb-portal.p2 ellipse { stroke: #0f6e56; } .nb-portal.p2 ellipse:first-child { fill: rgba(15, 110, 86, 0.12); }
.nb-portal.p3 ellipse { stroke: #993c1d; } .nb-portal.p3 ellipse:first-child { fill: rgba(153, 60, 29, 0.12); }
.nb-portal.p4 ellipse { stroke: #854f0b; } .nb-portal.p4 ellipse:first-child { fill: rgba(133, 79, 11, 0.12); }
.nb-special circle, .nb-special rect { fill: rgba(127, 119, 221, 0.15); stroke: #534ab7; stroke-width: 3; }
.nb-special path { fill: none; stroke: #534ab7; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.nb-stop polygon { fill: #c0392b; stroke: #7a1f16; stroke-width: 3; }
.nb-stop rect { fill: #fff; }
.nb-ice rect { fill: #d6ecfa; stroke: #85b7eb; stroke-width: 3; }
.nb-ice path { fill: none; stroke: #fff; stroke-width: 4; stroke-linecap: round; }
.nb-snow path { fill: #fbfcff; stroke: #85b7eb; stroke-width: 3; stroke-linejoin: round; }
.nb-snow circle { fill: #b5d4f4; }
.nb-wind rect { fill: rgba(181, 212, 244, 0.35); stroke: #85b7eb; stroke-width: 2.5; stroke-dasharray: 8 6; }
.nb-wind path { fill: none; stroke: #378add; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.nb-belt rect { fill: #b4b2a9; stroke: #444441; stroke-width: 3.5; }
.nb-belt path { fill: none; stroke: #f1efe8; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.nb-press rect { fill: #d3d1c7; stroke: #444441; stroke-width: 3.5; }
.nb-press path { fill: none; stroke: #444441; stroke-width: 7; stroke-linecap: round; }
.nb-press.up .nb-press-spikes { fill: #888780; stroke: #2c2c2a; stroke-width: 2.5; stroke-linejoin: round; }
.nb-crumble rect { fill: #e2d6bd; stroke: #888780; stroke-width: 3; }
.nb-crumble path { fill: none; stroke: #5f5e5a; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.nb-hole ellipse { fill: #444441; stroke: #2c2c2a; stroke-width: 3; }
.nb-hole .nb-hole-in { fill: #1b1b1a; }
.nb-bridge rect { fill: #c99a5b; stroke: #6b4220; stroke-width: 3.5; }
.nb-bridge path { fill: none; stroke: #6b4220; stroke-width: 3; }
.nb-water rect { fill: rgba(55, 138, 221, 0.25); }
.nb-water path { fill: none; stroke: #185fa5; stroke-width: 3.5; stroke-linecap: round; }
.nb-crate rect { fill: #e0b878; stroke: #6b4220; stroke-width: 4.5; }
.nb-crate path { fill: none; stroke: #6b4220; stroke-width: 3; }
.nb-iceblock rect { fill: rgba(133, 183, 235, 0.55); stroke: #185fa5; stroke-width: 4; }
.nb-iceblock path { fill: none; stroke: #fff; stroke-width: 4; stroke-linecap: round; }
.nb-rock path:first-child { fill: #b4b2a9; stroke: #444441; stroke-width: 4; stroke-linejoin: round; }
.nb-rock path + path { fill: none; stroke: #5f5e5a; stroke-width: 3; stroke-linecap: round; }
.nb-bat path { fill: rgba(139, 58, 30, 0.25); }
.nb-bat circle { fill: var(--danger); stroke: none; }
.nb-ghost path:first-child { fill: rgba(255, 255, 255, 0.75); }
.nb-ghost circle { fill: var(--danger); stroke: none; }
.nb-mirror ellipse { fill: rgba(181, 212, 244, 0.5); stroke: var(--danger); stroke-width: 4.5; }
.nb-sleeper .awake-face { display: none; }
.awake .nb-sleeper .asleep { display: none; }
.awake .nb-sleeper .awake-face { display: inline; }
.nb-sleeper circle.awake-face { fill: var(--danger); stroke: none; }
.twin .char-body { fill: #b5d4f4; }
.twin :is(.char-body, .char-line) { stroke: #185fa5; }
.twin .char-eye { fill: #185fa5; }
.twin .legs-b { display: none; }
.nb-flash { fill: rgba(250, 199, 117, 0.45); stroke: #ef9f27; stroke-width: 3; }
/* the square that stopped the figure (a wall, a fence it can't land on...) */
.nb-blocked { fill: rgba(226, 75, 74, 0.3); stroke: #d43c3b; stroke-width: 3.5; }
.nb-fog { fill: #2c2c2a; opacity: 0.92; }
.nb-fog-icon rect { fill: #2c2c2a; }
.nb-fog-icon circle { fill: #fac775; }
.nb-fog-icon path { fill: none; stroke: #fac775; stroke-width: 4; stroke-linecap: round; }
.nb-candle rect { fill: #f1efe8; stroke: var(--ink); stroke-width: 3.5; }
.nb-candle path { fill: #ef9f27; stroke: #854f0b; stroke-width: 2.5; }

/* A wall for each world (art.SKINS): the same rules, the world's own look */
:is(.nb-hedge, .nb-stones, .nb-panel, .nb-ice-wall, .nb-steel, .nb-rock-wall, .nb-planks, .nb-circuit, .nb-lava) :is(path, rect, circle) { stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.nb-hedge path:first-child { fill: #97c459; }
.nb-hedge .nb-hedge-leaf { fill: none; stroke: #3b6d11; stroke-width: 2.5; }
.nb-stones rect { fill: #d3d1c7; }
.nb-stones path { fill: none; stroke-width: 2.5; }
.nb-panel rect { fill: #b5d4f4; }
.nb-panel path { fill: none; }
.nb-panel circle { fill: #85b7eb; stroke-width: 2; }
.nb-ice-wall rect { fill: #85b7eb; stroke: #185fa5; }
.nb-ice-wall path { fill: none; stroke: #185fa5; stroke-width: 2.5; }
.nb-ice-wall .nb-ice-shine { stroke: #e6f1fb; stroke-width: 4; }
.nb-steel rect { fill: #b4b2a9; }
.nb-steel path { fill: none; }
.nb-steel .nb-steel-stripes { stroke: #ef9f27; stroke-width: 6; }
.nb-steel circle { fill: #888780; stroke-width: 2; }
.nb-rock-wall path:first-child { fill: #888780; }
.nb-rock-wall path { fill: none; stroke-width: 2.5; }
.nb-planks rect { fill: #a6703e; }
.nb-planks path { fill: none; stroke-width: 2.5; }
.nb-planks .nb-plank-board { stroke: #633806; stroke-width: 9; }
.nb-circuit rect { fill: #5dcaa5; }
.nb-circuit path { fill: none; stroke: #085041; stroke-width: 3; }
.nb-circuit circle { fill: #fac775; stroke-width: 2; }
.nb-lava rect { fill: rgba(216, 90, 48, 0.3); stroke: none; }
.nb-lava path, .nb-lava circle { fill: none; stroke: #d85a30; stroke-width: 3.5; }

/* Settings: a menu of pages, each with a back button */
.settings-menu { display: flex; flex-direction: column; gap: 8px; padding: 2px; }
.settings-link {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; padding: 10px 14px; text-align: start;
  background: var(--paper); border: var(--border); border-radius: var(--radius); cursor: pointer;
}
.settings-link > span { font-size: 1.1rem; font-weight: 600; }
.settings-link > small { color: var(--dim); }
.settings-link::after { content: '›'; align-self: flex-end; margin-top: -1.9rem; font-size: 1.4rem; line-height: 1; color: var(--dim); }
html[dir="rtl"] .settings-link::after { content: '‹'; }
.settings-link:hover, .settings-link:focus-visible { background: var(--active); }
.settings-back { align-self: flex-start; margin-bottom: 6px; }
.settings-page { display: flex; flex-direction: column; gap: 4px; padding: 2px; }
.settings-page[hidden], .settings-menu[hidden] { display: none; }
.help-text p { margin: 0 0 8px; }
.btn.danger { color: var(--danger); border-color: var(--danger); }

/* ── Achievements, statistics, board styles and accessories (rewards.js) ── */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.tabs { flex-wrap: wrap; }
.achievements-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin: 8px 0 0; padding: 0; list-style: none; }
.achievement-card { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--paper); border: var(--border); border-radius: var(--radius); }
.achievement-card .badge { flex: none; width: 58px; height: auto; }
.achievement-card h3 { margin: 0; font-size: 1rem; }
.achievement-card p { margin: 2px 0 0; font-size: 0.85rem; color: var(--dim); }
.achievement-card.locked { border-style: dashed; }
.achievement-card.locked h3 { color: var(--dim); }
.badge-ribbon { fill: #b4b2a9; stroke: var(--ink); stroke-width: 2.5; stroke-linejoin: round; }
.badge-ring { fill: #d3d1c7; stroke: var(--ink); stroke-width: 3; }
.badge-face { fill: var(--paper); stroke: var(--ink); stroke-width: 2; }
.badge-text { font-family: var(--font); font-weight: 700; fill: var(--ink); text-anchor: middle; direction: ltr; }
.badge.on .badge-ribbon { fill: #e24b4a; }
.badge.on .badge-ring { fill: #fac775; }
.badge:not(.on) > :not(.badge-ribbon, .badge-ring, .badge-face) { opacity: 0.35; }
.stats-list { display: grid; grid-template-columns: 1fr auto; gap: 0; margin: 8px 0 0; }
.stat-row { display: contents; }
.stat-row dt, .stat-row dd { margin: 0; padding: 7px 4px; border-bottom: 1.5px dashed var(--faint); }
.stat-row dd { font-weight: 700; text-align: end; font-variant-numeric: tabular-nums; }
.stats-title { margin: 18px 0 0; font-size: 1.1rem; }
.toast {
  position: fixed; inset-inline: 0; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 50; width: min(92vw, 360px); margin: 0 auto;
  display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--paper); border: var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); animation: toast-in 0.25s ease-out;
}
.toast[hidden] { display: none; }
.toast .badge { flex: none; width: 48px; height: auto; }
.toast-text { display: flex; flex-direction: column; }
@keyframes toast-in { from { transform: translateY(20px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* accessories */
.accessory :is(path, rect, circle) { stroke: var(--ink); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.acc-cap .acc-fill, .acc-cap .acc-brim { fill: #e24b4a; }
.acc-cap .acc-dot { fill: #fac775; }
.acc-bow .acc-fill { fill: #d4537e; }
.acc-knot { fill: #fac775; }
.acc-petal { fill: #f4c0d1; }
.acc-party .acc-fill { fill: #85b7eb; }
.acc-party .acc-stripe { fill: none; stroke: #fac775; stroke-width: 3.5; }
.acc-dark { fill: #2c2c2a; }
.acc-tophat .acc-band { fill: none; stroke: #e24b4a; stroke-width: 4; }
.acc-gold { fill: #fac775; }
.acc-gem { fill: #e24b4a; }
.acc-glasses circle { fill: rgba(230, 241, 251, 0.35); }
.acc-glasses path { fill: none; }
.nb-mimic .accessory { display: none; }

/* Board styles: the paper of the whole game (html[data-style], set by game.js). Each one sets the same colours as
   :root does for the notebook, so every screen, card and button follows. The settings show a swatch of each. */
html[data-style="grid"] {
  --bg: #f1efe6; --paper: #faf8f1;
  --rules: repeating-linear-gradient(to bottom, transparent 0 23px, rgba(60, 90, 150, 0.16) 23px 24px), repeating-linear-gradient(to right, transparent 0 23px, rgba(60, 90, 150, 0.16) 23px 24px);
  --margin-line: transparent 0, transparent 1px;
}
html[data-style="kraft"] {
  --bg: #d6b98c; --paper: #e6d0a8; --ink: #46301c; --dim: #6e4e30; --faint: rgba(70, 48, 28, 0.25);
  --trail: rgba(70, 48, 28, 0.5); --active: rgba(70, 48, 28, 0.1); --veil: rgba(214, 185, 140, 0.6); --chip-border: 1.5px solid rgba(70, 48, 28, 0.4);
  --rules: repeating-linear-gradient(to bottom, transparent 0 31px, rgba(110, 78, 48, 0.18) 31px 32px);
  --margin-line: transparent 0, transparent 1px;
}
html[data-style="chalk"] {
  --bg: #2c4637; --paper: #36553f; --ink: #f1efe8; --dim: #c3d1c6; --faint: rgba(241, 239, 232, 0.25);
  --danger: #f0997b; --trail: rgba(241, 239, 232, 0.55); --active: rgba(241, 239, 232, 0.12); --veil: rgba(44, 70, 55, 0.6);
  --chip-border: 1.5px solid rgba(241, 239, 232, 0.4);
  --rules: radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, 0.05), transparent 60%), radial-gradient(ellipse at 80% 70%, rgba(255, 255, 255, 0.04), transparent 50%);
  --margin-line: transparent 0, transparent 1px;
  color-scheme: dark;
}
html[data-style="blueprint"] {
  --bg: #1c4a85; --paper: #245896; --ink: #e6f1fb; --dim: #b5d4f4; --faint: rgba(230, 241, 251, 0.25);
  --danger: #f5c4b3; --trail: rgba(230, 241, 251, 0.55); --active: rgba(230, 241, 251, 0.12); --veil: rgba(28, 74, 133, 0.6);
  --chip-border: 1.5px solid rgba(230, 241, 251, 0.4);
  --rules: repeating-linear-gradient(to bottom, transparent 0 23px, rgba(230, 241, 251, 0.1) 23px 24px), repeating-linear-gradient(to right, transparent 0 23px, rgba(230, 241, 251, 0.1) 23px 24px);
  --margin-line: transparent 0, transparent 1px;
  color-scheme: dark;
}
/* in the dark styles, things drawn in a fixed light ink keep their own colours, and a few dark ones lighten */
html:is([data-style="chalk"], [data-style="blueprint"]) :is(.nb-ceiling-area, .obstacle.unknown) { fill: rgba(255, 255, 255, 0.08); background: rgba(255, 255, 255, 0.08); }
html:is([data-style="chalk"], [data-style="blueprint"]) :is(.nb-ceiling-beam, .nb-spikes) { fill: rgba(255, 255, 255, 0.3); }
/* the swatches in the settings */
.style-swatch[data-style="notebook"] { background: #ebe5d6 repeating-linear-gradient(to bottom, transparent 0 11px, rgba(60, 90, 150, 0.18) 11px 12px); --ink: #1f2c55; }
.style-swatch[data-style="grid"] { background: #f7f5ee; background-image: linear-gradient(rgba(60, 90, 150, 0.18) 1px, transparent 1px), linear-gradient(90deg, rgba(60, 90, 150, 0.18) 1px, transparent 1px); background-size: 10px 10px; --ink: #1f2c55; }
.style-swatch[data-style="kraft"] { background: #d6b98c; --ink: #46301c; }
.style-swatch[data-style="chalk"] { background: #2c4637; --ink: #f1efe8; }
.style-swatch[data-style="blueprint"] { background-color: #1c4a85; background-image: linear-gradient(rgba(230, 241, 251, 0.14) 1px, transparent 1px), linear-gradient(90deg, rgba(230, 241, 251, 0.14) 1px, transparent 1px); background-size: 10px 10px; --ink: #e6f1fb; }
.style-choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.style-choice { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px; }
.style-swatch { display: block; width: 100%; aspect-ratio: 1.4; border: 1.5px solid var(--faint); border-radius: 8px; }
.style-swatch svg { display: block; height: 100%; margin: 0 auto; }

/* tabs inside a settings page */
.settings-tabs { margin-bottom: 10px; }
.settings-tabs + .setting { margin-top: 0; }

/* ── The worlds map (map.js) ── */
.map-hint { margin: 0; text-align: center; color: var(--dim); font-size: 0.95rem; min-height: 1.3em; }
.map { display: block; width: 100%; max-width: 440px; height: auto; margin: 0 auto; overflow: visible; }
.map-road { fill: none; stroke: var(--ink); stroke-width: 4; stroke-linecap: round; stroke-dasharray: 2 12; opacity: 0.45; }
.map-road.walked { stroke-dasharray: 10 9; opacity: 0.85; }
.map-measure { fill: none; stroke: none; }
.map-world { cursor: pointer; outline: none; }
.map-world.locked { cursor: not-allowed; }
.map-node { fill: var(--paper); stroke: var(--ink); stroke-width: 3.5; transition: transform 0.15s; transform-box: fill-box; transform-origin: center; }
.map-world:not(.locked):hover .map-node { fill: var(--active); }
.map-world:focus-visible .map-node { stroke-width: 6; stroke-dasharray: 6 4; }
.map-world.locked .map-node { stroke-dasharray: 5 6; }
.map-world.locked > svg { filter: grayscale(1); opacity: 0.35; }
.map-world.finished .map-node { stroke-width: 5; }
.map-num { fill: var(--ink); }
.map-num-text { fill: var(--paper); font: 700 15px var(--font); text-anchor: middle; }
.map-name { fill: var(--ink); font: 700 19px var(--font); text-anchor: middle; }
.map-status { fill: var(--dim); font: 15px var(--font); text-anchor: middle; direction: ltr; }
.map-world.locked :is(.map-name, .map-status) { fill: var(--dim); }
.map-flag { fill: #e24b4a; stroke: var(--ink); stroke-width: 2.5; stroke-linejoin: round; }
.map-figure { pointer-events: none; }
#world-dialog .levels-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.home-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lang-choices { direction: ltr; }

/* ── The line boil (boil.js): what trembles besides the board, the map and the home picture ──
   boil.js sets html[data-boil] and the frame; --boil is the filter of the moment, or none. */
:root { --boil: none; }
html[data-boil="on"][data-boil-frame="0"] { --boil: url(#pboil0); }
html[data-boil="on"][data-boil-frame="1"] { --boil: url(#pboil1); }
html[data-boil="on"][data-boil-frame="2"] { --boil: url(#pboil2); }
/* buttons in focus or under the mouse: only the frame trembles (an outline drawn over it), never the text */
:is(.btn, .icon-btn, .settings-link) { position: relative; }
/* a clear focus ring for the keyboard, trembling or not */
:is(.btn, .icon-btn, .settings-link):focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
:is(.btn, .icon-btn, .settings-link)::before {
  content: ''; position: absolute; inset: -2px; border: var(--border); border-radius: var(--radius);
  pointer-events: none; opacity: 0;
}
.btn.danger::before { border-color: var(--danger); }
html[data-boil="on"] :is(.btn, .icon-btn, .settings-link):focus-visible:not(:disabled) { border-color: transparent; }
html[data-boil="on"] :is(.btn, .icon-btn, .settings-link):focus-visible:not(:disabled)::before { opacity: 1; filter: var(--boil); }
@media (hover: hover) {
  html[data-boil="on"] :is(.btn, .icon-btn, .settings-link):hover:not(:disabled) { border-color: transparent; }
  html[data-boil="on"] :is(.btn, .icon-btn, .settings-link):hover:not(:disabled)::before { opacity: 1; filter: var(--boil); }
  /* an obstacle you point at in My Journey */
  .obstacle:not(.unknown):hover .obstacle-art { filter: var(--boil); }
}
/* the character, accessory and board style you chose */
:is(.character-choice, .style-choice)[aria-pressed="true"] :is(.character-art, .style-swatch svg) { filter: var(--boil); }
/* the moment you win (or fall), a new badge, the key that is running, an obstacle met for the first time */
.result:not([hidden]) :is(#result-title, #result-stars) { filter: var(--boil); }
.toast .badge { filter: var(--boil); }
.pad.running .pad-key { filter: var(--boil); }
#intro-list .obstacle-art { filter: var(--boil); }

/* The developer's tools (level editor, Testing page): orange, the same in every board style */
:root { --dev: #f0a04b; --dev-hover: #f5b66f; --dev-ink: #3d1f00; --dev-edge: #b4530a; }
:is(.btn, .settings-link).dev { background: var(--dev); color: var(--dev-ink); border-color: var(--dev-edge); }
:is(.btn, .settings-link).dev::before { border-color: var(--dev-edge); }
.settings-link.dev > small, .settings-link.dev::after { color: var(--dev-ink); }
@media (hover: hover) { :is(.btn, .settings-link).dev:hover { background: var(--dev-hover); } }
.settings-link.dev:focus-visible { background: var(--dev-hover); }
.choices .btn.dev[aria-pressed="true"] { background: var(--dev-edge); color: #fff; }

/* ── Doodles (doodles.js): in the margins, behind the screens ── */
.doodles { position: absolute; top: 0; left: 0; z-index: 0; overflow: hidden; pointer-events: none; color: var(--ink); }
.screen { position: relative; z-index: 1; }
.doodle { position: absolute; line-height: 0; transform: rotate(var(--turn, 0deg)); }
.doodle > svg { display: block; width: 100%; height: 100%; overflow: visible; filter: var(--boil); }
.doodle.clickable { pointer-events: auto; cursor: pointer; }
.doodle[data-corner="bottom-right"] > svg { transform: scaleX(-1); }
.doodle[data-corner="top-left"] > svg { transform: scaleY(-1); }
.doodle[data-corner="top-right"] > svg { transform: scale(-1, -1); }
.doodle.hop > svg { animation: doodle-hop 0.5s ease-out; }
@keyframes doodle-hop { 40% { transform: translateY(-22%); } }
.doodle .drop.new { transform-box: fill-box; transform-origin: center; animation: drop-in 0.3s ease-out; }
@keyframes drop-in { from { transform: scale(0); } }
/* on the screen's title: a marker stroke behind it, or a wavy line under it */
:is(.doodle-highlight, .doodle-squiggle) { width: fit-content; margin-inline: auto; background-repeat: no-repeat; }
.doodle-highlight { padding-inline: 6px; background-position: center 72%; background-size: 100% 58%; }
.doodle-squiggle { padding-bottom: 8px; background-position: center bottom; background-size: min(100%, 160px) 10px; }

/* "Start here!": the first visit only. Above the button on a phone, beside it where there is room. */
.home-actions { position: relative; }
.start-here { display: flex; flex-direction: column; align-items: center; margin-bottom: -8px; font-size: 1.15rem; }
.start-here[hidden] { display: none; }
.start-here svg { width: 56px; height: auto; overflow: visible; transform: rotate(80deg); }
@media (min-width: 760px) {
  .start-here { position: absolute; top: 2px; inset-inline-end: calc(100% + 8px); width: 170px; margin: 0; }
  .start-here svg { width: 110px; transform: none; }
  html[dir="rtl"] .start-here svg { transform: scaleX(-1); }
}

/* the map's sticky note */
.sticky-tip { position: relative; width: 180px; margin: 18px auto 0; padding: 22px 16px 28px; transform: rotate(2.5deg); color: #1f2c55; text-align: center; }
.sticky-tip .sticky-art { position: absolute; inset: 0; z-index: -1; width: 100%; height: 100%; overflow: visible; }
.sticky-tip p { margin: 0; font-size: 0.98rem; line-height: 1.35; }
.sticky-tip b { display: block; font-size: 1.1rem; }
@media (min-width: 1000px) {
  .sticky-tip { position: absolute; top: 96px; inset-inline-start: calc(100% + 24px); margin: 0; }
}

/* three stars: the teacher's stamp comes down on the card */
.result-card { position: relative; }
.result-stamp { position: absolute; top: -30px; inset-inline-end: -26px; width: 84px; height: 84px; pointer-events: none; overflow: visible; }
.result-stamp:not([hidden]) { animation: stamp 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.3) 0.3s both; }
@keyframes stamp { from { transform: scale(1.9); opacity: 0; } }

/* The story (story.js): the whole page, a big line on top, the scene under it. At the end the page turns over.
   It is told in the notebook itself, whatever paper the game is set to. */
.story { --bg: #ebe5d6; --paper: #f3eee2; --ink: #1f2c55; --dim: #5a6285; --faint: rgba(31, 44, 85, 0.2); --border: 2px solid var(--ink);
  --danger: #8b3a1e; --poison: #6d3a86; --tree: #3b6d11; --tree-bg: #b5d08a; color-scheme: light; }
.story { width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border: 0; color: var(--ink); background: var(--bg); cursor: pointer; } /* plain paper: the scene draws its own lines */
.story[open] { display: grid; grid-template-rows: auto minmax(5.4em, auto) minmax(0, 1fr) auto; justify-items: center; gap: 12px; }
.story::backdrop { background: #ebe5d6; }
/* turning over: the page turns on its spine (on the right in Hebrew, on the left in English), and the screen under it shows */
.story.flipping { transform-origin: right center; backface-visibility: hidden; overflow: hidden; }
html[dir="ltr"] .story.flipping { transform-origin: left center; }
.story.flipping::backdrop { background: transparent; }
.story-shade { position: absolute; inset: 0; background: #1f2c55; opacity: 0; pointer-events: none; }
.story-skip { justify-self: end; min-height: 40px; padding: 4px 16px; background: var(--paper); border: var(--border); border-radius: var(--radius); }
.story-text { position: relative; align-self: end; max-width: 32ch; margin: 0; text-align: center; font-size: clamp(1.45rem, 4.2vw, 2.3rem); line-height: 1.4; text-wrap: balance; transition: opacity 0.2s, transform 0.2s; }
.story-text.leaving { opacity: 0; transform: translateY(-10px); }
.story-text.rattle { animation: rattle 0.45s linear; }
@keyframes rattle { 20% { transform: translateX(-6px) rotate(-1deg); } 40% { transform: translateX(6px) rotate(1deg); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
.st-word { position: relative; display: inline-block; opacity: 0; }
.st-word.in { animation: ink-in 0.28s ease-out forwards; }
.st-word.now { animation: none; opacity: 1; }
@keyframes ink-in { from { opacity: 0; filter: blur(3px); transform: translateY(3px); } to { opacity: 1; filter: none; transform: none; } }
/* the marked word: Blot eats it (a blot comes down on it), or a ghost erases it */
.st-word.marked::after { content: ''; position: absolute; inset: -2px -6px; background: #22357a; border-radius: 46% 54% 40% 60% / 55% 42% 58% 45%; transform: scale(0); }
.st-word.marked.eat::after { animation: eat 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.3) forwards; }
@keyframes eat { to { transform: scale(1) rotate(-4deg); } }
.st-word.marked.erase { animation: erase 0.9s ease-in forwards; }
@keyframes erase { 30% { filter: blur(1px); } to { opacity: 0.12; filter: blur(2px); } }
.story-pen { position: absolute; width: 34px; height: 34px; margin: -30px 0 0 -6px; opacity: 0; pointer-events: none; transition: left 0.12s, top 0.12s, opacity 0.2s; }
.story-pen.on { opacity: 1; }
.story-scene { width: min(100%, 860px); height: 100%; max-height: 52vh; overflow: hidden; filter: var(--boil); } /* off the page is off stage */
@media (max-width: 600px) { .story-scene { width: calc(100% + 32px); margin-inline: -16px; } } /* a phone: the page from edge to edge, as big as it gets */
.story-foot { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.story-dots { display: flex; gap: 6px; }
.story-dots span { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--ink); }
.story-dots span.on { background: var(--ink); }
.story-next { min-width: 150px; min-height: 46px; padding: 6px 20px; font-size: 1.15rem; color: var(--paper); background: var(--ink); border: var(--border); border-radius: var(--radius); }
.story-hint { color: var(--dim); }
@media (pointer: coarse) { .story-hint { display: none; } } /* a phone has no Space key: you tap */
/* the scene */
.st-rule { stroke: rgba(60, 90, 150, 0.35); stroke-width: 1.5; }
.st-margin { stroke: rgba(170, 60, 60, 0.45); stroke-width: 2; }
html[dir="rtl"] .st-margin-ltr, html[dir="ltr"] .st-margin-rtl { display: none; }
.st-rule, .st-margin, .st-way { fill: none; stroke-dasharray: 1; stroke-dashoffset: 1; }
.st-way { stroke: #22357a; stroke-width: 5; stroke-linecap: round; }
.st-ink { fill: #22357a; }
.st-dark { fill: #0d1430; } /* the cave: what is in front of it (a candle) still shines */
.st-key { font: 600 20px var(--font); fill: var(--ink); text-anchor: middle; }
.st-actor[data-stride="1"] .legs-a { display: none; }
.st-actor[data-stride="1"] .legs-b { display: inline; }
.st-bubble path { fill: var(--paper); stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; }
.st-bubble circle { fill: var(--ink); }
/* small loops: a friend's eyes blink inside a smudge, Stubby's flame flickers, a coffee stain snores */
.st-blink { transform-box: fill-box; transform-origin: center; animation: blink 3.4s infinite; }
.st-flicker { transform-box: fill-box; transform-origin: 50% 100%; animation: flicker 1.4s ease-in-out infinite; }
.st-snore { animation: snore 1.8s ease-in-out infinite; }
.st-hover { animation: hover 2.6s ease-in-out infinite; } /* a ghost floats */
@keyframes blink { 0%, 90%, 100% { transform: none; } 94% { transform: scaleY(0.1); } }
@keyframes flicker { 30% { transform: scale(0.93, 1.07) rotate(-3deg); } 70% { transform: scale(1.05, 0.95) rotate(2deg); } }
@keyframes snore { 50% { transform: translate(3px, -6px); opacity: 0.5; } }
@keyframes hover { 50% { transform: translateY(-5px); } }
@media (prefers-reduced-motion: reduce) {
  .story-text, .story-pen { transition: none; }
  .story-text.rattle, .st-word.marked.erase { animation-duration: 1ms; }
  .st-blink, .st-flicker, .st-snore, .st-hover { animation: none; }
}

/* My Journey, the story: its chapters, the open ones to watch (again) */
.story-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; margin: 8px 0 0; padding: 0; list-style: none; }
.story-card { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--paper); border: var(--border); border-radius: var(--radius); }
.story-card .story-cover { flex: none; width: 56px; height: 56px; }
.story-card-text { flex: 1; min-width: 0; }
.story-card h3 { margin: 0; font-size: 1rem; }
.story-when { margin: 2px 0 0; font-size: 0.85rem; color: var(--dim); }
.story-new { margin-inline-start: 6px; padding: 0 7px; font-size: 0.75rem; font-weight: 600; color: var(--paper); background: var(--ink); border-radius: 999px; vertical-align: 2px; } /* ink on paper, the other way round: readable on every paper */
.story-watch { flex: none; min-height: 40px; padding: 4px 14px; background: var(--paper); border: var(--border); border-radius: var(--radius); }
.story-card.locked { border-style: dashed; }
.story-card.locked h3 { color: var(--dim); }
.story-card.locked .story-cover { opacity: 0.35; filter: grayscale(1); }
.story-lock { flex: none; font-size: 0.85rem; color: var(--dim); }

/* ── A computer first ──
   The game is played mostly on a computer. A phone keeps the one narrow column above; from 1000px on the
   screens spread out, and from 1200px the whole interface grows with the window (the sizes are in rem). */
.home-tagline { text-wrap: balance; }
@media (min-width: 1200px) {
  html { font-size: clamp(16px, 0.5vw + 10px, 20px); }
  .app .main { grid-template-columns: minmax(340px, 460px) minmax(0, 1fr); }
  html[dir="rtl"] .app .main { grid-template-columns: minmax(0, 1fr) minmax(340px, 460px); }
}
@media (min-width: 1000px) {
  /* home: the picture and the name on one side, the menu on the other (in Hebrew the picture is on the right) */
  .screen.home { max-width: 1120px; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); grid-template-rows: auto 1fr; column-gap: 72px; align-items: center; }
  .home .top { grid-column: 1 / -1; align-self: start; }
  .home-hero { margin: 0 0 6vh; }
  .home-art { width: min(100%, 470px); }
  .home-title { font-size: 7rem; }
  .home-slogan { font-size: 2rem; }
  .home-tagline { max-width: 26ch; font-size: 1.25rem; }
  .home-actions { width: min(100%, 22rem); margin: 0 0 6vh; justify-self: center; gap: 14px; }
  .home-actions .btn { min-height: 3.1rem; font-size: 1.1rem; }
  .home-play { font-size: 1.6rem; }
  /* the first visit's "Start here": above the menu, not toward the picture */
  .start-here { position: absolute; top: auto; bottom: calc(100% + 6px); inset-inline-end: auto; inset-inline-start: 50%; width: auto; translate: -50% 0; flex-direction: row; gap: 8px; white-space: nowrap; }
  html[dir="rtl"] .start-here { translate: 50% 0; }
  .start-here svg { width: 64px; transform: rotate(90deg); }
  html[dir="rtl"] .start-here svg { transform: rotate(90deg) scaleY(-1); }

  /* My Journey: as wide as the board's screen, the cards side by side */
  .screen.journey-screen { max-width: 1120px; }
  .journey-screen .tabs { max-width: 720px; width: 100%; margin-inline: auto; }
  .obstacles-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); }
  .stats-list, #stats-deaths { width: 100%; max-width: 720px; margin-inline: auto; }
  .story-list { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
}
@media (min-width: 1000px) {
  /* the map (map.js, wide): across the page in two rows, every world in sight; the sticky note in the free corner
     under the first world (at the start of the line: the right in Hebrew) */
  .screen.map-screen { max-width: 1120px; position: relative; }
  .map.wide { max-width: none; max-height: calc(100vh - 140px); max-height: calc(100dvh - 140px); }
  .map-screen .sticky-tip { position: absolute; top: auto; bottom: 28px; inset-inline-start: 44px; margin: 0; }
}
@media (min-width: 1400px) { .screen.map-screen { max-width: min(1520px, 94vw); } } /* a big screen: a bigger map, still all in sight */
@media (min-width: 1000px) {
  /* the settings (game.js, WIDE_SETTINGS): a wide window, the menu on one side and the open page beside it; each
     side scrolls on its own, and the close button stays in view */
  #settings-dialog { width: min(62rem, 92vw); height: min(44rem, 88vh); padding: 20px 24px; }
  #settings-dialog > .settings-body { display: grid; grid-template-columns: 17rem minmax(0, 1fr); gap: 0 28px; min-height: 0; overflow: hidden; }
  #settings-dialog .settings-menu { overflow-y: auto; align-content: start; }
  #settings-dialog .settings-page { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 2px 10px 12px; }
  #settings-dialog .settings-back { display: none; }
  #settings-dialog .settings-link::after { content: none; }
  #settings-dialog .settings-link[aria-current="page"] { color: var(--paper); background: var(--ink); }
  #settings-dialog .settings-link[aria-current="page"] > small { color: inherit; opacity: 0.85; }
}
@media (min-width: 1000px) {
  /* the game's panel beside the board: bigger text, roomier buttons (the board keeps the rest of the width) */
  .app .status { font-size: 1.05rem; }
  .app .hint { font-size: 1.1rem; }
  .app .pad { gap: 8px; padding: 12px 14px; }
  .app .pad-key { width: 48px; height: 48px; font-size: 2.4rem; }
  .app .pad-input { font-size: 1.3rem; }
  .app .pad-count { font-size: 0.9rem; }
  .app .pad-preview { min-height: 32px; }
  .app .pad-note { font-size: 1rem; }
  .app .chip { min-height: 30px; padding: 0 10px; font-size: 1.2rem; }
  .app .actions .btn { min-height: 2.75rem; padding-inline: 18px; font-size: 1.1rem; }
}

/* Text can't be marked by dragging or a double click: on the pictures, the titles, the buttons and the board it only
   got in the way (a blue box). What you write (the pads, the editor's fields) and the help and about pages, which
   someone may want to copy from, still can. */
body { -webkit-user-select: none; user-select: none; }
:is(input, textarea, [contenteditable], .help-text) { -webkit-user-select: text; user-select: text; }

/* My Journey in the settings leads out of them, to its own screen: an "out of the box" arrow says so, instead of the
   menu's arrow (and a screen reader hears "leaves the settings") */
.settings-link.journey-link { padding-inline-end: 48px; }
.settings-link.journey-link::after, html[dir="rtl"] .settings-link.journey-link::after { content: none; }
.leave-icon { position: absolute; inset-inline-end: 14px; top: 50%; width: 1.35rem; height: 1.35rem; translate: 0 -50%; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
html[dir="rtl"] .leave-icon { transform: scaleX(-1); }
