/* =====================================================================
   Playdeck — arcade shell
   Tokens lifted from the "Games Arcade" design (oklch blue-slate ramp),
   with hex fallbacks preceding each oklch value for older engines.
   ===================================================================== */

:root {
  --bg:          #1c202b;
  --bg:          oklch(0.19 0.03 260);
  --surface:     #252a36;
  --surface:     oklch(0.24 0.03 260);
  --surface-2:   #2a2f3c;
  --surface-2:   oklch(0.26 0.03 260);
  --line:        #2e3341;
  --line:        oklch(0.28 0.03 260);
  --line-strong: #3b4150;
  --line-strong: oklch(0.34 0.03 260);
  --text:        #eff0f2;
  --text:        oklch(0.95 0.005 260);
  --text-bright: #f6f6f8;
  --text-bright: oklch(0.97 0.003 260);
  --muted:       #7e8492;
  --muted:       oklch(0.55 0.02 260);
  --on-accent:   #13161d;
  --on-accent:   oklch(0.14 0.02 260);

  --accent:      #4c7dd9;
  --accent-soft: rgba(76, 125, 217, 0.16);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;

  --pad-x: 48px;

  --sans: 'Space Grotesk', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Space Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;

  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

@media (max-width: 900px) { :root { --pad-x: 24px; } }
@media (max-width: 560px) { :root { --pad-x: 16px; } }

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { opacity: 0.85; }

code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--text-bright);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--accent); color: var(--on-accent); }

/* ------------------------------ layout ------------------------------ */

#library { display: flex; flex-direction: column; min-height: 100vh; }
#library[hidden], #player[hidden] { display: none !important; }

/* ------------------------------ top bar ----------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  padding: 22px var(--pad-x);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px) saturate(1.3);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; color: inherit; }
.brand:hover { opacity: 1; }

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  background: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14),
              0 4px 14px -4px var(--accent);
  position: relative;
  flex: none;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 9px 9px auto auto;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--on-accent);
  opacity: 0.55;
}

.brand-name {
  font: 700 22px/1 var(--sans);
  letter-spacing: -0.02em;
  color: var(--text-bright);
}

/* ------------------------------ search ------------------------------ */

.search { position: relative; display: flex; align-items: center; }

.search-icon {
  position: absolute;
  left: 13px;
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}

#search {
  width: 300px;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 11px 40px 11px 38px;
  color: var(--text);
  font: 500 14px var(--sans);
  outline: none;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
#search::placeholder { color: var(--muted); }
#search::-webkit-search-cancel-button { filter: invert(0.6); cursor: pointer; }
#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-kbd {
  position: absolute;
  right: 11px;
  font: 400 11px/1 var(--mono);
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 3px 6px;
  pointer-events: none;
  transition: opacity 0.15s var(--ease);
}
#search:focus ~ .search-kbd, #search:not(:placeholder-shown) ~ .search-kbd { opacity: 0; }

/* ------------------------------ filters ----------------------------- */

.filters {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px var(--pad-x) 0;
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }

/* With a dozen-plus categories the wrapped rows pushed every game below
   the fold on a phone. One swipeable row instead. */
@media (max-width: 760px) {
  .filters { padding-right: 0; }
  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-right: var(--pad-x);
    scroll-padding-left: var(--pad-x);
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip { scroll-snap-align: start; }
}

.chip {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 15px;
  font: 600 13px var(--sans);
  cursor: pointer;
  transition: all 0.16s var(--ease);
  white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: var(--muted); }
.chip[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.count {
  font: 400 12px var(--mono);
  color: var(--muted);
  white-space: nowrap;
  letter-spacing: 0.02em;
}
@media (max-width: 620px) { .count { display: none; } }

/* ------------------------------- grid ------------------------------- */

.stage { flex: 1; padding: 28px var(--pad-x) 64px; }

.shelf + .shelf { margin-top: 48px; }
.shelf[hidden] { display: none; }

.shelf-title {
  margin: 0 0 18px;
  font: 600 13px var(--sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 28px;
}
@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }
}

/* -------------------------------- card ------------------------------ */

.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: transform 0.2s var(--ease);
}
.card:hover, .card:focus-visible { transform: translateY(-3px); }
.card:focus-visible { outline-offset: 6px; }

.card-art {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background-color: var(--surface);
  background-size: cover;
  background-position: center;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.card:hover .card-art, .card:focus-visible .card-art {
  border-color: var(--accent);
  box-shadow: 0 14px 34px -18px rgba(0, 0, 0, 0.9);
}

.card-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Logos and other off-ratio art: show the whole thing, floating on the
   generated backdrop rather than cropped to fill. */
.card-art img.fit {
  object-fit: contain;
  padding: 9% 8%;
  filter: drop-shadow(0 3px 10px rgba(0, 0, 0, 0.55));
}

/* play affordance */
.card-play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(to top, rgba(10, 12, 18, 0.72), rgba(10, 12, 18, 0.12));
  opacity: 0;
  transition: opacity 0.2s var(--ease);
}
.card:hover .card-play, .card:focus-visible .card-play { opacity: 1; }

