/* ==========================================================================
   Mahjong — стили сайта и игрового поля.
   Темы задаются переменными на <html data-theme="...">.
   ========================================================================== */

:root {
  --font-display: "Cormorant", "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
  --radius-sm: 9px;
  --header-h: 64px;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
}

/* --- Темы ----------------------------------------------------------------- */

[data-theme="jade"] {
  color-scheme: dark;
  --bg: #0a2219;
  --bg-deep: #061811;
  --felt-1: #1c5641;
  --felt-2: #0e3326;
  --surface: rgba(255, 255, 255, .045);
  --surface-2: rgba(255, 255, 255, .08);
  --line: rgba(232, 206, 145, .16);
  --text: #f1ead8;
  --muted: #a6b9ad;
  --accent: #e2bf75;
  --accent-2: #f3d9a0;
  --accent-ink: #2a1d05;
  --pattern: rgba(232, 206, 145, .05);
  --tile-face-1: #fffcf3;
  --tile-face-2: #f1e7cf;
  --tile-edge: #dccca5;
  --tile-back-1: #1f8a5c;
  --tile-back-2: #145f40;
  --shadow: rgba(0, 0, 0, .45);
}

[data-theme="night"] {
  color-scheme: dark;
  --bg: #0d1226;
  --bg-deep: #070a17;
  --felt-1: #2a2f63;
  --felt-2: #12163a;
  --surface: rgba(255, 255, 255, .045);
  --surface-2: rgba(255, 255, 255, .08);
  --line: rgba(190, 200, 255, .16);
  --text: #eceefa;
  --muted: #a3a9cc;
  --accent: #e7b866;
  --accent-2: #f6d79b;
  --accent-ink: #2a1d05;
  --pattern: rgba(190, 200, 255, .05);
  --tile-face-1: #fffdf7;
  --tile-face-2: #ece5d3;
  --tile-edge: #d6cbb0;
  --tile-back-1: #3a4bb0;
  --tile-back-2: #24307a;
  --shadow: rgba(0, 0, 0, .5);
}

[data-theme="paper"] {
  color-scheme: light;
  --bg: #f3ecdc;
  --bg-deep: #e8dec7;
  --felt-1: #f8f2e3;
  --felt-2: #e6dabd;
  --surface: rgba(80, 50, 10, .04);
  --surface-2: rgba(80, 50, 10, .08);
  --line: rgba(120, 80, 20, .18);
  --text: #2b2216;
  --muted: #74654c;
  --accent: #a3361f;
  --accent-2: #c2482c;
  --accent-ink: #fff7ec;
  --pattern: rgba(163, 54, 31, .06);
  --tile-face-1: #ffffff;
  --tile-face-2: #f5efe2;
  --tile-edge: #ddd2ba;
  --tile-back-1: #b8442b;
  --tile-back-2: #86301e;
  --shadow: rgba(70, 40, 10, .28);
}

