/* 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: 16px;
  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 {
  width: 44px;
  min-height: 40px;
  padding: 4px;
  font-size: 1.2rem;
  background: transparent;
  border: var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
#settings-btn { font-size: 1.4rem; line-height: 1; }
.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; }
.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 .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; }
.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; }
.home-title { font-size: 3.6rem; }
.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; }
.home-reset { border-style: dashed; color: var(--danger); border-color: var(--danger); }
.home-stars { margin: 16px 0 0; text-align: center; color: var(--dim); font-variant-numeric: tabular-nums; }

/* My obstacles */
.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; font-size: 1.1rem; }
.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; 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; }
.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; }
.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; }
.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; }
.journey-links { display: flex; flex-direction: column; gap: 8px; }

/* ── 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; }
.map-icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.home-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
