:root {
  --bg: #9a1c22;
  --ink: #f6f4f2;
  --muted: rgba(246, 244, 242, 0.72);
  --card: rgba(18, 10, 12, 0.72);
  --line: rgba(255, 255, 255, 0.12);
  --accent: #ff6b5a;
  --accent2: #ffd2c8;
  --ok: #7dffa8;
  --radius: 16px;
  --font: "Outfit", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #7a1518;
  font-family: var(--font);
  color: var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#game-canvas {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
}
#ui-root {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 10;
}
#ui-root * { pointer-events: auto; }

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: max(0.75rem, env(safe-area-inset-top)) max(0.85rem, env(safe-area-inset-right)) max(0.85rem, env(safe-area-inset-bottom)) max(0.85rem, env(safe-area-inset-left));
  background: linear-gradient(180deg, rgba(120, 20, 24, 0.55), rgba(40, 8, 10, 0.72));
  backdrop-filter: blur(6px);
  -webkit-overflow-scrolling: touch;
  overflow: auto;
  overscroll-behavior: contain;
}
.screen.active { display: flex; }

#ui-menu.screen,
#ui-guide.screen,
#ui-levels.screen,
#ui-settings.screen {
  justify-content: safe center;
  touch-action: pan-y;
}

.cover {
  width: min(420px, 86vw);
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 18px;
  border: 1.5px solid var(--accent);
  box-shadow: 0 20px 50px rgba(0,0,0,0.6), 0 0 20px rgba(255, 107, 90, 0.25);
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}
.cover.sm {
  width: min(200px, 48vw);
  margin-bottom: 0.1rem;
}

.logo {
  font-weight: 800;
  letter-spacing: 0.04em;
  font-size: clamp(1.7rem, 5vw, 2.6rem);
  text-transform: uppercase;
  text-shadow: 0 0 12px rgba(255, 107, 90, 0.45);
}
.tag { color: var(--muted); font-weight: 500; margin-bottom: 0.35rem; }

.how-to {
  width: min(520px, 94vw);
  margin: 0.25rem 0 0.85rem;
  padding: 0.85rem 0.9rem 0.95rem;
  border-radius: 18px;
  background: rgba(0,0,0,0.32);
  border: 1px solid var(--line);
  text-align: center;
}
.how-to h3 {
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent2);
  margin-bottom: 0.65rem;
}
.how-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}
.how-card {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.7rem 0.55rem 0.75rem;
  text-align: center;
}
.how-card strong {
  display: block;
  font-size: 0.95rem;
  margin: 0.35rem 0 0.2rem;
}
.how-card p {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
  margin-bottom: 0.45rem;
}
.how-tip {
  margin-top: 0.65rem;
  font-size: 0.78rem;
  color: var(--accent2);
  font-weight: 600;
}

.info-panel {
  width: min(540px, 94vw);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin: 0.2rem 0 0.9rem;
}
.info-block {
  padding: 0.85rem 0.95rem;
  border-radius: 16px;
  background: rgba(0,0,0,0.34);
  border: 1px solid var(--line);
  text-align: left;
}
.info-block h3 {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent2);
  margin-bottom: 0.55rem;
}
.goal-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 0.75rem;
  align-items: center;
}
.goal-row p {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
  margin: 0;
}
.goal-row p strong { color: var(--ink); font-weight: 700; }

