:root {
  --bg-0: #05020f;
  --bg-1: #0a0420;
  --bg-2: #160734;
  --ink: #f4f1ff;
  --ink-dim: #b5a8e8;
  --ink-deep: #6b5f9a;
  --panel: rgba(20, 8, 48, 0.55);
  --panel-strong: rgba(28, 12, 64, 0.85);
  --border: rgba(157, 110, 255, 0.35);
  --border-soft: rgba(157, 110, 255, 0.15);
  --pink: #ff3ec8;
  --cyan: #25e2ff;
  --violet: #a26bff;
  --lime: #c8ff5b;
  --amber: #ffb547;
  --grid: rgba(255, 255, 255, 0.04);
  --shadow-cyan: 0 0 18px rgba(37, 226, 255, 0.55);
  --shadow-pink: 0 0 22px rgba(255, 62, 200, 0.55);
  --font-display: "Orbitron", "Eurostile", "Bahnschrift", "Microsoft YaHei", system-ui, sans-serif;
  --font-body: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-0);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 800px at 80% -10%, rgba(255, 62, 200, 0.18), transparent 60%),
    radial-gradient(1000px 700px at -10% 30%, rgba(37, 226, 255, 0.12), transparent 60%),
    radial-gradient(900px 600px at 50% 110%, rgba(162, 107, 255, 0.18), transparent 70%),
    linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 60%, #02010a 100%);
}

.stars {
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 12% 18%, rgba(255,255,255,0.65), transparent 50%),
    radial-gradient(1px 1px at 78% 32%, rgba(255,255,255,0.55), transparent 50%),
    radial-gradient(1px 1px at 24% 64%, rgba(255,255,255,0.7), transparent 50%),
    radial-gradient(1.2px 1.2px at 55% 80%, rgba(255,255,255,0.55), transparent 50%),
    radial-gradient(1px 1px at 88% 72%, rgba(255,255,255,0.55), transparent 50%),
    radial-gradient(1px 1px at 40% 12%, rgba(255,255,255,0.45), transparent 50%),
    radial-gradient(1.4px 1.4px at 8% 88%, rgba(255,255,255,0.5), transparent 50%);
  background-size: 100% 100%;
  pointer-events: none;
  opacity: 0.6;
  animation: drift 60s linear infinite;
}
@keyframes drift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(0, -60px, 0); }
}

.bg-glow {
  position: fixed;
  inset: 0;
  background:
    conic-gradient(from 200deg at 50% 50%,
      rgba(255, 62, 200, 0.08),
      rgba(37, 226, 255, 0.08),
      rgba(162, 107, 255, 0.08),
      rgba(255, 62, 200, 0.08));
  filter: blur(60px);
  pointer-events: none;
  opacity: 0.35;
}

html, body { overflow: hidden; }
body { height: 100dvh; }

.layout {
  position: relative;
  z-index: 1;
  max-width: 1480px;
  margin: 0 auto;
  padding: 14px 40px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100dvh;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.brand-tag {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.32em;
  color: var(--cyan);
  text-transform: uppercase;
  text-shadow: 0 0 12px rgba(37, 226, 255, 0.6);
}

.brand-title {
  font-family: var(--font-display);
  font-size: clamp(28px, 3.4vw, 40px);
  margin: 2px 0 0;
  letter-spacing: 0.08em;
  line-height: 0.95;
  background: linear-gradient(180deg, #fff 0%, #b9a3ff 60%, #6a48c2 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(162, 107, 255, 0.45));
}
.brand-title span {
  background: linear-gradient(180deg, var(--pink) 0%, #ff8be0 60%, #5a1d63 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-left: 0.18em;
  filter: drop-shadow(0 0 18px rgba(255, 62, 200, 0.55));
}

.brand-sub {
  color: var(--ink-dim);
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.04em;
}

.hud-top {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--ink);
  backdrop-filter: blur(10px);
  cursor: default;
}
.hud-toggle { cursor: pointer; transition: transform .15s ease, box-shadow .2s ease; }
.hud-toggle:hover { transform: translateY(-1px); box-shadow: var(--shadow-cyan); }
.hud-toggle[aria-pressed="false"] { color: var(--ink-deep); border-color: var(--border-soft); }
.hud-toggle[aria-pressed="false"] .hud-pill-value { color: var(--ink-deep); }
.hud-pill-label { color: var(--ink-dim); font-size: 10px; letter-spacing: 0.3em; }
.hud-pill-value { color: var(--cyan); text-shadow: 0 0 10px rgba(37, 226, 255, 0.55); }

.stage {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  gap: 28px;
  align-items: stretch;
  justify-content: center;
}

.side {
  flex: 0 1 280px;
  min-width: 220px;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-self: center;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  backdrop-filter: blur(12px);
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.03) inset,
    0 12px 40px rgba(10, 4, 32, 0.55);
}

.panel-title {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.4em;
  color: var(--ink-dim);
  margin-bottom: 10px;
  text-transform: uppercase;
}

.mini-canvas {
  width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  max-width: 200px;
  background:
    linear-gradient(135deg, rgba(255,62,200,0.06), rgba(37,226,255,0.06)),
    rgba(8, 2, 26, 0.65);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
}
.mini-canvas.tall { aspect-ratio: 120 / 280; max-width: 180px; }

.panel-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--ink-deep);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-align: center;
}

