:root {
  --bg-top: #081529;
  --bg-mid: #102a49;
  --bg-bottom: #183a59;
  --glass-bg: rgba(15, 32, 58, 0.72);
  --glass-border: rgba(255, 255, 255, 0.16);
  --glass-highlight: rgba(255, 255, 255, 0.08);
  --text-main: #f8fbff;
  --text-muted: #b6cbe3;
  --gold: #ffd166;
  --gold-deep: #f4a261;
  --red: #e63946;
  --red-bright: #ff4d5a;
  --pine: #2a9d8f;
  --pine-bright: #43c6ac;
  --ice: #72efdd;
  --board-size: min(74vmin, 540px);
  --radius-lg: 22px;
  --radius-md: 14px;
  --shadow-lg: 0 18px 48px rgba(3, 10, 22, 0.55);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  min-height: 100%;
  min-height: 100dvh;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-main);
  background: radial-gradient(circle at 20% 10%, #1c4470 0%, var(--bg-mid) 40%, var(--bg-top) 100%);
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
}

#snow-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.glass-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* Header */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-star {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, #ffe28a, #f4a261);
  color: #7c2d12;
  font-size: 26px;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 20px rgba(255, 209, 102, 0.4);
}

.brand h1 {
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(1.5rem, 2.6vw, 2rem);
  letter-spacing: 0.4px;
  line-height: 1.05;
  background: linear-gradient(180deg, #ffffff 10%, #ffe8a3 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
}

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

.difficulty-pill {
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.pill-easy {
  background: rgba(67, 198, 172, 0.2);
  color: #7bf1dc;
  border: 1px solid rgba(67, 198, 172, 0.45);
}

.pill-medium {
  background: rgba(255, 209, 102, 0.2);
  color: #ffe08a;
  border: 1px solid rgba(255, 209, 102, 0.45);
}

.pill-hard {
  background: rgba(230, 57, 70, 0.24);
  color: #ff8a93;
  border: 1px solid rgba(255, 77, 90, 0.5);
}

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: transform 0.14s ease, filter 0.14s ease, background 0.14s ease;
}

button:active {
  transform: scale(0.96);
}

.action-btn {
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 0.92rem;
  color: #fff;
}

.primary-btn {
  background: linear-gradient(135deg, var(--red-bright), #c1121f);
  box-shadow: 0 6px 18px rgba(230, 57, 70, 0.35);
}

.primary-btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-main);
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.ghost-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text-muted);
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 1.1rem;
  display: grid;
  place-items: center;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.full-width {
  width: 100%;
}

/* Main 3-Column Game Layout */
.game-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 280px;
  gap: 18px;
  align-items: start;
}

.hud-panel,
.leaderboard-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.stat-box {
  background: rgba(7, 18, 34, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.stat-box.accent-gold { border-left: 4px solid var(--gold); }
.stat-box.accent-red { border-left: 4px solid var(--red-bright); }
.stat-box.accent-pine { border-left: 4px solid var(--pine-bright); }
.stat-box.accent-ice { border-left: 4px solid var(--ice); }

.stat-label {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-muted);
}

.stat-value {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.55rem;
  font-weight: 700;
  color: #fff;
}

.stat-value.low-warning {
  color: #ff6b77;
  animation: pulseWarn 0.7s infinite alternate;
}

@keyframes pulseWarn {
  from { transform: scale(1); }
  to { transform: scale(1.1); }
}

.hud-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.powerup-guide {
  background: rgba(7, 18, 34, 0.45);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.powerup-guide h3 {
  font-family: 'Fredoka', sans-serif;
  font-size: 0.95rem;
  color: var(--gold);
}

.guide-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.guide-badge {
  flex: 0 0 28px;
  height: 28px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  color: #fff;
}

.bomb-badge {
  background: linear-gradient(135deg, #ff5964, #d90429);
  box-shadow: 0 0 12px rgba(255, 89, 100, 0.5);
}

.star-badge {
  background: linear-gradient(135deg, #ffe066, #f77f00);
  color: #4a1d05;
  box-shadow: 0 0 12px rgba(255, 224, 102, 0.55);
}

/* Board */
.board-stage {
  display: flex;
  justify-content: center;
  align-items: center;
}

.board-frame {
  position: relative;
  padding: 14px;
  border-radius: 26px;
  background: linear-gradient(160deg, rgba(25, 55, 92, 0.82), rgba(10, 23, 44, 0.9));
  border: 2px solid rgba(255, 225, 148, 0.25);
}

.board {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  border-radius: 16px;
  background: rgba(6, 15, 28, 0.65);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: inset 0 4px 20px rgba(0, 0, 0, 0.45);
}

.board-grid-cell {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  border: 1px solid rgba(255, 255, 255, 0.045);
}

.board-grid-cell.alt {
  background: rgba(255, 255, 255, 0.03);
}

.tile {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  padding: 4px;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease;
  will-change: transform;
  z-index: 2;
}

.tile-inner {
  width: 100%;
  height: 100%;
  border-radius: 13px;
  background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.04));
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
  position: relative;
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
}

.tile:hover .tile-inner {
  transform: scale(1.06);
  background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.08));
}

