@font-face { font-family: "Press Start 2P"; src: url("fonts/PressStart2P.ttf") format("truetype"); font-display: swap; }

:root {
  --bg: #0d0e13; --bg2: #14151d; --panel: #1b1d27; --panel2: #232634; --line: #2f3344;
  --text: #f3f3f6; --muted: #a2a6b6; --accent: #ffb13d; --accent2: #ff5f7e; --good: #7dff8a; --bad: #ff8f8f;
  --pixel: "Press Start 2P", ui-monospace, monospace;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(255, 177, 61, 0.10), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(95, 212, 255, 0.08), transparent 60%),
    radial-gradient(900px 700px at 50% 120%, rgba(255, 95, 126, 0.08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
/* Faint CRT scanlines over the library. */
.library-page::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 50;
  background: repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 3px);
}
a { color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); }

/* --- Header --- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px max(16px, calc((100vw - 1200px) / 2));
  background: rgba(13, 14, 19, 0.78); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.logo { margin: 0; font: 20px/1 var(--pixel); letter-spacing: 1px; color: var(--accent); text-shadow: 0 0 18px rgba(255, 177, 61, 0.55), 3px 3px 0 #7a3d00; }
.logo span { margin-left: 10px; color: var(--accent2); text-shadow: 0 0 18px rgba(255, 95, 126, 0.55), 3px 3px 0 #6b0f24; }
.who {
  display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 14px 6px 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; color: var(--text); font: inherit; cursor: pointer;
}
.who:hover { border-color: var(--accent); }
.avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--panel2); color: #111; font: 13px var(--pixel);
}
.avatar.big { width: 72px; height: 72px; font-size: 26px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4); }

/* --- Layout --- */
.library { max-width: 1200px; margin: 0 auto; padding: 8px 16px 48px; }
.shelf { margin-top: 28px; }
.shelf h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font: 13px/1.4 var(--pixel); letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.count { color: var(--accent); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar h2 { margin: 0; }
input, select {
  min-height: 44px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit;
}
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(255, 177, 61, 0.25); }
#search { width: min(320px, 100%); }
.btn {
  min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--accent); color: #1a1205; font: 600 15px system-ui, sans-serif;
}
.btn:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); min-height: 36px; padding: 6px 12px; }
.btn.ghost:hover { color: var(--text); border-color: var(--accent); }

/* --- System filter chips --- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip {
  min-height: 36px; padding: 6px 14px; border-radius: 999px; cursor: pointer; font: 600 14px system-ui, sans-serif;
  background: var(--panel); color: var(--muted); border: 1px solid var(--line);
}
.chip:hover { color: var(--text); border-color: var(--sys); }
.chip.on { background: var(--sys); border-color: var(--sys); color: #111; }

/* --- Game cards --- */
.grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid li { display: flex; flex-direction: column; min-width: 0; }
.card {
  --sys: var(--accent);
  position: relative; display: flex; flex-direction: column; text-decoration: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.card:hover, .card:focus-visible {
  transform: translateY(-4px) scale(1.02); border-color: var(--sys); outline: none;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--sys), 0 0 28px color-mix(in srgb, var(--sys) 45%, transparent);
}
.art { position: relative; aspect-ratio: 3 / 4; overflow: hidden; background: #08090c; container-type: inline-size; }
.art img { position: absolute; inset: 0; width: 100%; height: 100%; }
.art-bg { object-fit: cover; filter: blur(18px) saturate(1.4) brightness(0.55); transform: scale(1.2); }
.art-box { object-fit: contain; padding: 10px; filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.6)); }
.art-snap { object-fit: cover; image-rendering: pixelated; opacity: 0; transition: opacity 0.25s ease; }
.card:hover .art-snap, .card:focus-visible .art-snap { opacity: 1; }
.art.drawn {
  display: flex; flex-direction: column; justify-content: space-between; padding: 14px;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.04) 0 10px, transparent 10px 20px),
    linear-gradient(160deg, color-mix(in srgb, var(--sys) 75%, #000), color-mix(in srgb, var(--sys) 20%, #000));
}
.drawn-system { font: 8px/1.4 var(--pixel); text-transform: uppercase; color: rgba(255, 255, 255, 0.8); }
.drawn-title { font: clamp(8px, 7cqi, 12px)/1.6 var(--pixel); color: #fff; text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5); overflow-wrap: break-word; hyphens: auto; }
.art.drawn .art-snap { inset: 0; }
.card-info { display: block; padding: 10px 12px 12px; }
.card-info strong, .card-info > span { display: block; }
.card-info strong { font-size: 15px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card-info > span { color: var(--muted); font-size: 13px; margin-top: 3px; }
.card-info > span::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 2px; background: var(--sys); vertical-align: 1px; }
.card-info > span.tag::before { display: none; }
.badge {
  position: absolute; top: 8px; right: 8px; padding: 4px 6px 3px; border-radius: 6px;
  background: var(--accent2); color: #fff; font: 8px var(--pixel); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.credit { display: inline-block; padding: 6px 4px 0; color: var(--muted); font-size: 12px; text-decoration: none; }
.credit:hover { color: var(--text); text-decoration: underline; }

/* --- Horizontal shelves: playing now, continue --- */
.row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 320px); gap: 16px; overflow-x: auto; padding: 4px 4px 14px; margin: -4px; scroll-snap-type: x proximity; }
.row > * { scroll-snap-align: start; }
.card.wide { flex-direction: row; align-items: stretch; min-height: 116px; }
.card.wide .art { aspect-ratio: auto; width: 110px; flex: none; }
.card.wide .art.shot { width: 150px; }
.card.wide .art.shot img { object-fit: cover; image-rendering: pixelated; }
.card.wide .art.drawn { padding: 8px; }
.card.wide .drawn-title { font-size: 8px; }
.card.wide .card-info { align-self: center; padding: 12px 14px; }
.tag { display: inline-block !important; width: fit-content; margin-top: 8px !important; padding: 4px 10px; border-radius: 999px; font: 600 13px system-ui, sans-serif; }
.tag.join { background: var(--good); color: #062a0c !important; }
.tag.full { background: var(--panel2); }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 rgba(125, 255, 138, 0.7); animation: pulse 1.6s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 10px rgba(125, 255, 138, 0); } 100% { box-shadow: 0 0 0 0 rgba(125, 255, 138, 0); } }
#live h2 { color: var(--good); }

