@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@500;600;700;800&family=Instrument+Sans:wght@400;500;600;700&display=swap');

:root {
  color-scheme: dark;
  font-family: "Instrument Sans", system-ui, sans-serif;
  color: #f2f6f4;
  background: #080e12;
  --muted: #a9bcb7;
  --accent: #a7ef95;
  --accent-rgb: 167 239 149;
  --line: #283b37;
  --panel: #111c1d;
  --heading: "Barlow Condensed", "Arial Narrow", sans-serif;
}
.tetris {
  --accent: #ffd18a;
  --accent-rgb: 255 209 138;
  --muted: #bab6cb;
  --line: #363448;
  --panel: #191926;
}
*, *::before, *::after { box-sizing: border-box; }
body { min-width: 240px; min-height: 100svh; margin: 0; }
body::before {
  content: ""; position: fixed; z-index: -1; inset: 0;
  background: radial-gradient(ellipse at 47% 20%, rgb(var(--accent-rgb) / .115), transparent 64%),
    repeating-linear-gradient(115deg, transparent 0 87px, rgb(255 255 255 / .022) 88px 89px, transparent 90px 174px);
  animation: ambient 12s ease-in-out infinite alternate;
}
@keyframes ambient { to { opacity: .42; transform: scale(1.07); } }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button, .wallet {
  min-height: 39px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: inherit;
  cursor: pointer; font-size: .81rem; font-weight: 700; text-decoration: none;
}
button:hover, .wallet:hover { border-color: var(--accent); }
button:disabled { opacity: .42; cursor: default; }
[hidden] { display: none !important; }
.frame { max-width: 1180px; margin: auto; padding: 0 clamp(12px, 3vw, 36px); }
.masthead {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  min-height: 65px; border-bottom: 1px solid var(--line);
}
.brand { text-decoration: none; color: inherit; font-weight: 700; font-size: .88rem; white-space: nowrap; }
.brand::before { content: "←"; margin-right: .65em; color: var(--accent); }
.toolbar { display: flex; align-items: center; gap: 7px; }
.wallet b { color: var(--accent); }
.sound { min-width: 82px; }
.stage {
  --board-width: min(52vw, 580px, max(170px, calc(100svh - 142px)));
  display: grid; grid-template-columns: minmax(165px, 1fr) var(--board-width) minmax(153px, .67fr);
  gap: clamp(13px, 2.5vw, 30px); align-items: start; margin: 26px 0 22px;
}
.tetris .stage { --board-width: min(39vw, 348px, max(128px, calc((100svh - 136px) / 2))); }
.sidebar h1 {
  font: 800 clamp(3.4rem, 7vw, 6.35rem)/.78 var(--heading);
  letter-spacing: -.032em; margin: 10px 0 16px; text-transform: uppercase;
}
.world { color: var(--accent); font: 700 .94rem var(--heading); letter-spacing: .16em; text-transform: uppercase; }
.sidebar p, .guide p, .guide dt, .panel-copy { font-size: .82rem; line-height: 1.53; color: var(--muted); }
.sidebar p { max-width: 25ch; margin: 0 0 22px; }
.stats { margin: 0; display: grid; gap: 6px; }
.stats > div, .rack-box {
  padding: 8px 12px; min-width: 0; border: 1px solid var(--line); border-radius: 9px;
  background: linear-gradient(145deg, var(--panel), rgb(0 0 0 / .28));
}
.stats dt, .rack h2 { font: 700 .83rem var(--heading); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.stats dd { margin: 0; color: var(--accent); font: 700 1.85rem/.95 var(--heading); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.board-shell {
  min-width: 0; position: relative; isolation: isolate; width: 100%; aspect-ratio: 1;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: 15px;
  background: var(--panel); box-shadow: 0 15px 42px #0009, 0 0 26px rgb(var(--accent-rgb) / .10);
  overflow: hidden;
}
.tetris .board-shell { aspect-ratio: 1 / 2; }
#game { display: block; position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.overlay {
  position: absolute; z-index: 2; inset: 0; display: grid; place-items: center; padding: clamp(8px, 2vw, 22px);
  background: radial-gradient(ellipse at 50% 48%, #0d1718e8 0, #081017bb 58%, #080f1390);
  overflow: auto;
}
.tetris .overlay { background: radial-gradient(ellipse at 50% 48%, #171522ea, #11111cb5 68%, #0c0c14a0); }
.dialog {
  width: min(100%, 335px); padding: clamp(12px, 3vw, 25px) clamp(9px, 2.5vw, 20px);
  border: 1px solid color-mix(in srgb, var(--accent) 38%, var(--line)); border-radius: 13px;
  box-shadow: inset 0 1px rgb(255 255 255 / .09), 0 12px 40px #0008;
  background: linear-gradient(155deg, var(--panel), #0b1117);
  text-align: center;
}
.badge {
  display: grid; place-items: center; width: 44px; height: 44px; margin: 0 auto 11px;
  border: 1px solid rgb(var(--accent-rgb) / .40); border-radius: 12px;
  color: var(--accent); background: rgb(var(--accent-rgb) / .10); box-shadow: 0 0 25px rgb(var(--accent-rgb) / .12);
}
.badge::before { content: ""; width: 20px; height: 20px; background: currentColor; box-shadow: inset 0 0 0 4px rgb(0 0 0 / .16); transform: rotate(45deg); border-radius: 35% 70% 45% 70%; }
.tetris .badge::before { transform: none; width: 24px; height: 24px; border-radius: 2px; clip-path: polygon(0 0, 100% 0, 100% 34%, 67% 34%, 67% 100%, 34% 100%, 34% 34%, 0 34%); }
.dialog h2 { margin: 0; font: 800 clamp(1.85rem, 4.2vw, 3rem)/.9 var(--heading); letter-spacing: .01em; text-transform: uppercase; }
.panel-copy { margin: 9px auto 13px; max-width: 33ch; }
.dialog button { width: 100%; min-height: 44px; }
.dialog button + button { margin-top: 7px; }
.primary { background: var(--accent); border-color: var(--accent); color: #10201a; }
.primary:hover { box-shadow: 0 0 16px rgb(var(--accent-rgb) / .28); }
.rack { display: grid; gap: 9px; min-width: 0; }
.rack h2 { margin: 0 0 6px; }
#next-preview, #hold-preview { width: 100%; display: block; height: auto; max-width: 140px; margin: auto; }
.guide { border-top: 1px solid var(--line); padding-top: 11px; }
.guide p { margin: 0 0 11px; }
.guide dl { margin: 0; }
.guide dl > div { display: flex; flex-wrap: wrap; align-items: baseline; gap: 1px 8px; margin: 0 0 5px; }
.guide dd { margin: 0; font-size: .77rem; color: #f2f6f4; }
.kbd { font-size: .75rem; }
.touch { display: none; grid-column: 1 / -1; gap: 6px; }
.touch button { min-height: 44px; padding: 4px; touch-action: none; user-select: none; }
.touch button:active, .touch button.held { color: var(--accent); border-color: var(--accent); background: rgb(var(--accent-rgb) / .13); }
.toast {
  position: absolute; z-index: 3; top: 12px; left: 50%; transform: translateX(-50%);
  max-width: 95%; width: max-content; padding: 7px 12px; border: 1px solid var(--accent);
  border-radius: 100px; color: var(--accent); background: #0b141a; font-size: .75rem; font-weight: 700;
  pointer-events: none;
}
@media (max-width: 900px) {
  .stage, .tetris .stage {
    --board-width: min(65vw, 535px, max(190px, calc(100svh - 190px)));
    grid-template-columns: minmax(125px, 1fr) var(--board-width); gap: 12px 15px;
  }
  .tetris .stage { --board-width: min(56vw, 340px, max(156px, calc((100svh - 145px) / 2))); grid-template-columns: minmax(96px, 1fr) var(--board-width) minmax(70px, .53fr); }
  .snake .rack { grid-column: 1 / -1; }
}
@media (pointer: coarse), (max-width: 650px) {
  .touch { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tetris .touch { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .tetris .touch button { font-size: clamp(.63rem, 2vw, .8rem); }
}
@media (max-width: 560px) {
  .masthead { min-height: 51px; }
  .brand { font-size: .76rem; }
  .toolbar { gap: 4px; }
  button, .wallet { padding-inline: 7px; font-size: .74rem; min-height: 36px; }
  .sound { min-width: 68px; }
  #fullscreen { display: none; }
  .stage, .tetris .stage { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin: 12px 0; }
  .tetris .stage {
    --board-width: clamp(100px, calc((100svh - 240px) / 2), min(71vw, 288px));
    grid-template-columns: minmax(100px, var(--board-width)) minmax(55px, 100px);
    justify-content: center;
  }
  .sidebar { grid-column: 1 / -1; }
  .sidebar h1 { font-size: 2.85rem; margin: 4px 0 8px; }
  .world { font-size: .73rem; }
  .sidebar p { display: none; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .stats > div { padding: 5px 6px; }
  .stats dt, .rack h2 { font-size: .71rem; letter-spacing: .08em; }
  .stats dd { font-size: 1.38rem; }
  .snake .board-shell { width: min(100%, max(185px, calc(100svh - 234px)), 485px); justify-self: center; }
  .rack { gap: 5px; }
  .rack-box { padding: 5px; }
  .guide { display: none; }
  .snake .rack { display: none; }
  .overlay { padding: 6px; }
  .dialog { padding: 12px 7px; }
  .dialog .badge { margin-bottom: 7px; }
  .panel-copy { font-size: .72rem; margin: 7px auto 9px; }
  .dialog button { min-height: 38px; }
}
@media (max-height: 510px) and (orientation: landscape) {
  .masthead { min-height: 44px; }
  .stage, .tetris .stage { margin-block: 8px; gap: 8px; }
  .stage { --board-width: min(44vw, max(158px, calc(100svh - 104px))); }
  .tetris .stage { --board-width: min(38vw, max(102px, calc((100svh - 103px) / 2))); }
  .sidebar h1 { font-size: clamp(1.8rem, 6vw, 3.75rem); margin-block: 4px 7px; }
  .sidebar p, .guide, .badge { display: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats > div { padding: 5px 7px; }
  .stats dd { font-size: 1.4rem; }
}
@media (prefers-reduced-motion: reduce) { body::before { animation: none; } }
@media (max-width: 350px) {
  .masthead { flex-wrap: wrap; padding-block: 6px; gap: 5px; }
  .toolbar { flex: 1 1 100%; }
}
