:root {
  --ink: #18312d;
  --muted: #6c7872;
  --paper: #f3efe6;
  --card: #fffdf8;
  --accent: #e65d3e;
  --line: rgba(24, 49, 45, 0.16);
}

* { box-sizing: border-box; }

.game-shell,
.game-shell * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.game-shell img {
  -webkit-user-drag: none;
  user-drag: none;
}

html { color-scheme: light; width: 100%; height: 100%; overflow: hidden; touch-action: none; overscroll-behavior: none; }

body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-width: 0;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 22%, rgba(230, 93, 62, .08), transparent 23rem),
    linear-gradient(rgba(24,49,45,.025) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 100% 34px, auto;
  font-family: Avenir Next, Avenir, Inter, system-ui, sans-serif;
}

button, input { font: inherit; }
button { color: inherit; }

.panel-header {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; font-weight: 700; letter-spacing: -.03em; }
.brand-icon { display: block; width: 28px; height: 28px; object-fit: contain; cursor: pointer; touch-action: manipulation; }
.auto-assembling .brand-icon { animation: auto-assembly-pulse 1s ease-in-out infinite alternate; filter: drop-shadow(0 0 8px rgba(230,93,62,.65)); }
@keyframes auto-assembly-pulse { to { transform: scale(1.13) rotate(8deg); } }

.sound-button, .icon-button, .primary-button, .upload-button, .win-card button, .difficulty-button, .picture-button, .language-button { border: 0; cursor: pointer; }
.sound-button { display: flex; align-items: center; gap: 9px; background: none; font-size: 12px; text-transform: uppercase; letter-spacing: .14em; }
.sound-bars { display: flex; align-items: center; gap: 2px; height: 14px; }
.sound-bars i { display: block; width: 2px; height: 6px; background: var(--ink); border-radius: 2px; }
.sound-bars i:nth-child(2) { height: 12px; }.sound-bars i:nth-child(3) { height: 8px; }
.sound-button[aria-pressed="false"] .sound-bars { opacity: .3; }

main { width: 100vw; height: 100vh; height: 100dvh; margin: 0; padding: 0; overflow: hidden; }
.intro { padding: 34px 28px 28px; text-align: left; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 12px; color: var(--accent); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .24em; }
h1 { margin: 0; font: 600 clamp(38px, 3.5vw, 57px)/.96 "Playfair Display", Georgia, serif; letter-spacing: -.045em; }
h1 em { color: var(--accent); font-weight: 600; }
.lead { margin: 20px 0 0; color: var(--muted); font-size: 13px; line-height: 1.65; }