.tile.selected .tile-inner {
  transform: scale(1.1);
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.5), 0 0 18px rgba(255, 209, 102, 0.65);
  background: radial-gradient(circle at 30% 25%, rgba(255, 224, 130, 0.35), rgba(255, 209, 102, 0.1));
}

.tile.hint .tile-inner {
  animation: hintPulse 0.85s ease-in-out infinite alternate;
}

@keyframes hintPulse {
  from {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(114, 239, 221, 0.7);
  }
  to {
    transform: scale(1.1);
    box-shadow: 0 0 0 3px rgba(114, 239, 221, 0.85), 0 0 18px rgba(114, 239, 221, 0.7);
  }
}

.tile.matching .tile-inner {
  animation: tilePop 0.26s ease-out forwards;
}

@keyframes tilePop {
  0% { transform: scale(1); opacity: 1; }
  45% { transform: scale(1.22); opacity: 1; }
  100% { transform: scale(0.1); opacity: 0; }
}

.tile.special-bomb .tile-inner {
  border: 2px solid #ff6b77;
  box-shadow: 0 0 14px rgba(255, 77, 90, 0.75), inset 0 0 12px rgba(255, 120, 130, 0.45);
  animation: bombGlow 1.1s ease-in-out infinite alternate;
}

.tile.special-bomb .tile-inner::after {
  content: '✦';
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 11px;
  color: #ffe066;
  text-shadow: 0 0 6px #ff4d5a;
}

@keyframes bombGlow {
  from { box-shadow: 0 0 10px rgba(255, 77, 90, 0.6); }
  to { box-shadow: 0 0 20px rgba(255, 209, 102, 0.9); }
}

.tile.special-star .tile-inner {
  border: 2px solid #ffe066;
  background: radial-gradient(circle, rgba(255, 230, 128, 0.45), rgba(244, 162, 97, 0.18));
  box-shadow: 0 0 18px rgba(255, 209, 102, 0.85);
  animation: starSpinGlow 1.4s ease-in-out infinite alternate;
}

@keyframes starSpinGlow {
  from { transform: scale(0.98); box-shadow: 0 0 12px rgba(255, 209, 102, 0.65); }
  to { transform: scale(1.06); box-shadow: 0 0 24px rgba(255, 232, 140, 1); }
}

.tile svg {
  width: 82%;
  height: 82%;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.35));
  pointer-events: none;
}

/* FX Layer */
.fx-layer {
  position: absolute;
  inset: 14px;
  pointer-events: none;
  overflow: hidden;
  z-index: 10;
}

.floating-score {
  position: absolute;
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 1.25rem;
  color: #ffe885;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.75);
  transform: translate(-50%, -50%);
  animation: floatUp 0.85s ease-out forwards;
  white-space: nowrap;
}

@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(0.7); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(0.95); }
}

.spark-particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  animation: sparkFly 0.55s ease-out forwards;
}

@keyframes sparkFly {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.1); }
}

.combo-banner,
.toast-banner {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  pointer-events: none;
  padding: 6px 18px;
  border-radius: 999px;
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  white-space: nowrap;
}