/* --- База ----------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font: 16px/1.6 var(--font-body);
  color: var(--text);
  background-color: var(--bg);
  /* Узор сэйгайха (волны) поверх мягкого градиента */
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40'%3E%3Cg fill='none' stroke='%23e8ce91' stroke-opacity='.07' stroke-width='1.2'%3E%3Cpath d='M0 40a40 40 0 0 1 80 0M10 40a30 30 0 0 1 60 0M20 40a20 20 0 0 1 40 0M30 40a10 10 0 0 1 20 0'/%3E%3Cpath d='M-40 20a40 40 0 0 1 80 0M-30 20a30 30 0 0 1 60 0M-20 20a20 20 0 0 1 40 0M-10 20a10 10 0 0 1 20 0M40 20a40 40 0 0 1 80 0M50 20a30 30 0 0 1 60 0M60 20a20 20 0 0 1 40 0M70 20a10 10 0 0 1 20 0'/%3E%3C/g%3E%3C/svg%3E"),
    radial-gradient(ellipse 120% 80% at 50% 0%, var(--felt-2), var(--bg-deep) 70%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

[data-theme="paper"] body {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40'%3E%3Cg fill='none' stroke='%23a3361f' stroke-opacity='.06' stroke-width='1.2'%3E%3Cpath d='M0 40a40 40 0 0 1 80 0M10 40a30 30 0 0 1 60 0M20 40a20 20 0 0 1 40 0M30 40a10 10 0 0 1 20 0'/%3E%3Cpath d='M-40 20a40 40 0 0 1 80 0M-30 20a30 30 0 0 1 60 0M-20 20a20 20 0 0 1 40 0M-10 20a10 10 0 0 1 20 0M40 20a40 40 0 0 1 80 0M50 20a30 30 0 0 1 60 0M60 20a20 20 0 0 1 40 0M70 20a10 10 0 0 1 20 0'/%3E%3C/g%3E%3C/svg%3E"),
    radial-gradient(ellipse 120% 80% at 50% 0%, var(--felt-1), var(--bg-deep) 75%);
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent-2); }
img, svg { max-width: 100%; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.15; letter-spacing: .005em; }
h1 { font-size: clamp(2rem, 4vw, 2.9rem); margin: 0 0 .4em; }
h2 { font-size: clamp(1.6rem, 3vw, 2.1rem); margin: 1.6em 0 .55em; }
h3 { font-size: 1.35rem; margin: 1.3em 0 .4em; }
code { font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap { width: min(1200px, 100% - 2rem); margin-inline: auto; }

.skip-link {
  position: absolute; left: 1rem; top: -3rem; z-index: 100;
  background: var(--accent); color: var(--accent-ink); padding: .5rem 1rem; border-radius: 8px;
}
.skip-link:focus { top: .5rem; }

/* --- Кнопки ----------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 46px; padding: .6rem 1.4rem;
  font: 600 1rem/1 var(--font-body); letter-spacing: .01em;
  color: var(--accent-ink); text-decoration: none;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border: 0; border-radius: 999px; cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .35) inset, 0 8px 22px -10px var(--accent);
  transition: transform .15s var(--ease-out), box-shadow .2s, filter .2s;
}
.btn:hover { color: var(--accent-ink); filter: brightness(1.06); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-ghost {
  color: var(--text); background: var(--surface-2);
  box-shadow: 0 0 0 1px var(--line) inset;
}
.btn-ghost:hover { color: var(--text); background: var(--surface); }
.btn-small { min-height: 38px; padding: .4rem 1rem; font-size: .92rem; }

/* --- Шапка ------------------------------------------------------------------ */

.site-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg-deep) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.header-row { display: flex; align-items: center; gap: 1.5rem; height: var(--header-h); }
.brand { display: inline-flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--text); }
.brand img { display: block; filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .35)); }
.brand-name { font: 600 1.65rem/1 var(--font-display); letter-spacing: .02em; }
.brand:hover { color: var(--accent-2); }
.main-nav { display: flex; gap: .25rem; margin-right: auto; }
.main-nav a {
  padding: .45rem .8rem; border-radius: 999px;
  color: var(--muted); text-decoration: none; font-weight: 500; font-size: .95rem;
  transition: color .15s, background .15s;
}
.main-nav a:hover { color: var(--text); background: var(--surface); }
.main-nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.header-tools { display: flex; align-items: center; gap: .8rem; }
.lang-switch { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--surface); box-shadow: 0 0 0 1px var(--line) inset; }
.lang-switch a {
  padding: .2rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 700; letter-spacing: .06em;
  color: var(--muted); text-decoration: none;
}
.lang-switch a[aria-current="true"] { color: var(--accent-ink); background: var(--accent); }
.hub-link { font-size: .9rem; color: var(--muted); text-decoration: none; white-space: nowrap; }
.hub-link::before { content: "← "; }
.hub-link:hover { color: var(--accent); }

/* --- Игровая область ------------------------------------------------------- */

.game-shell { width: min(1480px, 100%); margin: 0 auto; padding: .9rem 1rem 0; }