.panel-stats {
  display: grid;
  gap: 12px;
}
.stat-label {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.35em;
  color: var(--ink-dim);
  text-transform: uppercase;
}
.stat-value {
  font-family: var(--font-display);
  font-size: 26px;
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow: 0 0 14px rgba(162, 107, 255, 0.55);
  margin-top: 2px;
}
.stat:nth-child(2) .stat-value { color: var(--cyan); text-shadow: 0 0 14px rgba(37, 226, 255, 0.5); }
.stat:nth-child(3) .stat-value { color: var(--pink); text-shadow: 0 0 14px rgba(255, 62, 200, 0.55); }

.panel-actions { display: flex; flex-direction: column; gap: 10px; }

.ghost-btn {
  appearance: none;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.25em;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .2s ease, border-color .2s ease, color .2s ease;
}
.ghost-btn:hover {
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: var(--shadow-cyan);
  transform: translateY(-1px);
}
.ghost-btn:active { transform: translateY(0); }

.board-wrap {
  position: relative;
  flex: 0 1 auto;
  min-width: 0;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
#board {
  width: auto;
  height: 100%;
  max-width: min(560px, 100%);
  max-height: 100%;
  aspect-ratio: 1 / 2;
  background:
    linear-gradient(180deg, rgba(255,62,200,0.05), transparent 30%, rgba(37,226,255,0.05) 100%),
    radial-gradient(60% 50% at 50% 0%, rgba(162, 107, 255, 0.15), transparent 70%),
    #050218;
  border-radius: 16px;
  display: block;
  box-shadow:
    inset 0 0 0 1px rgba(157, 110, 255, 0.4),
    0 0 0 1px rgba(157, 110, 255, 0.2),
    0 30px 80px rgba(11, 2, 33, 0.7),
    0 0 60px rgba(162, 107, 255, 0.18);
}
.board-frame {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  pointer-events: none;
  background:
    linear-gradient(180deg, transparent 0%, transparent 92%, rgba(5,2,24,0.7) 100%);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 40%, rgba(8, 2, 28, 0.5) 0%, rgba(5, 2, 24, 0.88) 70%);
  backdrop-filter: blur(6px);
  border-radius: 16px;
  transition: opacity .25s ease;
  z-index: 5;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.overlay-card {
  width: 90%;
  max-width: 460px;
  max-height: calc(100% - 16px);
  overflow-y: auto;
  text-align: center;
  padding: 26px 26px 22px;
  background: linear-gradient(180deg, rgba(28, 12, 64, 0.85), rgba(10, 4, 32, 0.85));
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 16px 60px rgba(0,0,0,0.5);
  scrollbar-width: thin;
  scrollbar-color: rgba(162,107,255,0.4) transparent;
}
.overlay-card::-webkit-scrollbar { width: 6px; }
.overlay-card::-webkit-scrollbar-thumb {
  background: rgba(162,107,255,0.45);
  border-radius: 99px;
}
.overlay-eyebrow {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.4em;
  color: var(--cyan);
  text-shadow: 0 0 10px rgba(37,226,255,0.6);
}
.overlay-title {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.04em;
  margin: 6px 0 8px;
  color: #fff;
  text-shadow: 0 0 18px rgba(162,107,255,0.6);
}
.overlay-text {
  margin: 0 0 14px;
  color: var(--ink-dim);
  font-size: 13px;
  line-height: 1.55;
}
.overlay-btn {
  appearance: none;
  border: none;
  margin-top: 18px;
  background: linear-gradient(135deg, var(--pink), var(--violet) 60%, var(--cyan));
  color: #0a0420;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.25em;
  font-size: 13px;
  padding: 12px 28px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 0 24px rgba(255,62,200,0.45), 0 0 32px rgba(37,226,255,0.25);
  transition: transform .15s ease, box-shadow .2s ease;
}
.overlay-btn:hover { transform: translateY(-1px) scale(1.02); box-shadow: 0 0 32px rgba(255,62,200,0.6), 0 0 40px rgba(37,226,255,0.35); }

