:root {
  color-scheme: dark;
  --library-bg: #071216;
  --library-surface: rgba(13, 30, 35, 0.88);
  --library-surface-strong: #10262b;
  --library-line: rgba(139, 215, 204, 0.2);
  --library-text: #eef8f4;
  --library-muted: #9bb5b0;
  --library-accent: #20d7d0;
  --library-gold: #f6a632;
  --library-shadow: rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--library-text);
  background:
    radial-gradient(circle at 9% 0%, rgba(32, 215, 208, 0.18), transparent 29rem),
    radial-gradient(circle at 96% 100%, rgba(246, 166, 50, 0.12), transparent 26rem),
    linear-gradient(rgba(32, 215, 208, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(32, 215, 208, 0.035) 1px, transparent 1px),
    var(--library-bg);
  background-size: auto, auto, 44px 44px, 44px 44px, auto;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  transition: background 180ms ease, color 180ms ease;
}

body.white-theme {
  color-scheme: light;
  --library-bg: #eef5f3;
  --library-surface: rgba(255, 255, 255, 0.9);
  --library-surface-strong: #ffffff;
  --library-line: rgba(19, 81, 83, 0.16);
  --library-text: #12363a;
  --library-muted: #5a7779;
  --library-accent: #078f8a;
  --library-gold: #a65c0d;
  --library-shadow: rgba(35, 75, 74, 0.15);
  background:
    radial-gradient(circle at 7% 0%, rgba(35, 190, 181, 0.16), transparent 30rem),
    radial-gradient(circle at 96% 100%, rgba(245, 175, 69, 0.15), transparent 28rem),
    linear-gradient(rgba(19, 82, 83, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(19, 82, 83, 0.035) 1px, transparent 1px),
    var(--library-bg);
}

body.bright-theme {
  --library-bg: #18383b;
  --library-surface: rgba(22, 49, 54, 0.9);
  --library-surface-strong: #20464a;
  --library-line: rgba(139, 215, 204, 0.24);
  --library-text: #f2faf7;
  --library-muted: #afd0c9;
  --library-accent: #5ce7dc;
  --library-gold: #ffc15a;
  --library-shadow: rgba(0, 0, 0, 0.3);
}

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--library-accent) 55%, transparent);
  outline-offset: 3px;
}

.library-app {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(18px, 3vw, 42px);
  display: grid;
  align-content: start;
  gap: 20px;
}

/* Keep the selected game in a true play viewport instead of making the player
   compete with the library chrome for the first screenful of height. */
.library-app.is-playing {
  grid-template-rows: minmax(0, 1fr);
  height: 100dvh;
  min-height: 100dvh;
  padding: clamp(10px, 1.4vw, 18px);
  gap: 10px;
  overflow: hidden;
}
.library-app.is-playing .library-header,
.library-app.is-playing .library-nav,
.library-app.is-playing .library-footer { display: none; }
.library-app.is-playing .player-view {
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  height: 100%;
  gap: 10px;
}
.library-app.is-playing .player-shell,
.library-app.is-playing .player-frame,
.library-app.is-playing .player-frame iframe {
  min-height: 0;
  height: 100%;
}
.library-app.is-playing .player-frame { aspect-ratio: auto; }

body.is-game-active {
  overflow: hidden;
  overscroll-behavior: none;
}

.library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-lockup {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  border: 1px solid color-mix(in srgb, var(--library-accent) 58%, var(--library-line));
  border-radius: 18px;
  color: var(--library-accent);
  background: linear-gradient(145deg, color-mix(in srgb, var(--library-accent) 20%, transparent), color-mix(in srgb, var(--library-gold) 12%, transparent));
  box-shadow: inset 0 0 24px color-mix(in srgb, var(--library-accent) 10%, transparent), 0 12px 28px var(--library-shadow);
  font-size: 0.78rem;
  font-weight: 950;
  letter-spacing: 0.12em;
}