/* --- Requests --- */
.requests { max-width: 720px; }
.request-form { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.request-form input { flex: 1 1 220px; }
.request-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.request-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.request-list li > span { min-width: 0; }
.request-list strong, .request-list .muted { display: block; }
.request-list .muted { font-size: 13px; }

/* --- Footer and controller hints --- */
.foot { max-width: 1200px; margin: 0 auto; padding: 0 16px 32px; font-size: 13px; }
.pad-hint { display: none; }
body.pad .pad-hint { display: inline; }
body.pad .key-hint { display: none; }

/* --- Player picker --- */
dialog.profiles {
  width: min(560px, calc(100vw - 32px)); padding: 24px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(5, 5, 8, 0.75); backdrop-filter: blur(4px); }
.profiles h2 { margin: 0 0 20px; text-align: center; font: 16px var(--pixel); color: var(--accent); }
.profile-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; margin-bottom: 20px; }
.profile-list:empty { display: none; }
.profile {
  display: flex; flex-direction: column; align-items: center; gap: 8px; width: 104px; padding: 12px 8px;
  background: none; border: 2px solid transparent; border-radius: 14px; color: var(--text); font: inherit; cursor: pointer;
}
.profile:hover, .profile:focus-visible { border-color: var(--accent); background: var(--panel); outline: none; }
.new-profile { display: flex; flex-wrap: wrap; gap: 10px; }
.new-profile input { flex: 1 1 160px; min-width: 0; }
.login { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.login h2 { margin: 0; }
.login > input, .login .new-profile { width: min(320px, 100%); }
.login .row { display: flex; gap: 10px; justify-content: center; }
.login p { margin: 0; text-align: center; }
.login .new-profile, .signup { width: min(420px, 100%); }
.signup { border-top: 1px solid var(--line); padding-top: 14px; }
.signup summary { cursor: pointer; color: var(--accent); text-align: center; margin-bottom: 12px; }
.signup p { margin-top: 10px; }

/* --- Toast --- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 100; max-width: calc(100vw - 32px);
  padding: 12px 18px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); transform: translate(-50%, 20px); opacity: 0; transition: 0.25s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --- Game page --- */
.player { display: flex; flex-direction: column; height: 100dvh; background: var(--bg); }
.player-bar {
  display: flex; align-items: center; gap: 16px; padding: 6px 16px; min-height: 44px;
  border-bottom: 2px solid var(--sys, var(--accent)); background: var(--bg2); font-size: 14px;
}
.back { display: inline-flex; align-items: center; min-height: 36px; color: var(--muted); text-decoration: none; }
.back:hover { color: var(--text); }
.now-playing { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: 600; }
.sync { color: var(--good); font-size: 13px; white-space: nowrap; }
.sync.bad { color: var(--bad); }
.stage { flex: 1; min-height: 0; }
#game { width: 100%; height: 100%; }
.join-banner {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%); z-index: 1000;
  min-height: 52px; padding: 14px 28px; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--good); color: #062a0c; font: 700 17px system-ui, sans-serif;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), 0 0 30px rgba(125, 255, 138, 0.5);
  animation: bob 1.6s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translate(-50%, -4px); } }

@media (max-width: 560px) {
  .logo { font-size: 15px; }
  .who #who-name { display: none; }
  .who { padding: 6px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
  .row { grid-auto-columns: minmax(240px, 85vw); }
  .sync { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Layout rules above set display on some elements; keep the hidden attribute winning. */
[hidden] { display: none !important; }