.overlay-tips {
  margin-top: 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 11px;
  color: var(--ink-dim);
  text-align: left;
}
.overlay-tips span {
  font-family: var(--font-display);
  letter-spacing: 0.15em;
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(37,226,255,0.45);
}
.overlay-tips em { font-style: normal; color: var(--ink-dim); }

/* ----- Difficulty picker ----- */
.difficulty-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 14px 0 14px;
}
.difficulty-row[hidden] { display: none; }
.diff-btn {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 9px 4px 8px;
  background: rgba(20, 8, 48, 0.55);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  color: var(--ink-dim);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .18s ease, border-color .18s ease, background .18s ease, color .18s ease;
}
.diff-btn .diff-label {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.14em;
  color: var(--ink);
}
.diff-btn .diff-sub {
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--ink-deep);
}
.diff-btn:hover {
  border-color: rgba(37, 226, 255, 0.6);
  color: var(--cyan);
}
.diff-btn:hover .diff-label { color: var(--cyan); }
.diff-btn[aria-checked="true"] {
  background: linear-gradient(135deg, rgba(255,62,200,0.28), rgba(162,107,255,0.28) 60%, rgba(37,226,255,0.24));
  border-color: var(--pink);
  box-shadow: 0 0 18px rgba(255, 62, 200, 0.35), inset 0 0 0 1px rgba(255,255,255,0.06);
  transform: translateY(-1px);
}
.diff-btn[aria-checked="true"] .diff-label { color: #fff; }
.diff-btn[aria-checked="true"] .diff-sub { color: rgba(255,255,255,0.78); }

/* ----- Share zone (game over) ----- */
.share-zone {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed rgba(157, 110, 255, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  position: relative;
}
.share-zone[hidden] { display: none; }

.share-sub {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.28em;
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(37, 226, 255, 0.45);
}

.share-card-wrap {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}
.share-card-wrap::before {
  content: "";
  position: absolute;
  inset: -8px;
  background: radial-gradient(60% 60% at 50% 30%, rgba(162,107,255,0.35), transparent 70%);
  filter: blur(18px);
  z-index: 0;
  pointer-events: none;
}
#share-card {
  /* Offscreen render target — the visible card is the <img> below,
     so iOS/Android long-press reliably offers "保存图片 / Save Image". */
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
#share-card-img {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 320px;
  aspect-ratio: 3 / 4;
  height: auto;
  border-radius: 14px;
  display: block;
  box-shadow:
    0 0 0 1px rgba(157,110,255,0.4),
    0 16px 40px rgba(5, 2, 24, 0.65);
  background: #0a0420;
  -webkit-touch-callout: default;
  -webkit-user-select: none;
  user-select: none;
}

.share-mobile-hint {
  margin: 6px 0 0;
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--ink-dim);
  text-align: center;
  text-transform: uppercase;
  display: none;
}
@media (pointer: coarse) {
  .share-mobile-hint { display: block; }
}
.share-mobile-hint[hidden] { display: none; }

.share-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  margin-top: 8px;
}
.share-actions:has(.share-btn:not([hidden]):nth-child(3)),
.share-actions.three {
  grid-template-columns: 1fr 1fr 1fr;
}

.share-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(20, 8, 48, 0.7);
  color: var(--ink);
  border-radius: 12px;
  padding: 11px 10px;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.18em;
  white-space: nowrap;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .18s ease, border-color .18s ease, color .18s ease;
}
.share-btn:hover {
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 16px rgba(37, 226, 255, 0.35);
  transform: translateY(-1px);
}
.share-btn-primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--pink), var(--violet) 60%, var(--cyan));
  color: #0a0420;
  font-weight: 700;
  box-shadow: 0 0 16px rgba(255,62,200,0.35);
}
.share-btn-primary:hover {
  color: #0a0420;
  border-color: transparent;
  box-shadow: 0 0 22px rgba(255,62,200,0.55), 0 0 28px rgba(37, 226, 255, 0.3);
}
.share-btn[hidden] { display: none; }

