:root {
  --bg: #06111d;
  --panel: #0c1a2b;
  --panel-2: #0f2135;
  --line: #1a2d44;
  --line-2: #22405f;
  --text: #ffffff;
  --muted: #9fb3c8;
  --dim: #6f86a0;
  --accent: #22d3ee;
  --accent-ink: #062033;
  --match: #2dd4bf;
  --card-back: #0e1f33;
  --card-face: #07111d;
  --danger: #fb7185;
  --amber: #fbbf24;
  --green: #34d399;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(1200px 700px at 50% -10%, #0b2236 0%, #06111d 60%) fixed, #06111d;
  color: var(--text);
  min-height: 100vh;
  display: flex; flex-direction: column;
}
button { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  width: 100%; height: 64px; padding: 0 clamp(16px, 3vw, 48px);
  border-bottom: 1px solid #163049;
  background: rgba(6, 17, 29, .6);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-icon { width: 40px; height: 40px; flex: none; }
.brand-logo { width: 110px; flex: none; display: block; border-radius: 4px; transition: opacity .15s; }
.brand-logo img { display: block; width: 100%; height: auto; }
.brand-logo:hover { opacity: .85; }
.brand-logo:focus-visible { outline: 2px solid #0ee6f5; outline-offset: 4px; }
.brand-sep { width: 1px; height: 28px; background: #1f4060; flex: none; }
.brand-title {
  color: #0ee6f5; font-size: 14px; font-weight: 600; letter-spacing: .5em;
  text-transform: uppercase; white-space: nowrap;
}
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.link-btn, .icon-btn {
  background: none; border: 0; display: inline-flex; align-items: center; gap: 8px;
  padding: 6px; border-radius: 8px; color: #c6d6e4; font-size: 16px;
  transition: color .15s;
}
.link-btn svg, .icon-btn svg { width: 24px; height: 24px; stroke-width: 1.8; }
.link-btn svg { color: #22d3ee; }
.link-btn:hover, .icon-btn:hover, .link-btn:hover svg { color: #0ee6f5; }
.topbar .divider { width: 1px; height: 24px; background: #1f4060; }
.modal-close svg { width: 20px; height: 20px; }
.icon-btn .snd-off { display: none; }
.icon-btn[aria-pressed="false"] .snd-on { display: none; }
.icon-btn[aria-pressed="false"] .snd-off { display: block; }

/* ---------- Layout ---------- */
.wrap { width: min(1780px, calc(100% - 32px)); margin: 16px auto 0; display: grid; gap: 12px; flex: 1; align-content: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr) auto auto; align-items: center; padding: 12px 8px; }
.stat {
  display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative;
  border-left: 1px solid var(--line-2); padding: 0 12px;
}
.stat:first-child { border-left: 0; }
.stat-label { font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat-value.warn { color: var(--danger); }
.progress { display: block; width: 140px; max-width: 80%; height: 4px; margin-top: 6px; background: var(--line-2); border-radius: 99px; overflow: hidden; }
.progress-bar { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s ease; }
.stat-status { min-width: 150px; }
.status { display: inline-flex; align-items: center; gap: 10px; font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.status i { width: 10px; height: 10px; border-radius: 50%; background: var(--dim); }
.status[data-state="playing"] i { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status[data-state="paused"] i { background: var(--amber); }
.status[data-state="won"] i { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.status[data-state="lost"] i { background: var(--danger); }

/* ---------- Side panels ---------- */
.play-row { display: grid; grid-template-columns: 290px minmax(0, 1fr) 290px; gap: 28px; align-items: start; }
.side { padding: 16px 16px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.side-title { margin: 0 0 6px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .25em; text-transform: uppercase; }
.side-left { gap: 0; }
.run-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.run-item:last-child { border-bottom: 0; }
.run-item > svg { width: 16px; height: 16px; color: var(--accent); stroke-width: 1.8; }
.run-item > div { flex: 1; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-width: 0; }
.run-label { font-size: 13px; color: #c6d6e4; }
.run-value { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.run-value.hot { color: var(--amber); }

.play-center { display: grid; gap: 10px; align-content: start; min-width: 0; }
.set-strip { display: flex; align-items: center; gap: 18px; padding: 10px 16px; }
.set-head { flex: none; width: 120px; }
.set-head .side-title { margin: 0 0 2px; }
.set-name { font-size: 13px; font-weight: 700; }
.set-grid { flex: 1; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; min-width: 0; }
.set-foot { flex: none; width: 120px; display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.set-foot .progress { width: 100%; max-width: none; margin: 0; }
.set-tile {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; font-size: 20px;
  background: rgba(0, 0, 0, .18); border: 1px solid var(--line);
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  filter: grayscale(1); opacity: .28; transition: opacity .3s, filter .3s, border-color .3s, box-shadow .3s;
}
.set-tile.found { filter: none; opacity: 1; border-color: var(--match); box-shadow: 0 0 8px rgba(45, 212, 191, .35); }
.set-tile.power { opacity: .45; border-style: dashed; }
.set-tile.power.found { border-style: solid; border-color: #a78bfa; box-shadow: 0 0 8px rgba(167, 139, 250, .4); }
.set-tile.power-bomb.found { border-color: var(--danger); box-shadow: 0 0 8px rgba(251, 113, 133, .4); }

/* Side columns hold two stacked panels */
.side-col { display: grid; gap: 12px; align-content: start; min-width: 0; }
.rules { margin: 0; }
.rules div { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.rules div:last-child { border-bottom: 0; }
.rules dt { color: #c6d6e4; }
.rules dd { margin: 0; font-weight: 800; text-align: right; }
.guide { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.guide li { display: flex; align-items: center; gap: 12px; }
.guide b { display: block; font-size: 14px; }
.guide small { display: block; font-size: 12px; color: var(--muted); line-height: 1.35; }
.guide-icon {
  flex: none; width: 40px; height: 32px; display: grid; place-items: center; border-radius: 6px; font-size: 18px;
  border: 1px solid var(--pc); background: color-mix(in srgb, var(--pc) 12%, transparent);
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}
.guide-icon.power-peek, .guide-icon.power-joker { --pc: #a78bfa; }
.guide-icon.power-freeze { --pc: #7dd3fc; }
.guide-icon.power-bomb { --pc: var(--danger); }
.guide-note { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
#powerPanel.off .guide { opacity: .35; filter: grayscale(1); }

/* ---------- Challenges ---------- */
.challenges { display: grid; gap: 8px; }
.challenge {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; text-align: left;
  background: rgba(0, 0, 0, .18); border: 1px solid var(--line); border-radius: 8px; color: var(--text);
  transition: border-color .2s, background .2s, box-shadow .2s;
}
.challenge:hover { border-color: var(--line-2); }
.challenge:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.challenge[aria-checked="true"] { border-color: var(--danger); background: rgba(251, 113, 133, .07); box-shadow: 0 0 10px rgba(251, 113, 133, .18); }
.ch-icon { flex: none; font-size: 20px; font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; }
.ch-text { flex: 1; min-width: 0; }
.ch-text b { display: block; font-size: 14px; }
.ch-text small { display: block; font-size: 12px; color: var(--muted); line-height: 1.35; }
.challenge .toggle-track { flex: none; }
.challenge[aria-checked="true"] .toggle-track { background: var(--danger); }
.challenge[aria-checked="true"] .toggle-knob { transform: translateX(18px); }
.ch-foot { margin: 4px 0 0; font-size: 12px; color: var(--muted); }

/* Hearts in the stats bar */
.stat-lives[hidden] { display: none; }
.hearts { display: flex; gap: 6px; margin-top: 2px; }
.heart svg { width: 26px; height: 26px; fill: var(--accent); stroke: none; filter: drop-shadow(0 0 6px rgba(34, 211, 238, .6)); transition: fill .3s, filter .3s; }
.heart.lost svg { fill: #22364d; filter: none; }
.heart.breaking svg { animation: heart-break .6s ease; }
@keyframes heart-break { 0% { fill: var(--danger); transform: scale(1.35); } 40% { transform: scale(.8) rotate(-12deg); } }

/* Fading memory: hidden card backs fade out while the game runs */
.board.fade .card:not(.flipped):not(.matched) .card-back {
  animation: fade-away var(--fade, 15s) linear forwards; animation-play-state: paused;
}
.board.fade.running .card:not(.flipped):not(.matched) .card-back { animation-play-state: running; }
@keyframes fade-away { 0%, 15% { opacity: 1; } to { opacity: .04; } }
.board.fade .card.glitch:not(.flipped):not(.matched) .card-back { animation: glitch .6s steps(2) 2; }
.board.fade .card:not(.flipped):not(.matched):hover { outline: 1px dashed rgba(34, 211, 238, .35); outline-offset: -1px; }

/* Glitch shuffle flash on the board frame */
.board-frame.glitching { animation: frame-glitch .5s steps(3); }
@keyframes frame-glitch {
  33% { border-color: #f0abfc; box-shadow: 0 0 26px rgba(240, 171, 252, .5); translate: 3px 0; }
  66% { border-color: var(--accent); translate: -3px 0; filter: hue-rotate(60deg); }
}

/* On/off switch (Power cards) */
.toggle { display: inline-flex; align-items: center; gap: 12px; background: none; border: 0; padding: 4px; font-size: 14px; color: var(--text); }
.toggle-track { position: relative; width: 42px; height: 24px; border-radius: 99px; background: #22364d; transition: background .2s; }
.toggle-knob { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle[aria-checked="true"] .toggle-track { background: var(--accent); }
.toggle[aria-checked="true"] .toggle-knob { transform: translateX(18px); }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.side-head .side-title { margin: 0; }
.side-head .toggle { gap: 8px; font-size: 12px; font-weight: 700; color: var(--muted); }
.toggle[aria-checked="true"] .toggle-state { color: var(--accent); }
.toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.theme {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 8px 4px; border-radius: 6px; background: rgba(0, 0, 0, .18); border: 1px solid var(--line);
  color: var(--muted); font-size: 12px; transition: border-color .2s, color .2s, box-shadow .2s;
}
.theme-emoji { font-size: 22px; line-height: 1.1; font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; }
.theme:hover { border-color: var(--line-2); color: var(--text); }
.theme:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme[aria-checked="true"] {
  border-color: var(--accent); color: var(--text); font-weight: 700;
  background: rgba(34, 211, 238, .08); box-shadow: 0 0 10px rgba(34, 211, 238, .25);
}

/* ---------- Board ---------- */
.board-frame {
  position: relative; padding: 18px 20px; border-radius: 10px;
  border: 2px solid var(--accent);
  background:
    linear-gradient(rgba(34, 211, 238, .04) 1px, transparent 1px) 0 0 / 34px 34px,
    linear-gradient(90deg, rgba(34, 211, 238, .04) 1px, transparent 1px) 0 0 / 34px 34px,
    #0a1828;
  box-shadow: 0 0 22px rgba(34, 211, 238, .28), inset 0 0 30px rgba(34, 211, 238, .06);
}
.board {
  display: grid; grid-template-columns: repeat(var(--cols, 6), 1fr); gap: 14px;
  /* Keep the whole game on screen: cap board width by the height left after the header, panels and footer. */
  max-width: max(320px, calc((100vh - 470px) * var(--ratio, 2))); margin: 0 auto;
}
.board.paused .card { visibility: hidden; }

.hint-pill {
  position: absolute; left: 50%; bottom: 14px; translate: -50% 0; pointer-events: none;
  padding: 6px 14px; border-radius: 99px; font-size: 13px; color: var(--text);
  background: rgba(10, 30, 45, .92); border: 1px solid rgba(34, 211, 238, .4);
  transition: opacity .3s;
}
.hint-pill.hide { opacity: 0; }
.hint-pill.pulse { animation: pill-in .3s ease; }
@keyframes pill-in { from { transform: translateY(6px) scale(.96); opacity: 0; } }

/* ---------- Cards ---------- */
.card { aspect-ratio: 4 / 3; perspective: 900px; border: 0; padding: 0; background: none; border-radius: 10px; }
.board[data-diff="hard"] .card { aspect-ratio: 1; }
.card:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.card-inner {
  display: block; position: relative; width: 100%; height: 100%; transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.3, .7, .3, 1);
}
.card.flipped .card-inner, .card.matched .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute; inset: 0; border-radius: 10px; display: grid; place-items: center;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.card-back {
  background: linear-gradient(160deg, var(--panel-2), var(--card-back));
  border: 1px solid var(--line-2); color: var(--accent);
  transition: border-color .2s, box-shadow .2s;
}
.card-back::before {
  content: ""; position: absolute; inset: 7px; opacity: .6;
  --c: var(--accent);
  background:
    linear-gradient(var(--c), var(--c)) left top / 10px 2px, linear-gradient(var(--c), var(--c)) left top / 2px 10px,
    linear-gradient(var(--c), var(--c)) right top / 10px 2px, linear-gradient(var(--c), var(--c)) right top / 2px 10px,
    linear-gradient(var(--c), var(--c)) left bottom / 10px 2px, linear-gradient(var(--c), var(--c)) left bottom / 2px 10px,
    linear-gradient(var(--c), var(--c)) right bottom / 10px 2px, linear-gradient(var(--c), var(--c)) right bottom / 2px 10px;
  background-repeat: no-repeat;
}
.card-back svg { font-size: clamp(20px, 2.6vw, 34px); }
.card:not(.flipped):not(.matched):hover .card-back { border-color: var(--accent); box-shadow: 0 0 12px rgba(34, 211, 238, .25); }
.card-front {
  transform: rotateY(180deg); background: var(--card-face);
  border: 2px solid var(--accent); box-shadow: 0 0 14px rgba(34, 211, 238, .4);
  font-size: clamp(26px, 3.8vw, 54px); line-height: 1;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}
.board[data-diff="hard"] .card-front { font-size: clamp(22px, 3vw, 42px); }
.card.matched .card-front { border-color: var(--match); box-shadow: 0 0 16px rgba(45, 212, 191, .45); animation: pop .45s ease .25s; }
.card.miss .card-front { border-color: var(--danger); box-shadow: 0 0 14px rgba(251, 113, 133, .4); animation: shake .35s ease; }

/* ---------- Power cards ---------- */
.card-front.power { flex-direction: column; display: flex; align-items: center; justify-content: center; gap: 4%; }
.power-emoji { line-height: 1; }
.power-tag {
  font: 800 clamp(8px, .75vw, 11px) "Segoe UI", system-ui, sans-serif; letter-spacing: .18em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 99px; background: rgba(255, 255, 255, .08);
}
.card-front.power-peek, .card-front.power-joker { --pc: #a78bfa; }
.card-front.power-freeze { --pc: #7dd3fc; }
.card-front.power-bomb { --pc: var(--danger); }
.card-front.power,
.card.matched .card-front.power {
  border-color: var(--pc); color: var(--pc);
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--pc) 18%, transparent), var(--card-face) 70%);
  box-shadow: 0 0 16px color-mix(in srgb, var(--pc) 45%, transparent);
}
.card.exploded .card-front { animation: boom .5s ease; opacity: .55; }
@keyframes boom { 30% { transform: rotateY(180deg) scale(1.15); filter: brightness(2); } }
.card.glitch .card-back { animation: glitch .6s steps(2) 2; }
@keyframes glitch {
  0% { transform: translate(2px, -1px); border-color: #f0abfc; }
  50% { transform: translate(-2px, 1px); border-color: var(--accent); filter: hue-rotate(90deg); }
}
.board.peeking .card:not(.matched) .card-inner { transform: rotateY(180deg); }
.board.peeking .card:not(.matched) .card-front { border-color: #a78bfa; box-shadow: 0 0 12px rgba(167, 139, 250, .45); }
.board-frame.shake { animation: frame-shake .45s ease; }
@keyframes frame-shake { 20% { translate: -6px 2px; } 40% { translate: 5px -2px; } 60% { translate: -4px 1px; } 80% { translate: 2px 0; } }

/* Floating "+300" / "×3" text */
.float {
  position: absolute; z-index: 3; pointer-events: none; translate: -50% -50%;
  font-size: 20px; font-weight: 900; color: var(--match); text-shadow: 0 0 10px rgba(45, 212, 191, .6);
  animation: float-up 1.1s ease-out forwards;
}
.float.hot { color: var(--amber); text-shadow: 0 0 10px rgba(251, 191, 36, .6); font-size: 24px; }
.float.combo { color: #a78bfa; text-shadow: 0 0 10px rgba(167, 139, 250, .6); font-size: 16px; }
.float.bomb { color: var(--danger); text-shadow: 0 0 12px rgba(251, 113, 133, .7); font-size: 26px; letter-spacing: .1em; }
@keyframes float-up { from { opacity: 0; transform: translateY(8px) scale(.8); } 15% { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-46px); } }

.stat-value.frozen, .stat-label.frozen { color: #7dd3fc; text-shadow: 0 0 10px rgba(125, 211, 252, .6); }
@keyframes pop { 50% { transform: rotateY(180deg) scale(1.07); } }
@keyframes shake { 25% { translate: -4px 0; } 75% { translate: 4px 0; } }

/* ---------- Overlay ---------- */
.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; border-radius: 8px;
  background: rgba(6, 14, 24, .78); backdrop-filter: blur(3px);
}
.overlay[hidden] { display: none; }
.overlay-card { text-align: center; padding: 20px; }
.overlay-emoji:empty { display: none; }
.overlay-emoji { font-size: 44px; margin-bottom: 4px; }
.overlay-card h2 { margin: 0 0 6px; font-size: 26px; font-weight: 900; }
.overlay-card p { color: var(--muted); margin: 0 0 18px; font-size: 14px; white-space: pre-line; line-height: 1.6; }

/* ---------- Controls ---------- */
.controls { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 14px 18px; padding: 14px 18px; }
.ctrl-group { display: flex; gap: 10px; }
.ctrl-sep { width: 1px; height: 32px; background: var(--line-2); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 8px 20px; min-height: 36px; border-radius: 6px; font-size: 14px; font-weight: 800;
  border: 1px solid transparent; transition: filter .15s, border-color .15s, color .15s;
}
.btn svg { font-size: 15px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary svg path[d^="M7 4"] { fill: currentColor; }
.btn-outline { background: none; border-color: #c9d6e3; color: var(--text); }
.btn-outline:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-outline .i-play { fill: currentColor; display: none; }
.btn-outline.is-paused .i-play { display: block; }
.btn-outline.is-paused .i-pause { display: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.segmented { display: inline-flex; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; background: rgba(0, 0, 0, .15); }
.segmented button {
  border: 0; background: none; padding: 8px 22px; min-height: 36px; font-size: 14px; font-weight: 600; color: var(--text);
  border-left: 1px solid var(--line); transition: background .2s, color .2s;
}
.segmented button:first-child { border-left: 0; }
.segmented button:hover { background: rgba(34, 211, 238, .08); }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 800; }

/* ---------- Keys ---------- */
.keys { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px 0; padding: 6px 0; }
.key-item { display: flex; align-items: center; gap: 10px; padding: 0 20px; border-left: 1px solid var(--line-2); font-size: 13px; color: var(--muted); }
.key-item:first-child { border-left: 0; }
.key-item .mouse { font-size: 20px; color: var(--accent); }
kbd {
  display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 8px;
  border: 1px solid var(--line-2); border-radius: 5px; background: var(--panel);
  font: 700 12px "Segoe UI", system-ui, sans-serif; color: var(--text);
}

/* ---------- Footer ---------- */
.footer { text-align: center; color: var(--muted); padding: 14px 16px 22px; font-size: 12px; letter-spacing: .2em; }
.footer a, .footer b { color: var(--accent); font-weight: 800; text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px; background: rgba(3, 8, 15, .7); backdrop-filter: blur(4px); }
.modal[hidden] { display: none; }
.modal-card { position: relative; width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; padding: 24px; box-shadow: 0 0 30px rgba(34, 211, 238, .15); }
.modal-card h2 { margin: 0 0 12px; font-size: 22px; font-weight: 900; }
.modal-card ul { margin: 0 0 20px; padding-left: 18px; color: var(--muted); line-height: 1.6; font-size: 14px; }
.modal-card b { color: var(--text); }
.modal-close { position: absolute; top: 14px; right: 14px; }

/* ---------- Fullscreen ---------- */
:fullscreen body, body:fullscreen { background: var(--bg); }

/* ---------- Responsive ---------- */
/* Header breakpoints */
@media (max-width: 960px) {
  .topbar { height: 56px; }
  .brand-icon { width: 32px; height: 32px; }
  .brand-logo { width: 84px; }
  .brand-title { font-size: 12px; letter-spacing: .3em; }
  .link-btn span { display: none; }
}
@media (max-width: 560px) {
  .brand-logo, .brand-sep { display: none; }
}

/* Side panels move under the board on narrower screens */
@media (max-width: 1280px) {
  .play-row { grid-template-columns: 1fr 1fr; gap: 12px; }
  .play-center { grid-column: 1 / -1; order: -1; }
  .theme-grid { grid-template-columns: repeat(4, 1fr); }
  .side-left { display: flex; }
}
@media (max-width: 640px) {
  .play-row { grid-template-columns: 1fr; }
  .theme-grid { grid-template-columns: repeat(3, 1fr); }
  .set-strip { flex-wrap: wrap; gap: 10px; }
  .set-grid { order: 3; flex-basis: 100%; }
  .set-tile { width: 32px; height: 32px; font-size: 18px; }
  .run-item { padding: 10px; gap: 10px; }
}

@media (max-width: 860px) {
  .ctrl-sep { display: none; }
  .stats { grid-template-columns: repeat(3, 1fr); row-gap: 12px; }
  .stat:nth-child(4) { border-left: 0; }
  .stat-status { min-width: 0; }
}
@media (max-width: 640px) {
  .wrap { width: calc(100% - 32px); }
  .stat { padding: 0 4px; }
  .stat-label { font-size: 10px; letter-spacing: .06em; }
  .stat-value { font-size: 19px; }
  .board-frame { padding: 10px; }
  .board { gap: 8px; max-width: none; }
  .board[data-diff="medium"], .board[data-diff="hard"] { --cols: 4 !important; }
  .card, .board[data-diff="hard"] .card { aspect-ratio: 1; }
  .card-back::before { inset: 5px; }
  .card-front { font-size: 30px !important; }
  .controls { padding: 12px; }
  .ctrl-group, .segmented { width: 100%; }
  .ctrl-group .btn, .segmented button { flex: 1; padding-left: 8px; padding-right: 8px; }
  .keys { display: none; }
}