.viz.goal { place-items: end center; }
.hole-pad {
  width: 36px;
  height: 12px;
  border-radius: 3px;
  background:
    radial-gradient(circle at 50% 45%, #0a0505 0 42%, transparent 44%),
    linear-gradient(180deg, #d8d8de, #b0b0ba);
  box-shadow: 0 2px 0 #8a8a98, inset 0 0 0 1px rgba(255,120,90,0.35);
}
.void-pad {
  width: 48px;
  height: 8px;
  border-radius: 99px;
  background: rgba(0,0,0,0.45);
  border: 1px dashed rgba(255,255,255,0.15);
}
.block-stand.fall {
  transform: translateY(6px) rotate(18deg);
  opacity: 0.7;
}

.guide-shell {
  width: min(560px, 100%);
  max-height: min(92dvh, 920px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 1.1rem 1rem 1.2rem;
  border-radius: 22px;
  background: rgba(10, 4, 6, 0.72);
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
  text-align: center;
  flex-shrink: 1;
  min-height: 0;
}
.guide-dots {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  margin-bottom: 0.75rem;
}
.guide-dots i {
  width: 8px; height: 8px;
  border-radius: 99px;
  background: rgba(255,255,255,0.22);
  display: block;
}
.guide-dots i.on {
  width: 22px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}
.guide-kicker {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent2);
  margin-bottom: 0.25rem;
}
.guide-shell h2 {
  font-size: clamp(1.35rem, 4vw, 1.85rem);
  margin-bottom: 0.75rem;
}
.guide-cover {
  width: min(280px, 70vw);
  margin: 0 auto 0.85rem;
}
.guide-text {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
  max-width: 36ch;
  margin: 0 auto;
}
.guide-text strong { color: var(--ink); }
.guide-step.hidden { display: none; }

.rule-grid,
.ctrl-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  text-align: center;
}
.rule-card,
.ctrl-card {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.7rem 0.5rem 0.75rem;
}
.rule-card strong,
.ctrl-card strong {
  display: block;
  font-size: 0.86rem;
  margin: 0.25rem 0 0.2rem;
}
.rule-card p,
.ctrl-card p {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
  margin: 0;
}
.rule-card p em,
.ctrl-card p em { color: var(--ink); font-style: normal; font-weight: 700; }

.ctrl-keys-big {
  min-height: 64px;
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  align-items: center;
  justify-content: center;
}
.ctrl-keys-big kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.35rem;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.45);
  font-size: 0.72rem;
  font-weight: 700;
  font-family: inherit;
}
.ctrl-keys-big .or {
  font-size: 0.65rem;
  color: var(--muted);
}
.ctrl-keys-big kbd.pad-mini { min-width: auto; padding: 0 0.45rem; }

.guide-nav {
  display: flex;
  gap: 0.55rem;
  justify-content: center;
  margin-top: 1rem;
}
.guide-nav .btn { min-width: 120px; }
.link-btn {
  margin-top: 0.65rem;
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.control-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0 0 0.7rem;
  padding: 0;
}
.control-list li {
  display: grid;
  grid-template-columns: 72px 1fr;
  grid-template-rows: auto auto;
  column-gap: 0.55rem;
  row-gap: 0.2rem;
  align-items: center;
  padding: 0.45rem 0.5rem;
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
}
.ctrl-label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent2);
}
.control-list .keys { justify-content: flex-start; grid-column: 2; }
.ctrl-desc {
  grid-column: 2;
  font-size: 0.72rem;
  color: var(--muted);
}

.pose-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding-top: 0.15rem;
}
.pose {
  text-align: center;
  min-width: 88px;
}
.pose strong {
  display: block;
  font-size: 0.82rem;
  margin-top: 0.15rem;
}
.pose span {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
}
.pose-arrow {
  color: var(--accent2);
  font-size: 1.1rem;
  opacity: 0.85;
}

.viz {
  height: 64px;
  display: grid;
  place-items: end center;
  position: relative;
  margin: 0 auto 0.15rem;
}
.tile-pad {
  width: 36px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(180deg, #ececf0, #c8c8d0);
  box-shadow: 0 2px 0 #9a9aa8;
}
.tile-pad.wide { width: 58px; }
.block-stand {
  width: 18px;
  height: 36px;
  border-radius: 4px;
  background: linear-gradient(145deg, #4a5058, #1e2228);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12), 0 6px 12px rgba(0,0,0,0.35);
  margin-bottom: 8px;
  position: relative;
  z-index: 1;
}
.block-lie {
  width: 48px;
  height: 18px;
  border-radius: 4px;
  background: linear-gradient(145deg, #4a5058, #1e2228);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12), 0 6px 12px rgba(0,0,0,0.35);
  margin-bottom: 8px;
  position: relative;
  z-index: 1;
}
.viz.standing .block-stand { animation: tipPulse 2.2s ease-in-out infinite; }
.viz.rolling .block-lie { animation: rollPulse 2.2s ease-in-out infinite; }
@keyframes tipPulse {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-2px) rotate(-6deg); }
}
@keyframes rollPulse {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(3px); }
}