.library-eyebrow {
  margin: 0 0 7px;
  color: var(--library-accent);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.library-header h1 {
  margin: 0;
  font-size: clamp(2rem, 4.5vw, 3.7rem);
  line-height: 0.98;
  letter-spacing: -0.07em;
}

.library-subtitle {
  margin: 9px 0 0;
  color: var(--library-muted);
  font-size: 0.94rem;
  line-height: 1.5;
}

.library-actions,
.volume-control,
.library-status,
.library-nav,
.library-heading,
.player-topbar,
.player-actions,
.card-meta,
.game-card-footer,
.library-stat-row {
  display: flex;
  align-items: center;
}

.library-actions { justify-content: end; gap: 9px; flex-wrap: wrap; }

.library-status,
.library-button,
.library-volume {
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--library-line);
  border-radius: 999px;
  color: var(--library-muted);
  background: color-mix(in srgb, var(--library-surface) 54%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  font-size: 0.83rem;
  font-weight: 800;
  white-space: nowrap;
}

.library-status::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--library-accent);
  box-shadow: 0 0 14px var(--library-accent);
}

.library-button { cursor: pointer; }
.library-button:hover { color: var(--library-text); background: var(--library-surface); }

.library-volume { gap: 8px; }
.library-volume input {
  width: clamp(100px, 12vw, 160px);
  height: 5px;
  accent-color: var(--library-accent);
  cursor: pointer;
}
.library-volume output { width: 38px; color: var(--library-text); text-align: right; font-variant-numeric: tabular-nums; }

.library-nav {
  gap: 6px;
  min-height: 50px;
  padding: 5px;
  border: 1px solid var(--library-line);
  border-radius: 15px;
  background: color-mix(in srgb, var(--library-surface) 76%, transparent);
  box-shadow: 0 14px 34px var(--library-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.library-nav button {
  min-height: 38px;
  padding: 8px 14px;
  border: 0;
  border-radius: 10px;
  color: var(--library-muted);
  background: transparent;
  font-size: 0.84rem;
  font-weight: 850;
  cursor: pointer;
}
.library-nav button:hover { color: var(--library-text); }
.library-nav button[aria-selected="true"] {
  color: var(--library-text);
  background: color-mix(in srgb, var(--library-accent) 17%, var(--library-surface-strong));
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--library-accent) 32%, transparent);
}
.library-nav button span { margin-left: 6px; color: var(--library-accent); font-size: 0.72rem; }

.library-view,
.player-view { display: grid; gap: 18px; }
.library-view[hidden], .player-view[hidden] { display: none !important; }