.share-toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: rgba(28, 12, 64, 0.95);
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 13px;
  letter-spacing: 0.08em;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 16px 40px rgba(5,2,24,0.6), 0 0 24px rgba(37,226,255,0.25);
  white-space: nowrap;
  z-index: 100;
  animation: toast-in 0.18s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.share-toast[hidden] { display: none; }

.touch-pad {
  display: none;
  margin: 4px auto 0;
  width: 100%;
  max-width: 380px;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 64px);
  gap: 10px;
}
.touch-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(20, 8, 48, 0.7);
  color: #fff;
  border-radius: 16px;
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.1em;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease, box-shadow .15s ease, border-color .15s ease;
  box-shadow: 0 4px 16px rgba(10, 4, 32, 0.55), inset 0 0 0 1px rgba(255,255,255,0.04);
}
.touch-btn:active {
  transform: translateY(1px) scale(0.98);
  border-color: var(--cyan);
  box-shadow: 0 0 18px rgba(37,226,255,0.45), inset 0 0 0 1px rgba(37,226,255,0.4);
}
.touch-rot { grid-column: 1 / 2; grid-row: 1 / 2; }
.touch-left { grid-column: 2 / 3; grid-row: 1 / 2; }
.touch-down { grid-column: 3 / 4; grid-row: 1 / 2; }
.touch-right { grid-column: 4 / 5; grid-row: 1 / 2; }
.touch-rot-cw { grid-column: 1 / 2; grid-row: 2 / 3; font-size: 22px; }
.touch-hold { grid-column: 2 / 3; grid-row: 2 / 3; font-size: 13px; letter-spacing: 0.18em; }
.touch-hard { grid-column: 3 / 5; grid-row: 2 / 3; font-size: 14px; letter-spacing: 0.22em; background: linear-gradient(135deg, rgba(255,62,200,0.35), rgba(162,107,255,0.35)); }

.footer {
  display: none;
}

/* Layout adjustments for tablets */
@media (max-width: 1000px) {
  .stage { gap: 18px; }
  .side { flex: 0 1 220px; min-width: 180px; max-width: 260px; }
  .layout { padding: 12px 18px 12px; }
  .mini-canvas { max-width: 160px; }
  .mini-canvas.tall { max-width: 150px; }
}

