:root { --edge: #e8e8f8; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #0a0a12; overflow: hidden; touch-action: none; overscroll-behavior: none; user-select: none; -webkit-user-select: none; }
body { font-family: 'Courier New', ui-monospace, monospace; font-weight: 700; color: var(--edge); }
#stage { position: fixed; inset: 0; display: grid; place-items: center; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#game { image-rendering: pixelated; image-rendering: crisp-edges; background: #000; cursor: crosshair; touch-action: none; }
.hidden { display: none !important; }

#hud { position: absolute; top: calc(var(--fy, 0px) + 6px); left: var(--fx, 0px); right: var(--fx, 0px); pointer-events: none; font-size: clamp(9px, 1.8vmin, 15px); text-shadow: 2px 2px 0 #000; letter-spacing: 1px; }
.hud-row { display: flex; justify-content: space-between; padding: 0 12px; gap: 8px; }
.hud-row span { white-space: nowrap; }
#hScore { color: #ffe066; } #hCombo { color: #7fe0ff; } #hLives { color: #ff8080; }

#banner { position: absolute; top: calc(var(--fy, 0px) + var(--fh, 384px) * 0.34); left: var(--fx, 0px); right: var(--fx, 0px); text-align: center; font-size: clamp(18px, 6vmin, 44px); color: #fff; text-shadow: 3px 3px 0 #b00, -1px -1px 0 #06f; pointer-events: none; letter-spacing: 3px; animation: pop .18s ease-out; }
@keyframes pop { from { transform: scale(2.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.overlay { position: absolute; inset: var(--fy, 0px) var(--fx, 0px); display: grid; place-items: center; background: rgba(4, 4, 14, .55); overflow-y: auto; padding: 8px; }
#menu { place-items: end center; padding-bottom: 6px; background: transparent; container-type: size; container-name: play; }
.panel { background: #101024; border: 3px solid var(--edge); box-shadow: 0 0 0 3px #101024, 0 0 24px #0008; padding: 10px 14px; max-width: min(94vw, 620px); max-height: calc(100% - 12px); overflow-y: auto; text-align: center; }
#menu .panel { background: rgba(16,16,36,.92); max-height: 96%; width: min(94%, 560px); }
.panel.wide { max-width: min(94vw, 720px); }
.panel h2 { margin: 4px 0 12px; letter-spacing: 2px; font-size: clamp(14px, 3vmin, 22px); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.btns { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.btns.inline { flex-direction: row; justify-content: center; flex-wrap: wrap; }
.btn { font-family: inherit; font-weight: 700; font-size: clamp(11px, 2.2vmin, 16px); letter-spacing: 2px; color: var(--edge); background: #1c1c3a; border: 2px solid var(--edge); padding: 10px 14px; min-height: 44px; cursor: pointer; text-transform: uppercase; }
.btn:hover, .btn:focus { background: #34346a; outline: none; }
.btn.sel { background: #4444aa; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.btn.danger { border-color: #ff6a6a; color: #ff9a9a; }
.btn:disabled { opacity: .4; cursor: default; }

input, select { font-family: inherit; font-weight: 700; font-size: 15px; background: #0a0a18; color: #7fffb0; border: 2px solid var(--edge); padding: 10px; min-height: 44px; width: min(70vw, 300px); text-align: center; }
label.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0; font-size: 13px; }
input[type=range] { width: 140px; min-height: 30px; padding: 0; }

.boardlist { font-size: clamp(10px, 1.9vmin, 14px); margin: 10px 0; text-align: left; max-height: 50vh; overflow-y: auto; }
.boardlist table { width: 100%; border-collapse: collapse; }
.boardlist td { padding: 4px 6px; border-bottom: 1px solid #2a2a4a; white-space: nowrap; }
.boardlist tr.me td { color: #ffe066; }

#offlineBar { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-size: 11px; color: #ffb066; text-shadow: 1px 1px 0 #000; pointer-events: none; }
#toasts { position: absolute; top: 10%; right: 8px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast { background: #101024ee; border: 2px solid #ffe066; color: #ffe066; padding: 8px 12px; font-size: 12px; animation: slidein .3s; max-width: 70vw; }
@keyframes slidein { from { transform: translateX(110%); } to { transform: none; } }
#portraitHint { position: absolute; bottom: 24px; left: 0; right: 0; text-align: center; font-size: 11px; color: #9fb; }
.statrow { display: flex; justify-content: space-between; gap: 14px; font-size: 13px; border-bottom: 1px solid #2a2a4a; padding: 6px 2px; }
.credline { font-size: clamp(10px, 1.8vmin, 14px); margin: 4px 0; }
.achvgrid { display: grid; grid-template-columns: 1fr; gap: 6px; text-align: left; font-size: 12px; }
.achv { border: 1px solid #333; padding: 6px 8px; color: #666; }
.achv.on { border-color: #ffe066; color: #ffe066; }

/* compact multi-column menu so it always fits the screen */
#menuBody { display: flex; flex-direction: row; flex-wrap: wrap; gap: 8px; justify-content: center; align-content: flex-start; }
#menuBody h2, #menuBody .statrow, #menuBody .credline, #menuBody .achvgrid,
#menuBody .boardlist, #menuBody .panel-head, #menuBody label.row, #menuBody #boardTabs, #menuBody .searchrow { flex: 0 0 100%; }
#menuBody .btn { flex: 1 1 170px; max-width: 320px; padding: 8px 12px; min-height: 42px; }
#menuBody .btn.small { flex: 0 0 100%; max-width: none; }
@media (max-height: 460px) {
  #menu .panel { width: min(96%, 520px); }
  #menuBody .btn { flex: 1 1 110px; min-height: 34px; font-size: clamp(10px, 2.6vh, 14px); }
  .panel { padding: 6px 10px; }
  #menuBody { gap: 6px; }
}
/* compact by actual playfield height (portrait phones have a short canvas strip) */
@container play (max-height: 360px) {
  #menu .panel { width: min(98%, 520px); }
  #menuBody { gap: 5px; }
  #menuBody .btn { flex: 1 1 104px; min-height: 32px; padding: 5px 8px; font-size: 11px; letter-spacing: 1px; }
  #menuBody .btn.small { min-height: 26px; }
}
