/* ===== Theme ===== */
:root {
  --ui-scale: 1;

  --bg: #11131b;
  --panel: rgba(22, 26, 38, 0.86);
  --panel-solid: #181c29;
  --panel-2: rgba(255, 255, 255, 0.06);
  --line: rgba(150, 165, 210, 0.2);          /* thin, quiet outlines everywhere (they were an opaque #313853) */
  --line-strong: rgba(160, 172, 210, 0.45);  /* the few outlines that carry meaning: the empty dots of the point budget */
  --soft: rgba(12, 14, 24, 0.7);             /* soft filled shapes without an outline of their own: the pills, the caption */
  --text: #eaeef8;
  --muted: #a3adc7;
  --accent: #ffcc4d;          /* the real challenges */
  --accent-ink: #231a00;
  --tut: #6ea8ff;             /* the tutorial */
  --ok: #5ee08a;
  --danger: #ff6b81;
  --focus: #6ec6ff;
  --warn: #ff7f5c;            /* a note that asks for care (coral): not the gold of "selected", not the red of "delete" */
  --guide: #e2d7ff;           /* GUIDE MODE: a pale violet that is not used for anything else (gold, blue, green, teal and pink are taken) */

  --stage-bg: #151925;
  --grid-dot: #2b3350;
  --band: rgba(79, 209, 197, 0.30);          /* was .20: nearly invisible on a dim projector */
  --band-ok: rgba(94, 224, 138, 0.38);
  --center: rgba(120, 232, 220, 0.85);
  --player: #ffcc4d;
  --player-ok: #7dffa8;
  --handle: #ff7eb6;
  --anchor: #ffffff;
  --anchor-stroke: #11131b;
  --sel: #4cc2ff;
  --rubber: rgba(255, 255, 255, 0.45);

  --radius: 0.7rem;
  --gap: 0.5rem;              /* the rhythm between the groups of the interface */
  /* three sizes of text in the interface: title, body, small (secondary text is also in the muted colour; nothing is under 11 px) */
  --fs-title: 1.1rem;
  --fs-body: 0.9rem;
  --fs-small: 0.78rem;
  --ui-max: 90rem;            /* the floating panels are never wider than this: on a huge screen they sit centred, not spread to the edges */
  --shadow: 0 0.6rem 2rem rgba(0, 0, 0, 0.45);
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, "Noto Sans Hebrew", sans-serif;
}

body.contrast {
  --bg: #000;
  --panel: #000;
  --panel-solid: #000;
  --panel-2: #0b0b0b;
  --line: #fff;
  --line-strong: #fff;
  --soft: #000;
  --text: #fff;
  --muted: #e6e6e6;
  --accent: #ffee00;
  --accent-ink: #000;
  --tut: #4db8ff;
  --ok: #00ff7f;
  --danger: #ff6b6b;
  --focus: #00e1ff;
  --guide: #f0e9ff;
  --warn: #ff9a78;
  --stage-bg: #000;
  --grid-dot: #3a3a3a;
  --band: rgba(0, 225, 255, 0.34);
  --band-ok: rgba(0, 255, 127, 0.42);
  --center: #7ff;
  --player: #ffee00;
  --player-ok: #00ff7f;
  --handle: #ff5cc8;
  --anchor-stroke: #000;
  --sel: #00e1ff;
  --rubber: rgba(255, 255, 255, 0.8);
}

/* In a tutorial stage the target band is blue, so it is obvious at a glance that this is practice and not a challenge */
body.is-tutorial {
  --band: rgba(110, 168, 255, 0.32);
  --center: rgba(160, 200, 255, 0.92);
}
body.contrast.is-tutorial {
  --band: rgba(77, 184, 255, 0.4);
  --center: #9cf;
}

* { box-sizing: border-box; }

html {
  font-size: calc(16px * var(--ui-scale));
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.35;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

h1, h2, h3, p { margin: 0; }

button, input, select { font: inherit; color: inherit; }

:focus-visible { outline: 0.18rem solid var(--focus); outline-offset: 0.15rem; }

.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after {
  animation: none !important;
  transition: none !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0.05em 0.4em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 0.35em;
  background: var(--panel-2);
  color: var(--text);
  font: 600 0.82em/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace;
  text-align: center;
  white-space: nowrap;
}

.keypair { white-space: nowrap; }
.keys { unicode-bidi: isolate; direction: ltr; display: inline-flex; gap: 0.2em; align-items: center; flex-wrap: nowrap; }

/* ===== The infinite canvas (fills the screen) ===== */
.board {
  position: fixed;
  inset: 0;
  background: var(--stage-bg);
}
.stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
  background-color: var(--stage-bg);
  background-image: radial-gradient(circle, var(--grid-dot) 1.3px, transparent 1.9px);
  background-repeat: repeat;
}
/* a mouse click gives the canvas focus too; the frame is only for keyboard users (ui.js sets body.kbd on Tab, removes it on a mouse press) */
.stage:focus-visible { outline: none; }
body.kbd .stage:focus-visible { outline: 0.18rem solid var(--focus); outline-offset: -0.18rem; }

/* the cursor is the pen tool (a nib with its tip at the hot spot); a small badge tells what a click will do:
   + adds a point on the line, - deletes the point, o closes the shape, / carries on from the end of the line */
