:root {
  --bg: #0e0b1a;
  --bg-elev: #16122a;
  --bg-card: #1c1736;
  --fg: #ece9ff;
  --fg-dim: #a39dc7;
  --accent: #7c5cff;
  --accent-2: #ff66c4;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  min-height: 100%;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(124, 92, 255, 0.25), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(255, 102, 196, 0.18), transparent 60%),
    var(--bg);
}

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

code {
  background: rgba(255, 255, 255, 0.08);
  padding: 0.1em 0.4em;
  border-radius: 6px;
  font-size: 0.9em;
}

.topbar {
  padding: calc(2rem + var(--safe-top)) clamp(1rem, 4vw, 2rem) 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.4rem;
  color: white;
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.4rem, 3.5vw, 2rem);
  letter-spacing: -0.01em;
}

.tagline {
  margin: 0.5rem 0 0;
  color: var(--fg-dim);
  font-size: 0.95rem;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem clamp(1rem, 4vw, 2rem) 4rem;
}

.library {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.library .status,
.library .empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--fg-dim);
  padding: 3rem 1rem;
}

.empty .empty-card {
  background: var(--bg-card);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 540px;
  margin: 0 auto;
  text-align: left;
}

.card {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  box-shadow: var(--shadow);
}

.card:hover,
.card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(124, 92, 255, 0.5);
  text-decoration: none;
}

.card .cover {
  aspect-ratio: 16 / 10;
  background:
    linear-gradient(135deg, rgba(124, 92, 255, 0.4), rgba(255, 102, 196, 0.3)),
    var(--bg-elev);
  background-size: cover;
  background-position: center;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.5rem;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.card .body {
  padding: 0.85rem 1rem 1rem;
}

.card h2 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.card .meta {
  margin: 0;
  color: var(--fg-dim);
  font-size: 0.85rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem clamp(1rem, 4vw, 2rem) calc(2rem + var(--safe-bottom));
  color: var(--fg-dim);
  font-size: 0.85rem;
  text-align: center;
}

/* ---------- player ---------- */

.player-body {
  margin: 0;
  background: black;
  color: white;
  overflow: hidden;
  height: 100dvh;
}

#player-shell {
  position: fixed;
  inset: 0;
  background: black;
}

#game-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: black;
  display: block;
}

.player-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1rem;
  background: black;
  color: white;
  z-index: 2;
  transition: opacity 0.3s ease;
}

.player-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.player-controls {
  position: absolute;
  top: calc(0.5rem + var(--safe-top));
  left: calc(0.5rem + var(--safe-left));
  right: calc(0.5rem + var(--safe-right));
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 3;
}

.ctrl {
  pointer-events: auto;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 1.1rem;
  text-decoration: none;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.15s ease;
}

.ctrl:hover, .ctrl:focus-visible {
  background: rgba(124, 92, 255, 0.7);
  text-decoration: none;
}

@media (hover: none) {
  /* fade controls after a moment of inactivity on touch */
  .player-controls.idle .ctrl { opacity: 0.25; }
}
