:root {
  --bg: #161618;
  --panel: #202226;
  --panel-2: #2a2d33;
  --text: #ececec;
  --muted: #a4abb2;
  --accent: #3fa35b;
  --accent-2: #4f8fd6;
  --warn: #ffd84a;
  --c-white: #f2f2f2;
  --c-yellow: #ffd500;
  --c-red: #d62828;
  --c-orange: #ff7a00;
  --c-green: #12a84a;
  --c-blue: #1e5bff;
  --c-unknown: #555;
  --c-empty: #33363c;
  --ui-zoom: 1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 "Segoe UI", system-ui, sans-serif;
}

[hidden] { display: none !important; }

.screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: #1c1e22;
  border-bottom: 1px solid #2c2f35;
}

.topbar h2 {
  margin: 0;
  font-size: 20px;
  white-space: nowrap;
}

.hint {
  flex: 1;
  color: var(--warn);
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color .2s;
}

.hint.flash { color: #7ee08f; }
.scan .hint { white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; }
.scan .hint.count-hint { color: var(--warn); }

select, button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid #3a3e46;
  border-radius: 8px;
  padding: 7px 12px;
}

button { cursor: pointer; font-weight: 600; }
button:hover:not(:disabled) { background: #343842; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: #2e7d43; border-color: #4cbb6a; color: #fff; }
button.primary:hover:not(:disabled) { background: #286c3a; }
button.ghost { background: transparent; }

kbd {
  font: 12px/1 Consolas, monospace;
  padding: 2px 5px;
  border: 1px solid #4a4f58;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #2a2d33;
}

/* ---------- стартовый экран ---------- */

.welcome-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: 32px 20px;
  text-align: center;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* Мини-демо сканирования: «камера» с кубиком и развёртка рядом, рисует demo.js. */
.demo { display: flex; align-items: center; gap: 18px; }
.demo-cam { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.demo-cam canvas {
  display: block;
  width: 260px;
  height: 195px;
  border-radius: 10px;
  background: #111316;
}
.demo-hint {
  width: 260px;
  min-height: 2.8em;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--warn);
  transition: color .2s;
}
.demo-hint.flash { color: #7ee08f; }
.demo-net {
  display: grid;
  grid-template-columns: repeat(4, 30px);
  grid-template-rows: repeat(3, 30px);
  gap: 3px;
  margin-bottom: 2.8em;
}
.demo-net .face { gap: 1px; padding: 2px; border-radius: 4px; }
.demo-net .cell { border-radius: 1px; }

@media (max-width: 420px) {
  .demo { gap: 12px; }
  .demo-cam canvas, .demo-hint { width: 196px; }
  .demo-cam canvas { height: 147px; }
  .demo-net { grid-template-columns: repeat(4, 26px); grid-template-rows: repeat(3, 26px); }
}
@media (max-width: 360px) {
  .demo-cam canvas, .demo-hint { width: 160px; }
  .demo-cam canvas { height: 120px; }
}

.hero h1 {
  margin: 4px 0 0;
  font-size: clamp(32px, 6vw, 48px);
  line-height: 1.1;
}

.lead {
  margin: 0;
  max-width: 520px;
  font-size: 18px;
  color: #cfd3d8;
}

button.start {
  margin-top: 6px;
  padding: 14px 44px;
  font-size: 22px;
  border-radius: 12px;
}

.camera-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: min(860px, 100%);
  margin: 0;
  padding: 0;
  list-style: none;
}

.steps li {
  padding: 18px 18px 16px;
  background: var(--panel);
  border-radius: 12px;
  text-align: start;
}

.step-num {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.steps h2 { margin: 10px 0 6px; font-size: 18px; }
.steps p { margin: 0; color: var(--muted); }

.about {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 8px 20px 32px;
  color: #cfd3d8;
}

.about h2 { margin: 28px 0 10px; font-size: 22px; color: var(--text); }
.about p { margin: 0 0 10px; }
.about ol { margin: 0; padding-inline-start: 22px; }
.about li { margin-bottom: 6px; }
.about ol + p { margin-top: 10px; }
.about a { color: #a8f0d8; }

.about details {
  margin-bottom: 8px;
  padding: 10px 14px;
  background: var(--panel);
  border-radius: 10px;
}
.about summary { cursor: pointer; font-weight: 600; color: var(--text); }
.about details p { margin: 8px 0 0; color: var(--muted); }

.site-foot {
  padding: 18px;
  border-top: 1px solid #2c2f35;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- скан ---------- */

.scan-body {
  flex: 1;
  display: flex;
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

.camera {
  flex: 1;
  display: flex;
  /* Кадр начинается на одной высоте с результатами, даже в высоком окне. */
  align-items: flex-start;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

.stage {
  position: relative;
  width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}

.stage video, .stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.stage video { object-fit: fill; }
.stage.mirror video { transform: scaleX(-1); }
#scanFeedback { pointer-events: none; }

button.toggle.on { background: #3a4a5c; border-color: var(--accent-2); }

.camera-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.scan-pause { flex-direction: column; gap: 16px; background: var(--bg); }

/* Поверх видео, не отражается вместе с ним. Без текста (фонарик горит, света хватает) — одна кнопка. */
.light-note {
  position: absolute;
  inset-inline: 8px;
  bottom: 8px;
  width: fit-content;
  max-width: calc(100% - 16px);
  margin-inline: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgb(0 0 0 / 0.72);
  color: #fff;
  font-size: 14px;
  line-height: 1.3;
  text-align: center;
}
.light-note button { flex: none; }

.side {
  width: 400px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.panel {
  background: var(--panel);
  border-radius: 10px;
  padding: 12px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
}

.count { color: var(--text); }
.count, .manual-progress, .paint-count { direction: ltr; unicode-bidi: isolate; }

.face {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  background: #0e0e10;
  border-radius: 6px;
  aspect-ratio: 1;
}

.face.big { width: 96px; flex: none; }

.preview-panel { display: flex; align-items: center; gap: 14px; }
.preview-panel h2 { margin-bottom: 4px; }
.preview-note { margin: 0; color: var(--muted); font-size: 13px; }

.cell { border-radius: 3px; background: var(--c-empty); }
.cell.white, .net-face .cell.white { background: var(--c-white); }
.cell.yellow, .net-face .cell.yellow { background: var(--c-yellow); }
.cell.red, .net-face .cell.red { background: var(--c-red); }
.cell.orange, .net-face .cell.orange { background: var(--c-orange); }
.cell.green, .net-face .cell.green { background: var(--c-green); }
.cell.blue, .net-face .cell.blue { background: var(--c-blue); }
.cell.unknown { background: var(--c-unknown); }

.net {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(3, auto);
  gap: 6px;
  /* Развёртка 4×3 сжимается, чтобы вся колонка помещалась по высоте окна. */
  /* Внутри увеличенной панели vh тоже умножается на --ui-zoom, поэтому высота окна делится обратно. */
  width: min(100%, calc((100vh / var(--ui-zoom) - 400px) * 4 / 3));
  width: min(100%, calc((100dvh / var(--ui-zoom) - 400px) * 4 / 3));
  min-width: 200px;
  margin: 0 auto;
}
.checking .net {
  width: min(100%, calc((100vh / var(--ui-zoom) - 470px) * 4 / 3));
  width: min(100%, calc((100dvh / var(--ui-zoom) - 470px) * 4 / 3));
}

.net-face {
  position: relative;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: inherit;
  min-width: 0;
  touch-action: manipulation;
}
.net-face[aria-disabled="true"] { cursor: default; }
.net-face[role="button"][aria-disabled="false"] { cursor: pointer; }
.net-face[role="button"][aria-disabled="false"]:hover { filter: brightness(1.12); }
.net-face:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.net-face button.cell { padding: 0; border: 0; min-width: 0; }
.net-face button.cell:disabled { opacity: 1; pointer-events: none; }
.net-face button.cell:hover:not(:disabled) { filter: brightness(1.2); }
.net-face button.cell:focus-visible { outline: 3px solid #fff; outline-offset: -3px; }
.net-face.oriented .face { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.net-face.saved .face { animation: pop .5s ease-out; }
.net-face.count-warning-face .face { outline: 2px solid var(--warn); outline-offset: 1px; }
.net-face .cell.count-warning { box-shadow: inset 0 0 0 2px var(--warn), inset 0 0 0 3px #151515; }
.net-face .cell.count-warning-center { outline: 1px dashed #151515; outline-offset: -3px; }

@keyframes pop {
  0% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.toolbar button { padding: 7px 6px; font-size: 14px; }
.toolbar #btnSolve { grid-column: 1 / -1; }
.toolbar .train-button { grid-column: 1 / -1; border-color: #68d6b3; color: #a8f0d8; font-weight: 700; }


.scan-problem { margin: 10px 0 0; color: #ffb36b; font-size: 13px; }

/* Заголовок и действия занимают свободные ниши креста. Верхняя правая — для подсказки поворота. */
.net-panel .net-heading {
  grid-area: 1 / 1;
  align-self: center;
  min-width: 0;
  margin: 0;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
  line-height: 1.2;
}
.net-tools {
  grid-area: 3 / 3 / 4 / 5;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.net-tools button { max-width: 100%; min-height: 44px; font-size: 14px; }
.manual-tools p { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.paint-palette { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.paint-color { display: flex; align-items: center; gap: 7px; padding: 8px; font-size: 13px; text-transform: capitalize; }
.paint-color .cell { display: block; width: 24px; height: 24px; border: 1px solid #777; }
.paint-color .eraser { background: linear-gradient(135deg, transparent 44%, #a4abb2 46%, #a4abb2 54%, transparent 56%); }
.paint-color[aria-pressed="true"] { outline: 2px solid #7ee08f; outline-offset: 2px; }
.paint-color.over-count { border-color: #ffb36b; color: #ffb36b; }

/* Пары наклеек через стык, которые человек сверяет с кубиком; мигает пара стыка, поворот через который показывает анимация. */
.seams { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.seam {
  position: absolute;
  border: 3px solid #ffd23f;
  border-radius: 9px;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .85), inset 0 0 0 2px rgba(0, 0, 0, .55);
}
.seam.active { animation: seam-pulse .9s ease-in-out infinite alternate; }
@keyframes seam-pulse {
  from { border-color: #ffd23f; }
  to { border-color: #fff6c8; box-shadow: 0 0 0 2px rgba(0, 0, 0, .85), 0 0 10px 2px rgba(255, 210, 63, .7); }
}

/* Подсказка поворота в пустом углу развёртки, над зелёной и оранжевой гранями. */
.turn-hint {
  grid-column: 3 / 5;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.turn-hint[hidden] { display: none; }
.turn-hint canvas { width: 56%; aspect-ratio: 1; flex: none; }
.turn-hint canvas.mirror { transform: scaleX(-1); }
.turn-hint p { margin: 0; font-size: 12px; font-weight: 600; color: var(--muted); }

.check-panel h2 { margin-bottom: 6px; }
.check-panel p { margin: 0 0 8px; }
.check-hold { font-weight: 600; }
.check-note { color: var(--muted); font-size: 13px; }


/* ---------- сборка ---------- */

.solve-topbar { align-items: flex-start; }
.solve-heading { flex: 1; min-width: 0; }
.solve-topbar h2 { color: var(--muted); font-size: 14px; font-weight: 600; }
.move-count { flex: none; margin: 2px 0 0 auto; color: #bfe0bf; font-weight: 700; font-size: 16px; }

.progress { height: 4px; background: #24262b; }
#progressBar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

.solve-body {
  flex: 1;
  display: flex;
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

.viewport {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.cube-frame { flex: 1; min-height: 0; display: flex; flex-direction: column; border-radius: 10px; overflow: hidden; }

.cube3d {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(#28303a, #121418);
  cursor: grab;
  touch-action: pan-y pinch-zoom;
}
.cube3d:active { cursor: grabbing; }
.cube3d canvas { display: block; position: relative; z-index: 1; }
.cube3d .cube-celebration {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}
.cube3d .cube-celebration[hidden] { display: none; }
@media (prefers-reduced-motion: reduce) {
  .cube3d .cube-celebration { display: none; }
}
.cube-miniature {
  position: absolute;
  z-index: 2;
  top: 10px;
  right: 10px;
  width: var(--miniature-size, 100px);
  height: var(--miniature-size, 100px);
  border: 1px solid rgba(190, 210, 230, .25);
  border-radius: 8px;
  box-sizing: border-box;
  pointer-events: none;
}
.pill {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(10, 10, 12, .8);
  font-weight: 700;
}

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}
.banner > div { min-width: 0; }

.swatch {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 2px solid #0c0c0e;
}
.swatch.none { display: none; }

.banner-title { font-size: 22px; font-weight: 700; }
.banner-title.done { color: #a5dca0; }
.banner-how {
  display: grid;
  align-items: center;
  min-height: 2lh;
  margin-top: 2px;
  color: #d0d4d8;
  font-size: 14px;
}
.banner-how > span, .banner-how-reserve > span { grid-area: 1 / 1; }
/* All possible captions share a hidden grid cell, reserving their maximum
   wrapped height at this width without clipping longer text on small screens. */
.banner-how-reserve { display: grid; visibility: hidden; pointer-events: none; }

.cube-legend {
  flex: none;
  padding: 0 12px;
  border: 1px solid #30343c;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  zoom: var(--ui-zoom);
}
.cube-legend summary { padding: 8px 0; cursor: pointer; }
.cube-legend summary:hover { color: var(--text); }
.cube-legend dl { margin: 0; }
.cube-legend dl > div { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; margin: 8px 0; }
.cube-legend dt { color: var(--text); }
.cube-legend dd { margin: 0; }
.cube-legend p { margin: 10px 0 12px; }

.moves {
  width: 340px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 10px;
  padding: 12px 6px 12px 12px;
  min-height: 0;
}

.moves h2 { margin: 0 0 8px; font-size: 18px; }

.moves ol {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0 6px 0 0;
  overflow-y: auto;
}

.moves li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.moves li:hover { background: #2b2f36; }
.moves li .num { width: 24px; text-align: end; color: #a0aab0; font-weight: 700; }
.moves li .text { flex: 1; white-space: pre; font-family: Consolas, monospace; }
.moves li .dot { width: 9px; height: 9px; border-radius: 50%; background: transparent; }
.moves li.done .text { color: #96ba9c; }
.moves li.done .dot { background: #78be8c; }
.moves li.current { background: #465666; }
.moves li.current .text { color: #fff; }

/* Lessons use the same cube and cursor as the short-solution player. */
.training-panel { width: 350px; flex: none; min-height: 0; overflow-y: auto; background: var(--panel); border-radius: 10px; padding: 16px; zoom: var(--ui-zoom); }
.training-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; color: #a8f0d8; }
.training-top select { width: auto; padding: 5px; font-size: 13px; }
.training-files { display: flex; gap: 8px; }
.training-files button { flex: 1; min-width: 0; padding: 7px 4px; font-size: 13px; }
.training-animation { display: flex; align-items: center; gap: 10px; margin: 10px 0 14px; color: var(--muted); font-size: 12px; }
.repair-panel { flex: none; max-height: 45%; overflow-y: auto; padding: 10px 14px; border: 2px solid #ffd166; border-radius: 10px; background: #1b1a12f2; color: var(--text); font-size: var(--repair-font, 15px); line-height: 1.4; }
.repair-panel h3 { margin: 0 0 4px; font-size: 1.13em; color: #ffd166; }
.repair-panel ul { margin: 0; padding-inline-start: 20px; }
.repair-panel li + li { margin-top: 4px; }
.demo-status { position: absolute; top: 52px; left: 12px; max-width: calc(100% - 24px); padding: 5px 9px; border-radius: 6px; background: #142d26e6; color: #b5f4d6; font-size: 12px; pointer-events: none; }
#trainingFileStatus:empty { display: none; }
.training-resume { padding: 9px; border-inline-start: 3px solid #68d6b3; background: #20362f; font-size: 12px; line-height: 1.5; }
.training-stages { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 16px; }
.training-stage { flex: 1; min-width: 28px; padding: 5px 3px; font-size: 12px; border-radius: 6px; text-align: center; }
.training-stage.selected { border-color: #68d6b3; background: #21433b; color: #d5fff0; }
.training-stage.complete { color: #a8f0d8; }
.training-stage.complete:not(.selected) { background: #20362f; }
.training-guide { display: block; margin: 0 0 14px; color: #a8f0d8; font-size: 12px; }
.site-foot a { color: #a8f0d8; }
.site-foot p { margin: 0 0 8px; }
.languages a[aria-current] { color: var(--text); font-weight: 600; text-decoration: none; }
.lang-offer { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 6px 16px; font-size: 14px; color: #d5fff0; background: #20362f; }
.lang-offer a { color: #d5fff0; }
.lang-offer button { min-height: 32px; padding: 2px 10px; font-size: 18px; line-height: 1; color: inherit; background: transparent; border: 0; }
.training-prompt { margin: 0; padding: 8px 16px; font-size: 13px; line-height: 1.4; text-align: center; color: #d5fff0; background: #20362f; }
.training-kicker { font-size: 12px; font-weight: 700; color: #a8f0d8; }
.training-lesson h2 { margin: 4px 0 16px; font-size: 23px; }
.training-section { margin-bottom: 14px; }
.training-section h3 { margin: 0 0 5px; font-size: 13px; color: #a8f0d8; }
.training-section p, .training-basics p { margin: 0; font-size: 14px; line-height: 1.55; }
.training-formula { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 8px 0; font-family: Consolas, monospace; }
.training-formula span { padding: 4px 6px; background: #131b20; border-radius: 4px; white-space: nowrap; }
.training-formula .current { background: #a8f0d8; color: #142d26; font-weight: 700; }
.training-muted { font-size: 12px; line-height: 1.5; color: var(--muted); }
.training-warning, .training-checkpoint { border-inline-start: 3px solid #68d6b3; background: #20362f; padding: 10px; border-radius: 5px; }
.training-warning { border-color: #ffba70; background: #3b3024; }
.training-warning h3 { color: #ffca91; }
.training-basics, .training-focus { margin-top: 16px; font-size: 13px; line-height: 1.5; }
.training-basics summary, .training-focus summary { cursor: pointer; color: #a8f0d8; }
.training-focus p { font-size: 13px; line-height: 1.55; }
.training-basics p { margin-top: 10px; color: var(--muted); font-size: 12px; }
.training-target { margin: 0 0 16px; padding: 10px; border: 1px solid #3a4a45; border-radius: 8px; background: #192922; }
.training-target figcaption { margin-bottom: 10px; font-size: 13px; font-weight: 600; color: #a8f0d8; }
.training-target-body { display: flex; align-items: center; gap: 12px; }
.training-target-body p { flex: 1; margin: 0; font-size: 11px; }
.training-net { --sticker: 11px; display: grid; flex: none; grid-template-columns: repeat(4, max-content); grid-template-rows: repeat(3, max-content); gap: 5px; }
.training-net-face { display: grid; grid-template-columns: repeat(3, var(--sticker)); grid-template-rows: repeat(3, var(--sticker)); gap: 2px; padding: 2px; border-radius: 4px; background: #0b0b0d; }
.training-net-face i { display: flex; align-items: center; justify-content: center; border-radius: 2px; color: #111; font: 700 8px/1 system-ui, sans-serif; }
.training-net-face i.kept, .training-net-face i.done { filter: brightness(0.55) saturate(0.85); }
.training-net-face i.todo { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.75), 0 0 4px rgba(255, 255, 255, 0.45); }
.training-net-face i.irrelevant.todo { color: #fff; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.55); }
.training-net-face i.irrelevant.done { color: #fff; }
.training-net-face i.current { outline: 2px solid #ff3df0; outline-offset: 0; z-index: 1; }
.training-rule { padding: 10px 12px; border: 1px solid #4a7a69; border-radius: 8px; background: #1b2f28; }
.training-rule p { font-size: 14px; line-height: 1.5; color: #e9fff6; }
.training-hold p { font-size: 13px; }
.training-modes { display: flex; gap: 0; margin-top: 10px; }
.training-modes button { flex: 1; padding: 7px 6px; font-size: 13px; border-radius: 0; }
.training-modes button:first-child { border-radius: 6px 0 0 6px; }
.training-modes button:last-child { border-radius: 0 6px 6px 0; }
.training-modes button.selected { background: #21433b; border-color: #68d6b3; color: #d5fff0; font-weight: 700; }
.training-mode-note { margin: 6px 0 0; }
.training-stats { margin: 0 0 14px; font-size: 12px; color: #ffe08a; }
.training-quiz { margin: 0 0 14px; padding: 12px; border: 1px solid #c58cf0; border-radius: 8px; background: #2a2236; }
.training-quiz .training-kicker { color: #e2c2ff; }
.training-question { margin: 6px 0 10px; font-size: 15px; line-height: 1.5; }
.training-options { display: grid; gap: 6px; }
.training-options button { text-align: start; padding: 8px 10px; font-size: 14px; }
.training-feedback { margin: 10px 0 0; padding: 7px 9px; border-radius: 5px; background: #3b2a24; color: #ffd0b0; font-size: 13px; line-height: 1.45; }
.training-feedback.ok { background: #20362f; color: #c9f7e5; }
.training-quiz-tools { display: flex; justify-content: flex-end; margin-top: 10px; }
.training-quiz-tools button { padding: 5px 10px; font-size: 12px; }
.training-block-title { font-weight: 700; color: #fff; margin-bottom: 4px !important; }
.training-piece { font-weight: 700; color: #ffc6f6; margin-bottom: 4px !important; }
.training-section .training-muted { margin-top: 4px; font-size: 12px; }
.training-formula-title { margin: 6px 0 0; font-size: 13px; color: #a8f0d8; }
/* Формула — одна строка ходов; группа формулы обведена рамкой, текущая группа — чуть ярче.
   Подписи групп не стоят под каждым ходом: подпись текущего шага показана отдельно под формулой. */
.training-formula { gap: 6px; }
.training-chunk { display: inline-flex; flex: none; gap: 2px; padding: 2px; border-radius: 6px; border: 1px solid #2b353b; background: #1a2226; }
.training-chunk.active { border-color: #4a7a69; }
.training-formula .done { color: #7d9b8f; }
.training-step { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 6px; margin: 0 0 3px; font-size: 13px; color: #fff; }
.training-step-kicker { color: var(--muted); }
.training-step-move { padding: 1px 6px; border-radius: 4px; background: #a8f0d8; color: #142d26; font: 700 13px/1.4 Consolas, monospace; }
.training-step-label { font-weight: 600; }
.training-gesture { margin: 0 0 14px; font-size: 13px; color: #e9fff6; }
.training-bottom { display: flex; gap: 12px; align-items: center; margin: 0 0 16px; padding: 10px; border: 1px solid #3a4a45; border-radius: 8px; background: #192922; }
.training-bottom figcaption { display: flex; flex-direction: column; gap: 4px; flex: 1; font-size: 11px; line-height: 1.45; color: var(--muted); }
.training-bottom strong { font-size: 13px; color: #a8f0d8; }
.training-bottom-grid { --cell: 20px; --band: 8px; --label: 10px; display: grid; flex: none; grid-template-columns: var(--label) var(--band) repeat(3, var(--cell)) var(--band) var(--label); grid-template-rows: var(--label) var(--band) repeat(3, var(--cell)) var(--band) var(--label); gap: 2px; padding: 3px; border-radius: 5px; background: #0b0b0d; }
.training-bottom-grid i { border-radius: 3px; }
.training-bottom-grid i.band { border-radius: 2px; opacity: 0.9; }
.training-bottom-grid i.marked { outline: 2px solid #ff3df0; outline-offset: 0; z-index: 1; }
.training-bottom-grid b { display: flex; align-items: center; justify-content: center; font: 700 9px/1 system-ui, sans-serif; color: #9aa6a0; }
.training-self { margin-top: 12px; font-size: 13px; line-height: 1.5; }
.training-self summary { cursor: pointer; color: #ffe08a; }
.training-self p { margin: 8px 0; font-size: 13px; }
.training-self-go { width: 100%; }
.practice .moves li:not(.done):not(.current) .text, .quiz-active .moves li.current .text { filter: blur(4px); }
.train-mode .moves { width: 200px; }
.train-mode .moves li { font-size: 12px; }
.train-mode .moves li .text { white-space: normal; }
.train-mode .move-count { font-size: 13px; }
@media (min-width: 901px) and (max-width: 1200px) {
  .train-mode .moves { display: none; }
  .training-panel { width: 330px; }
}

.solve-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 16px 14px;
  background: #1c1e22;
  border-top: 1px solid #2c2f35;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px;
  border: 1px solid #33373f;
  border-radius: 12px;
  background: #22252b;
}
.control-group button { white-space: nowrap; }

/* Wider, evenly sized Solve controls; phone layouts override the column count. */
.solve:not(.train-mode) .solve-foot {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 320px));
  align-items: stretch;
}
.solve:not(.train-mode) .control-group { min-width: 0; }
.solve:not(.train-mode) .control-group button {
  flex: 1;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* ---------- модальное окно ---------- */

.lesson-choice {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  box-sizing: border-box;
  padding: 24px;
  border: 1px solid #6e8798;
  border-radius: 14px;
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 12px 60px #000b;
}
.lesson-choice::backdrop { background: #000b; }
.lesson-choice h2 { margin: 0 0 12px; font-size: 22px; }
.lesson-choice p { margin: 0 0 22px; line-height: 1.5; color: #d4d8dc; }
.lesson-choice-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.lesson-choice-actions button { flex: 1 1 150px; min-height: 44px; }

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .55);
  z-index: 10;
}

.card {
  width: min(520px, calc(100vw - 32px));
  padding: 20px 22px;
  background: #24272d;
  border: 1px solid #3a3e46;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}

.card h3 { margin: 0 0 10px; font-size: 20px; }
.card p { margin: 0 0 18px; color: #d4d8dc; }
.card button { float: inline-end; }
.card::after { content: ""; display: block; clear: both; }

/* ---------- большой экран ---------- */

/* Панели и стартовая страница свёрстаны в пикселях и на большом мониторе остаются мелкими, поэтому там
   они увеличиваются целиком. Видео и 3D-куб занимают оставшееся место сами. У .welcome-body высота
   в vh, под zoom она выросла бы вместе с ним, поэтому увеличиваются её блоки, а не она сама. Ступень выбирается и по ширине, и по высоте,
   чтобы увеличенная боковая панель помещалась по высоте окна. */
@media (min-width: 1800px) and (min-height: 950px) { :root { --ui-zoom: 1.25; } }
@media (min-width: 2200px) and (min-height: 1100px) { :root { --ui-zoom: 1.5; } }
@media (min-width: 2600px) and (min-height: 1250px) { :root { --ui-zoom: 1.75; } }
@media (min-width: 3000px) and (min-height: 1450px) { :root { --ui-zoom: 2; } }
@media (min-width: 3800px) and (min-height: 1800px) { :root { --ui-zoom: 2.5; } }

.hero, .steps, .about, .site-foot, .card,
.topbar, .side, .moves, .pill, .solve-foot, .repair-panel { zoom: var(--ui-zoom); }

/* ---------- узкий экран (телефон) ---------- */

@media (max-width: 900px) {
  .solve-body { flex-direction: column; overflow-y: auto; }
  /* Камера и грань в кадре стоят рядом, под ними развёртка: всё это помещается в экран телефона,
     кнопки уходят ниже, под прокрутку. */
  .scan-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 128px;
    align-content: start;
    gap: 8px;
    padding: 8px;
    overflow-y: auto;
  }
  .side { display: contents; }
  /* Высота задана явно: без неё блок брал бы высоту у #stage, а fitStage — у блока, и оба оставались нулевыми.
     352px — шапка, развёртка и отступы. */
  .camera { height: calc(100vh - 352px); height: calc(100dvh - 352px); min-height: 180px; }
  .preview-panel { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px; }
  .preview-panel .face.big { width: 100%; }
  .net-panel, .toolbar, .check-panel { grid-column: 1 / -1; }
  /* На проверке грань в кадре не нужна: видео идёт на всю ширину и становится ниже, чтобы развёртка со стыками была на экране. */
  .checking .camera { grid-column: 1 / -1; height: calc(100vh - 560px); height: calc(100dvh - 560px); min-height: 140px; }
  .net-panel h2 { margin-bottom: 6px; }
  .net, .checking .net { width: min(100%, 260px); min-width: 0; }
  .moves { width: auto; }
  .scan .topbar { padding: 8px 12px; gap: 8px; }
  .scan .topbar h2 { display: none; }
  .viewport { flex: none; height: 62vh; }
  .moves { max-height: 40vh; }
  .topbar { flex-wrap: wrap; }
  .solve-topbar { flex-wrap: nowrap; gap: 10px; padding: 10px 12px; }
  .solve-topbar .banner-title { font-size: 19px; }
  .hint { order: 3; flex-basis: 100%; }
  .train-mode .viewport { height: 30vh; min-height: 190px; }
  .training-panel { width: auto; overflow: visible; flex: none; }
  .train-mode .moves { width: auto; max-height: 180px; flex: none; }
  .train-mode .moves ol { max-height: 130px; }
}

@media (max-width: 700px) {
  .solve-foot { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 8px; padding: 8px; }
  .control-group { min-width: 0; padding: 4px; }
  .control-group button { flex: 1; min-width: 0; padding: 7px 6px; white-space: normal; overflow-wrap: anywhere; }
  .train-mode .control-group button { font-size: 13px; min-height: 38px; }
  .train-mode .playback-controls #btnPlay { flex: .8; }
  .train-mode .playback-controls #btnRestart { flex: 1.2; }
  .view-controls { grid-column: 1 / -1; }
  .welcome-body { justify-content: flex-start; gap: 28px; }
  .steps { grid-template-columns: 1fr; }
}

/* Train keeps lesson navigation in the header and cube controls in its frame.
   Шапка урока — одна строка с понятной иерархией: слева название экрана (мелко) и текущий этап (крупно),
   в центре — семь этапов, справа — компактный переключатель режима и второстепенные действия. */
.solve:not(.train-mode) .train-only { display: none; }
.train-mode .solve-topbar {
  display: grid;
  grid-template-columns: fit-content(272px) minmax(0, 1fr) max-content max-content;
  grid-template-rows: auto auto;
  grid-template-areas: "title stages modes actions" "stage stages modes actions";
  align-items: center;
  gap: 0 14px;
  padding: 6px 12px;
}
.train-mode .solve-heading, .train-mode .training-header, .train-mode .training-tools { display: contents; }
.train-mode #playerHeading { grid-area: title; align-self: end; margin: 0; font-size: 11px; line-height: 1.2; font-weight: 500; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.training-turn-slot { flex: none; padding: 9px 12px; border: 1px solid #343e47; border-radius: 10px; background: #1c232a; }
.train-mode .banner { min-width: 0; margin: 0; }
.train-mode .cube-frame { position: relative; }
.train-mode .banner-title { font-size: 16px; }
.train-mode .banner-how { font-size: 13px; }
.train-mode .move-count { display: none; }
.training-stage-heading { grid-area: stage; align-self: start; display: flex; align-items: baseline; gap: 7px; min-width: 0; font-size: 14px; line-height: 1.25; font-weight: 700; white-space: nowrap; overflow: hidden; }
.training-stage-heading .training-kicker { font: inherit; color: #a8f0d8; }
.training-stage-heading strong { font: inherit; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.training-stages { grid-area: stages; display: flex; margin: 0; gap: 4px; flex-wrap: nowrap; min-width: 0; }
.training-stage { flex: 1; min-width: 0; min-height: 38px; padding: 3px 4px; border-radius: 7px; }
.training-mode-tools { grid-area: modes; min-width: 0; }
.training-modes { margin: 0; padding: 2px; gap: 2px; border: 1px solid #3a4248; border-radius: 9px; background: #14191c; }
.training-modes button, .training-modes button:first-child, .training-modes button:last-child { flex: none; min-height: 32px; padding: 4px 12px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; }
.training-modes button:hover:not(:disabled) { color: var(--text); background: #262c31; }
.training-modes button.selected { background: #214b40; border-color: #68d6b3; color: #d5fff0; font-weight: 700; }
.training-actions { grid-area: actions; display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
#trainingCameraSlot > button, .training-more { min-height: 32px; padding: 4px 10px; font-size: 12px; font-weight: 600; color: #c9d0d6; white-space: nowrap; }
.training-more { display: inline-flex; align-items: center; justify-content: center; gap: 7px; background: transparent; }
.training-more::after { content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-2px) rotate(45deg); }
.training-more[aria-expanded="true"] { background: #21433b; border-color: #68d6b3; color: #d5fff0; }
.training-more[aria-expanded="true"]::after { transform: translateY(2px) rotate(225deg); }
.training-menu { position: relative; }
.training-file-tools { position: absolute; top: calc(100% + 8px); inset-inline-end: 0; z-index: 30; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; width: 240px; max-width: calc(100vw - 24px); padding: 10px; background: #252a30; border: 1px solid #49535c; border-radius: 12px; box-shadow: 0 12px 32px #0007; }
.training-language { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px 2px; margin-top: 2px; border-top: 1px solid #414851; font-size: 14px; font-weight: 600; }
.training-language > span { flex-shrink: 0; white-space: nowrap; }
.training-language select { flex: 1; min-width: 0; max-width: 100%; min-height: 40px; padding: 7px 9px; font: inherit; }
.training-file-tools > button, .training-guide { display: flex; align-items: center; min-height: 40px; margin: 0; padding: 9px 12px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--text); font-size: 14px; font-weight: 600; text-align: start; text-decoration: none; }
.training-guide:hover { background: #343842; }
.training-file-tools :focus-visible, .training-more:focus-visible, .training-modes button:focus-visible { outline: 2px solid #9cebd1; outline-offset: 2px; }
#trainingCameraSlot, #trainingViewSlot { display: flex; }
.train-mode .cube3d { border-radius: 0; }
.cube-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; padding: 8px; background: #1c232a; border-top: 1px solid #343e47; }
.cube-tools .training-animation { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 0; font-size: 11px; }
.animation-options { display: flex; }
.animation-options button { min-height: 30px; padding: 5px 6px; border-radius: 0; font-size: 11px; font-weight: 600; }
.animation-options button:first-child { border-radius: 6px 0 0 6px; }
.animation-options button:last-child { border-radius: 0 6px 6px 0; }
.animation-options button[aria-pressed="true"] { background: #21433b; border-color: #68d6b3; color: #d5fff0; }
#trainingViewSlot { margin-inline-start: auto; }
#trainingViewSlot > button { min-height: 30px; padding: 5px 6px; font-size: 11px; white-space: nowrap; }
.train-mode .solve-body { display: grid; grid-template-columns: minmax(220px, .8fr) minmax(460px, 1.5fr) 174px; gap: 10px; padding: 10px; zoom: var(--ui-zoom); }
.train-mode .training-panel, .train-mode .moves, .train-mode .pill, .train-mode .cube-legend { zoom: 1; }
.train-mode .training-panel { display: flex; flex-direction: column; width: auto; padding: 14px 16px; overflow: auto; }
.training-panel-heading { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.training-panel-heading > strong { font-size: 13px; color: #a8f0d8; }
.training-mode-note { margin: 0; }
.training-resume { margin: 0 0 10px; padding: 6px 9px; font-size: 11px; }
.training-lesson { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(180px, 1fr); gap: 18px; min-height: 0; }
.training-current, .training-reference { min-width: 0; }
.training-reference { border-inline-start: 1px solid #363d3d; padding-inline-start: 16px; }
.training-section { margin-bottom: 12px; }
.training-section h3 { margin-bottom: 4px; font-size: 12px; }
.training-section p { font-size: 13px; line-height: 1.45; }
.training-rule { padding: 10px 12px; }
.training-rule p { color: #e9fff6; }
.training-hold { padding-bottom: 9px; border-bottom: 1px solid #363d3d; }
.training-hold p { font-size: 12px; }
.training-find { padding-inline-start: 10px; border-inline-start: 2px solid #cb83bb; }
.training-section .training-muted { font-size: 11px; line-height: 1.4; }
.training-action p:not(.training-block-title) { color: var(--muted); font-size: 12px; }
.training-formula-title { font-size: 12px; }
.training-formula { margin: 6px 0; gap: 5px; }
.training-formula span { padding: 3px 5px; font-size: 13px; }
.training-step { font-size: 12px; }
.training-step-move { font-size: 12px; }
.training-gesture { font-size: 12px; margin-bottom: 0; color: #c9d6d0; }
.training-target { padding: 10px; margin-bottom: 12px; }
.training-target-check { margin: 0 0 12px; font-size: 12px; line-height: 1.45; }
.training-target-body { flex-wrap: wrap; gap: 8px; }
.training-target-body p { flex-basis: 100%; font-size: 11px; }
.training-net { --sticker: 10px; }
.training-bottom { flex-wrap: wrap; padding: 8px; gap: 6px; margin-bottom: 12px; }
.training-bottom figcaption { min-width: 90px; font-size: 10px; }
.training-bottom-grid { --cell: 17px; --band: 7px; --label: 9px; }
.training-focus, .training-self, .training-basics { font-size: 12px; margin-top: 10px; }
.training-focus p, .training-self p, .training-basics p { font-size: 12px; line-height: 1.45; }
.train-mode .moves { width: auto; padding: 10px 6px; }
.train-mode .moves h2 { padding-inline-start: 6px; font-size: 14px; }
.train-mode .moves .move-stage { display: block; padding: 0; margin: 0 0 8px; border-radius: 0; background: transparent; }
.move-stage-title { display: block; width: 100%; padding: 7px 6px; border-radius: 5px; border: 0; background: #292e34; text-align: start; font-size: 11px; line-height: 1.4; color: #bbc3c9; }
.move-stage.active .move-stage-title { background: #21433b; color: #d5fff0; }
.move-stage.complete .move-stage-title::after { content: ' ✓'; color: #a8f0d8; }
.train-mode .moves .move-stage ol { overflow: visible; padding: 3px 0 0; }
.train-mode .moves li[data-move-index] { gap: 6px; padding: 3px 5px; font-size: 11px; }
.train-mode .moves li .num { width: 20px; }
.train-mode .moves li .dot { width: 6px; height: 6px; flex: none; }
.train-mode .solve-foot { display: flex; justify-content: center; gap: 12px; padding: 8px 10px; }
.train-mode .playback-controls, .train-mode .view-controls { display: none; }
.train-mode .control-group { padding: 4px; gap: 4px; }
.train-mode .control-group button { padding: 8px 14px; font-size: 13px; }
.group-controls button { color: #a8f0d8; border-color: #4a7a69; }
.train-mode .training-prompt { margin: 0 0 10px; padding: 8px 10px; border-inline-start: 3px solid #ffba70; border-radius: 5px; background: #3b3024; color: #ffdbb3; text-align: start; font-size: 11px; }
.train-mode .demo-status { left: 10px; right: 10px; top: 46px; max-width: fit-content; font-size: 10px; }
.move-stage-title { position: sticky; top: 0; z-index: 1; }
/* Ходы этапа собраны в группы урока; раскрыта текущая, остальные открываются по клику. */
.move-group { display: block !important; padding: 0 !important; margin: 2px 0; cursor: default !important; }
.move-group:hover { background: transparent !important; }
.move-group details { border-radius: 5px; }
.move-group summary { display: flex; flex-direction: column; gap: 1px; padding: 4px 6px; border-radius: 5px; cursor: pointer; list-style: none; }
.move-group summary::-webkit-details-marker { display: none; }
.move-group summary:hover { background: #2b2f36; }
.move-group-title { font-size: 11px; line-height: 1.35; color: #bbc3c9; }
.move-group-notation { font: 10px/1.3 Consolas, monospace; color: #7d8a93; }
.move-group.active > details > summary { background: #243a33; }
.move-group.active .move-group-title { color: #d5fff0; }
.move-group.complete .move-group-title { color: #96ba9c; }
.move-group.complete .move-group-title::after { content: ' ✓'; color: #78be8c; }
.move-group ol { padding-inline-start: 4px !important; }
.practice .move-group:not(.complete):not(.active) .move-group-notation { filter: blur(4px); }

/* Правило этапа: раскрыто при входе в этап, дальше сворачивается, чтобы не загораживать текущее действие. */
details.training-rule summary { cursor: pointer; font-size: 12px; font-weight: 600; color: #a8f0d8; list-style: none; display: flex; align-items: center; gap: 6px; }
details.training-rule summary::-webkit-details-marker { display: none; }
details.training-rule summary::before { content: '▸'; font-size: 11px; transition: transform .15s; }
details.training-rule[open] summary::before { transform: rotate(90deg); }
details.training-rule p { margin-top: 6px; }

/* Кнопки этапов: номер и короткое название. Текущий этап выделен сильнее всего, пройденные — лёгкой подсветкой. */
.training-stage { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; line-height: 1.2; }
.training-stage b { font-size: 13px; }
.training-stage span { max-width: 100%; font-size: 11px; font-weight: 500; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.training-stage.selected span, .training-stage.complete span { color: inherit; }
.training-stage.selected { box-shadow: 0 0 0 1px #68d6b3 inset; }

/* Карточки случаев: мини-кубики «вижу → делаю», текущий случай подсвечен. До четырёх карточек делят
   ширину поровну; если их больше, появляется прокрутка. */
.training-cases { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(calc(25% - 5px), 1fr); gap: 6px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: thin; }
.training-case { min-width: 0; margin: 0; padding: 5px; border: 1px solid #363d3d; border-radius: 8px; background: #1a2226; }
.training-case.current { border-color: #ff3df0; background: #2a1f2b; box-shadow: 0 0 0 1px #ff3df0 inset; }
.training-case figcaption { margin-top: 4px; font-size: 10px; line-height: 1.3; color: var(--muted); overflow-wrap: anywhere; }
.training-case.current figcaption { color: #ffd6fb; }
.case-scheme { display: block; width: 100%; max-width: 96px; margin: 0 auto; }
.case-scheme svg { display: block; width: 100%; height: auto; }
.training-case-section { margin-bottom: 10px; }
.training-cases-note { margin: 2px 0 0; font-size: 11px; color: var(--muted); }

@media (min-width: 901px) {
  .train-mode .solve-body { grid-template-rows: minmax(0, 1fr); }
  .train-mode .viewport { min-height: 0; }
  .training-panel-heading { display: none; }
  .training-lesson { gap: 14px; }
  .training-section { margin-bottom: 10px; }
  .training-hold { padding-bottom: 7px; }
}
/* Средняя ширина: та же одна строка, но этапы только номерами — название текущего этапа есть в заголовке. */
@media (min-width: 1001px) and (max-width: 1359px) {
  .train-mode .solve-topbar { grid-template-columns: fit-content(272px) max-content max-content max-content; justify-content: space-between; }
  .training-stage { flex: none; min-width: 38px; min-height: 34px; padding: 3px 4px; }
  .training-stage span { display: none; }
  .training-stage b { font-size: 14px; }
}
/* Планшет: заголовок, режим и действия в первой строке, этапы с подписями — во второй. */
@media (min-width: 601px) and (max-width: 1000px) {
  .train-mode .solve-topbar { grid-template-columns: minmax(0, 1fr) max-content max-content; grid-template-rows: auto auto; grid-template-areas: "stage modes actions" "stages stages stages"; gap: 6px 10px; padding: 6px 10px; }
  .training-stage { padding: 3px 2px; }
  .train-mode #playerHeading { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}
/* Узкие экраны: номер этапа над названием, чтобы название не обрезалось. */
@media (max-width: 1000px) {
  .training-stage-heading { flex-direction: column; align-items: flex-start; gap: 0; font-size: 14px; }
  .training-stage-heading .training-kicker { font-size: 11px; line-height: 1.2; font-weight: 600; }
  .training-stage-heading strong { max-width: 100%; white-space: normal; line-height: 1.2; }
}
@media (min-width: 901px) and (max-width: 1200px) {
  .train-mode .solve-body { grid-template-columns: minmax(220px, .6fr) minmax(560px, 1.6fr); }
  .train-mode .moves { display: none; }
  .train-mode .banner-title { font-size: 16px; }
  .training-section { margin-bottom: 8px; }
}
@media (min-width: 901px) and (max-height: 740px) {
  .train-mode .solve-topbar { padding-top: 4px; padding-bottom: 4px; }
  .train-mode .training-panel { padding: 10px 12px; }
  .training-panel-heading { margin-bottom: 8px; }
  .training-section { margin-bottom: 8px; }
  .training-rule { padding: 8px 10px; }
  .training-resume { font-size: 10px; margin-bottom: 7px; }
  .training-section p { font-size: 12px; }
  .training-section .training-muted, .training-action p:not(.training-block-title) { font-size: 11px; }
}
@media (max-width: 900px) {
  .train-mode .solve-topbar { flex: none; }
  .train-mode .solve-body { display: flex; zoom: 1; }
  .train-mode .viewport { min-height: 300px; }
  .train-mode .training-panel { overflow: visible; }
  .training-lesson { grid-template-columns: minmax(0, 1.6fr) minmax(180px, 1fr); }
  .train-mode .moves { width: auto; }
  .train-mode .moves ol { max-height: 140px; }
  .train-mode .moves .move-stage ol { max-height: none; }
}
@media (max-width: 600px) {
  .train-mode .banner-title { font-size: 16px; }
  .training-lesson { display: block; }
  .training-reference { border-inline-start: 0; border-top: 1px solid #363d3d; padding: 14px 0 0; margin-top: 16px; }
  .training-target-body { flex-wrap: nowrap; }
  .training-target-body p { flex-basis: auto; }
  .training-net { --sticker: 9px; }
  .train-mode .solve-foot { display: grid; grid-template-columns: minmax(0, 1fr); gap: 5px; padding: 6px; }
  .train-mode .control-group { padding: 3px; }
  .train-mode .control-group button { min-height: 34px; padding: 5px 8px; font-size: 12px; }

  /* Телефон: в первой строке текущий этап и действия, во второй — номера этапов, в третьей — режим во всю ширину.
     Название экрана остаётся только для читалок. Куб во всю ширину, под ним формула; список ходов и подсказки по клавишам не нужны. */
  .train-mode .solve-topbar { grid-template-columns: minmax(0, 1fr) max-content; grid-template-rows: auto auto auto; grid-template-areas: "stage actions" "stages stages" "modes modes"; gap: 6px 8px; padding: 6px 8px; }
  .train-mode #playerHeading { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  #trainingCameraSlot > button, .training-more { min-height: 30px; padding: 3px 8px; font-size: 11px; }
  .training-mode-tools { width: 100%; }
  .training-modes button, .training-modes button:first-child, .training-modes button:last-child { flex: 1; min-height: 34px; padding: 4px 8px; font-size: 13px; }
  .train-mode .banner { gap: 8px; }
  .train-mode .banner-title { font-size: 15px; }
  .train-mode .banner-how { font-size: 11px; line-height: 1.3; }
  .training-stages { gap: 4px; overflow-x: auto; scrollbar-width: thin; }
  .training-stage { flex: 1; min-width: 36px; min-height: 36px; padding: 3px 4px; }
  .training-stage span { display: none; }
  .training-stage b { font-size: 15px; }
  .training-turn-slot { padding: 8px 10px; }
  .train-mode .viewport { height: auto; min-height: 0; }
  .train-mode .cube-frame { flex: none; }
  .train-mode .cube3d { flex: none; aspect-ratio: 1 / 1; height: auto; width: 100%; max-height: 48vh; }
  .train-mode .cube-legend, .train-mode .moves, .training-panel-heading, .train-mode .training-prompt:empty { display: none; }
  .cube-tools { padding: 5px 6px; gap: 4px; }
  .cube-tools .training-animation { font-size: 10px; }
  .train-mode .training-panel { padding: 10px 10px 14px; }
  .training-section { margin-bottom: 9px; }
  .training-hold { padding-bottom: 7px; }
  .training-hold p { font-size: 12px; }
  .training-rule p, .training-section p { font-size: 13px; line-height: 1.45; }
  .case-scheme { max-width: 80px; }
  .training-formula span { font-size: 14px; padding: 4px 7px; }
  .training-reference { margin-top: 12px; padding-top: 12px; }
  .train-mode .solve-foot { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
  .train-mode .control-group button { min-height: 40px; padding: 4px 5px; font-size: 12px; line-height: 1.15; white-space: normal; }
  /* На телефоне формула стоит сразу после «что делаем», карточки случаев — ниже неё. */
  .training-current { display: flex; flex-direction: column; }
  .training-current > * { order: 1; }
  .training-current > .training-case-section { order: 2; }
  .training-formula-section { margin-bottom: 10px; }
}

/* Ручная раскраска: палитра и действия всегда рядом с развёрткой. */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.net-viewport { display: contents; }
.manual-entry .topbar { flex: none; flex-wrap: nowrap; gap: 12px; padding: 8px 16px; }
.manual-entry .topbar h2 { display: block; font-size: 18px; }
.manual-entry .camera, .manual-entry #btnMirror,
.manual-entry #cameraSelect, .manual-entry .net-heading,
.manual-entry .net-tools { display: none; }
.manual-progress { color: var(--muted); font-size: 13px; white-space: nowrap; }
.manual-header-tools { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }
.manual-header-tools > span { display: contents; }
.manual-header-tools button { padding: 6px 10px; font-size: 13px; white-space: nowrap; }
/* Keep the manual editor out of the camera grid at widths 601–900px. Its
   size-contained net needs the full height supplied by this flex layout. */
.manual-entry .scan-body { display: flex; justify-content: center; overflow: visible; }
.manual-entry .side { display: flex; flex: 1; width: auto; max-width: 960px; min-width: 0; gap: 8px; overflow: visible; }
.manual-entry .net-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.manual-entry .manual-tools { flex: none; }
.manual-entry .manual-tools p { margin: 0; }
.manual-entry .paint-palette { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; margin: 10px 0 0; }
.manual-entry .paint-color { justify-content: center; min-width: 0; min-height: 48px; padding: 6px; font-size: 12px; }
.manual-entry .paint-color > span:last-child { display: flex; flex-direction: column; min-width: 0; text-align: start; }
.manual-entry .paint-name { overflow-wrap: anywhere; }
.manual-entry .paint-color .cell { flex: none; width: 26px; height: 26px; }
.manual-entry .paint-count { font-variant-numeric: tabular-nums; color: var(--muted); }
.manual-entry .over-count .paint-count { color: #ffb36b; }
.manual-entry .net-viewport { display: grid; place-items: center; flex: 1; min-height: 0; container-type: size; }
.manual-entry .net {
  width: min(100cqw, calc(100cqh * 4 / 3)); min-width: 0; max-width: none;
  aspect-ratio: 4 / 3; grid-template-rows: repeat(3, minmax(0, 1fr));
}
.manual-entry .net-face.oriented .face { outline: none; }
.manual-entry .net-face.saved .face { animation: none; }
.manual-entry .net-face button.cell { aspect-ratio: 1; }
.manual-entry .net-face button.cell:disabled { cursor: default; }
.manual-entry .net-face button.cell:nth-child(5)::after { content: "•"; color: #111; }
.manual-entry .toolbar { flex: none; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.manual-entry .toolbar button { min-height: 40px; }
.manual-entry .toolbar :is(#btnSolve, .train-button) { grid-column: auto; }
.manual-help { width: min(480px, calc(100% - 32px)); max-height: calc(100dvh - 32px); padding: 20px; border: 1px solid #444b55; border-radius: 12px; background: var(--panel); color: var(--text); }
.manual-help::backdrop { background: #000a; }
.manual-help-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.manual-help h2 { margin: 0; font-size: 20px; }
.manual-help p { color: #cfd3d8; line-height: 1.5; }
.manual-help p:last-child { margin-bottom: 0; }
@media (max-width: 900px) {
  .manual-entry .topbar { flex-wrap: wrap; }
}
@media (max-width: 600px) {
  .manual-entry .topbar { flex-wrap: wrap; gap: 8px; padding: 8px; }
  .manual-entry .topbar h2 { min-width: 0; font-size: 15px; white-space: normal; overflow-wrap: anywhere; }
  .manual-progress { font-size: 11px; }
  .manual-header-tools { max-width: 100%; flex-wrap: wrap; gap: 4px; }
  .manual-header-tools button { max-width: 100%; padding: 7px; font-size: 11px; white-space: normal; overflow-wrap: anywhere; }
  .manual-entry .scan-body { padding: 6px; }
  .manual-entry .net-panel { padding: 6px; gap: 8px; }
  .manual-entry .manual-tools p { font-size: 11px; }
  .manual-entry .paint-palette { gap: 5px; margin-top: 8px; }
  .manual-entry .paint-color { flex-direction: column; gap: 3px; padding: 5px 2px; min-height: 58px; font-size: 11px; }
  .manual-entry .paint-color > span:last-child { text-align: center; }
  .manual-entry .paint-color .cell { width: 26px; height: 26px; }
  .manual-entry .paint-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .manual-entry .net { gap: 3px; }
  .manual-entry .net .face { gap: 2px; padding: 2px; }
  .manual-entry .toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .manual-entry .toolbar button { min-height: 42px; font-size: 13px; }
  .manual-entry #btnSave { grid-area: 1 / 1; }
  .manual-entry #btnLoad { grid-area: 1 / 2; }
  .manual-entry #btnSolve { grid-area: 2 / 1; }
  .manual-entry #btnTrain { grid-area: 2 / 2; }
}
@media (min-width: 601px) and (max-height: 500px) {
  .manual-entry .topbar { padding: 5px 12px; }
  .manual-entry .scan-body { padding: 8px; }
  .manual-entry .net-panel { display: grid; grid-template-columns: minmax(0, 1fr) 190px; grid-template-rows: minmax(0, 1fr) auto; padding: 8px; }
  .manual-entry .net-viewport { grid-area: 1 / 1 / 3 / 2; align-self: stretch; }
  .manual-entry .manual-tools { grid-area: 1 / 2; }
  .manual-entry .paint-palette { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; margin-top: 8px; }
  .manual-entry .paint-color { min-height: 36px; padding: 4px; font-size: 11px; }
  .manual-entry .manual-tools p { font-size: 11px; }
  .manual-entry .toolbar button { min-height: 34px; }
}
@media (max-width: 360px) {
  .manual-entry .topbar { gap: 6px; }
  .manual-entry .topbar h2 { font-size: 13px; }
  .manual-header-tools button { font-size: 10px; padding: 7px 6px; }
}

/* Справа налево (ar, fa, he, ur): интерфейс зеркалится, кубик — нет. Развёртки, 3D-кубик,
   миниатюра, демо, нотация и клавиши всегда слева направо: зелёная грань L слева, синяя R справа. */
:is(.net, .net-viewport, #preview, .face, .demo, .cube-frame, .training-net, .training-bottom-grid,
    .training-formula, .training-step-move, kbd, code) { direction: ltr; unicode-bidi: isolate; }
/* Стрелки кнопок урока — оформление, а не текст: в RTL они смотрят в другую сторону. */
.train-mode #btnPrev::before { content: var(--arrow-back) " "; }
.train-mode #btnNext::after { content: " " var(--arrow-next); }
#btnNextGroup::after { content: " " var(--arrow-next-group); }
#btnPrevGroup::before { content: var(--arrow-back-group) " "; }
.training-guide::after { content: " " var(--arrow-external); }
:root { --arrow-back: "←"; --arrow-next: "→"; --arrow-back-group: "⇤"; --arrow-next-group: "⇥"; --arrow-external: "↗"; }
[dir="rtl"] { --arrow-back: "→"; --arrow-next: "←"; --arrow-back-group: "⇥"; --arrow-next-group: "⇤"; --arrow-external: "↖"; }
/* Длинные слова (de, fi) не распирают кнопки; корейский переносится по словам, а не по слогам. */
body { overflow-wrap: break-word; }
:lang(ko) { word-break: keep-all; }

/* Candidate selection occupies the viewport; the editor uses the regular scan layout. */
.scan-camera-tools { display: flex; align-items: center; gap: 8px; min-width: 0; }
.scan-camera-tools select { min-width: 0; max-width: 100%; }
.scan.reviewing { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; height: 100dvh; padding: 12px; overflow-y: auto; }
.reviewing > .topbar, .reviewing .scan-body { display: none; }
.alignment-review { display: flex; flex-direction: column; align-items: center; gap: 9px; width: 100%; height: 100%; min-width: 0; min-height: 0; padding: 0 8px; }
.review-heading { flex: none; width: 100%; text-align: center; }
.review-heading h2 { margin: 0; font-size: clamp(20px, 3vmin, 44px); }
.review-secondary { flex: none; width: min(100%, 1100px); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(18px, 2.5vmin, 36px); }
.review-secondary button { font-size: clamp(13px, 1.7vmin, 25px); min-width: 0; min-height: clamp(44px, 5vmin, 66px); padding: 6px 10px; line-height: 1.15; text-wrap: balance; }
#reviewLoading { margin: 0; text-align: center; }
.review-editing #btnSolve, .review-editing #btnTrain { display: none; }
@media (max-width: 760px) {
  .scan.reviewing { padding: 8px; gap: 8px; }
  .alignment-review { padding: 0; gap: 7px; }
  .review-heading h2 { font-size: 18px; }
  .review-secondary button { font-size: 13px; padding: 6px; min-height: 46px; }
}

/* Reset shares the empty upper-right corner with the optional turn hint. */
.net-reset { grid-area: 1 / 3 / 2 / 5; display: flex; align-items: center; justify-content: center; min-width: 0; }
.net-reset button { max-width: 100%; min-height: 44px; font-size: 14px; }
.net:has(.turn-hint:not([hidden])) .net-reset { align-self: start; }
.net:has(.turn-hint:not([hidden])) .turn-hint { padding-top: 48px; }
.scan-finished .camera, .scan-finished .preview-panel, .scan-finished #checkPanel,
.scan-finished #scanCameraTools { display: none; }
/* Size the completed net from the space left above the action buttons. */
.scan-finished .topbar { flex: none; }
.scan-finished .scan-body { display: flex; justify-content: center; overflow: hidden; }
.scan-finished .side { display: flex; flex: 1; width: 100%; min-width: 0; min-height: 0; max-width: 1040px; overflow: visible; }
.scan-finished .net-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scan-finished .net-viewport { display: grid; place-items: center; flex: 1; min-height: 0; container-type: size; }
.scan-finished .net { width: min(100cqw, calc(100cqh * 4 / 3)); min-width: 0; aspect-ratio: 4 / 3; grid-template-rows: repeat(3, minmax(0, 1fr)); }
.scan-finished .toolbar { flex: none; }
.scan-finished .toolbar button { min-height: 44px; }
.scan-finished .toolbar :is(#btnSolve, #btnTrain) { grid-column: auto; }
.scan-finished.has-scan-cube .net { display: none; }
.scan-cube { width: 100%; height: 100%; min-width: 0; min-height: 0; cursor: grab; touch-action: none; }
.scan-cube:active { cursor: grabbing; }
.scan-cube canvas { display: block; width: 100%; height: 100%; }
#finishedEditTools :is(.net-reset, .net-tools) { display: contents; }
#finishedEditTools button { width: 100%; max-width: none; }

@media (max-width: 900px) {
  /* The cube occupies the visible body, with the move list below for scrolling. */
  .solve:not(.train-mode) .solve-topbar { flex: none; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 6px; padding: 6px 10px; }
  .solve:not(.train-mode) .solve-heading { display: contents; }
  .solve:not(.train-mode) #playerHeading { grid-area: 1 / 1; font-size: 12px; margin: 0; }
  .solve:not(.train-mode) .banner { grid-area: 2 / 1 / 3 / 3; margin-top: 0; gap: 7px; }
  .solve:not(.train-mode) .banner-title { font-size: 16px; line-height: 1.2; }
  .solve:not(.train-mode) .banner-how { font-size: 12px; line-height: 1.25; }
  .solve:not(.train-mode) .swatch { width: 26px; height: 26px; }
  .solve:not(.train-mode) .move-count { grid-area: 1 / 2; font-size: 13px; margin: 0; }
  .solve:not(.train-mode) .progress { flex: none; }
  .solve:not(.train-mode) .solve-body { gap: 8px; padding: 8px; overscroll-behavior-y: contain; }
  .solve:not(.train-mode) .viewport { flex: 0 0 100%; height: auto; min-height: 160px; }
  .solve:not(.train-mode) .cube-legend { font-size: 12px; }
  .solve:not(.train-mode) .cube-legend summary { padding: 5px 0; }
  .solve:not(.train-mode) .moves { max-height: none; }
  .solve:not(.train-mode) .solve-foot { flex: none; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 5px; padding: 5px; }
  .solve:not(.train-mode) .control-group { min-width: 0; padding: 3px; gap: 3px; }
  .solve:not(.train-mode) .control-group button { flex: 1; min-width: 0; min-height: 40px; padding: 5px 3px; font-size: 13px; white-space: normal; overflow-wrap: anywhere; }
  .solve:not(.train-mode) .playback-controls #btnPlay { flex: .8; }
  .solve:not(.train-mode) .playback-controls #btnRestart { flex: 1.2; }
  /* «Назад» и «Далее» — основные кнопки: отдельной строкой и крупнее; «Пуск», «Сначала» и вид — ниже. */
  .solve:not(.train-mode) .step-controls { grid-column: 1 / -1; }
  .solve:not(.train-mode) .step-controls button { min-height: 52px; font-size: 17px; }
  .solve:not(.train-mode) .step-controls #btnNext { flex: 1.6; }
  .solve:not(.train-mode) .view-controls { grid-column: auto; }
}
@media (min-width: 601px) and (max-height: 500px) {
  .scan-finished .side { flex-direction: row; }
  .scan-finished .toolbar { width: min(38%, 320px); align-content: center; }
}

/* A tall phone fits larger square faces in a three-column unfolded cross.
   The back face folds out below D, with its bottom edge turned toward D. */
@media (max-width: 600px) and (max-aspect-ratio: 3 / 5) {
  .scan-finished .net { width: min(100cqw, calc(100cqh * 3 / 4)); aspect-ratio: 3 / 4; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(0, 1fr)); }
  .scan-finished .net-face-B { grid-area: 4 / 2 / 5 / 3 !important; transform: rotate(180deg); }
  .scan-finished .net-reset { grid-area: 1 / 3 / 2 / 4; }
  .scan-finished .net-tools { grid-area: 3 / 3 / 5 / 4; }
}

/* The live scanner has a responsive strip of face tiles beside the camera. Other
   views retain the unfolded net and return its tools to the empty corners. */
.scan-faces-column { display: contents; }
.scan-edit-tools { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
.linear-scan > .topbar { flex: none; }
.linear-scan .scan-body { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: minmax(0, 1fr) auto auto; gap: 6px; padding: 6px; overflow: hidden; }
.linear-scan .side { display: contents; }
.linear-scan .camera { grid-area: 1 / 1 / 2 / 2; height: auto; min-height: 0; }
.linear-scan .scan-faces-column { grid-area: 1 / 2 / 2 / 3; display: flex; flex-direction: column; align-items: center; height: 100%; width: auto; min-width: 72px; max-width: 160px; min-height: 0; aspect-ratio: 1 / 7; gap: 6px; padding: 6px; border-radius: 10px; background: var(--panel); container-type: size;
  /* Title: 28px; gaps: 4+6+30px; counter: 18px. Seven square grids fill the rest. */
  --scan-face-size: min(100cqw, calc((100cqh - 86px) / 7));
}
.linear-scan .preview-panel { display: flex; flex: none; flex-direction: column; align-items: center; width: 100%; min-height: 0; padding: 0; gap: 4px; background: none; }
.linear-scan .preview-panel .face.big { width: var(--scan-face-size); }
.linear-scan .preview-panel > div:not(.face) { display: flex; justify-content: center; align-items: center; width: 100%; height: 28px; }
.linear-scan .preview-panel h2 { display: block; margin: 0; font-size: 12px; line-height: 14px; text-align: center; }
.linear-scan :is(.net-panel, .net-viewport) { display: contents; container-type: normal; }
.linear-scan .net { flex: none; width: var(--scan-face-size); min-width: 0; aspect-ratio: auto; margin: 0; grid-template-columns: var(--scan-face-size); grid-template-rows: repeat(6, var(--scan-face-size)); gap: 6px; }
.linear-scan #net .net-face { grid-column: 1 !important; grid-row: var(--scan-row) !important; transform: none; }
.linear-scan .net-heading { position: absolute; top: calc(100% + 4px); left: 50%; right: auto; width: 72px; transform: translateX(-50%); white-space: nowrap; display: block; height: 14px; margin: 0; font-size: 12px; line-height: 14px; text-align: center; }
.linear-scan .net-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.linear-scan :is(.seams, .turn-hint, #manualCameraSlot) { display: none; }
.linear-scan .toolbar { grid-area: 3 / 1 / 4 / 3; gap: 6px; }
.linear-scan :is(.net-reset, .net-tools) { display: contents; }
.linear-scan .toolbar button { width: 100%; max-width: none; min-height: 44px; padding: 5px 6px; font-size: 14px; line-height: 1.2; }
.linear-scan :is(#btnSolve, #btnTrain) { grid-column: auto; }
.linear-scan .camera-error { padding: 8px; font-size: 12px; }
.linear-scan .scan-pause { gap: 6px; }
.linear-scan .light-note { inset-inline: 4px; bottom: 4px; max-width: calc(100% - 8px); padding: 4px 8px; gap: 4px 8px; font-size: 12px; }
.linear-scan .light-note button { min-height: 32px; padding: 3px 8px; font-size: 12px; }
.linear-scan .scan-pause p { margin: 0; }
.linear-scan .scan-pause button { min-height: 36px; padding: 4px 6px; font-size: 12px; }
@media (max-width: 900px) {
  .scan:not(.manual-entry, .reviewing) .hint { font-size: 14px; line-height: 1.2; min-height: 2.4em; white-space: normal; overflow: visible; text-overflow: clip; }
  .linear-scan > .topbar { padding: 6px 8px; gap: 6px; }
  .linear-scan .scan-camera-tools { width: 100%; }
  .linear-scan .scan-camera-tools select { flex: 1; width: 0; }
  .linear-scan .scan-camera-tools :is(button, select) { min-height: 36px; padding: 5px 8px; font-size: 14px; }
}
@media (min-width: 601px) and (max-width: 900px) and (max-height: 500px) {
  .linear-scan .toolbar { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .linear-scan .scan-edit-tools { grid-column: span 2; }
  .linear-scan .toolbar:has(#btnSolve[hidden]) .scan-edit-tools { grid-column: 1 / -1; }
  .linear-scan #btnSave { grid-column: 1 / 3; }
  .linear-scan #btnLoad { grid-column: 3 / 5; }
}

@media (max-height: 600px) {
  .linear-scan .scan-faces-column { padding: 4px; gap: 4px; --scan-face-size: min(100cqw, calc((100cqh - 62px) / 7)); }
  .linear-scan .preview-panel { gap: 3px; }
  .linear-scan .preview-panel > div:not(.face) { height: 24px; }
  .linear-scan .preview-panel h2 { font-size: 11px; line-height: 12px; }
  .linear-scan .net { gap: 3px; }
  .linear-scan .net-heading { top: calc(100% + 2px); }
  .linear-scan .scan-faces-column .face { padding: 1px; gap: 1px; border-radius: 3px; }
  .linear-scan .scan-faces-column .cell { border-radius: 1px; }
}

@media (min-width: 760px) and (min-aspect-ratio: 4/3) {
  .linear-scan .scan-faces-column {
    min-width: 112px; max-width: 300px; aspect-ratio: 2 / 5;
    --scan-face-size: min(calc((100cqw - 6px) / 2), calc((100cqh - 86px) / 5));
  }
  .linear-scan .preview-panel .face.big { width: calc(2 * var(--scan-face-size) + 6px); }
  .linear-scan .net { width: calc(2 * var(--scan-face-size) + 6px); grid-template-columns: repeat(2, var(--scan-face-size)); grid-template-rows: repeat(3, var(--scan-face-size)); gap: 6px; }
  .linear-scan #net .net-face { grid-column: var(--scan-wide-column) !important; grid-row: var(--scan-wide-row) !important; }
}

/* Candidate states share the preview renderer and fill the space left by controls. */
.orientation-choices { display: flex; flex-direction: column; flex: 1; min-height: 0; width: 100%; gap: 8px; }
.orientation-grid { display: grid; flex: 1; min-height: 0; width: 100%; overflow-y: auto; grid-template-columns: repeat(var(--choice-count), minmax(0, 1fr)); grid-auto-rows: minmax(220px, 1fr); gap: 12px; }
.orientation-card { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 5px; border: 2px solid #62798a; border-radius: 14px; background: var(--panel); color: var(--text); gap: 8px; }
.orientation-pictures { display: flex; flex: 1; min-height: 0; min-width: 0; cursor: grab; touch-action: none; border-radius: 8px; }
.orientation-pictures:active { cursor: grabbing; }
.orientation-pictures:focus-visible { outline: 2px solid #22e5ff; outline-offset: -2px; }
.orientation-pictures canvas { display: block; width: 100%; height: 100%; min-width: 0; min-height: 0; }
.orientation-note { flex: none; margin: 0 6px; text-align: center; font-size: clamp(15px, 1.7vmin, 19px); line-height: 1.3; }
.review-repair { flex: none; margin: 0 auto 8px; text-align: center; max-width: 70ch; font-size: clamp(15px, 1.8vmin, 19px); line-height: 1.4; }
.orientation-label { flex: none; display: block; align-self: center; min-height: 48px; width: min(100%, 360px); padding: 10px 20px; font-size: clamp(18px, 2vmin, 24px); }
.choosing-orientation .review-heading { max-width: none; }
.scan.reviewing:has(.choosing-orientation) { grid-template-columns: minmax(0, 1fr); min-height: 0; }
.scan.reviewing:has(.choosing-orientation) .camera { display: none; }
@media (max-width: 1100px) {
  .orientation-grid[data-count="4"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .choosing-orientation.alignment-review { min-height: 0; }
  .orientation-grid { gap: 7px; }
  .orientation-grid[data-count="3"], .orientation-grid[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (orientation: portrait) {
  .orientation-grid, .orientation-grid[data-count] { grid-template-columns: minmax(0, 1fr); }
  .orientation-pictures { flex-direction: column; }
}
@media (min-width: 701px) and (max-height: 600px) {
  .scan.reviewing:has(.choosing-orientation) { height: 100dvh; overflow: hidden; }
  .choosing-orientation .review-heading h2 { font-size: 22px; }
  .choosing-orientation .review-secondary button { min-height: 38px; font-size: 14px; }
}