.keys {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  justify-content: center;
  align-items: center;
}
.keys kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.45rem;
  height: 1.45rem;
  padding: 0 0.28rem;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.45);
  font-size: 0.68rem;
  font-weight: 700;
  font-family: inherit;
}
.keys kbd.pad-mini { min-width: auto; padding: 0 0.4rem; letter-spacing: 0.05em; }
.keys .or {
  font-size: 0.65rem;
  color: var(--muted);
  margin: 0 0.1rem;
}

.rotate-gate {
  display: none;
  position: absolute; inset: 0;
  z-index: 40;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: linear-gradient(160deg, #1a0608 0%, #4a1014 55%, #120406 100%);
  text-align: center;
}
.rotate-card {
  width: min(340px, 92vw);
  padding: 1.5rem 1.2rem;
  border-radius: 22px;
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--line);
}
.phone-turn {
  font-size: 3rem;
  margin-bottom: 0.6rem;
  display: inline-block;
  animation: spinPhone 1.6s ease-in-out infinite;
}
@keyframes spinPhone {
  0%, 100% { transform: rotate(0deg); }
  40% { transform: rotate(90deg); }
  60% { transform: rotate(90deg); }
}
.rotate-card h2 { font-size: 1.35rem; margin-bottom: 0.4rem; }
.rotate-card p { color: var(--muted); font-size: 0.92rem; line-height: 1.4; }

/* Rotate lock only while playing — menus stay usable in portrait */
@media (orientation: portrait) and (max-width: 920px) {
  #ui-root.is-playing .rotate-gate { display: flex; }
  #ui-root.is-playing #ui-hud,
  #ui-root.is-playing #ui-pad { visibility: hidden !important; }
}

.bar {
  width: min(280px, 70vw); height: 6px;
  border-radius: 99px; background: rgba(255,255,255,0.12);
  overflow: hidden; margin-top: 0.5rem;
}
.bar > i {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.2s ease;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  width: min(280px, 82vw);
  flex-shrink: 0;
}
.stack.pad { margin-top: 1rem; }

.btn {
  appearance: none; border: 1px solid var(--line);
  background: rgba(255,255,255,0.08);
  color: var(--ink);
  font: inherit; font-weight: 700;
  padding: 0.9rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  min-height: 48px;
  touch-action: manipulation;
}
.btn:hover { background: rgba(255,255,255,0.14); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, #ff7a66, #e4453a);
  border-color: transparent;
  box-shadow: 0 10px 28px rgba(228, 69, 58, 0.35);
}
.btn.ghost { background: transparent; }

.topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: grid; grid-template-columns: 48px 1fr 48px;
  align-items: center;
  padding: 0.85rem 1rem;
}
.topbar h2 { text-align: center; font-size: 1.15rem; font-weight: 700; }

.icon-btn {
  width: 44px; height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.35);
  color: var(--ink);
  font: inherit; font-size: 1rem;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.96); }

.level-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
  width: min(420px, 92vw);
  margin: 3.5rem auto 0;
  max-height: calc(100vh - 6rem);
  overflow: auto;
  padding-bottom: 1rem;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}
.level-grid::-webkit-scrollbar {
  display: none; /* Chrome / Safari */
}

#ui-levels.screen {
  overflow: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#ui-levels.screen::-webkit-scrollbar {
  display: none;
}
.lvl {
  aspect-ratio: 1;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.35);
  color: var(--ink);
  font: inherit;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0.2rem;
  cursor: pointer;
}
.lvl strong { font-size: 1.25rem; }
.lvl.done { border-color: rgba(125, 255, 168, 0.45); box-shadow: inset 0 0 0 1px rgba(125,255,168,0.2); }
.lvl.locked { opacity: 0.4; cursor: not-allowed; }

.toggle {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.1rem;
  border-radius: 16px;
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--line);
}
.toggle input { width: 20px; height: 20px; }

.hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 0.75rem;
  gap: 0.5rem;
  background: linear-gradient(180deg, rgba(0,0,0,0.35), transparent);
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud.hidden, .dpad.hidden, .overlay.hidden { display: none !important; }
.hud-left, .hud-right, .hud-mid {
  display: flex; align-items: center; gap: 0.45rem;
}
.stat {
  min-width: 58px;
  padding: 0.35rem 0.55rem;
  border-radius: 12px;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--line);
  text-align: center;
  line-height: 1.05;
}
.stat span { display: block; font-weight: 800; font-size: 1.05rem; }
.stat small { color: var(--muted); font-size: 0.65rem; letter-spacing: 0.08em; }

