        :root {
            color-scheme: dark;
            /* Тёплая тёмная база с пониженным контрастом — мягче для глаз */
            --bg: #14120e;
            --panel: #1c1a14;
            --panel-soft: #232017;
            --field: #18150f;
            --line: #322e23;
            --line-soft: rgba(230, 218, 192, .08);
            --text: #e6ddcd;
            --muted: #978d7c;
            --accent: #d8a64b;
            --accent-dim: rgba(216, 166, 75, .18);
            --accent-grad: linear-gradient(180deg, #eec873, #bd8730);
            --green: #73d29d;
            --red: #db8a8a;
            --right: #73d29d;
            --left: #db8a8a;
            --shadow: 0 14px 36px rgba(0, 0, 0, .28);
            --shadow-soft: 0 6px 18px rgba(0, 0, 0, .22);
            --radius: 8px;
            --radius-lg: 11px;
            font-family: Inter, "Segoe UI", Arial, sans-serif;
        }

        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            min-height: 100vh;
            background:
                radial-gradient(circle at 16% -12%, rgba(216, 166, 75, .07), transparent 30rem),
                radial-gradient(circle at 86% 6%, rgba(115, 210, 157, .04), transparent 24rem),
                linear-gradient(180deg, #181610, var(--bg) 46%, #0c0b08);
            color: var(--text);
            font-size: 15px;
            line-height: 1.5;
        }

        button,
        input,
        select {
            font: inherit;
        }

        button {
            border: 1px solid var(--line);
            border-radius: 7px;
            background: var(--panel-soft);
            color: var(--text);
            padding: .5rem .85rem;
            cursor: pointer;
            transition: border-color .14s ease, transform .14s ease, background .14s ease, box-shadow .14s ease;
        }

        button:hover {
            border-color: rgba(216, 166, 75, .5);
            transform: translateY(-1px);
        }

        button:active {
            transform: translateY(0);
        }

        button:disabled {
            opacity: .4;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }

        button:focus-visible,
        input:focus-visible,
        select:focus-visible {
            outline: 2px solid rgba(216, 166, 75, .5);
            outline-offset: 1px;
        }

        button.primary {
            border-color: rgba(236, 198, 111, .35);
            background: var(--accent-grad);
            color: #1a1206;
            font-weight: 700;
            box-shadow: 0 4px 12px rgba(185, 132, 47, .22);
        }

        button.primary:hover {
            box-shadow: 0 6px 16px rgba(185, 132, 47, .32);
        }

        button.ghost {
            background: transparent;
        }

        input,
        select {
            width: 100%;
            border: 1px solid var(--line);
            border-radius: 7px;
            background: var(--field);
            color: var(--text);
            padding: .55rem .7rem;
            transition: border-color .14s ease, box-shadow .14s ease;
        }

        input:focus,
        select:focus {
            outline: none;
            border-color: var(--accent);
            box-shadow: 0 0 0 3px var(--accent-dim);
        }

        .page {
            width: min(1200px, calc(100% - 32px));
            margin: 0 auto;
            padding: 18px 0 28px;
        }

        a {
            color: inherit;
        }

        /* ── Шапка ──────────────────────────────────────────── */
        .hero {
            position: sticky;
            top: 10px;
            z-index: 20;
            display: flex;
            flex-wrap: wrap;
            gap: 12px;
            align-items: center;
            justify-content: space-between;
            border: 1px solid var(--line);
            border-radius: var(--radius-lg);
            background: linear-gradient(180deg, rgba(33, 30, 23, .94), rgba(22, 20, 15, .94));
            backdrop-filter: blur(8px);
            box-shadow: var(--shadow-soft);
            margin-bottom: 14px;
            padding: 10px 16px;
        }

        .hero-brand {
            display: flex;
            flex-direction: column;
            min-width: 0;
        }

        .toolbar {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            align-items: center;
        }

        h1,
        h2,
        h3,
        p {
            margin: 0;
        }

        h1 {
            font-size: clamp(1.2rem, 1.7vw, 1.6rem);
            font-weight: 600;
            line-height: 1.1;
        }

        /* Единый заголовок: «Gothic 1 Remake · Взлом замков» */
        .brand {
            display: inline-flex;
            flex-wrap: wrap;
            align-items: baseline;
            gap: .5ch;
        }

        .brand-game {
            color: var(--accent);
            font-weight: 700;
        }

        .brand-sep {
            color: var(--line);
        }

        .brand-app {
            color: var(--text);
            font-weight: 500;
        }

        /* Выбор количества пинов — сегментный переключатель в шапке */
        .pin-switch {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            border: 1px solid var(--line);
            border-radius: 999px;
            background: var(--field);
            padding: 3px 4px 3px 13px;
        }

        .pin-switch-label {
            color: var(--muted);
            font-size: .72rem;
            font-weight: 700;
            letter-spacing: .04em;
            text-transform: uppercase;
        }

        .pin-switch-options {
            display: inline-flex;
            gap: 2px;
        }

        .pin-switch-options button {
            min-width: 34px;
            border: 0;
            border-radius: 999px;
            background: transparent;
            color: var(--muted);
            font-weight: 700;
            padding: .32rem .1rem;
        }

        .pin-switch-options button:hover {
            transform: none;
            color: var(--text);
        }

        .pin-switch-options button.is-active {
            background: var(--accent-grad);
            color: #1a1206;
            box-shadow: 0 1px 6px rgba(185, 132, 47, .25);
        }

        /* Группа действий: Пример · Сбросить · Найти решение */
        .toolbar-actions {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            align-items: center;
        }

        /* Переключатель языка */
        .lang-switch {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            border: 1px solid var(--line);
            border-radius: 999px;
            background: var(--field);
            padding: 2px 8px 2px 10px;
        }

        .lang-globe {
            font-size: .9rem;
            opacity: .75;
            line-height: 1;
        }

        .lang-switch select {
            width: auto;
            border: 0;
            border-radius: 999px;
            background: transparent;
            color: var(--text);
            padding: .32rem .2rem;
            font-size: .82rem;
            font-weight: 600;
        }

        .lang-switch select:focus {
            box-shadow: none;
        }

        /* Тёмный читаемый выпадающий список опций (иначе серый на белом системном фоне) */
        .lang-switch option {
            background: var(--panel);
            color: var(--text);
        }

        /* Подсказка по работе со шкалой (прячется на время проигрывания решения) */
        .scale-hint {
            margin: 0;
            color: var(--muted);
            font-size: .8rem;
            line-height: 1.45;
        }

        body.has-solution .scale-hint {
            display: none;
        }

        /* ── Раскладка: шкала-ввод (широко) + узкое решение ──── */
        .layout {
            display: grid;
            grid-template-columns: minmax(0, 1fr) minmax(190px, 250px);
            gap: 16px;
            align-items: start;
        }

        .panel {
            border: 1px solid var(--line);
            border-radius: var(--radius-lg);
            background: rgba(28, 26, 20, .92);
            box-shadow: var(--shadow);
        }

        .panel-header {
            display: flex;
            justify-content: space-between;
            gap: 12px;
            align-items: center;
            padding: 13px 14px 0;
        }

        .panel-header h2 {
            font-size: 1rem;
            font-weight: 600;
        }

        .panel-body {
            display: grid;
            gap: 12px;
            padding: 14px;
        }

        .hint {
            color: var(--muted);
            font-size: .82rem;
        }

        .field label {
            display: block;
            margin-bottom: 5px;
            color: var(--muted);
            font-size: .72rem;
            font-weight: 700;
            line-height: 1;
            letter-spacing: .02em;
            text-transform: uppercase;
        }

        .start-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(48px, 1fr));
            gap: 5px;
        }

        .start-grid .field {
            border: 1px solid var(--line);
            border-radius: 7px;
            background: var(--field);
            padding: 5px;
        }

        .start-grid .field label {
            margin-bottom: 3px;
            font-size: .7rem;
            line-height: 1;
            text-align: center;
        }

        .start-grid input {
            text-align: center;
            font-size: .9rem;
            font-weight: 600;
            padding: .32rem .2rem;
        }

        .editor-card {
            display: grid;
            gap: 10px;
            border: 1px solid var(--line-soft);
            border-radius: var(--radius);
            background: rgba(24, 21, 15, .55);
            padding: 11px;
        }

        .compact-card {
            gap: 9px;
            padding: 10px;
        }

        .compact-card h3 {
            font-size: .92rem;
            font-weight: 600;
        }

        .card-title {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 12px;
        }

        .pill {
            flex: 0 0 auto;
            border: 1px solid var(--line);
            border-radius: 999px;
            color: var(--muted);
            font-size: .7rem;
            font-weight: 600;
            letter-spacing: .02em;
            padding: .22rem .55rem;
        }

        /* ── Шкала пинов: плоский вид (база) ─────────────────── */
        .pin-editor {
            display: grid;
            gap: 0;
            border-radius: var(--radius);
            overflow: hidden;
        }

        .pin-row {
            display: grid;
            grid-template-columns: 44px minmax(160px, 1fr) 48px;
            gap: 8px;
            align-items: center;
            border: 1px solid var(--line);
            background: #16140f;
            padding: 6px 8px;
            transition: background .14s ease, box-shadow .14s ease;
        }

        .pin-row:nth-child(odd) {
            background: #18150f;
        }

        .pin-row:nth-child(even) {
            background: #131109;
        }

        /* интерактив: имя · стрелка реакции · рельс · значение */
        .pin-row.configurable {
            grid-template-columns: 44px 38px minmax(140px, 1fr) 38px;
        }

        .pin-row + .pin-row {
            border-top: 0;
        }

        .pin-row.active {
            box-shadow: inset 3px 0 0 var(--right);
        }

        .pin-row.source {
            box-shadow: inset 3px 0 0 var(--accent);
        }

        .pin-name {
            color: var(--muted);
            font-weight: 600;
        }

        .pin-source {
            padding: .32rem .2rem;
            border-color: transparent;
            background: transparent;
            color: var(--muted);
            font-weight: 600;
        }

        .pin-row.source .pin-source {
            border-color: rgba(216, 166, 75, .45);
            background: var(--accent-dim);
            color: var(--accent);
        }

        .pin-value {
            font-family: Consolas, "Courier New", monospace;
            font-weight: 600;
            text-align: right;
        }

        .rail {
            position: relative;
            height: 32px;
            border: 1px solid var(--line);
            border-radius: 999px;
            background: linear-gradient(180deg, #2f2b23, #16130f);
        }

        .ticks {
            position: absolute;
            inset: 50% 18px auto;
            display: flex;
            justify-content: space-between;
            transform: translateY(-50%);
            pointer-events: none;
        }

        .tick {
            width: 1px;
            height: 11px;
            background: rgba(230, 221, 205, .18);
        }

        .dots {
            position: absolute;
            inset: 0 12px;
        }

        .dot {
            position: absolute;
            top: 50%;
            width: 23px;
            height: 23px;
            border-radius: 999px;
            padding: 0;
            transform: translate(-50%, -50%);
            color: transparent;
            background: #272218;
            border: 1px solid rgba(230, 221, 205, .2);
            transition: transform .12s ease, box-shadow .14s ease, background .14s ease;
        }

        .dot:hover {
            transform: translate(-50%, -50%) scale(1.08);
            color: rgba(230, 221, 205, .5);
        }

        .dot.selected {
            width: 29px;
            height: 29px;
            color: #1a1206;
            font-size: .76rem;
            font-weight: 700;
            background: var(--accent-grad);
            border-color: rgba(236, 198, 111, .55);
            box-shadow: 0 0 12px rgba(216, 166, 75, .22);
        }

        .pin-row.active .dot.selected {
            color: #0c1c14;
            background: linear-gradient(180deg, #b8f0d2, #4fb085);
            box-shadow: 0 0 16px rgba(115, 210, 157, .42);
        }

        .preview-effect {
            min-width: 0;
            padding: .36rem .18rem;
            font-size: .92rem;
            font-weight: 700;
        }

        .preview-effect[data-value="1"] {
            border-color: rgba(115, 210, 157, .5);
            background: rgba(115, 210, 157, .12);
            color: var(--right);
        }

        .preview-effect[data-value="-1"] {
            border-color: rgba(219, 138, 138, .5);
            background: rgba(219, 138, 138, .11);
            color: var(--left);
        }

        .preview-effect[data-value="0"] {
            color: var(--muted);
        }

        .preview-effect:disabled,
        .effect-toggle:disabled {
            cursor: default;
            opacity: 1;
            transform: none;
        }

        .preview-effect[data-locked="1"],
        .effect-toggle[data-locked="1"] {
            box-shadow: inset 0 0 0 1px rgba(236, 198, 111, .2);
        }

        /* ── Реакции ────────────────────────────────────────── */
        .reaction-list {
            display: grid;
            gap: 5px;
        }

        .reaction-card .reaction-list {
            font-size: .88rem;
        }

        .reaction-row {
            display: grid;
            grid-template-columns: 64px minmax(0, 1fr);
            gap: 6px;
            align-items: stretch;
            border: 1px solid var(--line);
            border-radius: 7px;
            background: #171410;
            padding: 5px;
        }

        .reaction-head {
            display: flex;
            justify-content: center;
            gap: 6px;
            align-items: center;
            color: var(--muted);
            min-width: 0;
            white-space: nowrap;
        }

        .lever {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            color: var(--text);
            font-weight: 600;
        }

        .arrow-badge {
            display: inline-grid;
            place-items: center;
            width: 23px;
            height: 21px;
            border-radius: 999px;
            border: 1px solid rgba(115, 210, 157, .38);
            background: rgba(115, 210, 157, .1);
            color: var(--right);
        }

        .effects {
            display: grid;
            grid-template-columns: repeat(var(--pin-count, 5), minmax(0, 1fr));
            gap: 4px;
            min-width: 0;
        }

        .effect {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 6px;
            border: 1px solid var(--line);
            border-radius: 7px;
            background: var(--field);
            padding: 4px 5px;
            min-width: 0;
        }

        .effect-name {
            color: var(--muted);
            font-size: .76rem;
            line-height: 1;
            white-space: nowrap;
        }

        .effect-toggle {
            min-width: 0;
            width: 29px;
            min-height: 25px;
            padding: .2rem .12rem;
            font-size: .9rem;
            font-weight: 700;
        }

        .effect-toggle[data-value="1"] {
            border-color: rgba(115, 210, 157, .5);
            background: rgba(115, 210, 157, .12);
            color: var(--right);
        }

        .effect-toggle[data-value="-1"] {
            border-color: rgba(219, 138, 138, .5);
            background: rgba(219, 138, 138, .11);
            color: var(--left);
        }

        .effect-toggle[data-value="0"] {
            color: var(--muted);
        }

        /* ── Решение ────────────────────────────────────────── */
        .status {
            border: 1px solid var(--line);
            border-radius: 7px;
            background: var(--field);
            color: var(--muted);
            padding: 11px 13px;
            min-height: 48px;
            line-height: 1.45;
        }

        .status.ok {
            border-color: rgba(115, 210, 157, .45);
            background: rgba(115, 210, 157, .07);
            color: #c8ecd8;
        }

        .status.bad {
            border-color: rgba(219, 138, 138, .55);
            background: rgba(219, 138, 138, .07);
            color: #f1cccc;
        }

        .preview {
            display: grid;
            gap: 11px;
        }

        .preview-actions {
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            gap: 10px;
        }

        /* Панель проигрывания: пошагово (← Шаг / Шаг →) и авто (Пуск/Пауза) */
        .playback {
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            gap: 6px;
        }

        .pb-row {
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            gap: 6px;
        }

        .pb-icon {
            min-width: 38px;
            padding: .42rem .5rem;
            line-height: 1;
            font-size: 1rem;
        }

        .pb-step {
            font-weight: 700;
            white-space: nowrap;
        }

        /* Главная кнопка авто-проигрывания — выделена акцентом */
        .pb-play {
            min-width: 92px;
            border-color: rgba(236, 198, 111, .35);
            background: var(--accent-grad);
            color: #1a1206;
            font-weight: 800;
            white-space: nowrap;
        }

        .pb-play:hover {
            box-shadow: 0 4px 12px rgba(185, 132, 47, .3);
        }

        .pb-play.is-playing {
            background: var(--panel-soft);
            color: var(--text);
            border-color: var(--line);
        }

        .pb-play:disabled {
            background: var(--panel-soft);
            color: var(--text);
            border-color: var(--line);
        }

        /* Индикатор прогресса «шаг / всего» */
        .pb-progress {
            min-width: 48px;
            padding: 0 6px;
            color: var(--muted);
            font-family: Consolas, "Courier New", monospace;
            font-weight: 700;
            font-size: .88rem;
            text-align: center;
            white-space: nowrap;
        }

        /* Контекстная кнопка справа: «Найти решение» / «Новый замок» */
        #mainAction {
            margin-left: auto;
            min-width: 130px;
        }

        #mainAction.is-new {
            background: var(--panel-soft);
            color: var(--text);
            border-color: var(--line);
            box-shadow: none;
            font-weight: 700;
        }

        #mainAction.is-new:hover {
            border-color: rgba(216, 166, 75, .5);
        }

        .speed-control {
            display: inline-grid;
            grid-template-columns: auto minmax(82px, 1fr);
            gap: 8px;
            align-items: center;
            min-height: 41px;
            border: 1px solid var(--line);
            border-radius: 7px;
            background: var(--panel-soft);
            color: var(--muted);
            padding: 4px 5px 4px 10px;
            font-size: .72rem;
            font-weight: 700;
            letter-spacing: .02em;
            text-transform: uppercase;
        }

        .speed-control select {
            min-height: 31px;
            border-color: transparent;
            background: var(--field);
            padding: .32rem .46rem;
            font-size: .86rem;
            font-weight: 600;
            text-transform: none;
        }

        .readout {
            display: flex;
            justify-content: space-between;
            gap: 12px;
            align-items: center;
            color: var(--muted);
            border: 1px solid var(--line-soft);
            border-radius: 7px;
            background: rgba(24, 21, 15, .45);
            padding: 8px 12px;
        }

        .state {
            color: var(--green);
            font-family: Consolas, "Courier New", monospace;
            font-weight: 600;
            overflow-wrap: anywhere;
        }

        .solution {
            display: grid;
            gap: 1px;
        }

        /* Компактная строка хода: № · пин · направление · состояние */
        .move {
            display: grid;
            grid-template-columns: 2.4ch 3ch 1.4ch minmax(0, 1fr);
            gap: 8px;
            align-items: center;
            padding: 3px 6px;
            border-radius: 4px;
            font-family: Consolas, "Courier New", monospace;
            font-size: .82rem;
        }

        .move:nth-child(even) {
            background: rgba(255, 255, 255, .025);
        }

        .move:hover {
            background: var(--accent-dim);
        }

        .move-num {
            color: var(--muted);
        }

        .move-pin {
            color: var(--text);
            font-weight: 700;
        }

        .move-dir {
            text-align: center;
        }

        .move-state {
            color: var(--muted);
            letter-spacing: .08em;
            overflow-wrap: anywhere;
        }

        .move-done {
            padding: 6px;
            color: var(--green);
            font-size: .86rem;
        }

        .dir-right {
            color: var(--right);
            font-weight: 700;
        }

        .dir-left {
            color: var(--left);
            font-weight: 700;
        }

        .dir-neutral {
            color: var(--muted);
            font-weight: 700;
        }

        /* ── Подвал ─────────────────────────────────────────── */
        .footer {
            position: relative;
            overflow: hidden;
            border-top: 1px solid var(--line);
            background: linear-gradient(180deg, rgba(30, 27, 20, .9), rgba(12, 11, 8, .96));
            color: var(--muted);
            font-size: .85rem;
            margin-top: 8px;
        }

        .footer-inner {
            display: flex;
            justify-content: center;
            gap: 10px;
            align-items: center;
            width: min(1200px, calc(100% - 32px));
            margin: 0 auto;
            min-height: 60px;
            padding: 16px 0;
        }

        .footer span {
            color: rgba(230, 221, 205, .5);
        }

        .footer a {
            display: inline-flex;
            align-items: center;
            min-height: 32px;
            color: var(--accent);
            font-weight: 600;
            padding: .16rem 0;
            text-decoration: none;
            transition: color .12s ease;
        }

        .footer a:hover {
            color: #e6ddcd;
        }

        /* ── Адаптив ────────────────────────────────────────── */
        @media (max-width: 1100px) {
            .layout {
                grid-template-columns: 1fr;
            }
        }

        @media (max-width: 740px) {
            .page {
                width: min(100% - 20px, 1200px);
                padding-top: 14px;
            }

            .hero {
                position: static;
                flex-direction: column;
                align-items: stretch;
            }

            .toolbar {
                justify-content: flex-start;
            }

            /* Пины — на свою строку; действия и переключатель языка — в одном ряду */
            .pin-switch {
                flex: 1 1 100%;
                justify-content: center;
            }

            .toolbar-actions {
                flex: 0 0 auto;
            }

            .lang-switch {
                margin-left: auto;
            }

            .preview-actions .playback {
                margin-left: 0;
            }

            .pin-row {
                grid-template-columns: 38px minmax(120px, 1fr) 40px;
            }

            .pin-row.configurable {
                grid-template-columns: 38px 36px minmax(100px, 1fr) 36px;
            }

            .reaction-row {
                grid-template-columns: 1fr;
            }

            .reaction-head {
                justify-content: flex-start;
            }

            .effects {
                grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
            }

            /* Управление одним рядом: скорость · в начало · шаги · пуск (с переносом) */
            .preview-actions {
                flex-direction: column;
                align-items: stretch;
                gap: 8px;
            }

            .playback {
                width: 100%;
                row-gap: 8px;
            }

            /* Каждая строка управления — на всю ширину */
            .pb-row {
                flex-basis: 100%;
            }

            .pb-row-main {
                justify-content: flex-start;
            }

            .pb-row-steps {
                justify-content: center;
            }

            /* Шаг · Пуск · Шаг — равномерно во всю ширину */
            .pb-row-steps .pb-step,
            .pb-row-steps .pb-play {
                flex: 1 1 auto;
            }

            .speed-control {
                min-height: 38px;
            }

            /* Главная кнопка — после управления, на всю ширину */
            #mainAction {
                width: 100%;
                min-width: 0;
                margin-left: 0;
            }

            .readout {
                flex-wrap: wrap;
            }
        }