/* Mobile: compact 3-column layout — panels hug the board sides instead of stacking below it */
@media (max-width: 720px) {
  html, body { overflow: hidden; }
  body { height: 100dvh; }

  .layout {
    padding: 8px 10px 10px;
    gap: 8px;
    height: 100dvh;
    min-height: 0;
  }

  .brand {
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
  }
  .brand-mark { flex: 1 1 auto; min-width: 0; }
  .brand-tag { font-size: 10px; letter-spacing: 0.24em; }
  .brand-title {
    font-size: 24px;
    margin: 2px 0 0;
    letter-spacing: 0.06em;
  }
  .brand-sub { display: none; }
  .hud-top { gap: 6px; flex-shrink: 0; }
  .hud-pill { padding: 5px 10px; font-size: 10px; }
  .hud-pill-label { font-size: 8px; letter-spacing: 0.22em; }

  .stage {
    display: grid;
    grid-template-columns: 62px minmax(0, 1fr) 62px;
    grid-template-areas: "left board right";
    gap: 6px;
    align-items: stretch;
    flex: 1 1 auto;
    min-height: 0;
  }
  .side-left  { grid-area: left;  }
  .board-wrap { grid-area: board; }
  .side-right { grid-area: right; }
  .side, .side-left, .side-right {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: initial;
    min-width: 0;
    max-width: none;
    align-self: stretch;
  }

  .panel {
    padding: 7px 6px;
    border-radius: 10px;
    box-shadow:
      0 0 0 1px rgba(255,255,255,0.03) inset,
      0 6px 18px rgba(10, 4, 32, 0.4);
  }
  .panel-hold, .panel-next { flex: 0 0 auto; }
  .panel-stats { flex: 1 1 auto; }
  .panel-actions { flex: 0 0 auto; }
  .panel-title {
    font-size: 8px;
    letter-spacing: 0.22em;
    margin-bottom: 3px;
  }
  .panel-hint { display: none; }

  .mini-canvas {
    max-width: 100%;
    margin: 0;
  }
  #hold {
    aspect-ratio: 1 / 1;
  }
  .mini-canvas.tall {
    aspect-ratio: 1 / 2.1;
    max-width: 100%;
  }

  .panel-stats { display: flex; flex-direction: column; gap: 6px; }
  .stat-label { font-size: 7px; letter-spacing: 0.15em; }
  .stat-value {
    font-size: 14px;
    line-height: 1.05;
    margin-top: 0;
    text-shadow: 0 0 8px rgba(162, 107, 255, 0.55);
  }
  .stat:nth-child(2) .stat-value { text-shadow: 0 0 8px rgba(37, 226, 255, 0.5); }
  .stat:nth-child(3) .stat-value { text-shadow: 0 0 8px rgba(255, 62, 200, 0.55); }

  .panel-actions {
    flex-direction: column;
    gap: 5px;
  }
  .panel-actions .ghost-btn {
    padding: 7px 4px;
    font-size: 8px;
    letter-spacing: 0.1em;
    border-radius: 9px;
  }

  .board-wrap {
    align-self: stretch;
    align-items: center;
    min-width: 0;
    height: 100%;
  }
  #board {
    width: 100%;
    height: auto;
    max-width: 100%;
    aspect-ratio: 1 / 2;
    border-radius: 10px;
  }

  .overlay { border-radius: 10px; }
  .overlay-card { padding: 16px 14px 14px; max-width: 360px; }
  .overlay-btn { margin-top: 12px; padding: 11px 22px; }
  .overlay-title { font-size: 18px; }
  .overlay-text { font-size: 12px; line-height: 1.5; }
  .difficulty-row { margin: 10px 0; gap: 4px; }
  .diff-btn { padding: 7px 2px 6px; }
  .diff-btn .diff-label { font-size: 11px; letter-spacing: 0.1em; }
  .diff-btn .diff-sub { font-size: 8px; letter-spacing: 0.14em; }
  .overlay-tips {
    grid-template-columns: auto 1fr auto 1fr;
    font-size: 10px;
    gap: 3px 8px;
  }

  .touch-pad {
    display: grid;
    grid-template-rows: repeat(2, 50px);
    gap: 6px;
    margin: 0;
    max-width: 100%;
    flex-shrink: 0;
  }
  .touch-btn {
    border-radius: 12px;
    font-size: 20px;
    box-shadow: 0 2px 10px rgba(10, 4, 32, 0.5), inset 0 0 0 1px rgba(255,255,255,0.04);
  }
  .touch-rot-cw { font-size: 20px; }
  .touch-hold { font-size: 11px; letter-spacing: 0.12em; }
  .touch-hard { font-size: 12px; letter-spacing: 0.16em; }

  .footer { display: none; }
}

/* Tiny phones */
@media (max-width: 380px) {
  .stage { grid-template-columns: 54px minmax(0, 1fr) 54px; gap: 5px; }
  .panel { padding: 6px 4px; }
  .panel-title { font-size: 7px; }
  .stat-value { font-size: 12px; }
  .touch-pad { grid-template-rows: repeat(2, 46px); }
  .touch-btn { font-size: 17px; }
}

/* Landscape phones — give the board horizontal space, hide unhelpful header bits */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  html, body { overflow: hidden; }
  .layout { height: 100dvh; padding: 6px 8px 6px; gap: 6px; }
  .brand { display: none; }
  .stage {
    display: grid;
    grid-template-columns: 70px minmax(0, 1fr) 70px;
    grid-template-areas: "left board right";
    gap: 6px;
  }
  .side, .side-left, .side-right {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: initial;
    min-width: 0;
    max-width: none;
    align-self: stretch;
  }
  .side-left { grid-area: left; }
  .board-wrap { grid-area: board; }
  .side-right { grid-area: right; }
  .board-wrap { align-self: stretch; align-items: center; height: 100%; }
  #board { width: 100%; height: auto; max-width: 100%; aspect-ratio: 1 / 2; }
  .touch-pad { display: none; }
  .footer { display: none; }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .stars { animation: none; }
  .overlay { transition: none; }
}
