@font-face { font-family: Manrope; src: url(manrope.woff2) format("woff2"); font-weight: 200 800; }
:root {
  --bg: #070707; --panel: #121214; --panel2: #1a1a1d; --line: #26262a; --text: #f4f4f6; --muted: #8a8a90;
  --blue: #2560cb; --pink: #e8458b; --ok: #3ccf74; --warn: #ffb020;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--text); font: 14px/1.45 Manrope, -apple-system, "Segoe UI", system-ui, sans-serif;
  display: flex; flex-direction: column; overflow: hidden; height: 100dvh; overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background-image: radial-gradient(60% 50% at 10% 0%, rgba(37, 96, 203, .22), transparent 70%),
                    radial-gradient(50% 45% at 100% 100%, rgba(232, 69, 139, .16), transparent 70%);
}
button {
  font: inherit; font-weight: 700; color: var(--text); background: var(--blue); border: 0; border-radius: 8px;
  padding: 7px 14px; cursor: pointer; touch-action: manipulation;
}
button:hover { filter: brightness(1.15); }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.sel { background: var(--pink); }
button:focus-visible { outline: 2px solid var(--pink); outline-offset: 2px; }

#top {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: rgba(7, 7, 7, .7); backdrop-filter: blur(8px); min-height: 60px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: .02em; text-transform: uppercase; }
.brand img { width: 28px; height: 28px; }
#game-title { margin: 0; font-size: 18px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
#tools { display: flex; gap: 6px; }
#tools button { padding: 5px 10px; font-size: 12px; background: var(--panel2); border: 1px solid var(--line); }
#tools button.sel { background: var(--pink); border-color: var(--pink); }
#hud { margin-left: auto; display: flex; gap: 18px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
#hud b { color: var(--text); font-size: 16px; margin-left: 4px; font-variant-numeric: tabular-nums; }
body:not(.playing) #mute { margin-left: auto; }
/* in full screen there's no window frame: square corners, a bit more room */
body.output #stage canvas { border-radius: 0; }

body:not(.playing) #back, body:not(.playing) #game-title, body:not(.playing) #tools,
body:not(.playing) #hud, body:not(.playing) #restart, body:not(.playing) #play { display: none; }
body.playing .brand, body.playing #home { display: none; }