.game-bar {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 1rem;
  padding: .55rem .6rem .55rem 1.1rem; margin-bottom: .8rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.game-title { display: flex; align-items: baseline; gap: .9rem; min-width: 0; }
.game-title h1 { flex: 0 1 auto; min-width: 0; font-size: clamp(1.3rem, 2.2vw, 1.7rem); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.layout-picker { position: relative; flex: none; }
.layout-picker summary {
  list-style: none; cursor: pointer; user-select: none;
  padding: .3rem .75rem; border-radius: 999px; font-size: .9rem; font-weight: 500;
  background: var(--surface-2); box-shadow: 0 0 0 1px var(--line) inset;
}
.layout-picker summary::-webkit-details-marker { display: none; }
.layout-picker summary::after { content: ""; display: inline-block; width: .45em; height: .45em; margin-left: .5em; border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: translateY(-.2em) rotate(45deg); opacity: .7; }
.layout-picker ul {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; min-width: 220px;
  margin: 0; padding: .35rem; list-style: none;
  background: var(--bg-deep); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: 0 18px 40px -12px var(--shadow);
}
.layout-picker li a {
  display: flex; justify-content: space-between; gap: 1rem; padding: .45rem .7rem; border-radius: 7px;
  color: var(--text); text-decoration: none; font-size: .95rem;
}
.layout-picker li a:hover, .layout-picker li a[aria-current="page"] { background: var(--surface-2); }

.game-stats { display: flex; gap: 1.4rem; margin: 0; }
.game-stats div { display: flex; flex-direction: column; align-items: center; min-width: 3.4rem; }
.game-stats dt { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); white-space: nowrap; }
.game-stats dd { margin: 0; font: 600 1.35rem/1.2 var(--font-display); font-variant-numeric: lining-nums tabular-nums; }

.game-actions { display: flex; gap: .3rem; }
.tool {
  display: inline-flex; align-items: center; gap: .4rem; height: 40px; padding: 0 .8rem;
  font: 500 .88rem/1 var(--font-body); color: var(--text);
  background: transparent; border: 0; border-radius: 10px; cursor: pointer;
  transition: background .15s, color .15s, transform .1s;
}
.tool:hover { background: var(--surface-2); color: var(--accent-2); }
.tool:active { transform: scale(.96); }
.tool:disabled { opacity: .4; pointer-events: none; }
.tool svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool-icon { padding: 0 .6rem; }
.tool[aria-pressed="true"] { background: var(--surface-2); color: var(--accent); }

.game-body { display: flex; gap: 1rem; align-items: flex-start; }

.stage {
  position: relative; flex: 1; min-width: 0;
  height: clamp(340px, calc(100svh - var(--header-h) - 92px), 900px);
  border-radius: calc(var(--radius) + 6px);
  background:
    radial-gradient(ellipse 70% 60% at 50% 45%, color-mix(in srgb, var(--felt-1) 85%, transparent), transparent 75%),
    linear-gradient(180deg, color-mix(in srgb, var(--felt-2) 70%, transparent), transparent);
  box-shadow: 0 0 0 1px var(--line) inset, 0 30px 60px -40px rgba(0, 0, 0, .6) inset;
  overflow: hidden;
  touch-action: manipulation;
}
.stage::after {
  /* Тонкая золотая рамка-орнамент */
  content: ""; position: absolute; inset: 8px; border-radius: calc(var(--radius) + 1px);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  pointer-events: none;
}

.stage-loading { position: absolute; inset: 0; display: grid; place-items: center; padding: 8%; transition: opacity .4s; }
.stage-preview { width: 100%; height: 100%; opacity: .35; }
.stage.ready .stage-loading { opacity: 0; pointer-events: none; }

/* --- Плитки ----------------------------------------------------------------- */

.board-scroll { position: absolute; inset: 0; overflow: hidden; }
.board-scroll.scrollable {
  /* margin: auto у поля центрирует его, а при переполнении даёт прокрутку без обрезания краёв */
  display: flex; overflow: auto; padding: 14px; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch; scrollbar-width: thin;
}
.board-scroll.scrollable .board { position: relative; left: auto; top: auto; transform: none; margin: auto; flex: none; }

.board {
  position: absolute; left: 50%; top: 50%;
  /* Размеры задаёт скрипт; плитки позиционируются абсолютно внутри */
  transform: translate(-50%, -50%);
}

.tile {
  --lift: 0px;
  position: absolute; left: 0; top: 0;
  width: var(--tw); height: var(--th);
  padding: 0; border: 0; cursor: pointer;
  border-radius: var(--tr);
  background: linear-gradient(155deg, var(--tile-face-1) 10%, var(--tile-face-2) 92%);
  box-shadow: var(--tile-depth);
  transform: translate(var(--x), calc(var(--y) - var(--lift)));
  transition: transform .18s var(--ease-out), filter .2s, opacity .25s, box-shadow .18s;
  -webkit-tap-highlight-color: transparent;
}
.tile::before {
  /* Блик и тонкий кант лица */
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(160deg, rgba(255, 255, 255, .9), rgba(255, 255, 255, 0) 38%);
  box-shadow: 0 0 0 1px rgba(150, 120, 60, .18) inset, 0 -2px 0 rgba(0, 0, 0, .04) inset;
  opacity: .75;
}
.tile svg { position: absolute; inset: 7% 8%; width: 84%; height: 86%; pointer-events: none; }

.board.dim-blocked .tile.blocked { filter: brightness(.86) saturate(.85); }
[data-theme="paper"] .board.dim-blocked .tile.blocked { filter: brightness(.88) saturate(.75); }

@media (hover: hover) {
  .tile.free:hover { --lift: calc(var(--tw) * .04); filter: brightness(1.04); }
}

.tile.selected {
  --lift: calc(var(--tw) * .07);
  background: linear-gradient(155deg, #fff6d8 10%, #f6dc95 95%);
  box-shadow: var(--tile-depth), 0 0 0 2px var(--accent), 0 0 24px 4px color-mix(in srgb, var(--accent) 55%, transparent);
}
.tile.hint { animation: hint-pulse 1s ease-in-out 3; }
@keyframes hint-pulse {
  0%, 100% { box-shadow: var(--tile-depth); }
  50% { box-shadow: var(--tile-depth), 0 0 0 3px #5fd3a1, 0 0 26px 6px rgba(95, 211, 161, .6); }
}
.tile.shake { animation: shake .32s; }
@keyframes shake {
  0%, 100% { transform: translate(var(--x), var(--y)); }
  25% { transform: translate(calc(var(--x) - 3px), var(--y)); }
  75% { transform: translate(calc(var(--x) + 3px), var(--y)); }
}
.tile.removing {
  pointer-events: none;
  animation: tile-out .42s var(--ease-out) forwards;
}
@keyframes tile-out {
  0% { opacity: 1; transform: translate(var(--x), calc(var(--y) - var(--lift))); }
  100% { opacity: 0; transform: translate(var(--x), calc(var(--y) - var(--th) * .35)) scale(.85); }
}
.tile.gone { display: none; }
.tile.appear { animation: tile-in .35s var(--ease-out); }
@keyframes tile-in {
  from { opacity: 0; transform: translate(var(--x), calc(var(--y) - var(--th) * .25)); }
}
.board.shuffling .tile { animation: shuffle-flip .5s var(--ease-out); }
@keyframes shuffle-flip {
  0% { transform: translate(var(--x), var(--y)); }
  45% { transform: translate(var(--x), calc(var(--y) - var(--th) * .12)) scaleX(.05); }
  100% { transform: translate(var(--x), var(--y)); }
}
.board.paused .tile svg { visibility: hidden; }

/* --- Оверлеи и панели ------------------------------------------------------- */

.overlay {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 1rem;
  background: color-mix(in srgb, var(--bg-deep) 55%, transparent);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: fade-in .3s;
}
.overlay[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; } }
.overlay-card {
  position: relative; width: min(440px, 100%); padding: 2.2rem 2rem 1.8rem; text-align: center;
  background: linear-gradient(180deg, color-mix(in srgb, var(--felt-2) 70%, var(--bg-deep)), var(--bg-deep));
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 20px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .7), 0 0 0 6px color-mix(in srgb, var(--accent) 7%, transparent);
  animation: card-in .45s var(--ease-out);
}
[data-theme="paper"] .overlay-card { background: linear-gradient(180deg, #fffaf0, #f3ead6); }
@keyframes card-in { from { opacity: 0; transform: translateY(14px) scale(.97); } }
.overlay-ornament {
  width: 64px; height: 64px; margin: -3.9rem auto .6rem;
  background: url("../img/favicon.056e421d77ca.svg") center/contain no-repeat;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .4));
}
.overlay-card h2 { margin: .2rem 0 .3rem; font-size: 2.3rem; color: var(--accent-2); }
[data-theme="paper"] .overlay-card h2 { color: var(--accent); }
.overlay-text { margin: 0 0 1.2rem; color: var(--muted); }
.overlay-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; margin: 0 0 1.5rem; }
.overlay-stats:empty { display: none; }
.overlay-stats div { padding: .6rem; border-radius: 10px; background: var(--surface); box-shadow: 0 0 0 1px var(--line) inset; }
.overlay-stats dt { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.overlay-stats dd { margin: 0; font: 600 1.5rem/1.2 var(--font-display); font-variant-numeric: lining-nums tabular-nums; }
.overlay-stats .record dd { color: var(--accent-2); }
.overlay-actions { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: center; }

.settings-panel {
  position: absolute; z-index: 25; top: 14px; right: 14px; width: min(320px, calc(100% - 28px));
  padding: 1.2rem 1.3rem 1.3rem;
  background: var(--bg-deep); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 24px 60px -16px rgba(0, 0, 0, .65);
  animation: card-in .3s var(--ease-out);
}
.settings-panel[hidden] { display: none; }
.settings-panel h2 { margin: 0 0 .8rem; font-size: 1.6rem; }
.settings-panel fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
.settings-panel legend { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: .5rem; }
.theme-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.theme-options label { display: flex; flex-direction: column; align-items: center; gap: .35rem; font-size: .8rem; cursor: pointer; text-align: center; }
.theme-options input { position: absolute; opacity: 0; }
.swatch { width: 100%; height: 44px; border-radius: 10px; box-shadow: 0 0 0 1px var(--line) inset; transition: box-shadow .15s; }
.theme-options input:checked + .swatch { box-shadow: 0 0 0 2px var(--accent); }
.theme-options input:focus-visible + .swatch { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch-jade { background: radial-gradient(circle at 50% 30%, #1c5641, #061811); }
.swatch-night { background: radial-gradient(circle at 50% 30%, #2a2f63, #070a17); }
.swatch-paper { background: radial-gradient(circle at 50% 30%, #fbf6ea, #e2d5b7); }
.switch { display: flex; align-items: center; gap: .7rem; margin: .65rem 0; cursor: pointer; font-size: .95rem; }
.switch input { position: absolute; opacity: 0; }
.switch span { position: relative; flex: none; width: 40px; height: 23px; border-radius: 999px; background: var(--surface-2); box-shadow: 0 0 0 1px var(--line) inset; transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: var(--text); transition: transform .2s var(--ease-out); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(17px); background: var(--accent-ink); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.settings-panel .btn { margin-top: .6rem; width: 100%; }

.toast {
  position: absolute; z-index: 22; left: 50%; bottom: 18px; max-width: min(520px, calc(100% - 32px));
  padding: .6rem 1rem; border-radius: 12px; font-size: .9rem; text-align: center;
  background: var(--bg-deep); color: var(--text); border: 1px solid var(--line);
  box-shadow: 0 14px 30px -12px rgba(0, 0, 0, .6);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .3s var(--ease-out);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.noscript { padding: 1rem; text-align: center; }

/* Лепестки при победе */
.petal {
  position: absolute; top: -20px; z-index: 21; width: 14px; height: 10px; pointer-events: none;
  border-radius: 80% 0 80% 0; background: linear-gradient(135deg, #ffd4e0, #f497b4);
  animation: petal-fall linear forwards;
}
@keyframes petal-fall {
  to { transform: translate(var(--drift), 110vh) rotate(var(--spin)); opacity: .2; }
}

/* --- Реклама ---------------------------------------------------------------- */

.ad-slot { display: flex; align-items: center; justify-content: center; margin: 1rem auto; overflow: hidden; }
.ad-top { width: min(728px, 100% - 2rem); height: 90px; }
.ad-below { width: min(728px, 100% - 2rem); height: 90px; margin-top: 1.4rem; }
.ad-side { display: none; flex: none; width: 300px; height: 600px; margin: 0; }
@media (min-width: 1400px) { .ad-side { display: flex; } }
@media (max-width: 760px) { .ad-top, .ad-below { height: 100px; width: min(320px, 100% - 2rem); } }
.ad-preview { border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); font-size: .8rem; background: var(--surface); }

/* --- Контент ---------------------------------------------------------------- */

.content { padding-bottom: 3rem; }
.page-top { padding-top: 2rem; }
.page-head { margin-bottom: 2rem; }
.lead { font-size: 1.15rem; color: var(--muted); max-width: 46rem; }
.prose { max-width: 50rem; }
.prose p, .prose li { color: color-mix(in srgb, var(--text) 88%, var(--muted)); }
.prose ul { padding-left: 1.2rem; }
.prose li { margin: .35rem 0; }
.prose li::marker { color: var(--accent); }
.intro { margin-top: 2.5rem; }
.intro h2:first-child { margin-top: 0; }
.section { margin-top: 3.5rem; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.link-more { white-space: nowrap; text-decoration: none; font-weight: 500; }
.cta { margin-top: 2.5rem; }
.breadcrumbs { font-size: .9rem; color: var(--muted); margin: 1.5rem 0 1rem; }
.breadcrumbs a { color: var(--muted); }
.breadcrumbs span { margin: 0 .25rem; opacity: .6; }
.page-top .breadcrumbs { margin-top: 0; }
.facts { display: flex; flex-wrap: wrap; gap: .6rem; padding: 0 !important; list-style: none; }
.facts li { padding: .45rem .9rem; border-radius: 999px; background: var(--surface); box-shadow: 0 0 0 1px var(--line) inset; margin: 0 !important; }

/* Карточки раскладок */
.layout-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; padding: 0; margin: 0; list-style: none; }
.layout-card {
  display: flex; flex-direction: column; height: 100%;
  color: var(--text); text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; transition: transform .2s var(--ease-out), border-color .2s, box-shadow .2s;
}
.layout-card:hover { color: var(--text); transform: translateY(-3px); border-color: color-mix(in srgb, var(--accent) 50%, transparent); box-shadow: 0 18px 40px -22px var(--shadow); }
.layout-card-art {
  position: relative; display: block; aspect-ratio: 16 / 10;
  background: radial-gradient(ellipse at 50% 40%, color-mix(in srgb, var(--felt-1) 70%, transparent), transparent 75%);
}
.layout-preview { position: absolute; inset: 1.1rem; width: calc(100% - 2.2rem); height: calc(100% - 2.2rem); }
.layout-preview rect, .stage-preview rect, .table-preview rect { stroke: rgba(0, 0, 0, .25); stroke-width: .3; }
.lp-z0 { fill: #d9cdb0; } .lp-z1 { fill: #e7dcc1; } .lp-z2 { fill: #f2e9d3; } .lp-z3 { fill: #faf4e4; } .lp-z4 { fill: #fffdf6; }
.layout-card-body { display: flex; flex-direction: column; gap: .15rem; padding: .8rem 1rem 1rem; border-top: 1px solid var(--line); }
.layout-card-name { font: 600 1.35rem/1.2 var(--font-display); }
.layout-card-meta { font-size: .85rem; color: var(--muted); }
.diff { font-weight: 600; }
.diff-easy { color: #6fd39f; } .diff-medium { color: #e8c169; } .diff-hard { color: #f08a7a; }
[data-theme="paper"] .diff-easy { color: #2e7d32; } [data-theme="paper"] .diff-medium { color: #a0670a; } [data-theme="paper"] .diff-hard { color: #b3261e; }

/* Шаги */
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; padding: 0; list-style: none; counter-reset: none; }
.steps li { position: relative; padding: 1.4rem 1.3rem 1.2rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.steps h3 { margin: .6rem 0 .3rem; }
.steps p { margin: 0; color: var(--muted); }
.step-num {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  font: 700 1.3rem/1 var(--font-display); color: var(--accent-ink);
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
}

/* Легенда плиток */
.tile-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.tile-legend figure { display: flex; align-items: center; gap: 1rem; margin: 0; padding: 1rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.mini-tiles { display: flex; gap: 6px; flex: none; }
.mini-tiles svg {
  width: 42px; height: 55px; padding: 4px 3px; border-radius: 6px;
  background: linear-gradient(155deg, var(--tile-face-1), var(--tile-face-2));
  box-shadow: -2px 2px 0 var(--tile-edge), -4px 4px 0 var(--tile-back-1), -5px 6px 8px rgba(0, 0, 0, .3);
}
.tile-legend figcaption { font-size: .92rem; color: var(--muted); }
.tile-legend strong { color: var(--text); }

/* FAQ */
.faq { display: grid; gap: .6rem; max-width: 50rem; }
.faq details { border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line); }
.faq summary { cursor: pointer; padding: 1rem 1.2rem; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 1rem; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--accent); font-size: 1.3rem; line-height: 1; transition: transform .2s; }
.faq details[open] summary::after { transform: rotate(45deg); }
.faq details p { margin: 0; padding: 0 1.2rem 1.1rem; color: var(--muted); }

/* Статистика */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-tile { display: flex; flex-direction: column; padding: 1.2rem 1.4rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.stat-value { font: 600 2.6rem/1.1 var(--font-display); color: var(--accent-2); font-variant-numeric: lining-nums tabular-nums; }
[data-theme="paper"] .stat-value { color: var(--accent); }
.stat-label { color: var(--muted); font-size: .9rem; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); }
.stats-table { width: 100%; border-collapse: collapse; font-variant-numeric: lining-nums tabular-nums; }
.stats-table th, .stats-table td { padding: .75rem 1rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.stats-table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; background: var(--surface); }
.stats-table tbody tr:last-child > * { border-bottom: 0; }
.stats-table tbody th a { display: inline-flex; align-items: center; gap: .7rem; color: var(--text); text-decoration: none; font-weight: 600; }
.table-preview { width: 52px; height: 34px; }

.not-found { text-align: center; padding-block: 4rem; }
.not-found .lead { margin-inline: auto; }
.big-404 { margin: 0; font: 700 clamp(5rem, 16vw, 9rem)/1 var(--font-display); color: var(--accent); opacity: .85; }

/* --- Подвал и cookie ------------------------------------------------------- */

.site-footer { margin-top: 2rem; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--bg-deep) 70%, transparent); }
.footer-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem 2rem; padding: 1.6rem 0 2rem; }
.footer-brand { display: flex; align-items: center; gap: .7rem; }
.footer-brand p { margin: 0; color: var(--muted); font-size: .9rem; max-width: 34rem; }
.footer-nav { display: flex; flex-wrap: wrap; gap: 1.2rem; }
.footer-nav a { color: var(--muted); font-size: .9rem; text-decoration: none; }
.footer-nav a:hover { color: var(--accent); }

.cookie-note {
  position: fixed; z-index: 60; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 1rem; width: min(640px, calc(100% - 24px));
  padding: .8rem .9rem .8rem 1.2rem; border-radius: 14px;
  background: var(--bg-deep); border: 1px solid var(--line); box-shadow: 0 18px 40px -14px rgba(0, 0, 0, .7);
  animation: card-in .4s var(--ease-out);
}
.cookie-note[hidden] { display: none; }
.cookie-note p { margin: 0; font-size: .88rem; color: var(--muted); }

/* --- Полноэкранный режим --------------------------------------------------- */

.game-shell:fullscreen { width: 100%; padding: .8rem; background: var(--bg); overflow: auto; }
.game-shell:fullscreen .stage { height: calc(100vh - 90px); max-height: none; }

/* --- Адаптив ---------------------------------------------------------------- */

@media (max-width: 1360px) {
  .tool span { display: none; }
  .tool { padding: 0 .65rem; }
}

@media (max-width: 860px) {
  :root { --header-h: 56px; }
  .main-nav { display: none; }
  .header-tools { margin-left: auto; }
  .game-shell { padding: .5rem .4rem 0; }
  .game-bar { grid-template-columns: 1fr auto; gap: .4rem .8rem; padding: .5rem .6rem; margin-bottom: .5rem; }
  .game-title { grid-column: 1 / -1; justify-content: space-between; }
  .game-stats { gap: .9rem; }
  .game-stats dd { font-size: 1.15rem; }
  .game-actions { justify-content: flex-end; }
  .tool { height: 38px; padding: 0 .55rem; }
  .stage { height: calc(100svh - var(--header-h) - 132px); min-height: 300px; border-radius: var(--radius); }
  .stage::after { inset: 5px; }
}

@media (max-width: 520px) {
  .brand-name { font-size: 1.4rem; }
  .hub-link { display: none; }
  .game-title h1 { font-size: 1.2rem; }
  .game-stats div { min-width: 0; }
  .game-stats dt { font-size: .6rem; }
  .tool[data-action="fullscreen"], .tool[data-action="pause"] { display: none; }
  .game-bar { gap: .4rem .5rem; }
  .game-stats { gap: .7rem; }
  .game-actions { gap: 0; }
  .tool { padding: 0 .45rem; }
  .cookie-note { flex-direction: column; align-items: stretch; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