.combo-banner {
  top: 24px;
  background: linear-gradient(135deg, #ffd166, #f77f00);
  color: #3b1704;
  font-size: 1.05rem;
  box-shadow: 0 8px 24px rgba(247, 127, 0, 0.5);
  animation: popIn 0.25s ease-out;
}

.toast-banner {
  bottom: 24px;
  background: rgba(15, 32, 58, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 0.92rem;
}

@keyframes popIn {
  from { opacity: 0; transform: translateX(-50%) scale(0.7); }
  to { opacity: 1; transform: translateX(-50%) scale(1); }
}

/* Leaderboard */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-header h2 {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.2rem;
}

.storage-badge {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
}

.storage-badge.cloud {
  background: rgba(67, 198, 172, 0.22);
  color: #7bf1dc;
}

.diff-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: rgba(6, 15, 28, 0.5);
  padding: 5px;
  border-radius: 12px;
}

.diff-tab {
  padding: 7px 6px;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 800;
  font-size: 0.82rem;
}

.diff-tab.active {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.score-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.score-list.compact {
  max-height: 190px;
  overflow-y: auto;
  padding-right: 4px;
}

.score-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(7, 18, 34, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.9rem;
}

.score-row.highlight {
  background: rgba(255, 209, 102, 0.2);
  border-color: rgba(255, 209, 102, 0.55);
}

.score-rank {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
}

.score-row:nth-child(1) .score-rank { color: #ffd166; }
.score-row:nth-child(2) .score-rank { color: #e2e8f0; }
.score-row:nth-child(3) .score-rank { color: #f4a261; }

.score-initials {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  letter-spacing: 2px;
  font-size: 1rem;
}

.score-points {
  font-weight: 800;
  color: var(--gold);
}

.score-empty {
  text-align: center;
  padding: 20px 10px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 11, 23, 0.76);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: min(100%, 600px);
  max-height: 92vh;
  overflow-y: auto;
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
}

.modal-emblem {
  font-size: 2.6rem;
  line-height: 1;
}

.modal-card h2 {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.7rem;
}

.modal-lead {
  color: var(--text-muted);
  font-size: 0.96rem;
  line-height: 1.45;
}

.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 4px;
}

.diff-card {
  padding: 16px 12px;
  border-radius: 16px;
  background: rgba(8, 20, 38, 0.65);
  border: 2px solid rgba(255, 255, 255, 0.14);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.diff-card:hover {
  transform: translateY(-3px);
}

.diff-easy:hover {
  border-color: var(--pine-bright);
  box-shadow: 0 10px 24px rgba(67, 198, 172, 0.25);
}

.diff-medium:hover {
  border-color: var(--gold);
  box-shadow: 0 10px 24px rgba(255, 209, 102, 0.25);
}

.diff-hard:hover {
  border-color: var(--red-bright);
  box-shadow: 0 10px 24px rgba(230, 57, 70, 0.3);
}

.diff-card-icon {
  font-size: 1.8rem;
}

.diff-card-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.2rem;
}

.diff-card-meta {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--gold);
}

.diff-card-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.diff-card-best {
  margin-top: 4px;
  font-size: 0.78rem;
  color: #d6e6f7;
  background: rgba(255, 255, 255, 0.08);
  padding: 3px 9px;
  border-radius: 999px;
}

/* Game Over */
.summary-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.summary-stat {
  background: rgba(7, 18, 34, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-stat span {
  font-size: 0.76rem;
  text-transform: uppercase;
  color: var(--text-muted);
}

.summary-stat strong {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.35rem;
  color: var(--gold);
}

.initials-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 209, 102, 0.08);
  border: 1px solid rgba(255, 209, 102, 0.25);
}

.initials-label {
  font-weight: 800;
  font-size: 0.92rem;
  color: #ffe8a3;
}

.initials-inputs {
  display: flex;
  gap: 10px;
}

.initial-box {
  width: 56px;
  height: 62px;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.26);
  background: rgba(7, 18, 34, 0.8);
  color: #fff;
  font-family: 'Fredoka', sans-serif;
  font-size: 1.9rem;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  outline: none;
}

.initial-box:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.3);
}

.saved-confirmation {
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(67, 198, 172, 0.18);
  border: 1px solid rgba(67, 198, 172, 0.45);
  color: #9bf6e4;
  font-weight: 700;
  font-size: 0.92rem;
}