.dpad {
  position: absolute;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  width: 156px; height: 156px;
}
.pad-btn {
  position: absolute;
  width: 48px; height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.45);
  color: var(--ink);
  font-size: 1.1rem;
  cursor: pointer;
}
.pad-btn.n { left: 54px; top: 4px; }
.pad-btn.s { left: 54px; bottom: 4px; }
.pad-btn.w { left: 4px; top: 54px; }
.pad-btn.e { right: 4px; top: 54px; }

.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 4, 6, 0.55);
  backdrop-filter: blur(8px);
  padding: 1rem;
}
.card {
  width: min(340px, 92vw);
  padding: 1.5rem 1.25rem;
  border-radius: 22px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
  text-align: center;
}
.card h2 { font-size: 1.6rem; margin-bottom: 0.4rem; }
.card.win h2 { color: var(--ok); }
.muted { color: var(--muted); margin-bottom: 1rem; }
.card .stack { margin: 0 auto; }

/* —— Mobile portrait menus (landscape uses the block below) —— */
@media (max-width: 720px) and (orientation: portrait) {
  #ui-menu.screen,
  #ui-guide.screen,
  #ui-levels.screen,
  #ui-settings.screen,
  #ui-boot.screen {
    justify-content: flex-start;
    align-items: center;
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  }
  .logo {
    font-size: clamp(1.45rem, 7vw, 2rem);
  }
  .tag {
    font-size: 0.88rem;
    margin-bottom: 0.2rem;
  }
  .cover.sm {
    width: min(160px, 42vw);
  }
  .stack {
    width: min(320px, 92vw);
    gap: 0.55rem;
  }
  .btn {
    padding: 0.85rem 1rem;
    font-size: 0.95rem;
  }

  .guide-shell {
    width: 100%;
    padding: 0.85rem 0.75rem 1rem;
    border-radius: 18px;
  }
  .guide-shell h2 {
    font-size: 1.25rem;
    margin-bottom: 0.55rem;
  }
  .guide-cover {
    width: min(200px, 58vw);
    margin-bottom: 0.55rem;
  }
  .guide-text {
    font-size: 0.88rem;
    max-width: none;
    padding: 0 0.15rem;
  }
  .rule-grid,
  .ctrl-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
  }
  .rule-card,
  .ctrl-card {
    padding: 0.55rem 0.4rem 0.6rem;
    border-radius: 12px;
  }
  .rule-card strong,
  .ctrl-card strong {
    font-size: 0.78rem;
  }
  .rule-card p,
  .ctrl-card p {
    font-size: 0.68rem;
  }
  .viz {
    height: 52px;
  }
  .ctrl-keys-big {
    min-height: 52px;
    gap: 0.22rem;
  }
  .ctrl-keys-big kbd {
    min-width: 1.35rem;
    height: 1.35rem;
    font-size: 0.65rem;
  }
  .guide-nav {
    flex-wrap: wrap;
    margin-top: 0.75rem;
    gap: 0.45rem;
  }
  .guide-nav .btn {
    min-width: 0;
    flex: 1 1 120px;
  }
  .link-btn {
    margin-top: 0.45rem;
    padding: 0.35rem;
  }

  .level-grid {
    width: min(420px, 94vw);
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.45rem;
  }
  .card {
    width: min(360px, 94vw);
    padding: 1.2rem 1rem;
  }
}

@media (max-width: 380px) {
  .rule-grid,
  .ctrl-grid {
    grid-template-columns: 1fr;
  }
  .cover.sm { width: min(140px, 50vw); }
  .logo { font-size: 1.35rem; }
}