.stage[data-cursor="cur-pen"] { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M3 29 L17.4 24 L27.5 13.9 L19 5.4 L8.9 15.5 Z' fill='white' stroke='black' stroke-width='1.6' stroke-linejoin='round'/%3E%3Cpath d='M3 29 L14.6 17.4' stroke='black' stroke-width='1.3' stroke-linecap='round'/%3E%3Ccircle cx='15.9' cy='16.1' r='1.9' fill='black'/%3E%3Cpath d='M12.2 20.2 L20.4 12' stroke='black' stroke-width='1' stroke-linecap='round' opacity='0.0'/%3E%3C/svg%3E") 3 29, crosshair; }
.stage[data-cursor="cur-add"] { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M3 29 L17.4 24 L27.5 13.9 L19 5.4 L8.9 15.5 Z' fill='white' stroke='black' stroke-width='1.6' stroke-linejoin='round'/%3E%3Cpath d='M3 29 L14.6 17.4' stroke='black' stroke-width='1.3' stroke-linecap='round'/%3E%3Ccircle cx='15.9' cy='16.1' r='1.9' fill='black'/%3E%3Cpath d='M12.2 20.2 L20.4 12' stroke='black' stroke-width='1' stroke-linecap='round' opacity='0.0'/%3E%3Ccircle cx='26' cy='26' r='5' fill='%235ee08a' stroke='black' stroke-width='1.3'/%3E%3Cpath d='M26 22.8v6.4M22.8 26h6.4' stroke='black' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") 3 29, copy; }
.stage[data-cursor="cur-del"] { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M3 29 L17.4 24 L27.5 13.9 L19 5.4 L8.9 15.5 Z' fill='white' stroke='black' stroke-width='1.6' stroke-linejoin='round'/%3E%3Cpath d='M3 29 L14.6 17.4' stroke='black' stroke-width='1.3' stroke-linecap='round'/%3E%3Ccircle cx='15.9' cy='16.1' r='1.9' fill='black'/%3E%3Cpath d='M12.2 20.2 L20.4 12' stroke='black' stroke-width='1' stroke-linecap='round' opacity='0.0'/%3E%3Ccircle cx='26' cy='26' r='5' fill='%23ff6b81' stroke='black' stroke-width='1.3'/%3E%3Cpath d='M22.8 26h6.4' stroke='black' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") 3 29, not-allowed; }
.stage[data-cursor="cur-close"] { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M3 29 L17.4 24 L27.5 13.9 L19 5.4 L8.9 15.5 Z' fill='white' stroke='black' stroke-width='1.6' stroke-linejoin='round'/%3E%3Cpath d='M3 29 L14.6 17.4' stroke='black' stroke-width='1.3' stroke-linecap='round'/%3E%3Ccircle cx='15.9' cy='16.1' r='1.9' fill='black'/%3E%3Cpath d='M12.2 20.2 L20.4 12' stroke='black' stroke-width='1' stroke-linecap='round' opacity='0.0'/%3E%3Ccircle cx='26' cy='26' r='3.6' fill='white' stroke='black' stroke-width='1.8'/%3E%3C/svg%3E") 3 29, pointer; }
.stage[data-cursor="cur-continue"] { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M3 29 L17.4 24 L27.5 13.9 L19 5.4 L8.9 15.5 Z' fill='white' stroke='black' stroke-width='1.6' stroke-linejoin='round'/%3E%3Cpath d='M3 29 L14.6 17.4' stroke='black' stroke-width='1.3' stroke-linecap='round'/%3E%3Ccircle cx='15.9' cy='16.1' r='1.9' fill='black'/%3E%3Cpath d='M12.2 20.2 L20.4 12' stroke='black' stroke-width='1' stroke-linecap='round' opacity='0.0'/%3E%3Cpath d='M23.2 29.2 L29.2 22.8' stroke='black' stroke-width='4' stroke-linecap='round'/%3E%3Cpath d='M23.2 29.2 L29.2 22.8' stroke='white' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") 3 29, pointer; }
.stage[data-cursor="cur-move"] { cursor: move; }
.stage[data-cursor="cur-handle"] { cursor: grab; }
.stage[data-cursor="cur-locked"] { cursor: not-allowed; }
.stage[data-cursor="cur-blocked"] { cursor: default; }
.stage[data-cursor="cur-pan"] { cursor: grab; }
.stage[data-cursor="cur-panning"] { cursor: grabbing; }

.band { fill: none; stroke: var(--band); stroke-linecap: round; stroke-linejoin: round; transition: stroke 0.2s; }
circle.band { fill: var(--band); stroke: none; }
.band.ok { stroke: var(--band-ok); }
circle.band.ok { fill: var(--band-ok); }
.center { fill: none; stroke: var(--center); stroke-linecap: round; stroke-linejoin: round; }

.player { fill: none; stroke: var(--player); stroke-linecap: round; stroke-linejoin: round; }
.player.ok { stroke: var(--player-ok); }
/* the line is coloured piece by piece (inline style): green = on the shape, yellow = partly, red = off it */
.player.seg { stroke-linecap: round; }
.player.locked { opacity: 0.9; }
.rubber { fill: none; stroke: var(--rubber); stroke-linecap: round; }

.handle-line { stroke: var(--handle); }
.handle-line.dim { opacity: 0.6; }
.handle-dot { fill: var(--handle); stroke: var(--anchor-stroke); stroke-width: 1.5; }
.handle-dot.dim { opacity: 0.55; }
.handle-dot.hover { fill: #fff; }

.anchor { fill: var(--anchor); stroke: var(--anchor-stroke); }
.anchor.sel { fill: var(--sel); stroke: #fff; }
.anchor.hover { fill: var(--accent); }
.anchor.sel.hover { fill: var(--sel); }
.close-ring { fill: none; stroke: var(--ok); }

/* GUIDE MODE: the ideal solution as a faint helper under the player's own line. It never takes a click. The points and handles are
   about half transparent (a little less in high contrast), the order numbers a little firmer so they can be read */
.layer-guide { pointer-events: none; }
.guide-shapes { opacity: 0.5; }
.guide-nums { opacity: 0.7; }
body.contrast .guide-shapes { opacity: 0.6; }
body.contrast .guide-nums { opacity: 0.85; }
.guide-line { stroke: var(--guide); }
.guide-dot { fill: var(--guide); }
.guide-node { fill: none; stroke: var(--guide); }
.guide-num { fill: var(--guide); font-weight: 700; paint-order: stroke; stroke: var(--stage-bg); stroke-linejoin: round; }

/* the blinking "start here" marker: it only describes where a good beginning is, it never takes clicks */
.layer-start { pointer-events: none; }
.start-ring { fill: none; stroke: var(--ok); transform-box: fill-box; transform-origin: center; animation: startPulse 1.5s ease-out infinite; }
.start-dot { fill: var(--ok); stroke: #0b0d14; stroke-width: 1.5; animation: startBlink 1s ease-in-out infinite; }
.start-label { fill: var(--ok); font-weight: 700; paint-order: stroke; stroke: var(--stage-bg); stroke-linejoin: round; }
.start-fade { animation: markerIn 0.4s ease-out; }
@keyframes markerIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes startPulse {
  0% { transform: scale(0.45); opacity: 0.95; }
  100% { transform: scale(1.5); opacity: 0; }
}
@keyframes startBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

/* the animated tutorial pointer */
.demo-cursor { fill: #fff; stroke: #11131b; stroke-width: 1.4; stroke-linejoin: round; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5)); }
.demo-ripple { fill: none; stroke: var(--accent); transform-box: fill-box; transform-origin: center; animation: ripple 0.6s ease-out infinite; }
@keyframes ripple { from { transform: scale(0.5); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }
.demo-badge { fill: var(--accent); stroke: #11131b; stroke-width: 1; }
.demo-badge-text { fill: var(--accent-ink); font-weight: 700; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

/* ===== Floating interface ===== */
.ui {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--gap);
  padding: var(--gap) 0.6rem;
  pointer-events: none;
}
.ui-top, .ui-bottom { display: flex; flex-direction: column; gap: var(--gap); align-items: stretch; width: 100%; max-width: var(--ui-max); margin-inline: auto; }
.ui-top { position: relative; }   /* the invisible caption probe is measured inside it */
.panel {
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

/* ===== Key legend: hidden unless the player asks for it in the settings (the keyboard button's pop-up always has it) ===== */
.shortcuts { display: none; padding: 0.25rem 0.7rem; font-size: var(--fs-small); }
body.show-legend .shortcuts { display: block; }
.sc-list { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 1.1rem; min-width: 0; }
.sc { display: inline-flex; align-items: center; gap: 0.35rem; white-space: nowrap; }
.sc-label { color: var(--muted); margin-inline-end: 0.1rem; }
.sc-keys { display: inline-flex; align-items: center; gap: 0.15rem; }
.sc-sep { color: var(--muted); margin-inline: 0.05rem; }
.is-pc .sc-keys.mac, .is-mac .sc-keys.pc { opacity: 0.55; }
.shortcuts kbd { font-size: var(--fs-small); padding: 0 0.28em; min-width: 1.25em; }
/* the keys of a row: key caps and mouse words (plain muted text) joined with a quiet plus; always read left to right, also in a Hebrew page */
.sc-mouse { color: var(--muted); white-space: nowrap; }
.sc-plus { color: var(--muted); padding-inline: 0.05em; }

/* ===== One panel: the slim top bar, a thin line, the strip of all stages ===== */
.headpanel { display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  min-height: 2.5rem;
}
.menu-btn { gap: 0.4rem; }
.mode-ico { color: var(--accent); }   /* the game being played: stays visible when its name is hidden on a narrow screen */
.menu-game { font-weight: 600; max-width: 9rem; overflow: hidden; text-overflow: ellipsis; }
.tb-title { display: flex; align-items: baseline; gap: 0.4rem; min-width: 0; }
.tb-title h1 { font-size: var(--fs-title); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* "· 2/9": a small, quiet suffix (blue in the tutorial, which is blue everywhere) */
.tb-count { flex: none; color: var(--muted); font-size: var(--fs-body); white-space: nowrap; }
.tb-count.tutorial { color: var(--tut); }
/* two small tags in the top bar: the difficulty level (a button, always there) and GUIDE MODE (only while it is on) */
.tb-tag { flex: none; padding: 0.02rem 0.6rem; border-radius: 99rem; font-size: var(--fs-small); font-weight: 700; line-height: 1.5; white-space: nowrap; }
.tb-tag[hidden] { display: none; }
.level-btn { display: inline-flex; align-items: center; gap: 0.35rem; align-self: center; border: 1px solid var(--line-strong); background: transparent; color: var(--muted); font-family: inherit; cursor: pointer; }
.level-btn:hover { color: var(--text); border-color: var(--accent); }
.level-btn.on { border-color: var(--accent); color: var(--accent); background: rgba(255, 204, 77, 0.12); }
.level-btn .band-hint { width: 1.3rem; height: 0.8rem; }
.guide-badge { border: 1px solid var(--guide); color: var(--guide); background: rgba(226, 215, 255, 0.1); letter-spacing: 0.03em; }
.kbd-btn { flex: none; gap: 0.35rem; }
.kbd-label { color: var(--muted); font-size: var(--fs-small); }
/* under the strip's "Tutorial" label: the first column of the status row, at its start edge */
.tut-skip { grid-column: 1; justify-self: start; pointer-events: auto; border-color: var(--tut); color: var(--tut); flex: none; min-height: 1.75rem; padding: 0.1rem 0.55rem; }
.tut-skip[hidden] { display: none; }
[dir="rtl"] .tut-skip .ico { transform: scaleX(-1); }
.tut-skip:hover:not(:disabled) { background: rgba(110, 168, 255, 0.16); border-color: var(--tut); }

/* the row under the strip has three columns (nothing | the two pills or the result banner | the big button), so the pills stay
   centred on the screen while Confirm / Next sits at the end of the row (the left edge in Hebrew), under the strip's own edge.
   A column that is too small for its content grows, so nothing overlaps; the centring only gives way when the window is tight */
.statusrow { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 0.4rem 0.7rem; pointer-events: none; }
/* this stage's points and match: two soft pills (a fill, no outline), centred and clearly apart from each other */
.status-main { grid-column: 2; display: flex; justify-content: center; align-items: stretch; gap: 0.7rem; flex-wrap: wrap; min-width: 0; }
.primary-wrap { grid-column: 3; justify-self: end; display: flex; padding: 0.1rem; }
.pill {
  position: relative;
  pointer-events: auto;
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.2rem 0.85rem 0.35rem;
  background: var(--soft);
  border-radius: 99rem;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  white-space: nowrap;
}
body.contrast .pill, body.contrast .caption, body.contrast .result-banner { border: 1px solid var(--line); }
/* after Confirm: ONE centred banner in the place of the two pills (success colour like a green caption), saying how the stage went */
.pill[hidden], .result-banner[hidden] { display: none; }
.result-banner {
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 0.05rem 0.9rem;
  min-width: 0;
  max-width: 100%;
  min-height: 2.15rem;
  padding: 0.2rem 1rem 0.3rem;
  background: var(--soft);
  border-inline-start: 0.28rem solid var(--ok);
  border-radius: 0.9rem;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  animation: pop 0.2s ease-out;
}
.result-icon { align-self: center; width: 1.3rem; height: 1.3rem; color: var(--ok); }
.result-banner h2 { font-size: var(--fs-title); color: var(--ok); line-height: 1.5; }
.result-stats { display: contents; color: var(--muted); font-size: var(--fs-body); }
.result-stats span:empty { display: none; }
.result-saved { font-weight: 800; color: var(--accent); }
.result-banner.guide { border-inline-start-color: var(--guide); }
.result-guide { color: var(--guide); font-weight: 700; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.pill b { font-size: var(--fs-title); font-variant-numeric: tabular-nums; line-height: 1.3; }
.pill-label { font-size: var(--fs-small); font-weight: 700; color: var(--muted); letter-spacing: 0.02em; }
/* the two pills keep a fixed width, so the row does not shift sideways while the sentence in them changes (widest sentence: 245 px in Hebrew, 322 px in English) */
.stat-match { min-width: 16rem; justify-content: center; }
html[lang="en"] .stat-match { min-width: 20.5rem; }
.stat-points #pointsLeft { min-width: 6.5rem; }
html[lang="en"] .stat-points #pointsLeft { min-width: 4.5rem; }
.stat-small { font-size: var(--fs-small); color: var(--muted); }
.stat-msg { max-width: 14rem; overflow: hidden; text-overflow: ellipsis; }
.stat-points.over b, .stat-points.over .stat-small { color: var(--danger); }
.stat-points.shake { animation: shake 0.35s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-0.3rem); }
  75% { transform: translateX(0.3rem); }
}
.stat-match.pass b { color: var(--ok); }
/* the total score: gold, with a trophy, so it cannot be mistaken for this stage's numbers */
.stat-score {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-inline-start: auto;
  padding: 0.1rem 0.7rem;
  border: 1.5px solid var(--accent);
  border-radius: 0.7rem;
  background: linear-gradient(135deg, rgba(255, 204, 77, 0.3), rgba(255, 204, 77, 0.1));
  color: var(--accent);
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 0 0.8rem rgba(255, 204, 77, 0.18);
}
.stat-score:hover { background: linear-gradient(135deg, rgba(255, 204, 77, 0.42), rgba(255, 204, 77, 0.16)); }
.stat-score .ico { width: 1rem; height: 1rem; }
.stat-score b { font-size: var(--fs-title); font-variant-numeric: tabular-nums; line-height: 1.2; color: #fff; }
.score-label { font-size: var(--fs-small); font-weight: 700; }
.score-of { font-size: var(--fs-small); color: #c8d0e4; }
.score-live { color: var(--ok); font-weight: 700; font-size: var(--fs-body); white-space: nowrap; direction: ltr; unicode-bidi: isolate; }
.score-live:empty { display: none; }
b.bump { animation: bump 0.7s ease-out; display: inline-block; }
@keyframes bump {
  0% { transform: scale(1); }
  30% { transform: scale(1.45); color: var(--ok); }
  100% { transform: scale(1); }
}

.pips { display: inline-flex; flex-wrap: nowrap; gap: 0.15rem; align-self: center; }
.pip {
  width: 0.5rem; height: 0.5rem;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
  transition: background 0.15s, border-color 0.15s;
}
.pip.used { background: var(--accent); border-color: var(--accent); }
/* the tick after the last dot of the ideal solution's budget, in the gap between two dots */
.pip { position: relative; }
.pip.ideal-end { margin-inline-end: 0.22rem; }
.pip.ideal-end::after { content: ""; position: absolute; top: -0.22rem; bottom: -0.22rem; inset-inline-end: -0.19rem; width: 2px; border-radius: 1px; background: var(--ok); }
.stat-ideal { padding-inline-start: 0.5rem; border-inline-start: 1px solid var(--line); }
.stat-ideal.at-ideal { color: var(--ok); font-weight: 700; }
.stat-points.over .pip.used { background: var(--danger); border-color: var(--danger); }
body.is-tutorial .pip.used { background: var(--tut); border-color: var(--tut); }
/* the total score does not count in the tutorial: a quiet chip, not the gold, glowing one */
body.is-tutorial .stat-score { border-color: var(--line); background: var(--panel-2); color: var(--muted); box-shadow: none; }
body.is-tutorial .stat-score:hover { background: rgba(255, 255, 255, 0.12); }
body.is-tutorial .stat-score b { color: var(--text); }

.meter { position: absolute; inset-inline: 0.45rem; bottom: 0.1rem; height: 0.18rem; border-radius: 99rem; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.meter-fill { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.15s, background 0.15s; }
.stat-match.pass .meter-fill { background: var(--ok); }
body.is-tutorial .meter-fill { background: var(--tut); }
body.is-tutorial .stat-match.pass .meter-fill { background: var(--ok); }

/* ===== Strip of all stages: tutorial in blue, real challenges in gold (the score is shown on the current stage; a check mark on the others) ===== */
.stripbar { padding: 0.25rem 0.4rem 0.3rem; border-top: 1px solid var(--line); }
.strip {
  display: flex;
  align-items: stretch;
  gap: 0.25rem;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  scroll-behavior: smooth;
}
.strip::-webkit-scrollbar { display: none; }
.strip-sep {
  flex: none;
  align-self: center;
  padding: 0 0.4rem;
  font-size: var(--fs-small);
  font-weight: 500;
  white-space: nowrap;
  border-inline-start: 1px solid var(--line);
}
.strip-sep.tut { color: var(--tut); border-inline-start-color: transparent; }
.strip-sep.chal { color: var(--accent); }
.strip-item {
  flex: none;
  position: relative;
  width: 3.9rem;
  padding: 0.1rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  cursor: pointer;
  transition: opacity 0.2s;
}
.strip-item.tut { border-color: rgba(110, 168, 255, 0.3); }
.strip-item.chal { border-color: rgba(255, 204, 77, 0.28); }
.strip-item:hover { border-color: rgba(255, 255, 255, 0.6); }
.strip-item.tut.current { border-color: var(--tut); box-shadow: 0 0 0 2px var(--tut) inset; background: rgba(110, 168, 255, 0.16); }
.strip-item.chal.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; background: rgba(255, 204, 77, 0.14); }
.strip-item .thumb { display: block; width: 100%; aspect-ratio: 1.9; background: var(--stage-bg); border-radius: 0.3rem; }
.strip-item .thumb path { fill: none; stroke-width: 28; stroke-linecap: round; stroke-linejoin: round; }
.strip-item.tut .thumb path { stroke: var(--tut); }
.strip-item.chal .thumb path { stroke: var(--accent); }
.strip-item .n, .strip-item .s {
  position: absolute;
  font-size: var(--fs-small);
  line-height: 1;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 0.08rem 0.2rem;
  border-radius: 0.25rem;
  background: rgba(10, 12, 20, 0.78);
}
.strip-item .n { top: 0.2rem; inset-inline-start: 0.2rem; color: var(--text); }
/* the score sits in the opposite bottom corner from the number, so the two never cover each other (the digits themselves are isolated left-to-right in a <bdi>) */
.strip-item .s { bottom: 0.2rem; inset-inline-end: 0.2rem; color: var(--ok); }
.strip-item .s:empty { display: none; }
.strip-item.done { border-color: rgba(94, 224, 138, 0.45); }
.strip-item.done .thumb path { stroke: var(--ok); }

/* ===== The caption (under the status row, only when there is something to say) and the toolbar ===== */
.caption {
  pointer-events: auto;
  align-self: center;
  /* a fixed width (the text held to about 66 characters a line, see .hint; 62 made the longest lesson five lines tall, and the room for the demo
     button), so the box does not change when the text or the button changes: nothing may move when a demo starts or ends */
  width: min(96%, calc(66ch + 12rem));
  font-size: var(--fs-body);
  display: flex;
  align-items: center;
  gap: 0.3rem 0.9rem;
  flex-wrap: wrap;
  padding: 0.3rem 0.5rem 0.3rem 0.9rem;
  background: var(--soft);
  border-inline-start: 0.22rem solid var(--accent);
  border-radius: var(--radius);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  animation: popDown 0.2s ease-out;
}
.caption[hidden] { display: none; }
.caption.probe { position: absolute; top: 0; left: 0; right: 0; margin-inline: auto; visibility: hidden; pointer-events: none; animation: none; }
body.is-tutorial .caption { border-inline-start-color: var(--tut); }
.caption.demo { border-inline-start-color: var(--focus); }
@keyframes pop { from { transform: translateY(0.4rem); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes popDown { from { transform: translateY(-0.4rem); opacity: 0; } to { transform: none; opacity: 1; } }
.hint { flex: 1 1 14rem; min-width: 0; max-width: 66ch; font-size: var(--fs-body); }
.hint[hidden] { display: none; }
.caption.demo .hint { font-weight: 600; }
.dock-actions [hidden] { display: none; }
.dock-actions { display: flex; gap: 0.3rem; margin-inline-start: auto; }
.dock-actions .btn.quiet { color: var(--tut); }
.dock-actions .btn { min-width: 9.5rem; }   /* "Show demo" and "Skip the demo" take turns in the same place and are the same size */
.dock-actions:empty { display: none; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.8rem;
  padding: 0.3rem 0.5rem;
}
.tool-group { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }
.tool-group[hidden] { display: none; }
.tool-group + .tool-group { padding-inline-start: 0.8rem; border-inline-start: 1px solid var(--line); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.4rem;
  padding: 0.3rem 0.8rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  cursor: pointer;
  font-size: var(--fs-body);
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, transform 0.05s, opacity 0.2s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn.icon { min-width: 2.4rem; padding: 0.3rem; }
/* toolbar buttons carry a visible name. While learning (the tutorial) the keys that do the same thing are written under it; in the
   challenges they are in the tooltip and appear above the button when it has the keyboard focus (so the toolbar does not change height) */
.btn.tool { position: relative; gap: 0.5rem; padding: 0.25rem 0.75rem; text-align: start; }
.btn-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.btn-label { font-weight: 600; font-size: var(--fs-body); }
.btn-hint { display: none; color: var(--muted); font-size: var(--fs-small); white-space: normal; max-width: 21rem; text-align: start; }
.btn-hint .keys { display: inline-flex; font-weight: 600; color: var(--text); }
body.is-tutorial .btn-hint { display: block; }
body:not(.is-tutorial) .btn.tool:focus-visible .btn-hint {
  display: block;
  position: absolute;
  bottom: calc(100% + 0.4rem);
  inset-inline-start: 0;
  z-index: 3;
  width: max-content;
  padding: 0.3rem 0.6rem;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: 0.5rem;
  box-shadow: var(--shadow);
}
.btn.icon.txt { font-weight: 700; }

/* "Delete everything": at the physical left end of the toolbar in both languages (the wrapper reads left to right, the button keeps the page's direction),
   with clear space between it and the tools; red text and a faint red outline, a red wash only when the mouse is on it; gone while a demo plays */
.wipe-wrap { flex: 1 1 auto; display: flex; direction: ltr; padding-right: 1.6rem; }
[dir="ltr"] .wipe-wrap { order: -1; }
html[dir="rtl"] .wipe-btn { direction: rtl; }
html[dir="ltr"] .wipe-btn { direction: ltr; }
.btn.wipe-btn { color: var(--danger); background: transparent; border-color: rgba(255, 107, 129, 0.35); }
.btn.wipe-btn:hover:not(:disabled), body.is-tutorial .btn.wipe-btn:hover:not(:disabled) { background: rgba(255, 107, 129, 0.14); border-color: var(--danger); }
body.demo-running .wipe-wrap { display: none; }
.btn.small { min-height: 1.9rem; padding: 0.1rem 0.6rem; font-size: var(--fs-small); }
.btn.small.icon { min-width: 2rem; padding: 0.15rem; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
/* a main button of a dialog that cannot be pressed yet: clearly "off" (flat grey) but still easy to read (the big Confirm button keeps its dimmed look) */
.dlg .btn.primary:disabled { opacity: 1; background: var(--panel-2); border-color: var(--line-strong); color: var(--muted); }
body.contrast .dlg .btn.primary:disabled { background: #000; border: 1px dashed #bdbdbd; color: #bdbdbd; }   /* (white outlines mean "can be pressed" in high contrast: disabled is dashed and grey) */
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #2a0510; font-weight: 700; }
.btn.danger-fill:hover:not(:disabled) { filter: brightness(1.08); border-color: var(--danger); }
body.contrast .btn.danger-fill { color: #000; }
/* a secondary choice that must not compete with the main ones (the welcome screen) */
.btn.quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn.quiet:hover:not(:disabled) { color: var(--text); background: var(--panel-2); border-color: var(--line); }
.confirm { font-size: var(--fs-title); min-height: 2.3rem; min-width: 8.5rem; padding-inline: 1.3rem; }
.confirm:not(:disabled) { animation: glow 1.6s ease-in-out infinite; }
.confirm.next { background: var(--ok); border-color: var(--ok); color: #04210f; }
body.contrast .confirm.next { color: #000; }
@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 204, 77, 0.55); }
  50% { box-shadow: 0 0 0 0.45rem rgba(255, 204, 77, 0); }
}
/* in the tutorial the big button is blue and pulses blue (the green "next" state stays green) */
body.is-tutorial .btn.primary:not(.next) { background: var(--tut); border-color: var(--tut); color: #04122b; }
body.contrast.is-tutorial .btn.primary:not(.next) { color: #000; }
body.is-tutorial .btn:hover:not(:disabled) { border-color: var(--tut); }
body.is-tutorial .confirm:not(:disabled):not(.next) { animation-name: glow-tut; }
@keyframes glow-tut {
  0%, 100% { box-shadow: 0 0 0 0 rgba(110, 168, 255, 0.55); }
  50% { box-shadow: 0 0 0 0.45rem rgba(110, 168, 255, 0); }
}
.confirm.next:not(:disabled) { animation-name: glow-ok; }
/* "Next": the arrow comes after the words and points the way the page is read (mirrored in Hebrew) */
.confirm.next .ico { order: 2; }
[dir="rtl"] .confirm.next .ico, [dir="rtl"] #btnUndo .ico, [dir="rtl"] #btnRedo .ico { transform: scaleX(-1); }
@keyframes glow-ok {
  0%, 100% { box-shadow: 0 0 0 0 rgba(94, 224, 138, 0.55); }
  50% { box-shadow: 0 0 0 0.45rem rgba(94, 224, 138, 0); }
}

.ico { display: inline-block; width: 1.15em; height: 1.15em; flex: none; }
.ico svg { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* the whole interface is locked while a demo is playing, except "skip" */
body.demo-running .toolbar .btn,
body.demo-running .stripbar .strip-item { pointer-events: none; opacity: 0.55; }

/* ===== Pop-ups from the top bar ===== */
.pop {
  pointer-events: auto;
  position: absolute;
  top: var(--pop-top, 3.2rem);
  z-index: 8;
  min-width: 15rem;
  max-width: min(32rem, 94vw);
  padding: 0.5rem;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: pop 0.15s ease-out;
}
.pop[hidden] { display: none; }
.menu-pop { inset-inline-start: 0.5rem; }
.sc-pop { inset-inline-end: 0.5rem; width: min(36rem, 94vw); padding: 0.3rem 0.6rem 0.6rem; font-size: var(--fs-body); max-height: calc(100vh - var(--pop-top, 3.2rem) - 1rem); max-height: calc(100dvh - var(--pop-top, 3.2rem) - 1rem); overflow: auto; }
/* the shortcut table: Action | PC | Mac, rows under quiet headings, the column of this computer's platform tinted a little (the other one stays fully readable) */
.sc-table { width: 100%; border-collapse: collapse; }
.sc-table th, .sc-table td { padding: 0.4rem 0.6rem; text-align: start; vertical-align: middle; border-bottom: 1px solid var(--line); }
.sc-table thead th { position: sticky; top: 0; z-index: 1; background: var(--panel-solid); border-bottom-color: var(--line-strong); padding-block: 0.5rem; color: var(--muted); font-size: var(--fs-small); font-weight: 600; }
.sc-table th.sc-group { padding: 0.85rem 0.6rem 0.25rem; border-bottom: 0; color: var(--muted); font-size: var(--fs-small); font-weight: 700; letter-spacing: 0.04em; }
.sc-table .sc-action { font-weight: 500; color: var(--text); }
.sc-table td { white-space: nowrap; }
.sc-table tbody tr:nth-child(odd):not(:first-child) > * { background-image: linear-gradient(rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.035)); }
.sc-table tbody:last-child tr:last-child > * { border-bottom: 0; }
.sc-table kbd { font-size: 0.86em; padding: 0.02em 0.4em; min-width: 1.5em; }
.sc-tag { display: inline-block; padding: 0 0.65rem; border: 1px solid currentColor; border-radius: 99rem; font-weight: 700; line-height: 1.6; }
.sc-tag.pc { color: var(--tut); }
.sc-tag.mac { color: var(--handle); }
.is-pc .sc-tag.pc { background: rgba(110, 168, 255, 0.18); }
.is-mac .sc-tag.mac { background: rgba(255, 126, 182, 0.18); }
.is-pc .sc-table .sc-col-pc { background-color: rgba(110, 168, 255, 0.07); }
.is-mac .sc-table .sc-col-mac { background-color: rgba(255, 126, 182, 0.07); }
.is-pc .sc-table thead .sc-col-pc, .is-mac .sc-table thead .sc-col-mac { background-color: var(--panel-solid); background-image: linear-gradient(rgba(150, 165, 210, 0.14), rgba(150, 165, 210, 0.14)); }
body.contrast .sc-table th, body.contrast .sc-table td { border-bottom-color: #666; }
body.contrast .sc-table thead th { border-bottom-color: #fff; }
body.contrast .sc-table tbody tr:nth-child(odd):not(:first-child) > * { background-image: linear-gradient(rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.1)); }
body.ui-tiny .sc-table th, body.ui-tiny .sc-table td { padding: 0.35rem 0.4rem; }
.pop-section { padding: 0.2rem 0.2rem 0.4rem; }
.pop-label { font-size: var(--fs-small); color: var(--muted); margin-bottom: 0.25rem; }
.pop-list { display: grid; gap: 0.1rem; padding: 0.2rem 0; border-block: 1px solid var(--line); }
.pop-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.6rem;
  background: transparent;
  border: 0;
  border-radius: 0.5rem;
  cursor: pointer;
  text-align: start;
  font-size: var(--fs-body);
}
.pop-item:hover:not(:disabled) { background: var(--panel-2); }
.pop-guide { padding-top: 0.2rem; }
.guide-toggle { width: 100%; }
.guide-toggle .ico { color: var(--guide); }
.guide-text { display: grid; flex: 1; min-width: 0; }
.guide-name { font-weight: 600; letter-spacing: 0.02em; }
.guide-sub { color: var(--muted); font-size: var(--fs-small); }
.guide-sub:empty { display: none; }
/* locked: muted, with a lock, but it can be pressed (it opens the teaser) */
.guide-toggle.locked { opacity: 0.7; }
.guide-toggle.locked .switch { display: none; }
.guide-toggle.locked .ico { color: var(--muted); }
.switch { position: relative; flex: none; width: 2.3rem; height: 1.3rem; border: 1px solid var(--line-strong); border-radius: 99rem; background: var(--panel-2); transition: background 0.15s, border-color 0.15s; }
.switch i { position: absolute; top: 50%; inset-inline-start: 0.2rem; width: 0.82rem; height: 0.82rem; margin-top: -0.41rem; border-radius: 50%; background: var(--muted); transition: inset-inline-start 0.15s, background 0.15s; }
.guide-toggle[aria-pressed="true"] .switch { background: var(--guide); border-color: var(--guide); }
.guide-toggle[aria-pressed="true"] .switch i { inset-inline-start: 1.1rem; background: #1d1634; }

/* ===== The menu as a row of buttons in the top bar =====
   The same element as the pop-up above: ui.js moves #menuPop into the top bar when the window is wide enough (body.ui-nav) and the CSS
   restyles it as a row. There is no menu button then. From NAV_FULL_W on the buttons carry their words; between NAV_W and that
   (body.ui-nav-compact) they are icons only: the words are tooltips, and stay for a screen reader (visually hidden, not removed). */
body.ui-nav #btnMenuToggle { display: none; }
body.ui-nav .topbar { flex-wrap: nowrap; }
body.ui-nav .menu-pop { position: static; display: flex; align-items: center; flex: none; gap: 0.35rem; min-width: 0; max-width: none; padding: 0; background: none; border: 0; border-radius: 0; box-shadow: none; animation: none; }
body.ui-nav .menu-pop .pop-section { padding: 0; }
body.ui-nav .menu-pop .pop-label { display: none; }
body.ui-nav .menu-pop .mode-switch .seg { padding: 0.12rem 0.6rem; gap: 0.35rem; font-size: var(--fs-small); }
body.ui-nav .menu-pop .mode-switch .seg .ico { width: 1rem; height: 1rem; }
body.ui-nav .menu-pop .pop-list, body.ui-nav .menu-pop .pop-guide { display: flex; align-items: center; gap: 0.1rem; padding: 0 0 0 0; border: 0; padding-inline-start: 0.35rem; border-inline-start: 1px solid var(--line); }
body.ui-nav .menu-pop .pop-item { width: auto; gap: 0.35rem; min-height: 1.9rem; padding: 0.15rem 0.5rem; border-radius: 0.5rem; font-size: var(--fs-small); white-space: nowrap; }
body.ui-nav .menu-pop .pop-item .ico { width: 1.1rem; height: 1.1rem; }
body.ui-nav .guide-text { display: block; }
body.ui-nav .guide-sub, body.ui-nav .guide-toggle .switch { display: none; }
body.ui-nav .guide-toggle.locked { opacity: 0.65; }   /* the state is the button itself: dim and locked, plain, or lit when GUIDE MODE is on */
body.ui-nav .guide-toggle[aria-pressed="true"] { color: var(--guide); background: rgba(226, 215, 255, 0.14); box-shadow: inset 0 0 0 1px var(--guide); }
body.ui-nav .guide-badge { display: none; }   /* the lit button says it already */
body.ui-nav .tb-title { flex: 0 1 auto; }
body.ui-nav-compact .kbd-label, body.ui-nav-compact .score-label { display: none; }
body.ui-nav-compact .kbd-btn { min-width: 2rem; padding: 0.1rem; }
body.ui-nav-compact .menu-pop .pop-item { position: relative; justify-content: center; min-width: 2rem; padding: 0.15rem 0.4rem; }
body.ui-nav-compact .menu-pop .pop-item > span:not(.ico) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  inset-inline: 0;
  top: var(--toast-top, 9rem);
  margin: 0 auto;
  width: max-content;
  max-width: min(90%, 30rem);
  padding: 0.4rem 0.9rem;
  background: var(--panel-solid);
  border: 1px solid var(--accent);
  border-radius: 0.9rem;
  text-align: center;
  font-size: var(--fs-body);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-0.4rem);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 9;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ===== Dialogs ===== */
.dlg {
  width: min(34rem, 94vw);
  max-height: 92vh;
  padding: 0;
  background: var(--panel-solid);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.dlg.wide { width: min(60rem, 96vw); }
.dlg::backdrop { background: rgba(5, 7, 12, 0.72); }
.dlg.soft[open] { animation: dlgIn 0.24s ease-out; }
.dlg.soft[open]::backdrop { animation: fadeIn 0.24s ease-out; }
@keyframes dlgIn { from { opacity: 0; transform: translateY(0.6rem) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.dlg-body { padding: 1.1rem 1.3rem 1.3rem; overflow: auto; max-height: 92vh; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.6rem; }
.dlg-title { font-size: 1.5rem; }
.dlg h3 { font-size: 1.05rem; margin: 1rem 0 0.4rem; color: var(--muted); }
.dlg h3.h-tut { color: var(--tut); }
.dlg h3.h-chal { color: var(--accent); }
.dlg-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.1rem; }
/* Settings is long at a big interface size: it scrolls, but Reset and Close always stay in view at the bottom */
#dlgSettings .dlg-actions { position: sticky; bottom: -1.3rem; margin-bottom: -1.3rem; padding: 0.6rem 0 1.3rem; background: var(--panel-solid); }
.lead { font-size: 1.1rem; color: var(--muted); margin: 0.2rem 0 0.6rem; }

.mode-switch {
  display: inline-flex;
  flex: none;
  padding: 0.15rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 99rem;
}
.seg {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 0;
  background: transparent;
  border-radius: 99rem;
  padding: 0.25rem 0.9rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}
.seg .ico { width: 1.1rem; height: 1.1rem; }
.seg:hover { color: var(--text); }
.seg[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* The difficulty level: three options, each with a tiny picture of the band (thick, medium, thin) */
.level-switch .seg { gap: 0.45rem; padding: 0.22rem 0.8rem; }
.band-hint { width: 1.7rem; height: 1rem; flex: none; }
.band-hint path { fill: none; stroke-linecap: round; }
.bh-band { stroke: currentColor; opacity: 0.4; }
.bh-line { stroke: currentColor; stroke-width: 1; stroke-dasharray: 2 2; }
.level-label { color: var(--muted); font-size: 0.9rem; font-weight: 600; }
.level-note { margin-top: 0.35rem; color: var(--muted); font-size: 0.85rem; }

/* the GUIDE MODE teaser (the button is still locked in this game): a small picture, what it is, how far the player is, Got it */
.teaser-dlg { width: min(30rem, 94vw); }
.teaser { padding: 1.3rem 1.6rem 1.2rem; text-align: center; }
.teaser-pic { display: block; width: min(14rem, 70%); height: auto; margin: 0 auto 0.5rem; overflow: visible; }
.teaser-pic .t-band { fill: none; stroke: var(--band); stroke-width: 14; stroke-linecap: round; }
.teaser-pic .t-center { fill: none; stroke: var(--center); stroke-width: 2; stroke-dasharray: 6 5; stroke-linecap: round; }
.teaser-pic .guide-line { stroke-width: 1.5; }
.teaser-pic .guide-node { stroke-width: 2; }
.teaser .dlg-title { font-size: 1.35rem; letter-spacing: 0.03em; }
.teaser-text { margin-top: 0.5rem; text-align: start; }
.teaser-state { margin-top: 0.9rem; padding: 0.6rem 0.9rem 0.7rem; border-radius: 0.4rem; background: var(--soft); text-align: start; }
.teaser-progress { font-weight: 700; }
.teaser-bar { height: 0.4rem; margin: 0.4rem 0; border-radius: 99rem; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.teaser-bar i { display: block; height: 100%; width: 0; border-radius: 99rem; background: var(--guide); }
.teaser-next { color: var(--muted); font-size: var(--fs-body); }
.teaser .dlg-actions { justify-content: center; margin-top: 1rem; }
body.contrast .teaser-state { border: 1px solid var(--line); }

/* the level dialog: three options (a picture of the band, the name, one line about the band, what is saved on that level), a warning, Switch / Cancel */
.level-dlg { width: min(36rem, 94vw); }
.level-body { padding: 1.3rem 1.5rem 1.2rem; }
.level-body .dlg-title { font-size: 1.4rem; }
.level-body .level-note { margin-top: 0.3rem; font-size: var(--fs-body); }
.level-options { display: grid; gap: 0.5rem; margin-top: 0.8rem; }
.level-opt { display: block; cursor: pointer; }
.level-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.level-card { display: flex; align-items: center; gap: 0.9rem; padding: 0.6rem 0.9rem; background: var(--panel-2); border: 2px solid var(--line); border-radius: 0.8rem; transition: border-color 0.12s, background 0.12s; }
.level-opt:hover .level-card { border-color: var(--line-strong); }
.level-opt input:checked + .level-card { border-color: var(--accent); background: rgba(255, 204, 77, 0.1); }
.level-opt input:focus-visible + .level-card { outline: 0.18rem solid var(--focus); outline-offset: 0.15rem; }
.level-card .band-hint.big { width: 3rem; height: 1.7rem; color: var(--accent); }
.level-info { display: grid; gap: 0.05rem; min-width: 0; }
.level-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.2rem 0.6rem; }
.level-name { font-size: 1.05rem; }
.level-current { padding: 0 0.5rem; border: 1px solid var(--line-strong); border-radius: 99rem; color: var(--muted); font-size: var(--fs-small); }
.level-current:empty { display: none; }
.level-opt.current .level-current { border-color: var(--accent); color: var(--accent); }
.level-band { color: var(--muted); font-size: var(--fs-body); }
.level-progress { font-size: var(--fs-body); font-weight: 600; font-variant-numeric: tabular-nums; }
/* the warning is a NOTE, not a card: a flat neutral surface with a coral bar at the start (no outline, no gold: gold means "selected" in this dialog) */
.level-warn { display: flex; align-items: flex-start; gap: 0.7rem; margin-top: 0.9rem; padding: 0.6rem 0.9rem; border-inline-start: 3px solid var(--warn); border-radius: 0.3rem; background: var(--soft); font-size: var(--fs-body); }
body.contrast .level-warn { border: 1px solid var(--line); border-inline-start: 4px solid var(--warn); }
.level-warn .ico { width: 1.3rem; height: 1.3rem; margin-top: 0.1rem; color: var(--warn); }
.level-warn b { font-weight: 700; }
.level-body .dlg-actions { margin-top: 1rem; justify-content: flex-end; }
.level-open { justify-self: start; gap: 0.5rem; min-width: 11rem; justify-content: flex-start; }
.level-open .band-hint { width: 1.7rem; height: 1rem; color: var(--accent); }
.level-open .ico { margin-inline-start: auto; width: 1rem; height: 1rem; }
[dir="rtl"] .level-open .ico { transform: scaleX(-1); }
/* on a phone the three level options must fit the dialog: no little band pictures on the segmented controls, and tighter buttons */
body.ui-tiny .level-switch .band-hint { display: none; }
body.ui-tiny .level-switch .seg { padding: 0.22rem 0.55rem; }
body.ui-tiny .level-row, body.ui-tiny .board-switches { justify-content: center; }
body.ui-tiny .level-card { gap: 0.6rem; padding: 0.5rem 0.6rem; }
body.ui-tiny .level-card .band-hint.big { width: 2.2rem; }
body.ui-tiny .level-body { padding: 1rem 0.9rem 0.9rem; }

/* Welcome: a calm screen. Title, one line, two big game cards (icon, name, one sentence, a clear Start) and Misha's Challenges across both, a quiet row underneath */
.welcome-dlg { width: min(62rem, 94vw); }   /* wide enough for the one-line sentences of both cards (Hebrew and English) from 1366 px up */
.welcome { padding: 1.4rem 1.8rem 1.2rem; text-align: center; }
.welcome .dlg-title { font-size: 1.9rem; line-height: 1.2; }
.welcome-sub { margin-top: 0.2rem; color: var(--muted); font-size: 1.1rem; }
/* the tutorial is blue everywhere in the game, so the line about it is too */
.welcome-note {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: fit-content;
  max-width: 100%;
  margin: 0.9rem auto 0;
  padding: 0.35rem 1rem;
  border: 1px solid rgba(110, 168, 255, 0.45);
  border-radius: 99rem;
  background: rgba(110, 168, 255, 0.12);
  font-size: 0.95rem;
  text-align: start;
}
.welcome-note::before { content: ""; flex: none; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--tut); }
.welcome-level { margin-top: 0.9rem; }
.level-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 0.4rem 0.8rem; }
.dlg h3.welcome-choose { margin: 1.1rem 0 0.5rem; font-size: 0.9rem; font-weight: 600; }
.mode-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; text-align: start; }
.mode-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: start;
  gap: 0.75rem;
  padding: 1.3rem 1.4rem 1.2rem;
  background: var(--panel-2);
  border: 2px solid var(--line);
  border-radius: 1rem;
  cursor: pointer;
  text-align: start;
  transition: border-color 0.15s, background 0.15s, transform 0.15s, box-shadow 0.15s;
}
.mode-card:hover { border-color: var(--accent); background: rgba(255, 204, 77, 0.07); transform: translateY(-2px); box-shadow: 0 0.5rem 1.4rem rgba(0, 0, 0, 0.35); }
.mode-card:focus-visible { border-color: var(--accent); outline: 0.2rem solid var(--focus); outline-offset: 0.2rem; }
.mode-card:active { transform: none; }
.mode-icon { display: grid; place-items: center; width: 4rem; height: 4rem; border: 1px solid rgba(255, 204, 77, 0.35); border-radius: 1rem; background: rgba(255, 204, 77, 0.13); color: var(--accent); }
.mode-icon .ico { width: 2.8rem; height: 2.8rem; }
.mode-name { display: block; font-size: 1.3rem; font-weight: 700; }
.mode-desc { display: block; margin-top: 0.2rem; color: var(--muted); font-size: 0.92rem; }
.mode-go { display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.3rem 1rem; border-radius: 99rem; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.mode-go .ico { width: 1rem; height: 1rem; }
[dir="rtl"] .mode-go .ico { transform: scaleX(-1); }
.mode-card:hover .mode-go { filter: brightness(1.08); }
/* the owner's own challenges: one wide card under the two games, icon - text - button in one row */
.mode-card.wide { grid-column: 1 / -1; grid-template-rows: none; grid-template-columns: auto 1fr auto; align-items: center; justify-items: stretch; gap: 1.1rem; padding-block: 0.9rem; }
.mode-card.wide .mode-icon { width: 3.2rem; height: 3.2rem; }
.mode-card.wide .mode-icon .ico { width: 2.2rem; height: 2.2rem; }
.mode-card.wide .mode-go { justify-self: end; }
/* a game with one level only: its rows of level controls give way */
.field[hidden], .board-level[hidden], .board-fixed[hidden] { display: none; }
.welcome-more { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.4rem 0.8rem; margin-top: 1rem; }

/* Delete everything: the warning, the list of what goes, what stays, then Cancel (first, focused) and the red button */
.wipe-dlg { width: min(34rem, 94vw); }
.wipe { padding: 1.4rem 1.6rem 1.2rem; }
.wipe-icon { display: inline-grid; place-items: center; width: 3rem; height: 3rem; margin-bottom: 0.6rem; border: 1px solid rgba(255, 107, 129, 0.5); border-radius: 50%; background: rgba(255, 107, 129, 0.12); color: var(--danger); }
.wipe-icon .ico { width: 1.5rem; height: 1.5rem; }
.wipe .dlg-title { font-size: 1.4rem; }
.wipe-intro { margin-top: 0.6rem; color: var(--muted); }
.wipe-list { margin: 0.4rem 0 0; padding-inline-start: 1.3rem; display: grid; gap: 0.25rem; }
.wipe-list li::marker { color: var(--danger); }
.wipe-final { margin-top: 0.8rem; font-weight: 700; }
.wipe-keeps { margin-top: 0.4rem; color: var(--muted); font-size: var(--fs-body); }
.wipe .dlg-actions { margin-top: 1.1rem; }

/* the question about the animated demos */
.ask-dlg { width: min(30rem, 94vw); }
.ask { padding: 1.5rem 1.6rem 1.3rem; text-align: center; }
.ask-icon { display: inline-grid; place-items: center; width: 3.2rem; height: 3.2rem; margin-bottom: 0.7rem; border: 1px solid rgba(110, 168, 255, 0.45); border-radius: 50%; background: rgba(110, 168, 255, 0.14); color: var(--tut); }
.ask-icon .ico { width: 1.4rem; height: 1.4rem; }
.ask .dlg-title { font-size: 1.25rem; line-height: 1.35; }
.ask-note { margin-top: 0.6rem; color: var(--muted); }
.ask .dlg-actions { justify-content: center; margin-top: 1.2rem; }
.field-note { margin: 0; font-size: 0.85rem; color: var(--muted); }
.field-note[hidden] { display: none; }

.field { display: grid; gap: 0.25rem; margin-top: 0.8rem; }
.field label, .field .lbl { color: var(--muted); font-size: 0.9rem; }
.field .mode-switch { justify-self: start; }
.field.check { display: flex; align-items: center; gap: 0.6rem; }
.field.check label { color: var(--text); font-size: 1rem; }
.field input[type="checkbox"] { width: 1.3rem; height: 1.3rem; accent-color: var(--accent); flex: none; }
.field input[type="text"], .field select, .board-tools select {
  min-height: 2.5rem;
  padding: 0.3rem 0.6rem;
  background: var(--bg);
  border: 1px solid #6b7596;
  border-radius: 0.5rem;
  color: var(--text);
}
body.contrast .field input[type="text"], body.contrast .field select, body.contrast .board-tools select { border-color: #fff; }
.slider-row { display: flex; align-items: center; gap: 0.8rem; }
.slider-row input[type="range"] { flex: 1; accent-color: var(--accent); height: 1.6rem; }
.slider-row output { min-width: 3.2rem; text-align: end; font-variant-numeric: tabular-nums; }

/* Stage menu */
.stage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: 0.6rem; }
.stage-card {
  display: grid;
  gap: 0.2rem;
  padding: 0.5rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  cursor: pointer;
  text-align: start;
}
.stage-card.tut { border-color: rgba(110, 168, 255, 0.45); }
.stage-card.chal { border-color: rgba(255, 204, 77, 0.4); }
.stage-card:hover { border-color: #fff; }
.stage-card.current.tut { border-color: var(--tut); box-shadow: 0 0 0 2px var(--tut) inset; }
.stage-card.current.chal { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.stage-card .thumb { width: 100%; aspect-ratio: 1080 / 720; background: var(--stage-bg); border-radius: 0.4rem; }
.stage-card .thumb path { fill: none; stroke-width: 20; stroke-linecap: round; stroke-linejoin: round; }
.stage-card.tut .thumb path { stroke: var(--tut); }
.stage-card.chal .thumb path { stroke: var(--accent); }
.stage-card.done .thumb path { stroke: var(--ok); }
.stage-card .name { font-weight: 600; }
.stage-card .meta { font-size: 0.8rem; color: var(--muted); }
.stage-card.done .meta { color: var(--ok); }

/* Leaderboard */
.tabs { margin-bottom: 0.7rem; }
.board-switches { display: flex; flex-wrap: wrap; align-items: center; gap: 0.2rem 1.4rem; margin-bottom: 0.7rem; }
.board-switches .tabs { margin-bottom: 0; }
.board-level { display: flex; align-items: center; gap: 0.5rem; }
.submit-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.4rem 1rem 1rem; }
.submit-box[hidden] { display: none; }
.your-score { color: var(--accent); font-weight: 700; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; align-items: end; }
.form-row .field { margin-top: 0.4rem; }
/* one plain sentence about who sees the name, right above the Save button */
.form-note { margin-top: 0.7rem; font-size: 0.9rem; color: var(--text); }
.form-msg { min-height: 1.3rem; margin-top: 0.5rem; }
.form-msg.ok { color: var(--ok); }
.form-msg.err { color: var(--danger); }
.board-tools { display: flex; align-items: center; gap: 0.6rem; margin: 1rem 0 0.5rem; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); max-height: 40vh; }
.board-table { width: 100%; border-collapse: collapse; }
.board-table th, .board-table td { padding: 0.45rem 0.7rem; text-align: start; border-bottom: 1px solid var(--line); }
.board-table th { position: sticky; top: 0; background: var(--panel-solid); color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.board-table td.num, .board-table th.num { font-variant-numeric: tabular-nums; }
.board-table tr.me td { background: rgba(255, 204, 77, 0.14); font-weight: 700; }
.board-table tr:last-child td { border-bottom: 0; }
.board-empty { padding: 1rem; text-align: center; color: var(--muted); }
.board-mode { margin-top: 0.7rem; font-size: 0.85rem; color: var(--muted); }

.final-score { font-size: 4rem; font-weight: 800; color: var(--accent); text-align: center; line-height: 1.1; }
.final .lead { text-align: center; }
.final-ideal { text-align: center; color: var(--muted); margin-top: 0.4rem; }
.final-level { text-align: center; color: var(--accent); font-weight: 600; margin-top: -0.3rem; }
.final-guide { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 0.4rem 0.9rem; margin: 0.9rem auto 0; padding: 0.55rem 1rem; border: 1px solid var(--guide); border-radius: var(--radius); background: rgba(226, 215, 255, 0.08); }
.final-guide[hidden] { display: none; }
.final-guide .ico { width: 1.6rem; height: 1.6rem; color: var(--guide); }
.final-guide p { flex: 1 1 14rem; text-align: start; }
.final-guide .btn { border-color: var(--guide); color: var(--guide); }

/* ===== Smaller laptop and phone widths =====
   These follow the EFFECTIVE window size (window size divided by the interface size, set by ui.js on <body>), because a media
   query cannot see the interface size: a 1366 px window at 200% is laid out like a 683 px one.
     ui-narrow  up to 62rem wide (992 px at the normal size)    ui-tiny  up to 40rem wide    ui-short  under 30rem tall */
body.ui-narrow .topbar { flex-wrap: wrap; }
body.ui-narrow .menu-game { display: none; }
body.ui-narrow .tool-group + .tool-group { padding-inline-start: 0; border-inline-start: 0; }
/* too narrow for the pills and the big button side by side: the button gets its own row under them (centred, a wide target), the whole width on a phone */
body.ui-stack .statusrow { display: flex; flex-direction: column; align-items: center; }
body.ui-stack .status-main { width: 100%; }
body.ui-stack .tut-skip { order: 9; align-self: center; }   /* stacked: below the pills and the big button */
body.ui-stack .primary-wrap { width: min(100%, 26rem); }
body.ui-stack .primary-wrap .btn { flex: 1; }
body.ui-tiny .primary-wrap { width: 100%; }
/* the keyboard button keeps only its icon when the window is narrow (the top bar would wrap; its tooltip has the words) */
body.ui-narrow .kbd-label { display: none; }
body.ui-narrow .kbd-btn { min-width: 2rem; padding: 0.1rem; }
body.ui-narrow .pips { display: none; }   /* the numbers say the same; without the dots (up to 15) the two pills always fit beside the big button */
body.ui-narrow .btn-hint { display: none; }   /* (the keys are in the tooltip; with the keyboard focus they show above the button, see .btn-hint) */
body.ui-tiny .btn.tool .btn-text { display: none; }
/* below 1200 effective px "Delete everything" is only its icon: with the words it would push the toolbar onto a second row (English lessons, whose key hints are long;
   ui.js sets ui-roomy from 1200 px up). The tooltip and the dialog have the words */
body:not(.ui-roomy) .wipe-label { display: none; }
body:not(.ui-roomy) .btn.wipe-btn { min-width: 2.4rem; padding: 0.3rem; }
body:not(.ui-roomy) .wipe-wrap { padding-right: 0.6rem; }
body.ui-tiny .btn.tool { padding: 0.3rem; min-width: 2.4rem; }
/* the match sentence goes on its own line only when the two pills no longer fit side by side (they need about 620 px) */
body.ui-tiny .stat-msg { max-width: none; white-space: normal; flex-basis: 100%; text-align: center; }
body.ui-tiny .stat-match { min-width: 0; flex-wrap: wrap; justify-content: center; }
body.ui-tiny .pill { padding-inline: 0.6rem; gap: 0.3rem; }
/* the points pill must fit a phone: the "left" count loses its fixed width, so the ideal number fits beside it */
body.ui-tiny .stat-points #pointsLeft, html[lang="en"] body.ui-tiny .stat-points #pointsLeft { min-width: 0; }
body.ui-tiny .stat-ideal { padding-inline-start: 0.4rem; }
body.ui-tiny .form-row, body.ui-tiny .mode-cards { grid-template-columns: 1fr; }
/* the welcome cards lie flat on a phone: icon beside the text, the Start button under them */
body.ui-tiny .mode-card { grid-template-columns: auto 1fr; grid-template-rows: auto auto; align-items: center; column-gap: 0.9rem; row-gap: 0.6rem; padding: 0.8rem 0.9rem; }
body.ui-tiny .mode-icon { width: 3.2rem; height: 3.2rem; }
body.ui-tiny .mode-icon .ico { width: 2rem; height: 2rem; }
body.ui-tiny .mode-go { grid-column: 1 / -1; justify-self: stretch; justify-content: center; }
body.ui-tiny .mode-card.wide .mode-go { justify-self: stretch; }
body.ui-tiny .welcome { padding: 1.2rem 1rem 1rem; }
body.ui-tiny .welcome .dlg-title { font-size: 1.6rem; }
body.ui-tiny .welcome-more { justify-content: center; }
/* a very short window: the stage strip is left out (the menu lists every stage) and a long tutorial sentence scrolls instead of eating the canvas */
body.ui-short .stripbar { display: none; }
body.ui-short .hint { max-height: 2.7rem; overflow: auto; }
body.ui-short .score-of { display: none; }
/* ... and every row counts: the pills lose the dots and the "left" count, the score chip its words, so the big button still fits beside the pills and the top bar stays one row */
body.ui-short .pips, body.ui-short #pointsLeft, body.ui-short .score-label { display: none; }
