/* Game Hub Lab: the student's 60-30-10 palette.
   60% #030303 background, 30% #1f0670 surfaces, 10% #BBDF32 accent.
   Signature touches: Steam-style shelves, chess.com-style board, Scratch-colored blocks. */
:root, :root:not([data-theme="light"]) {
  --bg: #030303;
  --violet: #1f0670;
  --surface: #1f0670;
  --surface-2: #2a0e8a;
  --surface-3: #13044a;
  --accent: #BBDF32;
  --accent-ink: #030303;
  --accent-soft: color-mix(in srgb, #BBDF32 16%, transparent);
  --ink: #f4f2ff;
  --ink-2: #b9b2e0;
  --line: rgb(255 255 255 / 10%);
  --bad: #ff6b6b;
  --good: #BBDF32;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 0 rgb(255 255 255 / 5%) inset, 0 10px 30px rgb(0 0 0 / 45%);
  --font: "Inter", "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Avenir Next", "Segoe UI Black", "Arial Black", "Roboto", system-ui, sans-serif;
  --max: 1180px;
  color-scheme: dark;
}

body { background: var(--bg); }
.accent { color: var(--accent); }
.grow { flex: 1; }
.eyebrow { display: block; text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; font-weight: 800; color: var(--accent); }
h1, h2, h3 { font-weight: 800; letter-spacing: -.01em; }

.app-header { background: color-mix(in srgb, var(--bg) 88%, transparent); }
.app-header .brand { text-decoration: none; color: var(--ink); font-weight: 900; }
.app-main { padding-bottom: calc(96px + var(--safe-bottom)); max-width: var(--max); }
.tabbar { background: color-mix(in srgb, var(--surface-3) 92%, transparent); }
.tabbar a[aria-current="page"] { color: var(--accent); }

.btn { background: var(--surface-2); color: var(--ink); border-color: var(--line); font-weight: 650; }
.btn.primary { font-weight: 800; }
.btn.ghost { background: transparent; }
.btn.danger, .btn.ghost.danger { color: var(--bad); }
.btn.danger-fill { background: var(--bad); color: #fff; }
.btn.big { min-height: 56px; padding: 0 28px; font-size: 1.15rem; }
.chip { background: var(--surface); color: var(--ink); border-color: var(--line); }
.notice { color: var(--ink); }
input, select, textarea { background: var(--surface-3); color: var(--ink); border-color: var(--line); }
dialog.sheet { background: var(--surface-3); color: var(--ink); border: 1px solid var(--line); }
.card { background: var(--surface); }
.list { background: var(--surface); }
.pill { padding: 4px 10px; border-radius: 999px; background: var(--surface); color: var(--ink-2); font-size: .8rem; font-weight: 700; }
.tag { display: inline-block; padding: 1px 8px; margin: 0 4px 4px 0; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: .72rem; font-weight: 700; }

/* ---------- Home ---------- */
.hero {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: center;
  padding: 24px; border-radius: 22px;
  background: radial-gradient(120% 140% at 100% 0%, #3a17b8 0%, var(--violet) 45%, #0b0228 100%);
  border: 1px solid var(--line);
}
.hero h2 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 6px 0 8px; }
.hero p { color: var(--ink-2); max-width: 46ch; }
.hero-art { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; justify-items: center; }
.hero-art span {
  width: 84px; height: 84px; display: grid; place-items: center; font-size: 2.6rem;
  background: rgb(3 3 3 / 55%); border-radius: 22px; border: 1px solid rgb(187 223 50 / 35%);
  box-shadow: 0 0 0 4px rgb(187 223 50 / 6%);
}
.hero-art span:nth-child(2n) { transform: translateY(14px) rotate(4deg); }
.hero-art span:nth-child(2n+1) { transform: rotate(-4deg); }
@media (max-width: 640px) { .hero { grid-template-columns: 1fr; } .hero-art { display: none; } }

.recent-row { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.recent { display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 8px 14px 8px 8px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface-3); color: var(--ink); font: inherit; text-align: left; white-space: nowrap; }
.recent small { display: block; color: var(--ink-2); font-size: .75rem; }
.r-icon { width: 40px; height: 40px; display: grid; place-items: center; font-size: 1.4rem; border-radius: 10px; background: var(--surface); }

.shelf { display: grid; gap: 12px; }
.builtins { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .builtins { grid-template-columns: 1fr; } }
.builtin-tile {
  position: relative; display: flex; align-items: center; gap: 14px; min-height: 120px; padding: 18px;
  border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-align: left; font: inherit;
  background: linear-gradient(135deg, var(--surface-2), var(--surface-3)); overflow: hidden;
}
.builtin-tile::after { content: ""; position: absolute; inset: auto -30px -30px auto; width: 120px; height: 120px; border-radius: 50%; background: rgb(187 223 50 / 9%); }
.bt-icon { flex: none; width: 72px; height: 72px; display: grid; place-items: center; font-size: 2.6rem; border-radius: 18px; background: var(--bg); color: var(--accent); }
.bt-copy b { display: block; font-family: var(--font-display); font-size: 1.25rem; }
.bt-copy small { display: block; color: var(--ink-2); }
.bt-go { position: absolute; right: 14px; top: 12px; font-size: .8rem; font-weight: 800; color: var(--accent); }
.shelf.scroll { grid-auto-flow: column; grid-auto-columns: minmax(250px, 300px); overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.shelf.scroll > * { scroll-snap-align: start; }

/* ---------- Cards ---------- */
.game-card { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.card-hit { display: block; padding: 0; border: 0; background: var(--bg); cursor: pointer; }
.game-card .art { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: grid; place-items: center; font-size: 3.4rem; color: var(--accent); }
.game-card .art.builtin { background: radial-gradient(circle at 30% 30%, var(--surface-2), var(--bg)); }
.game-card .art.link { background: repeating-linear-gradient(45deg, #0b0228 0 14px, #12043d 14px 28px); font-size: 2.4rem; gap: 4px; align-content: center; }
.game-card .art.link small { font-size: .8rem; color: var(--ink-2); }
.gc-body { padding: 12px 14px 4px; flex: 1; }
.gc-body h3 { margin: 0 0 2px; }
.gc-body p { margin: 0 0 6px; }
.gc-actions { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 14px 14px; }
.like.on { color: #ff7aa8; border-color: #ff7aa8; }
.lib-grid, .comm-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
.lab-hero { display: flex; justify-content: space-between; gap: 16px; align-items: center; flex-wrap: wrap; background: linear-gradient(120deg, var(--surface), #0b0228); }
.template { display: flex; flex-direction: column; gap: 6px; text-align: left; color: var(--ink); border: 1px solid var(--line); font: inherit; cursor: pointer; }
.template img { border-radius: 10px; aspect-ratio: 4 / 3; object-fit: cover; }
.my-games .mini { width: 72px; height: 54px; border-radius: 8px; object-fit: cover; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 10px 0; }
.stats div { background: var(--surface); padding: 12px; border-radius: 12px; }
.stats b { display: block; font-size: 1.6rem; color: var(--accent); font-family: var(--font-display); }
.stats small { color: var(--ink-2); }
.add-link .field input, .add-link .field select { width: 100%; }
textarea { width: 100%; font-family: var(--font-mono); font-size: 14px; }

/* ---------- Screen heads ---------- */
.screen-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.screen-head h2 { margin: 0; }
.back { padding-left: 4px; }
.play-desc { margin-top: -4px; }

/* ---------- Tables (chess, checkers, pool) ---------- */
.setup-card { max-width: 560px; }
.choice-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 10px 0 14px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--surface-3); border: 1px solid var(--line); cursor: pointer; }
.choice:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.choice small { display: block; color: var(--ink-2); }
.table-layout { display: grid; grid-template-columns: auto minmax(220px, 300px); justify-content: start; gap: 16px; align-items: start; }
@media (max-width: 820px) { .table-layout { grid-template-columns: 1fr; } }
.table-surface { display: flex; flex-direction: column; gap: 10px; }
.status { margin: 0; font-weight: 800; color: var(--ink); }
.status.over { color: var(--accent); font-size: 1.15rem; }
.board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: min(calc(100vw - 32px), calc(100dvh - 310px), 640px); min-width: 280px; aspect-ratio: 1;
  border-radius: 10px; overflow: hidden; border: 6px solid var(--surface-3); box-shadow: var(--shadow); touch-action: manipulation;
}
.sq { position: relative; display: grid; place-items: center; border: 0; padding: 0; font: inherit; cursor: pointer; }
.sq.light { background: #e9e4fb; }
.sq.dark { background: #5b3fc4; }
.sq.last::before { content: ""; position: absolute; inset: 0; background: rgb(187 223 50 / 38%); }
.sq.sel::before { content: ""; position: absolute; inset: 0; background: rgb(187 223 50 / 60%); }
.sq.check { background: radial-gradient(circle, #ff4d4d 0%, #ff4d4d55 55%, transparent 75%), #5b3fc4; }
.sq small { position: absolute; font-size: .62rem; font-weight: 800; opacity: .75; }
.sq.light small { color: #5b3fc4; } .sq.dark small { color: #e9e4fb; }
.sq .file { right: 4px; bottom: 1px; } .sq .rank { left: 4px; top: 1px; }
.piece { position: relative; font-size: min(8.4vw, 6.2dvh, 54px); line-height: 1; }
.piece.w { color: #ffffff; text-shadow: 0 0 1px #030303, 0 1px 0 #030303, 0 -1px 0 #030303, 1px 0 0 #030303, -1px 0 0 #030303, 0 3px 5px rgb(0 0 0 / 40%); }
.piece.b { color: #030303; text-shadow: 0 1px 0 rgb(255 255 255 / 35%); }
.checker { position: relative; width: 76%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; font-size: min(4.5vw, 3.4dvh, 26px); box-shadow: 0 4px 0 rgb(0 0 0 / 35%), inset 0 0 0 5px rgb(255 255 255 / 18%); }
.checker.w { background: #BBDF32; color: #030303; }
.checker.b { background: #030303; color: #BBDF32; }
.dot { position: absolute; width: 30%; aspect-ratio: 1; border-radius: 50%; background: rgb(3 3 3 / 35%); }
.dot.cap { width: 86%; background: transparent; border: 5px solid rgb(3 3 3 / 35%); }
.pool-wrap { border-radius: 18px; padding: 12px; background: #3d2a12; box-shadow: var(--shadow); }
.pool-wrap canvas { width: 100%; height: auto; border-radius: 8px; touch-action: none; }
.pool-controls label { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.pool-controls input { flex: 1; }
.moves { max-height: 340px; overflow: auto; padding-left: 26px; columns: 2; margin: 0 0 10px; }
.move-card h3 { margin-top: 0; }

/* ---------- Player: a handheld console, d-pad left, action button right ---------- */
.player { display: flex; flex-direction: column; gap: 10px; }
.hud { display: flex; gap: 16px; align-items: center; font-weight: 700; color: var(--ink-2); }
.hud b { color: var(--accent); font-size: 1.25rem; font-family: var(--font-display); }
.console {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "dpad stage action";
  align-items: center; gap: 18px; padding: 16px; border-radius: 28px;
  background: linear-gradient(160deg, var(--surface-2), var(--surface-3)); border: 1px solid var(--line);
  user-select: none; -webkit-user-select: none;
}
.console .dpad { grid-area: dpad; }
.console .action { grid-area: action; }
.stage-wrap {
  grid-area: stage; justify-self: center; position: relative; width: 100%;
  max-width: max(280px, calc((100dvh - 300px) * 4 / 3)); border-radius: 14px; overflow: hidden; border: 3px solid #030303; background: #000;
}
canvas.stage { width: 100%; height: auto; aspect-ratio: 4 / 3; touch-action: none; }
@media (max-width: 760px), (orientation: portrait) {
  .console { grid-template-columns: 1fr auto; grid-template-areas: "stage stage" "dpad action"; }
  .stage-wrap { max-width: 100%; }
}
.overlay { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; background: rgb(3 3 3 / 62%); text-align: center; padding: 20px; }
.overlay[hidden] { display: none; }
.overlay-title { font-family: var(--font-display); font-size: 1.6rem; font-weight: 900; margin: 0; }
.overlay-title.win { color: var(--accent); }
.overlay-title.lose { color: #ff9aa2; }
.dpad { display: grid; grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(3, 54px); gap: 4px; }
.dpad .up { grid-column: 2; grid-row: 1; } .dpad .left { grid-column: 1; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; } .dpad .down { grid-column: 2; grid-row: 3; }
.pad-btn { border-radius: 14px; border: 1px solid var(--line); background: #030303; color: var(--ink); font-size: 1.2rem; touch-action: none; }
.pad-btn.held, .pad-btn:active { background: var(--accent); color: var(--accent-ink); }
.pad-btn.action { width: 88px; height: 88px; border-radius: 50%; font-size: 2rem; color: var(--accent); box-shadow: 0 5px 0 #000; }

/* ---------- Editor ---------- */
body[data-screen="edit"] .app-main { max-width: 1500px; }
.ed-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.title-input { font-family: var(--font-display); font-weight: 800; font-size: 1.1rem; min-width: 0; flex: 1 1 200px; max-width: 360px; }
.ed-grid { display: grid; grid-template-columns: 230px minmax(0, 1fr) minmax(280px, 360px); gap: 12px; align-items: start; }
@media (max-width: 1180px) { .ed-grid { grid-template-columns: 190px minmax(0, 1fr) 290px; } }
@media (max-width: 900px) {
  .ed-grid { grid-template-columns: 200px minmax(0, 1fr); }
  .ed-stage { grid-column: 1 / -1; grid-row: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
}
@media (max-width: 640px) { .ed-grid { grid-template-columns: 1fr; } .ed-stage { grid-template-columns: 1fr; } .ed-palette { position: static !important; max-height: none; } .ed-palette .palette { flex-direction: row; flex-wrap: wrap; } }
.ed-grid > .card { margin: 0; padding: 12px; }
.ed-palette { position: sticky; top: 70px; max-height: calc(100dvh - 160px); overflow: auto; }
.cats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; margin-bottom: 10px; }
.cat { display: flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 8px; border-radius: 10px; border: 1px solid transparent; background: var(--surface-3); color: var(--ink); font: inherit; font-size: .85rem; font-weight: 700; }
.cat i { width: 14px; height: 14px; border-radius: 50%; background: var(--c); }
.cat.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 22%, var(--surface-3)); }
.palette { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.pal {
  min-height: 40px; padding: 6px 12px; border: 0; border-radius: 8px; text-align: left; font: inherit; font-size: .88rem; font-weight: 700;
  background: var(--c); color: #0a0a0a; box-shadow: 0 3px 0 color-mix(in srgb, var(--c) 60%, black); cursor: pointer;
}
.pal:active { transform: translateY(2px); box-shadow: 0 1px 0 color-mix(in srgb, var(--c) 60%, black); }
.pal.hat-pal { border-radius: 16px 16px 8px 8px; }
.ed-scripts { min-height: 300px; background: radial-gradient(circle at 1px 1px, rgb(255 255 255 / 7%) 1px, transparent 0) 0 0 / 18px 18px, var(--surface-3); }
.ed-scripts h3 { margin: 2px 0 10px; }
.script { margin: 0 0 18px; }
.hat, .blk > .blk-label, .c-head, .blk:not(.c-blk) {
  --ink-b: #0a0a0a;
}
.hat { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 10px 12px; border-radius: 18px 18px 6px 6px; background: var(--c); color: #0a0a0a; font-weight: 800; width: fit-content; max-width: 100%; }
.bstack, .c-body { list-style: none; margin: 0; padding: 0; }
.bstack { padding-left: 0; }
.blk { margin-top: 3px; }
.blk:not(.c-blk) { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 6px 8px 6px 12px; border-radius: 6px; background: var(--c); color: #0a0a0a; font-weight: 700; width: fit-content; max-width: 100%; box-shadow: 0 2px 0 color-mix(in srgb, var(--c) 60%, black); }
.c-blk { width: fit-content; max-width: 100%; min-width: 220px; }
.c-head, .c-mid, .c-foot { background: var(--c); color: #0a0a0a; font-weight: 800; }
.c-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 6px 8px 6px 12px; border-radius: 6px 6px 0 0; }
.c-body { margin-left: 18px; padding: 4px 0 6px 6px; border-left: 14px solid var(--c); margin-left: 0; }
.c-mid { padding: 4px 12px; }
.c-foot { height: 16px; border-radius: 0 0 6px 6px; width: 120px; padding-left: 12px; font-size: .8rem; line-height: 16px; }
.blk-label { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.bf { min-height: 34px; padding: 2px 8px; border-radius: 999px; border: 0; background: #ffffff; color: #0a0a0a; font-size: 16px; font-weight: 700; width: auto; }
.bf.num { width: 76px; text-align: center; }
.bf.txt { width: 130px; }
.cond { display: inline-flex; gap: 4px; align-items: center; padding: 2px 4px; border-radius: 999px; background: color-mix(in srgb, #5cb1d6 85%, black); flex-wrap: wrap; }
.tools { display: inline-flex; gap: 2px; margin-left: 4px; }
.tool { min-width: 34px; min-height: 34px; border-radius: 8px; border: 0; background: rgb(0 0 0 / 18%); color: #0a0a0a; font-weight: 900; cursor: pointer; }
.slot { margin-top: 4px; min-height: 34px; padding: 0 12px; border-radius: 8px; border: 2px dashed rgb(255 255 255 / 22%); background: transparent; color: var(--ink-2); font: inherit; font-size: .8rem; cursor: pointer; }
.slot.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); font-weight: 800; }
.issues .notice { margin: 0 0 8px; }
.ed-stage canvas { border-radius: 10px; border: 2px solid var(--surface-2); }
.sprites { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.sprite-chip { display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 4px 10px 4px 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-3); color: var(--ink); font: inherit; font-size: .85rem; font-weight: 700; }
.sprite-chip.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.sprite-chip.add { padding-left: 10px; color: var(--accent); }
.sc-art { width: 32px; height: 32px; display: grid; place-items: center; font-size: 1.3rem; border-radius: 8px; }
.props summary { cursor: pointer; font-weight: 800; min-height: 36px; }
.prop-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 8px 0; }
.prop-grid label { display: flex; flex-direction: column; gap: 2px; font-size: .8rem; color: var(--ink-2); font-weight: 700; }
.prop-grid input, .prop-grid select { min-height: 40px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; }
.swatch.on { outline: 3px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