/* Short landscape — center menu / levels / settings (override portrait flex-start) */
@media (orientation: landscape) and (max-height: 560px) {
  #ui-menu.screen,
  #ui-guide.screen,
  #ui-levels.screen,
  #ui-settings.screen,
  #ui-boot.screen {
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 0.4rem max(0.75rem, env(safe-area-inset-right)) 0.5rem max(0.75rem, env(safe-area-inset-left));
    gap: 0.45rem;
  }

  #ui-menu.screen {
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }

  .cover.sm,
  .guide-cover,
  .guide-dots { display: none; }

  .logo {
    font-size: clamp(1.25rem, 4.5vh, 1.65rem);
    text-align: center;
    width: 100%;
  }
  .tag {
    display: block;
    font-size: 0.8rem;
    margin-bottom: 0.15rem;
    text-align: center;
  }

  .guide-shell {
    width: min(720px, 96vw);
    max-height: calc(100dvh - 0.7rem);
    margin: 0 auto;
    padding: 0.4rem 0.65rem 0.55rem;
    border-radius: 14px;
  }
  .guide-shell h2 {
    font-size: 0.98rem;
    margin-bottom: 0.28rem;
  }
  .guide-kicker {
    font-size: 0.58rem;
    margin-bottom: 0.05rem;
  }
  .guide-text {
    font-size: 0.72rem;
    line-height: 1.35;
    max-width: none;
  }
  .rule-grid,
  .ctrl-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.35rem;
  }
  .rule-card,
  .ctrl-card {
    padding: 0.35rem 0.3rem 0.4rem;
    border-radius: 10px;
  }
  .rule-card strong,
  .ctrl-card strong {
    font-size: 0.68rem;
    margin: 0.1rem 0 0.08rem;
  }
  .rule-card p,
  .ctrl-card p {
    font-size: 0.58rem;
    line-height: 1.25;
  }
  .viz {
    height: 32px;
    margin-bottom: 0;
  }
  .tile-pad { width: 28px; height: 7px; }
  .tile-pad.wide { width: 44px; }
  .block-stand { width: 11px; height: 22px; margin-bottom: 3px; }
  .block-lie { width: 28px; height: 11px; margin-bottom: 3px; }
  .hole-pad { width: 28px; height: 9px; }
  .ctrl-keys-big {
    min-height: 32px;
    gap: 0.16rem;
  }
  .ctrl-keys-big kbd {
    min-width: 1.15rem;
    height: 1.15rem;
    font-size: 0.58rem;
    padding: 0 0.22rem;
  }
  .guide-nav {
    margin-top: 0.35rem;
    gap: 0.35rem;
    justify-content: center;
  }
  .guide-nav .btn {
    min-width: 0;
    flex: 1 1 110px;
    min-height: 38px;
    padding: 0.45rem 0.7rem;
  }
  .link-btn {
    margin-top: 0.25rem;
    font-size: 0.72rem;
  }

  /* Centered button row — Play / Levels / How to / Settings */
  .stack {
    flex-direction: row;
    flex-wrap: wrap;
    width: min(640px, 92vw);
    max-width: 100%;
    margin-inline: auto;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
  }
  .stack.pad {
    margin-top: 0.35rem;
    width: min(420px, 90vw);
    flex-direction: column;
  }
  .overlay .stack {
    flex-direction: column;
    flex-wrap: nowrap;
    width: min(280px, 100%);
  }
  .overlay .stack .btn {
    flex: 0 0 auto;
    width: 100%;
  }
  .stack .btn {
    flex: 1 1 140px;
    max-width: 200px;
    padding: 0.65rem 0.8rem;
    min-height: 42px;
  }

  /* Levels grid centered under topbar */
  #ui-levels.screen {
    justify-content: center;
    align-items: center;
  }
  #ui-levels .topbar,
  #ui-settings .topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
  }
  .level-grid {
    width: min(520px, 88vw);
    margin: 2.75rem auto 0.5rem;
    max-height: calc(100dvh - 4rem);
    justify-content: center;
    overflow: hidden;
    scrollbar-width: none;
  }

  #ui-settings .stack.pad {
    margin-top: 2.75rem;
  }
}

/* Ultra-short landscape (SE / folded browser chrome) */
@media (orientation: landscape) and (max-height: 380px) {
  .rule-grid,
  .ctrl-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.25rem;
  }
  .viz { display: none; }
  .ctrl-keys-big { min-height: 26px; }
  .guide-shell h2 { font-size: 0.9rem; }
  .guide-nav .btn { min-height: 34px; padding: 0.35rem 0.55rem; }
}

@media (pointer: fine) and (hover: hover) {
  .dpad { display: none !important; }
}
@media (max-width: 520px) {
  .level-grid { grid-template-columns: repeat(4, 1fr); gap: 0.5rem; }
}