.game-shell { width: 100%; height: 100%; display: flex; align-items: stretch; background: rgba(255,253,248,.82); backdrop-filter: blur(12px); }
.control-panel { min-width: 0; height: 100%; display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.game-toolbar { padding: 28px; display: flex; flex-direction: column; gap: 24px; align-items: stretch; }
.difficulty-picker, .tiling-picker, .language-picker { min-width: 0; margin: 0; padding: 0; border: 0; }
.difficulty-picker legend, .tiling-picker legend, .language-picker legend { margin-bottom: 9px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .18em; }
.difficulty-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: #e7e4db; }
.difficulty-button { min-width: 0; padding: 9px 4px 8px; color: var(--muted); background: transparent; font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; }
.difficulty-button span { display: block; font-size: 9px; }
.difficulty-button small { display: block; margin-top: 3px; font-size: 8px; opacity: .75; }
.difficulty-button.active { color: white; background: var(--ink); box-shadow: 0 3px 9px rgba(24,49,45,.18); }
.tiling-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.tiling-button { display: grid; min-width: 0; min-height: 68px; grid-template-columns: 28px minmax(0, 1fr); grid-template-rows: 1fr 1fr; column-gap: 9px; align-items: center; padding: 9px 10px; cursor: pointer; color: var(--muted); background: #efede6; border: 1px solid transparent; text-align: left; }
.tiling-button strong { align-self: end; overflow: hidden; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.tiling-button.active { color: white; background: var(--ink); border-color: var(--ink); }
.tiling-icon { grid-row: 1 / 3; display: block; width: 27px; height: 27px; background: currentColor; }
.tiling-icon-hex { clip-path: polygon(25% 7%,75% 7%,100% 50%,75% 93%,25% 93%,0 50%); }
.tiling-icon-triangle { clip-path: polygon(50% 5%,96% 90%,4% 90%); }
.tiling-icon-square { clip-path: inset(7%); }
.tiling-icon-rhombus { clip-path: polygon(50% 4%,96% 50%,50% 96%,4% 50%); transform: scaleX(.72); }
.tiling-icon-spectre { clip-path: polygon(18% 27%,39% 27%,50% 0,68% 16%,68% 46%,89% 46%,100% 73%,82% 89%,63% 73%,53% 100%,11% 100%,0 73%,18% 58%); }
.game-stats { display: flex; width: 100%; flex-wrap: nowrap; align-items: center; justify-content: space-between; gap: 18px; white-space: nowrap; }
.game-stat { display: inline-flex; min-width: 0; align-items: center; gap: 9px; }
.game-stat:last-child { margin-left: auto; }
.stat-label, .progress-copy span { color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .18em; }
.game-stat strong { font: 600 clamp(23px, 2vw, 27px)/1 "Playfair Display", serif; font-variant-numeric: tabular-nums; }
.progress-wrap { width: 100%; }
.progress-copy { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.progress-copy strong { font-size: 11px; }
.progress-track { height: 3px; overflow: hidden; background: #d9d8cf; }
.progress-track span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .35s ease; }
.reference-card { position: relative; display: block; width: 336px; max-width: 100%; height: auto; aspect-ratio: 1 !important; margin: 0; padding: 4px; overflow: hidden; cursor: pointer; background: #fff; border: 1px solid rgba(24,49,45,.2); box-shadow: 0 8px 24px rgba(24,49,45,.14); }
.reference-card img { display: block; width: 100%; height: 100%; object-fit: cover; }
.preview-status { position: absolute; inset: 4px; z-index: 1; display: block; width: calc(100% - 8px); height: calc(100% - 8px); pointer-events: none; }
.preview-viewport { position: absolute; z-index: 3; display: none; min-width: 5px; min-height: 5px; pointer-events: none; border: 2px solid #ffcc62; border-radius: 2px; box-shadow: 0 0 0 1px rgba(24,49,45,.8), inset 0 0 0 1px rgba(255,255,255,.55); background: rgba(255,204,98,.08); }
.reference-card.is-loading .preview-viewport { opacity: 0; }
.preview-loading { position: absolute; inset: 4px; z-index: 2; display: grid; place-content: center; justify-items: center; gap: 13px; overflow: hidden; color: rgba(255,255,255,.86); background: linear-gradient(145deg, #193630, #254b43 52%, #122a26); font-size: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: .16em; opacity: 0; pointer-events: none; transition: opacity .22s ease; }
.preview-loading::before { content: ""; position: absolute; inset: -50%; background: linear-gradient(105deg, transparent 38%, rgba(255,255,255,.13) 48%, rgba(255,255,255,.2) 50%, rgba(255,255,255,.13) 52%, transparent 62%); transform: translateX(-55%); animation: preview-shimmer 1.5s ease-in-out infinite; }
.reference-card.is-loading .preview-loading { opacity: 1; }
.reference-card.has-preview-error .preview-loading { color: #fff; background: linear-gradient(145deg, #50342e, #7e4438); }
.reference-card.has-preview-error .preview-loading::before { display: none; }
.preview-loading-mark { position: relative; width: 42px; height: 36px; filter: drop-shadow(0 5px 10px rgba(0,0,0,.2)); }
.preview-loading-mark i { position: absolute; width: 22px; height: 22px; background: currentColor; clip-path: polygon(50% 0,100% 25%,100% 75%,50% 100%,0 75%,0 25%); animation: preview-pulse 1.2s ease-in-out infinite alternate; }
.preview-loading-mark i:nth-child(1) { left: 0; top: 7px; color: #f5d2b4; }
.preview-loading-mark i:nth-child(2) { left: 10px; top: 0; color: #e65d3e; animation-delay: -.4s; }
.preview-loading-mark i:nth-child(3) { left: 20px; top: 7px; color: #74b8a9; animation-delay: -.8s; }
@keyframes preview-shimmer { 60%,100% { transform: translateX(55%); } }
@keyframes preview-pulse { from { transform: translateY(1px) scale(.94); opacity: .75; } to { transform: translateY(-1px) scale(1.04); opacity: 1; } }
.lock-control { display: flex; align-items: center; gap: 11px; cursor: pointer; }
.lock-control input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.lock-control > span:last-child { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.lock-control strong { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; }
.lock-control small { color: var(--muted); font-size: 10px; line-height: 1.3; }
.switch { position: relative; width: 34px; height: 19px; flex: 0 0 auto; background: #c9cbc4; border-radius: 20px; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 13px; height: 13px; background: white; border-radius: 50%; box-shadow: 0 1px 4px rgba(24,49,45,.25); transition: transform .2s; }
.lock-control input:checked + .switch { background: var(--accent); }
.lock-control input:checked + .switch::after { transform: translateX(15px); }
.lock-control input:focus-visible + .switch { outline: 2px solid var(--ink); outline-offset: 2px; }
.actions { display: grid; grid-template-columns: 1fr; align-items: stretch; gap: 9px; }
.icon-button, .primary-button { display: flex; align-items: center; justify-content: center; gap: 9px; min-height: 42px; padding: 0 16px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; }
.actions .primary-button { min-height: 54px; }
.actions .primary-button { container-type: inline-size; }
.actions .primary-button span { min-width: 0; text-align: center; white-space: normal; overflow-wrap: anywhere; line-height: 1.15; }
.icon-button { background: transparent; border: 1px solid var(--line); }
.icon-button[aria-pressed="true"] { background: #e9e6dd; }
.primary-button { background: var(--ink); color: white; }
.icon-button svg, .primary-button svg, .upload-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; }

.canvas-frame { position: relative; display: block; overflow: hidden; background: linear-gradient(145deg, #1d3430, #0f2421); box-shadow: inset 0 0 0 1px rgba(255,255,255,.12), inset 0 0 34px rgba(0,0,0,.28); aspect-ratio: 1 !important; touch-action: none; }
#gameCanvas { position: absolute; left: 0; top: 0; display: block; width: auto; height: auto; max-width: none; max-height: none; cursor: grab; touch-action: none; transform-origin: 0 0; will-change: transform; }
#gameCanvas.dragging { cursor: grabbing; }
.loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; background: #dfe0d8; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .14em; transition: opacity .3s; }
.loading.hidden { opacity: 0; pointer-events: none; }
.loading-spinner { width: 28px; height: 28px; border: 2px solid rgba(24,49,45,.15); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.win-card { position: absolute; inset: 50% auto auto 50%; display: none; transform: translate(-50%,-50%); width: min(330px, calc(100% - 40px)); padding: 28px; text-align: center; background: rgba(255,253,248,.94); box-shadow: 0 16px 60px rgba(12,26,23,.3); border: 1px solid white; }
.win-card.visible { display: block; animation: reveal .45s ease both; }
.win-icon { color: var(--accent); font-size: 32px; }
.win-card p { margin: 8px 0 4px; color: var(--accent); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .2em; }
.win-card strong { display: block; font: 600 28px "Playfair Display", serif; }
.win-card button { margin-top: 20px; padding: 11px 20px; color: white; background: var(--ink); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; }
.win-card button:disabled { cursor: wait; opacity: .45; }
@keyframes reveal { from { opacity: 0; transform: translate(-50%,-45%) scale(.96); } }

.game-footer { margin-top: auto; padding: 22px 28px; display: flex; flex-direction: column; align-items: flex-start; gap: 16px; border-top: 1px solid var(--line); }
.game-footer p { margin: 0; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }
.mouse-icon { display: inline-block; width: 12px; height: 17px; margin-right: 7px; vertical-align: middle; border: 1px solid currentColor; border-radius: 7px; position: relative; }
.mouse-icon::before { content: ""; position: absolute; left: 50%; top: 3px; height: 4px; border-left: 1px solid; }
.upload-button { display: flex; align-items: center; gap: 8px; padding: 10px 0; color: var(--ink); background: none; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; }
.upload-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
footer { padding: 0 20px 38px; text-align: center; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .2em; }
footer span { color: var(--ink); font-weight: 700; }
.game-meta { padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .16em; }
.game-meta span { color: var(--ink); font-weight: 700; }

.modal { width: min(720px, calc(100% - 32px)); max-height: calc(100vh - 32px); padding: 0; overflow: auto; color: var(--ink); background: var(--card); border: 1px solid rgba(24,49,45,.18); box-shadow: 0 30px 100px rgba(12,26,23,.35); }
.modal::backdrop { background: rgba(12,26,23,.62); backdrop-filter: blur(5px); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 24px 28px 20px; border-bottom: 1px solid var(--line); }
.modal-header p { margin: 0 0 4px; color: var(--accent); font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .2em; }
.modal-header h2 { margin: 0; font: 600 34px/1 "Playfair Display", Georgia, serif; }
.modal-close { width: 38px; height: 38px; cursor: pointer; color: var(--muted); background: transparent; border: 1px solid var(--line); font-size: 25px; line-height: 1; }
.gallery-modal[open] { display: flex; flex-direction: column; overflow: hidden; }
.gallery-modal .modal-header, .gallery-modal .gallery-upload, .gallery-modal .gallery-ok { flex: 0 0 auto; }
.gallery-grid { display: grid; min-height: 0; flex: 1 1 auto; grid-template-columns: repeat(3, 1fr); grid-auto-rows: max-content; align-content: start; gap: 14px; padding: 28px; overflow: auto; overscroll-behavior: contain; }
.gallery-item { min-width: 0; height: max-content; padding: 4px 4px 11px; overflow: hidden; cursor: pointer; color: var(--ink); background: white; border: 1px solid var(--line); text-align: left; outline: 2px solid transparent; outline-offset: 2px; }
.gallery-item.active { outline-color: var(--accent); }
.gallery-item img, .thumb-placeholder { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #d9d8cf; }
.gallery-item strong { display: block; padding: 10px 8px 0; font-size: 11px; }
.gallery-upload { display: flex; align-items: center; justify-content: center; gap: 9px; margin: 24px 28px 0; min-height: 44px; cursor: pointer; color: white; background: var(--ink); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; }
.gallery-upload input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.gallery-upload svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.gallery-ok { display: block; width: calc(100% - 56px); min-height: 48px; margin: 0 28px 24px; cursor: pointer; color: white; background: var(--accent); border: 0; box-shadow: 0 -10px 24px var(--card); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
.settings-modal { width: min(560px, calc(100% - 32px)); }
.settings-modal .language-picker { padding: 24px 28px 0; }
.settings-modal .difficulty-picker { padding: 24px 28px 18px; }
.settings-modal .tiling-picker { padding: 0 28px 18px; }
.settings-modal .difficulty-picker legend, .settings-modal .tiling-picker legend, .settings-modal .language-picker legend { margin-bottom: 14px; color: var(--ink); font-size: 12px; letter-spacing: .1em; }
.settings-modal .tiling-button { min-height: 64px; grid-template-rows: 1fr; }
.settings-modal .tiling-button strong { align-self: center; }
.settings-modal .tiling-icon { grid-row: auto; }
.language-options { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 5px; }
.language-button { display: grid; min-width: 0; min-height: 52px; place-items: center; gap: 1px; padding: 5px 2px; color: var(--muted); background: #efede6; border: 1px solid transparent; }
.language-button span { font-size: 21px; line-height: 1; }
.language-button small { font-size: 8px; font-weight: 800; letter-spacing: .08em; }
.language-button.active { color: white; background: var(--ink); border-color: var(--ink); }
.settings-ok { position: sticky; bottom: 0; display: block; width: calc(100% - 56px); min-height: 48px; margin: 0 28px 24px; cursor: pointer; color: white; background: var(--accent); border: 0; box-shadow: 0 -10px 24px var(--card); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
.setting-row { display: flex; align-items: center; gap: 18px; padding: 22px 28px; cursor: pointer; border-bottom: 1px solid var(--line); }
.setting-row > span:first-child { display: flex; min-width: 0; flex: 1; flex-direction: column; gap: 4px; }
.setting-row strong { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }
.setting-row small { color: var(--muted); font-size: 11px; }
.setting-row input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.setting-row input:checked + .switch { background: var(--accent); }
.setting-row input:checked + .switch::after { transform: translateX(15px); }
.setting-row input:focus-visible + .switch { outline: 2px solid var(--ink); outline-offset: 2px; }
.confirm-modal { width: min(440px, calc(100% - 32px)); }
.confirm-content { padding: 34px; text-align: center; }
.confirm-icon { display: grid; width: 54px; height: 54px; margin: 0 auto 18px; place-items: center; color: white; background: var(--accent); border-radius: 50%; font-size: 28px; }
.confirm-content p { margin: 0 0 7px; color: var(--accent); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .16em; }
.confirm-content h2 { margin: 0; font: 600 28px/1.12 "Playfair Display", Georgia, serif; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 28px; }
.confirm-actions button { min-height: 46px; cursor: pointer; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; }
.confirm-cancel { color: var(--ink); background: transparent; border: 1px solid var(--line); }
.confirm-restart { color: white; background: var(--ink); border: 1px solid var(--ink); }

/* Полноэкранная адаптивная оболочка. Canvas не растягивается: его собственное
   соотношение сторон сохраняет все шестиугольники равносторонними. */
.control-panel { min-width: 0; min-height: 0; overflow: hidden; background: rgba(255,253,248,.92); }
.panel-header { min-height: clamp(40px, 7vh, 64px); padding-inline: clamp(12px, 2.2vw, 28px); }
.intro { padding: clamp(10px, 2.3vh, 28px) clamp(12px, 2.2vw, 28px); }
.eyebrow { margin-bottom: clamp(5px, 1vh, 12px); }
h1 { font-size: clamp(25px, 3.4vw, 52px); }
.lead { margin-top: clamp(8px, 1.6vh, 20px); font-size: clamp(10px, 1vw, 13px); line-height: 1.45; }
.game-toolbar { min-height: 0; flex: 1; padding: clamp(10px, 2.3vh, 28px) clamp(12px, 2.2vw, 28px); gap: clamp(8px, 1.8vh, 20px); overflow: hidden; }
.reference-card { align-self: center; flex: 0 1 auto; }
.actions { grid-template-columns: 1fr; gap: clamp(5px, .8vw, 9px); }
.actions .primary-button { min-width: 0; min-height: clamp(38px, 6vh, 54px); padding-inline: clamp(5px, .9vw, 14px); gap: clamp(4px, .6vw, 9px); font-size: clamp(9px, calc(.85vw + 3px), 11px); letter-spacing: .07em; }
.actions .primary-button svg { width: clamp(14px, 1.2vw, 17px); flex: 0 0 auto; }
@container (max-width: 78px) {
  .primary-button span { display: none; }
  .primary-button svg { width: 20px; height: 20px; }
}
.game-footer { display: none; }

@media (orientation: landscape) {
  .game-shell { flex-direction: row; }
  .canvas-frame {
    width: min(100vh, calc(100vw - 250px));
    width: min(100dvh, calc(100vw - 250px));
    height: min(100vh, calc(100vw - 250px));
    height: min(100dvh, calc(100vw - 250px));
    flex: 0 0 min(100dvh, calc(100vw - 250px));
    order: 2;
  }
  .control-panel { flex: 1 1 auto; height: 100%; order: 1; border-right: 1px solid var(--line); }
  .reference-card { width: min(100%, 42vh); width: min(100%, 42dvh); }
}

@media (orientation: portrait) {
  .game-shell { flex-direction: column; }
  .canvas-frame {
    width: min(100vw, calc(100vh - 220px));
    width: min(100vw, calc(100dvh - 220px));
    height: min(100vw, calc(100vh - 220px));
    height: min(100vw, calc(100dvh - 220px));
    flex: 0 0 min(100vw, calc(100dvh - 220px));
    align-self: center;
    order: 2;
  }
  .control-panel { width: 100%; flex: 1 1 auto; order: 1; border-right: 0; border-bottom: 1px solid var(--line); }
  .panel-header { min-height: clamp(38px, 6vh, 56px); }
  .intro { display: none; }
  .eyebrow { display: none; }
  h1 { font-size: clamp(23px, 7vw, 38px); line-height: .95; }
  h1 br { display: none; }
  .lead { display: none; }
  .game-toolbar {
    display: grid;
    grid-template-columns: minmax(110px, 44%) minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    column-gap: clamp(9px, 3vw, 22px);
    row-gap: clamp(7px, 1.4vh, 14px);
    align-items: stretch;
  }
  .reference-card { grid-column: 1; grid-row: 1 / 4; width: 100%; height: auto; max-height: 100%; align-self: center; justify-self: start; }
  .game-stats { grid-column: 2; grid-row: 1; gap: 8px; }
  .game-stat { gap: 5px; }
  .stat-label, .progress-copy span { font-size: clamp(7px, 2vw, 10px); letter-spacing: .1em; }
  .game-stat strong { font-size: clamp(18px, 5.5vw, 27px); }
  .progress-wrap { grid-column: 2; grid-row: 2; }
  .actions { grid-column: 2; grid-row: 3; grid-template-columns: 1fr; align-content: stretch; }
  .actions .primary-button { min-height: 0; height: 100%; font-size: clamp(7px, 2vw, 10px); }
}

@media (orientation: landscape) and (max-height: 880px) {
  .actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (orientation: landscape) and (max-height: 620px) {
  .panel-header { min-height: 40px; }
  .brand { font-size: 13px; }
  .brand-icon { width: 22px; height: 22px; }
  .intro { display: none; }
  .eyebrow, .lead { display: none; }
  h1 { font-size: clamp(22px, 4.4vh, 31px); }
  h1 br { display: none; }
  .game-toolbar { padding-block: 8px; gap: 7px; }
  .reference-card { width: min(100%, 34vh); width: min(100%, 34dvh); }
  .game-stat strong { font-size: clamp(18px, 4.5vh, 24px); }
  .progress-copy { margin-bottom: 4px; }
  .actions { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .actions .primary-button { min-height: 36px; }
}

@media (max-width: 580px) {
  .modal { width: calc(100% - 18px); max-height: calc(100dvh - 18px); }
  .modal-header { padding: 18px; }
  .modal-header h2 { font-size: 28px; }
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; padding: 18px; }
  .gallery-upload { margin-inline: 18px; }
  .settings-modal .difficulty-picker { padding-inline: 18px; }
  .settings-modal .tiling-picker { padding-inline: 18px; }
  .settings-modal .language-picker { padding-inline: 18px; }
  .language-options { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .settings-ok { width: calc(100% - 36px); margin-inline: 18px; }
  .gallery-ok { width: calc(100% - 36px); margin-inline: 18px; }
  .tiling-button { min-height: 60px; padding: 7px 8px; }
}

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