#home { flex: 1; overflow-y: auto; padding: 24px 28px 16px; }
.intro { color: var(--muted); margin: 0 0 18px; }
#shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.card {
  display: flex; flex-direction: column; text-align: left; padding: 0; overflow: hidden; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; font-weight: 400; transition: transform .12s, border-color .12s;
}
.card:hover { filter: none; transform: translateY(-3px); border-color: var(--c); }
.card canvas { width: 100%; aspect-ratio: 8 / 5; display: block; background: #000; }
.card .meta { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; }
.card .tag {
  align-self: flex-start; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em;
  background: #1e1e1e; padding: 3px 7px; border-radius: 4px; color: var(--c);
}
.card h3 { margin: 2px 0 0; font-size: 17px; font-weight: 800; }
.card p { margin: 0; color: var(--muted); font-size: 13px; }
.card .best { margin-top: 4px; font-size: 12px; color: var(--muted); }
.card .best b { color: var(--text); }
#ver { color: #555; font-size: 11px; margin-top: 22px; }

#play { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 18px 20px 10px; }
#stage-wrap { flex: 1; min-height: 0; min-width: 0; position: relative; display: flex; }
#stage { flex: 1; min-height: 0; min-width: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; touch-action: none; }
#stage canvas { display: block; border-radius: 10px; box-shadow: 0 0 0 1px var(--line), 0 20px 60px rgba(0, 0, 0, .6); touch-action: none; }
#game-help { color: var(--muted); font-size: 12px; text-align: center; margin: 10px 0 0; }
#overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#overlay[hidden] { display: none; }
#overlay.passive .box { pointer-events: none; }
#overlay .box {
  pointer-events: auto; background: rgba(18, 18, 20, .94); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px 30px; text-align: center; min-width: 260px; box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
#overlay h2 { margin: 0 0 6px; font-size: 22px; font-weight: 800; text-transform: uppercase; }
#overlay p { margin: 0 0 16px; color: var(--muted); }
#overlay p:empty { display: none; }
#overlay button:empty { display: none; }

/* board games (DOM grids) */
.board { display: grid; gap: 4px; user-select: none; }
.cell {
  display: flex; align-items: center; justify-content: center; border-radius: 6px; background: var(--panel2);
  font-weight: 800; cursor: pointer; font-variant-numeric: tabular-nums;
}

/* Play on phone panel */
#phone-panel { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; }
#phone-panel[hidden] { display: none; }
#phone-panel .box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px 26px; text-align: center; max-width: 380px; }
#phone-panel h2 { margin: 0 0 6px; font-size: 20px; font-weight: 800; text-transform: uppercase; }
#phone-panel p { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
#phone-qr svg { width: 240px; height: 240px; border-radius: 10px; display: block; margin: 0 auto; }
#phone-url { margin: 12px 0 4px; font-size: 16px; font-weight: 800; user-select: text; -webkit-user-select: text; }
#phone-other { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
#phone-other a { color: var(--muted); cursor: pointer; text-decoration: underline; margin: 0 4px; }
body.playing #phone { display: none; }

/* leaderboard */
#board-panel { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; padding: 16px; }
#board-panel[hidden] { display: none; }
#board-panel .box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px 22px; width: 100%; max-width: 420px; max-height: 100%; display: flex; flex-direction: column; }
#board-panel h2 { margin: 0; font-size: 20px; font-weight: 800; text-transform: uppercase; }
#board-title { margin: 2px 0 12px; color: var(--muted); }
#board-list { overflow-y: auto; min-height: 60px; }
#board-list .row { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; padding: 7px 8px; border-radius: 8px; font-variant-numeric: tabular-nums; }
#board-list .row:nth-child(odd) { background: var(--panel2); }
#board-list .row.me { background: rgba(232, 69, 139, .2); box-shadow: inset 0 0 0 1px var(--pink); }
#board-list .rk { color: var(--muted); font-weight: 800; }
#board-list .row:nth-child(-n+3) .rk { color: var(--warn); }
#board-list .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board-list .sc { font-weight: 800; }
#board-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
#board-foot p { flex-basis: 100%; margin: 0; }
.muted { color: var(--muted); }
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; font-weight: 700; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); max-width: calc(100% - 32px); text-align: center; }
#toast[hidden] { display: none; }
body:not(.playing) #board-btn { display: none; }

/* phones */
@media (max-width: 640px) {
  #top { padding: 8px 10px; gap: 6px 8px; min-height: 0; }
  .brand { font-size: 14px; }
  .brand img { width: 24px; height: 24px; }
  button { padding: 6px 10px; font-size: 13px; }
  #game-title { font-size: 15px; }
  #hud { order: 10; width: 100%; margin-left: 0; justify-content: space-between; gap: 8px; font-size: 10px; }
  #hud b { font-size: 15px; }
  #home { padding: 14px 12px 12px; }
  .intro { margin-bottom: 12px; font-size: 13px; }
  #shelf { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { border-radius: 10px; }
  .card .meta { padding: 8px 10px 10px; gap: 2px; }
  .card h3 { font-size: 15px; }
  .card p { display: none; }
  .card .tag { font-size: 9px; }
  .card .best { font-size: 11px; }
  #play { padding: 8px 8px 6px; }
  #game-help { font-size: 11px; margin-top: 6px; }
  #overlay .box { min-width: 0; width: calc(100% - 40px); max-width: 320px; padding: 18px 20px; }
}
/* touch screens: bigger targets */
body.touch #tools button { padding: 7px 11px; }