.card-play span {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  transform: scale(0.85);
  transition: transform 0.2s var(--ease);
  box-shadow: 0 6px 20px -6px rgba(0, 0, 0, 0.8);
}
.card:hover .card-play span { transform: scale(1); }
.card-play svg { width: 15px; height: 15px; margin-left: 2px; }

.card-fav {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  background: rgba(12, 14, 20, 0.6);
  backdrop-filter: blur(6px);
  color: var(--text);
  cursor: pointer;
  opacity: 0;
  transform: scale(0.9);
  transition: all 0.16s var(--ease);
}
.card:hover .card-fav, .card:focus-within .card-fav, .card-fav.on { opacity: 1; transform: scale(1); }
.card-fav:hover { background: rgba(12, 14, 20, 0.85); }
.card-fav.on { color: var(--accent); }
.card-fav svg { width: 15px; height: 15px; }

.card-badge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  font: 400 10px var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-bright);
  background: rgba(12, 14, 20, 0.66);
  backdrop-filter: blur(6px);
  border-radius: 5px;
  padding: 4px 7px;
}

.card-name {
  font: 600 15px var(--sans);
  color: var(--text);
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ------------------------------- empty ------------------------------ */

.empty { padding: 72px 0 40px; text-align: center; max-width: 480px; margin: 0 auto; }
.empty[hidden] { display: none; }

.empty-art svg { width: 108px; height: 72px; }
.empty-art rect { fill: none; stroke: var(--line-strong); stroke-width: 2; }
.empty-art .dash { stroke: var(--accent); stroke-dasharray: 5 5; }

.empty-title { margin: 22px 0 8px; font: 600 18px var(--sans); color: var(--text-bright); }
.empty-body { margin: 0; font: 500 14px/1.7 var(--sans); color: var(--muted); }

/* ------------------------------ buttons ----------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--r-sm);
  font: 600 14px var(--sans);
  cursor: pointer;
  border: 1px solid transparent;
  padding: 9px 18px;
  transition: all 0.16s var(--ease);
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; flex: none; }

.btn-accent { background: var(--accent); color: var(--on-accent); }
.btn-accent:hover { opacity: 0.86; }

.btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--text);
  font-weight: 500;
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-pill { border-radius: 999px; padding: 13px 28px; }

.btn-icon {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--text);
  padding: 9px;
  width: 36px;
}
.btn-icon:hover { background: var(--surface-2); }
.btn-icon.on { color: var(--accent); border-color: var(--accent); }

.more-wrap { display: flex; justify-content: center; margin-top: 44px; }
.more-wrap[hidden] { display: none; }

/* ------------------------------- footer ----------------------------- */

.foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 20px var(--pad-x);
  border-top: 1px solid var(--line);
  font: 400 12px var(--mono);
  color: var(--muted);
}

/* ============================== player ============================== */

#player { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.player-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px var(--pad-x);
  border-bottom: 1px solid var(--line);
  flex: none;
}

.player-title {
  font: 700 18px var(--sans);
  letter-spacing: -0.01em;
  color: var(--text-bright);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-actions { display: flex; align-items: center; gap: 8px; }

@media (max-width: 720px) {
  .player-bar { flex-wrap: wrap; }
  .player-title { order: -1; width: 100%; text-align: center; }
  #fs-btn span { display: none; }
  #fs-btn { padding: 9px; width: 36px; }
}

.player-view {
  flex: 1;
  min-height: 0;
  padding: 20px var(--pad-x);
  display: flex;
}

.frame-shell {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: var(--r-lg);
  overflow: hidden;
  border: 1px solid var(--line);
  background:
    repeating-linear-gradient(135deg,
      #252a36 0 14px, #232834 14px 28px);
  background:
    repeating-linear-gradient(135deg,
      oklch(0.24 0.03 260) 0 14px,
      oklch(0.22 0.03 260) 14px 28px);
}

#game-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #000;
}

/* fullscreen: the shell fills the screen, corners squared off */
.frame-shell:fullscreen { border-radius: 0; border: 0; }
.frame-shell:-webkit-full-screen { border-radius: 0; border: 0; }

/* loader */
.loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: var(--bg);
  font: 400 12px var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  transition: opacity 0.3s var(--ease);
}
.loader[hidden] { display: none; }
.loader.fade { opacity: 0; pointer-events: none; }

.loader-bars { display: flex; gap: 5px; align-items: flex-end; height: 26px; }
.loader-bars[hidden] { display: none; }
#loader-message {
  width: min(32rem, calc(100vw - 64px));
  text-align: center;
  line-height: 1.6;
  letter-spacing: 0;
  text-transform: none;
}
.loader-bars i {
  width: 5px;
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  animation: bar 1s var(--ease) infinite;
}
.loader-bars i:nth-child(2) { animation-delay: 0.12s; }
.loader-bars i:nth-child(3) { animation-delay: 0.24s; }
.loader-bars i:nth-child(4) { animation-delay: 0.36s; }
@keyframes bar { 0%, 100% { transform: scaleY(0.3); opacity: 0.45; } 50% { transform: scaleY(1); opacity: 1; } }