.modal-leaderboard-wrap {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-leaderboard-wrap h3 {
  font-family: 'Fredoka', sans-serif;
  font-size: 1rem;
  color: var(--text-muted);
  text-align: center;
}

.modal-footer-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hidden {
  display: none !important;
}

/* Responsive — Desktop compact / iPad mini Landscape (1133x744) */
@media (max-height: 820px) and (min-width: 861px) {
  :root {
    --board-size: min(calc(100dvh - 140px), calc(100vw - 590px), 520px);
  }
  .app-shell {
    gap: 12px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .hud-panel,
  .leaderboard-panel {
    padding: 14px;
    gap: 12px;
  }
  .stat-box {
    padding: 9px 12px;
  }
  .stat-value {
    font-size: 1.35rem;
  }
}

@media (max-width: 1060px) {
  :root {
    --board-size: min(calc(100vw - 310px), calc(100dvh - 150px), 520px);
  }
  .game-layout {
    grid-template-columns: 230px minmax(0, 1fr);
  }
  .leaderboard-panel {
    grid-column: 1 / -1;
  }
}

/* iPad mini Portrait (744x1133) & Tablet */
@media (max-width: 860px) {
  :root {
    --board-size: min(86vw, calc(100dvh - 300px), 560px);
  }
  .app-shell {
    gap: 12px;
    padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  .game-layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .hud-panel {
    padding: 12px 14px;
    gap: 10px;
  }
  .stat-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
  }
  .stat-box {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 8px 10px;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid transparent;
  }
  .stat-box.accent-gold { border-left-color: rgba(255, 255, 255, 0.1); border-top-color: var(--gold); }
  .stat-box.accent-red { border-left-color: rgba(255, 255, 255, 0.1); border-top-color: var(--red-bright); }
  .stat-box.accent-pine { border-left-color: rgba(255, 255, 255, 0.1); border-top-color: var(--pine-bright); }
  .stat-box.accent-ice { border-left-color: rgba(255, 255, 255, 0.1); border-top-color: var(--ice); }
  .hud-controls {
    flex-direction: row;
  }
  .powerup-guide {
    display: none;
  }
  .difficulty-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* iPhone 16 Portrait (393x852) & Mobile PWA */
@media (max-width: 520px) {
  :root {
    --board-size: min(
      calc(100vw - 40px - env(safe-area-inset-left) - env(safe-area-inset-right)),
      calc(100dvh - 255px - env(safe-area-inset-top) - env(safe-area-inset-bottom)),
      353px
    );
  }
  .app-shell {
    gap: 10px;
    padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }
  .top-bar {
    gap: 8px;
  }
  .brand {
    gap: 8px;
  }
  .brand-star {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-size: 20px;
  }
  .brand h1 {
    font-size: 1.25rem;
  }
  .subtitle {
    display: none;
  }
  .top-actions {
    gap: 6px;
  }
  .difficulty-pill {
    padding: 4px 10px;
    font-size: 0.72rem;
  }
  .icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    font-size: 1rem;
  }
  .action-btn {
    padding: 8px 11px;
    font-size: 0.82rem;
    min-height: 38px;
  }
  .hud-panel {
    padding: 10px;
    gap: 8px;
    border-radius: 18px;
  }
  .stat-grid {
    grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
    gap: 6px;
  }
  .stat-box {
    padding: 6px 6px;
    border-radius: 11px;
  }
  .stat-label {
    font-size: 0.66rem;
    letter-spacing: 0.4px;
    white-space: nowrap;
  }
  .stat-value {
    font-size: 1.22rem;
  }
  .board-frame {
    padding: 8px;
    border-radius: 20px;
  }
  .fx-layer {
    inset: 8px;
  }
  .tile {
    padding: 2.5px;
  }
  .tile-inner {
    border-radius: 9px;
  }
  .tile svg {
    width: 86%;
    height: 86%;
  }
  .difficulty-grid {
    grid-template-columns: 1fr;
  }
  .modal-card {
    padding: 20px 16px;
  }
  .initial-box {
    width: 50px;
    height: 56px;
    font-size: 1.7rem;
  }
}
