:root {
  --bg: #fff;
  --ink: #2b2150;
  --muted: #6f6792;
  --card: #fff;
  --brand: #5b2fc9;
  --brand-2: #ff8a3d;
  --line: #e2dcf3;
  --tray: #f4f1fb;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 500 16px/1.4 "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;                        /* iOS < 15.4 не знает dvh */
  height: 100dvh;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;          /* долгое нажатие на планшете не вызывает меню */
  overscroll-behavior: none;            /* без «оттягивания» страницы */
}
button { touch-action: manipulation; } /* без зума по двойному тапу */

/* режим: обычный / магический круг */
.mode { flex: none; display: flex; gap: 2px; padding: 3px; margin: 0; border-radius: 999px; background: rgba(255,255,255,.12); }
.mode button { display: inline-flex; align-items: center; gap: 5px; border: 0; background: none; color: #fff;
  padding: 4px 12px; border-radius: 999px; font: inherit; font-size: 13.5px; font-weight: 600; white-space: nowrap; cursor: default; opacity: .8; }
.mode button.is-on { background: #fff; color: var(--ink); opacity: 1; }
.mode svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: hover) { .mode button:not(.is-on):hover { opacity: 1; background: rgba(255,255,255,.14); } }
/* ручка свободного поворота у выбранной детали (круг) */
.knob { cursor: grab; }
.knob circle { fill: #fff; stroke: var(--brand); stroke-width: .06; filter: drop-shadow(0 .05px .1px rgba(0,0,0,.3)); }
.knob-line { stroke: var(--brand); stroke-width: .04; stroke-dasharray: .12 .1; pointer-events: none; }
.knob path { fill: none; stroke: var(--brand); stroke-width: .07; stroke-linecap: round; stroke-linejoin: round; }
/* окно «Премиум» */
.modal__card--narrow { width: min(460px, 100%); }
.pr h2 { margin: 0 0 4px; font-size: 24px; font-weight: 800; }
.pr__note { margin: 4px 0 0; padding: 10px 14px; border-radius: 12px; background: var(--tray); color: var(--muted); font-size: 14px; font-weight: 600; }
.lbl-short { display: none; }

.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.btn--icon { padding: 9px; }
/* полоса игры (общая шапка ~/Kreativ-Labor/spiele-leiste): вкладки прижаты к ленте образцов, справа режим и кнопка ленты */
.kl-spielleiste--tabs { flex-wrap: nowrap; align-items: flex-end; gap: 10px; min-height: 44px; padding: 0 12px 0 12px; }
.kl-spielleiste--tabs > .mode, #btnTpl { align-self: center; }
.kl-spielleiste--tabs > .mode { margin-left: auto; }
#btnTpl { flex: none; padding: 5px 9px; }
#btnTpl svg { width: 22px; height: 18px; }
.mode:empty, body.is-free .mode { display: none; }
.mode:empty + #btnTpl, body.is-free #btnTpl { margin-left: auto; }
/* Freies Spiel / Reise (klReise): переключатель и карта — по центру полосы; в путешествии нет вкладок и «Magischer Kreis» */
.kl-spielleiste--tabs > .kl-modus, .kl-spielleiste--tabs > .kl-karte { align-self: center; }
.kl-spielleiste--tabs > .kl-karte { padding-bottom: 6px; }
.kl-in-reise .tabs, .kl-in-reise #modeSwitch { display: none; }
.kl-in-reise #btnTpl { margin-left: auto; }
.kl-in-reise .gallery { justify-content: center; }
#winKarte { display: flex; justify-content: center; margin: 10px 0 4px; }
/* окна (Premium, Album) */
.modal { position: fixed; inset: 0; z-index: 21; display: flex; padding: 16px; /* 15.10.2026: выше общей шапки (z-index 20), иначе крестик альбома под ней */
  background: rgba(43, 33, 80, .45); overflow-y: auto; }
.modal[hidden] { display: none; }
.modal__card { position: relative; margin: auto; background: #fff; border-radius: 22px; width: min(860px, 100%); min-width: 0;
  padding: 26px 28px; box-shadow: 0 20px 50px rgba(40, 20, 90, .3); animation: pop .3s ease-out; }
.modal__close { position: absolute; right: 12px; top: 10px; border: 0; background: none; font-size: 30px; line-height: 1;
  color: var(--muted); padding: 4px 10px; cursor: default; }
.pm__sub { margin: 0 0 12px; color: var(--muted); font-weight: 600; }
.pm__list { margin: 0 0 14px; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 15px; }
.pm__list li { padding-left: 26px; position: relative; }
.pm__list li::before { content: '✔'; position: absolute; left: 2px; color: #1faa59; font-weight: 800; }
@media (max-width: 720px) {
  .modal__card { padding: 22px 18px; }
}
@media (max-width: 480px) {
  .mode button { padding: 4px 9px; font-size: 12.5px; }
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 999px;
  padding: 9px 14px;
  background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600;
  box-shadow: 0 1px 0 var(--line), 0 2px 8px rgba(60, 30, 120, .08);
  cursor: pointer;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; }
.btn .ico { font-size: 18px; line-height: 1; }
.btn--ghost { background: rgba(255,255,255,.14); color: #fff; box-shadow: none; }
.btn--primary { background: var(--brand-2); color: #fff; }

/* лента образцов */
body.no-tpl .gallery { display: none; }
/* категории — вкладки как в браузере; открытая белая и сливается с лентой */
body.no-tpl .tabs { display: none; }
.tabs {
  display: flex; gap: 4px;
  padding: 6px 12px 0;
  flex: 1; min-width: 0;
  overflow-x: auto; scrollbar-width: none;
  min-height: 35px;                     /* место до заполнения скриптом — поле не «прыгает» */
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  display: flex; align-items: baseline; gap: 6px;
  padding: 4px 14px 5px;
  border: 0; border-radius: 8px 8px 0 0;
  background: rgba(255,255,255,.12); color: #fff;
  font: inherit; font-size: 14px; font-weight: 500; white-space: nowrap;
  cursor: default;
}
.tab small { font-size: 12px; font-weight: 400; opacity: .7; }
.tab__geschenk { margin-left: 5px; font-size: 15px; line-height: 1; }
.tab.is-open { background: var(--bg); color: var(--ink); }
.tab.is-open small { color: var(--muted); opacity: 1; }
@media (hover: hover) { .tab:not(.is-open):hover { background: rgba(255,255,255,.22); } }
.gallery { cursor: grab; }
.gallery.is-dragging, .gallery.is-dragging .tpl { cursor: grabbing; }
.gallery {
  display: flex; gap: 10px;
  padding: 10px 16px;
  overflow-x: auto;
  scrollbar-width: thin;
  flex: none;
  border-bottom: 1px solid var(--line);
  min-height: 186px;                    /* = высота образца + отступы (на телефоне ниже — см. @media 600px) */
}
.tpl {
  flex: none;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 10px 6px;
  border: 2px solid transparent; border-radius: var(--radius);
  background: none;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--muted);
  cursor: pointer; position: relative;
}
@media (hover: hover) { .tpl:hover { background: var(--tray); } }  /* на планшете hover «залипает» */
.tpl svg { height: 110px; width: auto; max-width: 160px; overflow: visible; }
.tpl svg polygon { fill: #fff; stroke: #222; stroke-width: 1.1; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.tpl.is-active { border-color: var(--brand); color: var(--brand); background: var(--tray); }
.tpl .done { position: absolute; top: 4px; right: 6px; font-size: 14px; color: #1faa59; }

.stage { position: relative; flex: 1; min-height: 0; }
#board { width: 100%; height: 100%; display: block; touch-action: none; }
#trayBg { fill: var(--tray); }
.area { fill: #fcfbff; stroke: #c7bde6; stroke-width: .05; stroke-dasharray: .3 .2; }
/* дуэль: подписи игроков и черта посередине */
.area__label { font-size: .6px; font-weight: 800; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.area__label--p1 { fill: #2f7de1; }
.area__label--p2 { fill: #e8702a; }
.divider { stroke: var(--brand); stroke-width: .08; }
#helpText { fill: #b9b2d3; font-size: .55px; font-weight: 600; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }

.piece { cursor: grab; transform-box: view-box; transform-origin: 0 0; }
.piece polygon {
  stroke: #1d1a2b;
  stroke-width: .04;
  stroke-linejoin: round;
}
.piece.is-selected polygon { stroke: var(--brand); stroke-width: .1; }
.piece.is-dragging { cursor: grabbing; }
.piece.is-dragging polygon { filter: drop-shadow(0 .12px .2px rgba(0,0,0,.35)); }
.piece.is-anim { transition: transform .18s ease-out; }
/* подсказка: такая же деталь мигает */
.piece.is-hint polygon { animation: hint .6s ease-in-out 4; }
@keyframes hint { 50% { stroke: #fff; stroke-width: .16; filter: brightness(1.25) drop-shadow(0 0 .25px #ffd21f); } }

.tools {
  position: relative;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  background: var(--tray);
  flex: none;
}

.win {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: rgba(43, 33, 80, .3);
  z-index: 21; /* выше общей шапки, как .modal */
}
.win[hidden] { display: none; }
.win__card {
  background: var(--card); border-radius: 22px;
  padding: 24px 28px; text-align: center; max-width: 340px; margin: 16px;
  box-shadow: 0 20px 50px rgba(40, 20, 90, .3);
  animation: pop .35s cubic-bezier(.2, 1.6, .4, 1);
}
.win__emoji { font-size: 54px; }
.win h2 { margin: 6px 0 4px; font-weight: 700; }
.win p { margin: 0 0 18px; color: var(--muted); }
.win__extra { display: grid; gap: 4px; margin: -8px 0 16px; font-weight: 700; color: var(--brand); }
.win__extra:empty { display: none; }
/* премиум-режимы внизу: переключатели со словом */
.btn--toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn--toggle.is-on { background: var(--brand); color: #fff; }
/* секундомер в углу поля */
/* часики «на время»: выключены — белый круглый значок, включены — фиолетовая плашка «⏱ 0:00» (видно, что время идёт) */
.corner .clock { gap: 7px; font-variant-numeric: tabular-nums; }
.corner .clock svg { width: 24px; height: 24px; stroke-width: 2.2; }
.clock b, .clock small { display: none; }
.corner .clock.is-on { width: auto; background: var(--brand); color: #fff; padding: 0 16px 0 12px; }
.corner .clock.is-on svg { stroke: #fff; }
.clock.is-on b { display: inline; font-size: 18px; }
.clock.is-on small { display: inline; color: rgba(255,255,255,.8); font-size: 13px; font-weight: 600; }
.clock.is-on small:empty { display: none; }
/* «по очереди»: закрытые категории */
.tab svg { width: 12px; height: 12px; margin-right: -2px; align-self: center; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.tab.is-locked { opacity: .6; }
.gallery.is-locked .tpl { opacity: .35; }
.gallery__lock { flex: none; align-self: center; display: flex; gap: 8px; align-items: center; max-width: 260px; margin: 0 8px 0 0;
  font-size: 14px; font-weight: 700; color: var(--muted); }
.gallery__lock svg { flex: none; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* «Schwer»: образец только силуэтом; подсказанные детали — цветом и с линиями */
body.is-hard .tpl svg polygon { fill: #3d2f73; stroke: #3d2f73; }
.tpl svg polygon.rev, body.is-hard .tpl svg polygon.rev { stroke: #222; }
/* строка под названием образца: звёзды и рекорд. Есть всегда (даже пустая) — лента не меняет высоту
   при включении часиков, и поле под ней не прыгает */
.tpl__meta { display: flex; gap: 6px; justify-content: center; height: 14px; margin-top: -3px; font-size: 12px; line-height: 14px; }
.tpl__meta i { font-style: normal; }
.tpl__stars { color: #f2a900; letter-spacing: 1px; }
.tpl__best { font-weight: 700; color: var(--brand); }
.btn .count { min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--tray); color: var(--brand); font-size: 12px; font-weight: 800; text-align: center; }
.btn.is-on .count { background: rgba(255,255,255,.25); color: #fff; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn[hidden] { display: none; }
/* меню «Spielmodi»: над нижней панелью */
/* кнопки в правом верхнем углу поля */
.corner { position: absolute; top: 20px; left: 22px; z-index: 4; display: flex; flex-wrap: wrap; justify-content: flex-start; gap: 6px;
  max-width: calc(100% - 28px); pointer-events: none; }
.corner > * { pointer-events: auto; }
/* все кнопки угла одной высоты — при включении часиков ряд не прыгает */
.corner .btn { height: 44px; padding: 0 15px; font-size: 15px; line-height: 1; justify-content: center; }
.corner .btn svg { width: 18px; height: 18px; }
.corner { align-items: center; }
.corner .btn--icon, .corner .clock { width: 44px; padding: 0; }
.corner .btn--icon svg { width: 24px; height: 24px; stroke-width: 2.2; }
.modes { position: absolute; top: calc(100% + 8px); left: 0; z-index: 8;
  width: min(360px, calc(100vw - 24px)); padding: 6px; display: grid; gap: 2px;
  background: #fff; border-radius: 16px; box-shadow: 0 12px 30px rgba(40, 20, 90, .25); }
.modes[hidden] { display: none; }
.modes__row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 0; border-radius: 12px; background: none;
  font: inherit; color: var(--ink); text-align: left; cursor: default; }
@media (hover: hover) { .modes__row:hover { background: var(--tray); } }
.modes__row > svg { flex: none; width: 22px; height: 22px; fill: none; stroke: var(--brand); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.modes__row span { flex: 1; display: grid; }
.modes__row b { font-size: 15px; }
.modes__row small { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.switch { flex: none; width: 38px; height: 22px; border-radius: 999px; background: #d9d3ea; position: relative; transition: background .15s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.modes__row.is-on .switch { background: var(--brand); }
.modes__row.is-on .switch::after { left: 19px; }
/* сообщение посередине поля («Auf Zeit ist an …») */
.toast { position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%); z-index: 5; pointer-events: none;
  width: max-content; max-width: min(440px, calc(100% - 32px)); padding: 14px 20px; border-radius: 16px;
  background: #fff; color: var(--ink); font-size: 16px; text-align: center; line-height: 1.4;
  box-shadow: 0 12px 30px rgba(40, 20, 90, .22); border: 2px solid var(--brand); }
.toast[hidden] { display: none; }
.toast b { color: var(--brand); }
.toast.is-in { animation: toast 3.2s ease-out forwards; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -40%); } 8%, 85% { opacity: 1; transform: translate(-50%, -50%); } 100% { opacity: 0; transform: translate(-50%, -50%); } }
/* дуэль: отсчёт 3-2-1 */
.countdown { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; pointer-events: none;
  font-size: 120px; font-weight: 900; color: var(--brand); text-shadow: 0 4px 0 #fff, 0 8px 30px rgba(60, 30, 120, .3); }
.countdown[hidden] { display: none; }
.countdown.is-pop { animation: pop .5s cubic-bezier(.2, 1.6, .4, 1); }
/* победа: звёзды */
.win__stars { font-size: 34px; color: #f2a900; letter-spacing: 4px; line-height: 1; }
/* альбом наклеек */
.album h2 { margin: 0 0 4px; font-size: 24px; font-weight: 800; }
.album__group { margin-top: 18px; }
.album__group h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 17px; }
.album__group h3 small { color: var(--muted); font-weight: 600; }
.badge { font-size: 22px; filter: grayscale(1) opacity(.35); }
.badge.is-on { filter: none; }
.album__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.sticker { display: grid; justify-items: center; align-content: center; gap: 2px; padding: 10px 4px 8px; min-height: 104px;
  border-radius: 14px; background: #fff7df; border: 2px solid #ffe3a3; text-align: center; }
.sticker__emo { font-size: 40px; line-height: 1.1; }
.sticker__name { font-size: 12px; font-weight: 700; color: var(--ink); }
.sticker__stars { font-size: 12px; color: #f2a900; letter-spacing: 1px; min-height: 14px; }
.sticker.is-empty { background: var(--tray); border: 2px dashed var(--line); }
.sticker.is-empty svg { height: 48px; width: auto; max-width: 80px; }
.sticker.is-empty svg polygon { fill: #e9e4f6; stroke: #cfc6e8; stroke-width: 1; vector-effect: non-scaling-stroke; }
.sticker.is-empty .sticker__name { color: var(--muted); }
.album__info { margin: 18px 0 0; font-size: 13px; color: var(--muted); }
.win__btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 22; }

@media (max-width: 600px) {
  .btn { padding: 8px 11px; font-size: 14px; }
  .lbl-long { display: none; }
  .lbl-short { display: inline; }
  .btn--icon { padding: 8px; }
  .tab { padding: 4px 10px 5px; font-size: 13px; }
  .tpl svg { height: 80px; max-width: 100px; }
  .gallery { min-height: 156px; }
  .tabs { min-height: 34px; }
  .corner .btn--icon, .corner .clock { width: 40px; padding: 0; }
  .corner .btn--icon svg { width: 21px; height: 21px; }
  .corner { top: 14px; left: 14px; gap: 4px; }
  .corner .btn { height: 40px; padding: 0 11px; font-size: 13.5px; }
  .clock b { font-size: 16px; }
}
/* ?free=1 — бесплатная версия без премиум-кнопок */
body.is-free .mode { display: none; }


/* телефон (15.10.2026): полоса игры в два ряда — сверху «Freies Spiel | Reise» и кнопка ленты, снизу вкладки или карта этапов.
   В один ряд вкладкам почти не оставалось места (по-русски «Свободная игра | Путешествие» длиннее), а карта этапов вылезала за край. */
@media (max-width: 560px) {
  .kl-spielleiste--tabs { flex-wrap: wrap; row-gap: 0; padding-top: 6px; }
  .kl-spielleiste--tabs::before { content: ''; order: -1; flex-basis: 100%; height: 6px; }
  .kl-spielleiste--tabs > .kl-modus { order: -3; }
  .kl-spielleiste--tabs > #btnTpl { order: -2; margin-left: auto; }
  .kl-spielleiste--tabs > .kl-karte { margin: 0 auto; }
}

/* телефон горизонтально (15.10.2026): лента фигур ниже — полю больше места */
@media (orientation: landscape) and (max-height: 500px) { .gallery { min-height: 0; padding-block: 4px; } .tpl { padding: 4px 8px 2px; gap: 2px; } .tpl svg { height: 56px; max-width: 84px; } }