.library-overview {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: end;
  padding: clamp(20px, 3vw, 30px);
  border: 1px solid var(--library-line);
  border-radius: 22px;
  background:
    linear-gradient(115deg, color-mix(in srgb, var(--library-accent) 13%, transparent), transparent 55%),
    radial-gradient(circle at 94% 20%, color-mix(in srgb, var(--library-gold) 15%, transparent), transparent 13rem),
    var(--library-surface);
  box-shadow: 0 20px 50px var(--library-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.overview-kicker { margin: 0 0 8px; color: var(--library-accent); font-size: 0.72rem; font-weight: 900; letter-spacing: 0.17em; }
.library-overview h2 { margin: 0; font-size: clamp(1.35rem, 3vw, 2rem); letter-spacing: -0.05em; }
.library-overview p { max-width: 630px; margin: 10px 0 0; color: var(--library-muted); font-size: 0.95rem; line-height: 1.55; }

.library-stat-row { gap: 8px; }
.library-stat {
  min-width: 92px;
  padding: 11px 13px;
  border: 1px solid var(--library-line);
  border-radius: 13px;
  background: color-mix(in srgb, var(--library-surface-strong) 76%, transparent);
}
.library-stat span { display: block; color: var(--library-muted); font-size: 0.64rem; font-weight: 900; letter-spacing: 0.12em; }
.library-stat strong { display: block; margin-top: 5px; color: var(--library-text); font-size: 1.15rem; font-variant-numeric: tabular-nums; }

.library-heading { justify-content: space-between; gap: 14px; }
.library-heading h2 { margin: 0; font-size: 1.15rem; letter-spacing: -0.03em; }
.library-heading p { margin: 0; color: var(--library-muted); font-size: 0.82rem; }

.library-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.game-card {
  overflow: hidden;
  border: 1px solid var(--library-line);
  border-radius: 20px;
  background: var(--library-surface);
  box-shadow: 0 18px 42px var(--library-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}
.game-card:hover,
.game-card:focus-within {
  transform: translateY(-4px);
  border-color: color-mix(in srgb, var(--library-accent) 55%, var(--library-line));
  box-shadow: 0 24px 52px var(--library-shadow), 0 0 0 1px color-mix(in srgb, var(--library-accent) 18%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.game-card[hidden] { display: none; }

.game-card-launch {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.game-cover {
  position: relative;
  aspect-ratio: 2.05 / 1;
  overflow: hidden;
  isolation: isolate;
}
.game-cover::before,
.game-cover::after { content: ""; position: absolute; pointer-events: none; }
.game-cover::before { inset: 0; z-index: -1; background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), transparent 44%); }
.game-cover::after { right: -4%; bottom: -34%; width: 56%; height: 110%; border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 50%; transform: rotate(-19deg); box-shadow: -18px -13px 0 -8px rgba(255, 255, 255, 0.08), -38px -28px 0 -18px rgba(255, 255, 255, 0.06); }
.game-cover--bubble { background: radial-gradient(circle at 17% 20%, rgba(255, 232, 255, 0.32), transparent 22%), linear-gradient(135deg, #28265d, #1c7280 58%, #f2a94e); }
.game-cover--shrine { background: radial-gradient(circle at 84% 18%, rgba(255, 211, 113, 0.42), transparent 24%), linear-gradient(135deg, #102f40, #205d64 58%, #1b283e); }
.game-cover--tetris { background: radial-gradient(circle at 80% 20%, rgba(110, 246, 255, 0.32), transparent 25%), linear-gradient(135deg, #18204f, #2e3d8a 58%, #e05b99); }
.game-cover--pang { background: radial-gradient(circle at 82% 17%, rgba(255, 245, 174, 0.35), transparent 24%), linear-gradient(135deg, #103a56, #137f86 54%, #f36c56); }
.game-cover--airstrike { background: #071631; }
.game-cover--airstrike::after { display: none; }
.game-cover--airstrike img { inset: 0; width: 100%; height: 100%; max-width: none; object-fit: cover; filter: saturate(1.08) contrast(1.04); }
.airstrike-cover-badge { position: absolute; right: 7%; bottom: 10%; z-index: 2; padding: 5px 7px; border: 1px solid rgba(143, 234, 255, 0.5); color: #effcff; background: rgba(5, 22, 43, 0.68); box-shadow: 3px 3px 0 rgba(0,0,0,0.22); font-size: 0.58rem; font-weight: 900; letter-spacing: 0.09em; }
.game-cover img { position: absolute; right: 8%; bottom: -8%; z-index: 1; height: 112%; max-width: 54%; object-fit: contain; filter: drop-shadow(0 14px 15px rgba(0, 0, 0, 0.35)); transition: transform 220ms ease; }
.game-card:hover .game-cover img { transform: translateY(-4px) scale(1.035); }
.game-cover--bubble img { right: 3%; height: 122%; max-width: 58%; }
.game-cover--airstrike img { right: auto; bottom: auto; width: 100%; height: 100%; max-width: none; object-fit: cover; filter: saturate(1.08) contrast(1.04); transition: transform 220ms ease, filter 220ms ease; }
.game-card:hover .game-cover--airstrike img { transform: scale(1.035); filter: saturate(1.14) contrast(1.07); }
.cover-blocks { position: absolute; top: 13%; right: 8%; width: 45%; height: 75%; transform: rotate(7deg); filter: drop-shadow(0 13px 10px rgba(2, 7, 28, 0.35)); }
.cover-blocks::after { content: ""; position: absolute; right: 8%; bottom: 2%; width: 68%; height: 9%; background: rgba(255, 255, 255, 0.12); box-shadow: 0 16px 0 rgba(255, 255, 255, 0.08), 0 32px 0 rgba(255, 255, 255, 0.05); }
.cover-blocks i { position: absolute; display: block; width: 21%; aspect-ratio: 1; border: 1px solid rgba(255, 255, 255, 0.42); box-shadow: inset 4px 4px 0 rgba(255, 255, 255, 0.24), 0 0 0 3px rgba(11, 18, 56, 0.15); }
.cover-blocks i:nth-child(1), .cover-blocks i:nth-child(2), .cover-blocks i:nth-child(3), .cover-blocks i:nth-child(4) { background: #56e0e5; }
.cover-blocks i:nth-child(1) { top: 9%; left: 18%; }
.cover-blocks i:nth-child(2) { top: 9%; left: 39%; }
.cover-blocks i:nth-child(3) { top: 9%; left: 60%; }
.cover-blocks i:nth-child(4) { top: 30%; left: 39%; }
.cover-blocks i:nth-child(5), .cover-blocks i:nth-child(6), .cover-blocks i:nth-child(7) { background: #ffd16a; }
.cover-blocks i:nth-child(5) { top: 51%; left: 18%; }
.cover-blocks i:nth-child(6) { top: 51%; left: 39%; }
.cover-blocks i:nth-child(7) { top: 72%; left: 18%; }
.cover-balloon { position: absolute; top: 12%; right: 10%; width: 43%; aspect-ratio: 1; border: 2px solid rgba(255, 255, 255, 0.5); border-radius: 50%; background: radial-gradient(circle at 31% 24%, #fff5c6 0 8%, transparent 9%), radial-gradient(circle at 37% 31%, #ffb25f, #f26361 63%, #9d2f5b); box-shadow: inset -10px -12px 0 rgba(125, 32, 74, 0.2), 0 16px 18px rgba(6, 24, 38, 0.3); transform: rotate(-8deg); }
.cover-balloon::before { content: ""; position: absolute; right: 37%; bottom: -21%; width: 10%; height: 23%; background: #ffd36f; clip-path: polygon(0 0, 100% 0, 50% 100%); }
.cover-balloon::after { content: ""; position: absolute; right: 27%; bottom: -31%; width: 2px; height: 17%; background: rgba(255, 255, 255, 0.7); transform: rotate(-9deg); transform-origin: top; }
.cover-balloon i, .cover-balloon b { position: absolute; top: 48%; width: 9%; height: 9%; border-radius: 50%; background: #4a204a; }
.cover-balloon i { left: 28%; }
.cover-balloon b { right: 28%; }
.cover-copy { position: absolute; top: 18%; left: 6%; z-index: 2; max-width: 48%; }
.cover-copy small { display: block; color: rgba(255, 255, 255, 0.76); font-size: 0.65rem; font-weight: 900; letter-spacing: 0.18em; }
.cover-copy strong { display: block; margin-top: 7px; color: #fff; font-size: clamp(1.25rem, 2.6vw, 2.2rem); line-height: 0.98; letter-spacing: -0.07em; }
.cover-copy em { display: inline-block; margin-top: 13px; padding: 5px 8px; border: 1px solid rgba(255, 255, 255, 0.32); border-radius: 999px; color: #fff; background: rgba(4, 17, 25, 0.22); font-size: 0.65rem; font-style: normal; font-weight: 850; }

.game-card-body { padding: 17px 18px 18px; }
.card-meta { justify-content: space-between; gap: 10px; color: var(--library-muted); font-size: 0.73rem; font-weight: 800; }
.card-meta span:last-child { color: var(--library-accent); }
.game-card h3 { margin: 8px 0 5px; font-size: clamp(1.25rem, 2.2vw, 1.6rem); letter-spacing: -0.055em; }
.game-card-description { min-height: 44px; margin: 0; color: var(--library-muted); font-size: 0.9rem; line-height: 1.55; }
.game-card-footer { justify-content: space-between; gap: 12px; margin-top: 17px; }
.game-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.game-tags span { padding: 5px 8px; border: 1px solid var(--library-line); border-radius: 7px; color: var(--library-muted); font-size: 0.69rem; font-weight: 850; }
.launch-label { display: inline-flex; align-items: center; gap: 6px; color: var(--library-accent); font-size: 0.82rem; font-weight: 900; }
.launch-label::after { content: "↗"; font-size: 1rem; transition: transform 180ms ease; }
.game-card:hover .launch-label::after { transform: translate(2px, -2px); }

.player-view { min-height: 0; gap: 12px; }
.player-topbar { justify-content: space-between; gap: 14px; min-height: 52px; }
.player-topbar-copy { min-width: 0; }
.player-topbar h2 { margin: 0; font-size: clamp(1.1rem, 2.5vw, 1.55rem); letter-spacing: -0.045em; }
.player-topbar p { margin: 4px 0 0; color: var(--library-muted); font-size: 0.78rem; }
.player-actions { justify-content: end; gap: 8px; flex-wrap: wrap; }
.player-volume { display: inline-flex; align-items: center; gap: 7px; min-height: 40px; padding: 8px 10px; border: 1px solid var(--library-line); border-radius: 999px; color: var(--library-muted); background: color-mix(in srgb, var(--library-surface) 54%, transparent); font-size: 0.78rem; font-weight: 800; white-space: nowrap; }
.player-volume input { width: clamp(88px, 10vw, 128px); accent-color: var(--library-accent); cursor: pointer; }
.player-volume output { min-width: 34px; color: var(--library-text); font-variant-numeric: tabular-nums; text-align: right; }
.player-shell { position: relative; overflow: hidden; min-height: 0; height: 100%; border: 1px solid var(--library-line); border-radius: 22px; background: #020708; box-shadow: 0 28px 70px var(--library-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08); }
.player-frame { position: relative; width: 100%; height: 100%; min-height: 0; }
.player-frame iframe { display: block; width: 100%; height: 100%; border: 0; background: #020708; }
.player-frame[data-state="loading"] iframe,
.player-frame[data-state="error"] iframe { visibility: hidden; }
.player-loading { position: absolute; inset: 0; z-index: 2; display: grid; place-content: center; justify-items: center; gap: 8px; padding: 24px; color: var(--library-text); background: radial-gradient(circle at 50% 38%, rgba(32, 215, 208, 0.13), transparent 24rem), #071216; text-align: center; }
.player-loading[hidden] { display: none; }
.player-loading-mark { display: grid; place-items: center; width: 62px; height: 62px; border: 1px solid color-mix(in srgb, var(--library-accent) 65%, transparent); border-radius: 18px; color: var(--library-accent); font-size: 0.72rem; font-weight: 950; letter-spacing: 0.16em; box-shadow: 0 0 30px color-mix(in srgb, var(--library-accent) 16%, transparent), inset 0 0 24px color-mix(in srgb, var(--library-accent) 8%, transparent); animation: player-pulse 1.5s ease-in-out infinite; }
.player-loading strong { font-size: 1.1rem; }
.player-loading > span:not(.player-loading-mark) { color: var(--library-muted); font-size: 0.86rem; }
.player-loading .library-button { margin-top: 8px; }
.player-loading.is-error { background: radial-gradient(circle at 50% 38%, rgba(255, 92, 97, 0.13), transparent 24rem), #180f14; }
.player-loading.is-error .player-loading-mark { color: var(--library-gold); border-color: var(--library-gold); animation: none; }
@keyframes player-pulse { 0%, 100% { transform: scale(1); opacity: .74; } 50% { transform: scale(1.04); opacity: 1; } }
.player-empty { display: grid; place-items: center; min-height: 420px; color: var(--library-muted); }

.library-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--library-muted); font-size: 0.78rem; }
.library-footer p { margin: 0; }

@media (max-width: 900px) {
  .library-header { align-items: start; flex-direction: column; }
  .library-actions { justify-content: start; }
  .library-overview { grid-template-columns: 1fr; align-items: start; }
  .library-stat-row { justify-content: start; }
}

@media (max-width: 640px) {
  .library-app { padding: 14px; gap: 14px; }
  .brand-lockup { width: 48px; height: 48px; border-radius: 15px; }
  .library-header h1 { font-size: 2.35rem; }
  .library-subtitle { font-size: 0.86rem; }
  .library-actions { align-items: stretch; width: 100%; }
  .library-status, .library-button { min-height: 38px; font-size: 0.76rem; }
  .library-volume { flex: 1; min-width: 0; }
  .library-volume input { width: min(40vw, 150px); }
  .library-nav { overflow-x: auto; }
  .library-nav button { flex: 0 0 auto; padding-inline: 11px; font-size: 0.76rem; }
  .library-overview { padding: 18px; border-radius: 17px; }
  .library-overview p { font-size: 0.86rem; }
  .library-stat { min-width: 80px; padding: 9px 10px; }
  .library-stat strong { font-size: 1rem; }
  .library-grid { grid-template-columns: 1fr; }
  .game-cover { aspect-ratio: 1.8 / 1; }
  .game-card-body { padding: 15px; }
  .game-card-description { min-height: auto; }
  .player-topbar { align-items: start; flex-direction: column; }
  .player-actions { width: 100%; }
  .player-actions .library-button { flex: 1; }
  .player-volume { flex: 1 1 100%; justify-content: space-between; }
  .player-volume input { flex: 1; width: auto; }
  .player-shell { border-radius: 14px; }
  .library-footer { align-items: start; flex-direction: column; }
}

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