:root {
  color-scheme: dark;
  --bg: #161618;
  --panel: #202226;
  --text: #ececec;
  --muted: #adb5bf;
  --line: #383d45;
  --accent: #7ee08f;
}
* { box-sizing: border-box; }
html { scroll-padding-top: 24px; }
body { overflow-wrap: break-word; margin: 0; background: var(--bg); color: var(--text); font: 17px/1.65 "Segoe UI", system-ui, sans-serif; }
a { color: #98c7ff; text-underline-offset: .18em; }
a:hover { color: #c6e1ff; }
a:focus-visible { outline: 3px solid var(--accent); outline-offset: 5px; border-radius: 2px; }
.skip { position: absolute; top: -100px; inset-inline-start: 20px; background: var(--panel); padding: 12px; }
.skip:focus { top: 12px; }
.page { width: min(1100px, 100%); margin: auto; padding: 28px 24px 56px; }
.guide-nav { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 22px; font-size: 15px; }
.back-link::before { content: "← "; }
[dir="rtl"] .back-link::before { content: "→ "; }
.languages { color: var(--muted); }
.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; margin: -28px -24px 16px; padding: 6px 16px; font-size: 15px; background: #20362f; }
.lang-offer a { color: #d5fff0; }
.lang-offer button { padding: 2px 10px; font-size: 20px; line-height: 1; color: #d5fff0; background: transparent; border: 0; cursor: pointer; }
header { max-width: 810px; margin: 22px 0 32px; }
.eyebrow { margin: 20px 0 8px; color: var(--accent); font-size: 13px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
h1 { font-size: clamp(32px, 6vw, 52px); line-height: 1.15; letter-spacing: -.035em; margin: 0 0 20px; }
h2 { margin: 0 0 18px; font-size: 28px; line-height: 1.25; letter-spacing: -.025em; }
h3 { margin: 23px 0 6px; font-size: 17px; }
p { margin: 0 0 14px; }
.lead { font-size: 20px; color: #d2d8df; }
.muted, figcaption, footer { color: var(--muted); }
.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 34px; align-items: start; }
.contents { position: sticky; top: 24px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; font-size: 14px; }
.contents strong { display: block; margin-bottom: 10px; }
.contents ol { padding-inline-start: 22px; margin: 0; }
.contents li { margin: 7px 0; }
.contents .extra { display: block; margin-top: 14px; }
section { margin-bottom: 24px; padding: 28px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
section:target { border-color: var(--accent); }
.stage-number { color: var(--accent); display: block; margin-bottom: 10px; font-size: 13px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.note { border-inline-start: 3px solid var(--accent); padding-inline-start: 15px; color: #d2d8df; }
ul, ol { padding-inline-start: 24px; }
li + li { margin-top: 8px; }
code { font: .93em/1.65 Consolas, "Liberation Mono", monospace; color: #f6de9a; overflow-wrap: anywhere; }
.formula { padding: 12px 15px; border-radius: 9px; background: #141619; border: 1px solid #363b43; }
.formula code { display: block; font-size: 15px; word-spacing: .15em; }
.formula code + code { margin-top: 8px; }
.notation { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 16px 0; }
.notation div { display: flex; align-items: flex-start; gap: 8px; padding: 10px; background: #2a2d33; border-radius: 7px; font-size: 14px; }
.notation b { display: inline-block; width: 22px; color: #fff; font-size: 22px; line-height: 1.3; }
.notation span { color: var(--muted); min-width: 0; }
.notation strong { color: var(--text); }
.guide-illustration { margin: 22px 0; padding-top: 0; border-top: 0; }
.guide-illustration img { display: block; width: 100%; max-width: 660px; height: auto; margin: 0 auto 12px; }
.piece-examples { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 22px 0 16px; }
.piece-examples figure { margin: 0; padding: 0 8px 16px; border: 1px solid var(--line); border-radius: 12px; background: #1b1e22; text-align: center; }
.piece-examples img { display: block; width: 100%; max-width: 220px; height: auto; margin: auto; direction: ltr; }
.piece-examples figcaption strong { display: block; color: var(--text); font-size: 17px; font-weight: 600; }
.piece-examples figcaption span { display: block; }
.move-frames { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; list-style: none; padding: 0; margin: 22px 0; }
.move-frames li { margin: 0; padding: 0 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: #1b1e22; }
.move-frames figure { padding: 0; margin: 0; border: 0; }
.move-frames img { width: 100%; height: auto; display: block; }
.move-frames figcaption { font-size: 14px; }
.move-frames strong { color: var(--text); }
.compact-steps { margin: 15px 0; }
figure { margin: 23px 0 0; padding-top: 22px; border-top: 1px solid var(--line); }
.net { --size: clamp(42px, 10.3vw, 65px); display: grid; grid-template-columns: repeat(4, var(--size)); grid-template-rows: repeat(3, auto); gap: 7px; width: max-content; margin: 0 auto 16px; }
.face { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 3px; background: #111316; border-radius: 5px; width: var(--size); height: var(--size); }
.face i { border-radius: 2px; background: #555b64; }
.face .U { background: #f2f2f2; }
.face .D { background: #ffd500; }
.face .F { background: #d62828; }
.face .B { background: #ff7a00; }
.face .L { background: #12a84a; }
.face .R { background: #1e5bff; }
.face-U { grid-column: 2; grid-row: 1; }
.face-L { grid-column: 1; grid-row: 2; }
.face-F { grid-column: 2; grid-row: 2; }
.face-R { grid-column: 3; grid-row: 2; }
.face-B { grid-column: 4; grid-row: 2; }
.face-D { grid-column: 2; grid-row: 3; }
figcaption { font-size: 14px; }
.check { margin-top: 18px; padding: 13px 15px; border-radius: 8px; background: #24372a; }
.check strong { color: #b4edbd; }
footer { margin: 30px 0 0; font-size: 14px; }
@media (max-width: 760px) {
  .page { padding: 20px 16px 38px; }
  .lang-offer { margin: -20px -16px 16px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .contents { position: static; }
  .contents ol { columns: 2; column-gap: 26px; }
  .contents li { break-inside: avoid; }
  section { padding: 22px 18px; }
}
@media (max-width: 390px) {
  body { font-size: 16px; }
  .contents ol { columns: 1; }
  .notation { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media print {
  :root { color-scheme: light; }
  body, section { background: white; color: black; }
  .page { width: 100%; padding: 0; }
  .layout { display: block; }
  .contents, .guide-nav, .skip, .lang-offer { display: none; }
  section { break-inside: avoid; border-color: #aaa; }
  .note, .muted, figcaption, footer { color: #333; }
  .net { print-color-adjust: exact; }
  .formula { background: #eee; }
  code { color: #222; }
}
.rule { padding: 13px 15px; border: 1px solid #4a7a69; border-radius: 9px; background: #1b2f28; color: #e9fff6; }
.rules { margin: 14px 0 20px; }
.rules li + li { margin-top: 10px; }
.formulas { width: 100%; border-collapse: collapse; font-size: 14px; margin: 10px 0 16px; }
.formulas th, .formulas td { text-align: start; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.formulas th { color: var(--muted); font-weight: 600; }
.formulas td:nth-child(3) { color: var(--muted); }
.formula.chunks { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; }
.formula.chunks span { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; border-radius: 7px; background: #1d2126; }
.formula.chunks small { color: var(--muted); font-size: 12px; }
.cases { display: flex; flex-wrap: wrap; gap: 14px; margin: 16px 0; }
.case { margin: 0; padding: 0; border: 0; width: 140px; }
.mini { display: grid; grid-template-columns: repeat(3, 26px); gap: 3px; padding: 5px; width: max-content; border-radius: 6px; background: #111316; }
.mini b { height: 26px; border-radius: 3px; background: #555b64; }
.mini .D { background: #ffd500; }
.mini .U { background: #f2f2f2; }
.case figcaption { margin-top: 6px; font-size: 13px; line-height: 1.4; }
/* Карточки случаев — те же мини-кубики, что показывает урок: вид сверху или вид снизу (кубик наклонён верхом от себя). */
.case-scheme { padding: 6px 10px; border-radius: 8px; background: #1b1e22; }
.case-scheme svg { display: block; width: 100%; height: auto; }
/* Циферблаты: стрелка идёт по часовой и против; числа помогают тем, кто не привык к стрелочным часам. */
.clocks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 18px 0; }
.clock { margin: 0; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #1b1e22; text-align: center; }
.clock svg { width: 150px; height: 150px; margin: 0 auto 8px; display: block; }
.clock text { fill: #ececec; font: 700 15px system-ui, sans-serif; text-anchor: middle; }
.clock .hand { transform-origin: 60px 60px; animation: clock-cw 6s linear infinite; }
.clock .hand.ccw { animation-name: clock-ccw; }
.clock figcaption { font-size: 14px; text-align: start; }
@keyframes clock-cw { from { transform: rotate(0deg); } 40% { transform: rotate(90deg); } 55% { transform: rotate(90deg); } to { transform: rotate(360deg); } }
@keyframes clock-ccw { from { transform: rotate(0deg); } 40% { transform: rotate(-90deg); } 55% { transform: rotate(-90deg); } to { transform: rotate(-360deg); } }
@media (prefers-reduced-motion: reduce) {
  .clock .hand { animation: none; transform: rotate(60deg); }
  .clock .hand.ccw { transform: rotate(-60deg); }
}
@media (max-width: 560px) {
  .piece-examples { grid-template-columns: 1fr; }
  .piece-examples figure { display: flex; align-items: center; padding: 0 14px 0 0; text-align: start; }
  .piece-examples img { width: 60%; margin: 0; flex-shrink: 0; }
  .piece-examples figcaption { flex: 1; }
  .clocks { grid-template-columns: 1fr; }
  .case { width: calc(50% - 7px); }
}
@media (max-width: 760px) {
  .formulas, .formulas tbody, .formulas tr, .formulas td { display: block; }
  .formulas thead { display: none; }
  .formulas tr { padding: 8px 0; border-bottom: 1px solid var(--line); }
  .formulas td { border: 0; padding: 2px 0; }
}
@media print {
  .rule, .formula.chunks span { background: #f3f3f3; color: black; }
  .mini { print-color-adjust: exact; }
}

/* Справа налево (ar, fa, he, ur): страница зеркалится, но кубик — нет. Развёртка, картинки,
   нотация и формулы всегда слева направо: зелёная грань L слева, синяя R справа. */
:is(.net, .mini, .case-scheme, .clocks, .notation, .formula, code, kbd, .move-frames img, .guide-illustration img) { direction: ltr; unicode-bidi: isolate; }
.back-home::after { content: " →"; }
[dir="rtl"] .back-home::after { content: " ←"; }
:lang(ko) { word-break: keep-all; }