/* fullscreen affordances */
.fs-hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(12, 14, 20, 0.82);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 9px 18px;
  font: 500 13px var(--sans);
  color: var(--text);
  pointer-events: none;
  animation: hintOut 3s var(--ease) forwards;
}
.fs-hint[hidden] { display: none; }
.fs-hint kbd {
  font: 400 12px var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 2px 6px;
}
@keyframes hintOut { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }

.fs-exit {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: rgba(12, 14, 20, 0.7);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s var(--ease);
}
.fs-exit[hidden] { display: none; }
.frame-shell:hover .fs-exit { opacity: 1; }

.player-foot {
  flex: none;
  padding: 0 var(--pad-x) 18px;
  font: 400 11px var(--mono);
  color: var(--muted);
  letter-spacing: 0.04em;
  text-align: center;
}

/* ================================ auth =============================== */

#login[hidden], #admin[hidden] { display: none !important; }

#login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px var(--pad-x);
}

.auth-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 20px; }
.auth-card .brand { justify-content: center; margin-bottom: 4px; }

.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 4px;
}

.auth-tab {
  flex: 1;
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 9px;
  font: 600 13px var(--sans);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.16s var(--ease);
}
.auth-tab[aria-selected="true"] { background: var(--surface-2); color: var(--text-bright); }

.auth-hint {
  margin: 0;
  padding: 11px 14px;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--text);
  font: 500 13px/1.5 var(--sans);
}
.auth-hint[hidden] { display: none; }

#auth-form { display: flex; flex-direction: column; gap: 14px; }

.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-field span { font: 600 12px var(--sans); color: var(--muted); }
.auth-field input {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 11px 13px;
  color: var(--text);
  font: 500 14px var(--sans);
  outline: none;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.auth-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.auth-error { margin: 0; font: 500 13px var(--sans); color: #ff8a8a; }
.auth-error[hidden] { display: none; }

.auth-submit { width: 100%; }
.auth-submit[disabled] { opacity: 0.6; cursor: default; }

/* ------------------------------ user menu ----------------------------- */

.user-menu { position: relative; }
.user-menu[hidden] { display: none; }

.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 5px 12px 5px 5px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.16s var(--ease);
}
.user-menu-btn:hover { background: var(--surface); border-color: var(--line-strong); }

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font: 700 12px var(--sans);
  color: #fff;
  background: var(--accent);
  flex: none;
}

.user-name { font: 600 13px var(--sans); }
@media (max-width: 620px) { .user-name { display: none; } }

.user-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  padding: 6px;
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, 0.7);
  z-index: 30;
}
.user-menu-panel[hidden] { display: none; }

.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 9px 11px;
  font: 500 13px var(--sans);
  color: var(--text);
  cursor: pointer;
}
.user-menu-item:hover { background: var(--surface-2); }
.user-menu-item[hidden] { display: none; }

/* ================================ admin ================================ */

#admin { display: flex; flex-direction: column; min-height: 100vh; }

.admin-view { flex: 1; padding: 28px var(--pad-x) 64px; display: flex; flex-direction: column; gap: 40px; }

.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-tile-value { font: 700 28px var(--sans); color: var(--text-bright); letter-spacing: -0.02em; }
.stat-tile-label { font: 600 12px var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 40px;
}

.admin-panel { min-width: 0; }

.admin-stream-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.admin-stream-help { margin: -10px 0 18px; color: var(--muted); font: 400 13px/1.5 var(--sans); }
.admin-stream-empty { padding: 18px; border: 1px dashed var(--line); border-radius: var(--r-md); color: var(--muted); background: var(--surface); font: 400 13px/1.6 var(--sans); }
.admin-stream-empty code { color: var(--text); font-family: var(--mono); }
.admin-stream-note { margin-top: 12px; }
.admin-stream-open[hidden] { display: none; }

.admin-list { display: flex; flex-direction: column; gap: 4px; }

.admin-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--line);
}

.admin-row-name {
  flex: 1;
  min-width: 0;
  font: 600 14px var(--sans);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-row-meta { font: 400 12px var(--mono); color: var(--muted); white-space: nowrap; }

.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.online-dot.on { background: #4ad991; box-shadow: 0 0 0 3px rgba(74, 217, 145, 0.2); }

.role-badge {
  flex: none;
  font: 600 10px var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
}
.role-badge.admin { background: var(--accent-soft); color: var(--accent); }

.admin-empty { padding: 16px 12px; font: 500 13px var(--sans); color: var(--muted); }

.admin-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); }

.admin-table { width: 100%; border-collapse: collapse; font: 500 13px var(--sans); }
.admin-table th, .admin-table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.admin-table th { font: 600 11px var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table td.admin-actions { display: flex; gap: 8px; }
.admin-table .btn { padding: 6px 12px; font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .card:hover { transform: none; }
}
