@import url("/icons/src/regular/style.css");
@import url("/icons/src/fill/style.css");

:root {
  color-scheme: light;
  --bg: #f2f2f2;
  --surface: #ffffff;
  --text: #252629;
  --text-soft: #72757b;
  --line: #d1d3d6;
  --accent: #7ed6d6;
  --accent-dark: #48b8bd;
  --shadow: rgba(40, 43, 48, 0.2);
  --radius: 16px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  font-family: Bahnschrift, "Microsoft YaHei", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }

html,
body { width: 100%; min-width: 320px; min-height: 100%; }

body {
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
}

.return-transition {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  color: #f7f7f3;
  background:
    radial-gradient(circle at 50% 38%, rgba(126, 214, 214, 0.2), transparent 32%),
    #132126;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 220ms ease, visibility 220ms ease;
}

.return-transition img { width: min(30vw, 220px); }
.return-transition strong { font-size: clamp(24px, 3vw, 38px); letter-spacing: 0.04em; }
.return-transition span { color: rgba(247, 247, 243, 0.72); font-size: clamp(15px, 1.5vw, 20px); }
.return-transition > div {
  width: min(42vw, 320px);
  height: 5px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}
.return-transition i {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: #7ed6d6;
  animation: return-transition-progress 1.1s ease-in-out infinite alternate;
}

html[data-entry="game-return"] body:not([data-view-ready="true"]) .return-transition {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

html[data-entry="game-return"] body:not([data-view-ready="true"]) .pairing-screen,
html[data-entry="game-return"] body:not([data-view-ready="true"]) .library-shell {
  visibility: hidden;
}

@keyframes return-transition-progress {
  from { transform: translateX(-105%); }
  to { transform: translateX(245%); }
}

button,
a { font: inherit; -webkit-tap-highlight-color: transparent; }

button { color: inherit; }

button:focus-visible,
a:focus-visible {
  outline: 4px solid color-mix(in srgb, var(--accent) 78%, white);
  outline-offset: 4px;
}

.brand-logo { display: block; object-fit: contain; object-position: left center; }

.library-shell {
  position: fixed;
  inset: var(--host-topbar-height) 0 0;
  z-index: 20;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  min-height: calc(100vh - var(--host-topbar-height));
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.92), transparent 43%),
    var(--bg);
  opacity: 1;
  transform: translateY(0);
  transition: opacity 320ms ease 80ms, transform 420ms var(--ease-out) 80ms;
}

body[data-phase="pairing"] .library-shell {
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
}

.game-host-frame {
  position: fixed;
  z-index: 180;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100dvh;
  border: 0;
  background: #000;
}

/* Let the library canvas continue behind its controls so the header is not a separate band. */
body[data-phase="library"] .library-shell {
  inset: 0;
  min-height: 100vh;
  padding-top: var(--host-topbar-height);
}

/* Pairing and in-game chrome keep the dark theme. */
body[data-phase="library"] .host-topbar {
  border-bottom-color: transparent;
  color: #273034;
  background: transparent;
  box-shadow: none;
}

body[data-phase="library"] .host-topbar-logo {
  content: url("/assets/brand/logo-horizontal-dark.png");
}

body[data-phase="library"] :is(.host-player-summary, .host-room-code, .host-topbar-button, .host-icon-button) {
  border-color: rgba(48, 56, 59, 0.09);
  color: #30383b;
  background: rgba(255, 255, 255, 0.46);
}

body[data-phase="library"] .host-player-avatars:empty::before {
  border-color: rgba(39, 48, 52, 0.28);
}

body[data-phase="library"] .host-player-avatars > img,
body[data-phase="library"] .host-player-avatars .player-chip {
  border-color: #f4f5f5;
}

body[data-phase="library"] .host-player-avatars .player-chip::after {
  border-color: #f4f5f5;
}

body[data-phase="library"] :is(.host-topbar-button, .host-icon-button):hover,
body[data-phase="library"] .host-topbar-button[aria-pressed="true"],
body[data-phase="library"] .host-topbar-button[aria-expanded="true"] {
  border-color: rgba(72, 184, 189, 0.34);
  background: rgba(234, 246, 246, 0.72);
}

body[data-phase="library"] .host-topbar-button[aria-pressed="true"] {
  box-shadow: none;
}

.console-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  padding: 0 clamp(32px, 4vw, 76px);
}

.console-actions,
.console-room,
.player-presence {
  display: flex;
  align-items: center;
}

.console-wordmark { width: 150px; height: 64px; }
.console-actions { gap: 10px; min-width: 0; }
.player-presence { gap: 7px; flex-wrap: nowrap; max-width: min(34vw, 390px); overflow: hidden; padding: 5px 2px; }

.player-chip {
  position: relative;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 3px solid var(--surface);
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.76);
  background: #a8abb0;
  box-shadow: 0 0 0 1px #c9cbd0, 0 4px 12px rgba(28, 30, 34, 0.14);
  filter: grayscale(1);
  opacity: 0.48;
  transition: transform 220ms var(--ease-out), filter 180ms ease, opacity 180ms ease;
}

.player-chip img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
  user-select: none;
}
.player-chip.online { filter: none; opacity: 1; transform: translateY(-2px); }
.player-chip.waiting { border-style: dashed; opacity: .72; }
.player-chip em {
  position: absolute;
  top: -6px;
  right: -7px;
  padding: 1px 4px;
  border-radius: 5px;
  color: #1a1308;
  background: #ffc25c;
  font-size: 9px;
  font-style: normal;
}
.player-chip::after {
  content: attr(data-order);
  position: absolute;
  right: -6px;
  bottom: -6px;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  width: 19px;
  height: 19px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  color: #485154;
  background: #d6dadd;
  font: 900 10px/1 Arial, sans-serif;
  box-shadow: 0 1px 4px rgba(25, 32, 34, 0.16);
}
.player-chip.ready::after { color: #123035; background: var(--accent); }

.console-room {
  flex: 0 0 auto;
  gap: 9px;
  height: 42px;
  padding: 0 14px;
  border: 1px solid #d1d5d7;
  border-radius: 12px;
  color: #283134;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 5px 16px rgba(42, 44, 49, 0.08);
}

.console-room i {
  color: var(--accent-dark);
  font-size: 19px;
  transform: rotate(-12deg);
}

.console-room strong {
  font: 900 18px/1 Consolas, monospace;
  letter-spacing: 0.1em;
}

.console-fullscreen-button {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid #d1d5d7;
  border-radius: 12px;
  color: #3c4245;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 5px 16px rgba(42, 44, 49, 0.08);
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.console-fullscreen-button i { font-size: 20px; }

.console-fullscreen-button:hover {
  color: #132126;
  border-color: var(--accent);
  background: var(--accent);
  transform: translateY(-1px);
}

.console-fullscreen-button:active { transform: translateY(0) scale(0.96); }

.console-home {
  display: grid;
  grid-template-rows: clamp(500px, 61vh, 660px) auto;
  align-content: start;
  min-height: 0;
  padding-top: 0;
}

.game-picker {
  position: relative;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 72px;
  align-items: center;
  min-height: 0;
  transform: translateY(44px);
}

.game-rail {
  display: flex;
  align-items: center;
  gap: clamp(18px, 2vw, 34px);
  overflow-x: auto;
  overflow-y: hidden;
  height: 100%;
  padding: 22px calc(50vw - clamp(200px, 17vw, 310px)) 28px;
  scroll-behavior: smooth;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.game-rail::-webkit-scrollbar { display: none; }

.game-card {
  position: relative;
  flex: 0 0 clamp(400px, 34vw, 620px);
  aspect-ratio: 4 / 3;
  padding: 0;
  overflow: hidden;
  border: 5px solid transparent;
  border-radius: var(--radius);
  background: #dfe1e4;
  box-shadow: 0 12px 30px rgba(44, 47, 52, 0.16);
  cursor: pointer;
  scroll-snap-align: center;
  transform: scale(0.9);
  transition: transform 260ms var(--ease-out), border-color 180ms ease, box-shadow 220ms ease, opacity 180ms ease;
}

.game-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.all-games-card {
  display: grid;
  flex-basis: clamp(156px, 12vw, 210px);
  place-content: center;
  justify-items: center;
  aspect-ratio: 1;
  overflow: visible;
  border-width: 4px;
  border-radius: 50%;
  color: #3e4649;
  background:
    radial-gradient(circle at 50% 42%, rgba(126, 214, 214, 0.22), transparent 48%),
    #f8f9f9;
}

.all-games-card-icon {
  display: grid;
  grid-template-columns: repeat(2, 27px);
  gap: 7px;
  color: var(--accent-dark);
}

.all-games-card-icon i {
  width: 27px;
  aspect-ratio: 1;
  border: 3px solid currentColor;
  border-radius: 4px;
}

.all-games-card strong {
  position: absolute;
  bottom: calc(100% + 14px);
  left: 50%;
  font-size: clamp(18px, 1.5vw, 25px);
  line-height: 1;
  white-space: nowrap;
  transform: translateX(-50%);
}

.all-games-card small { display: none; }

.game-card:not(.selected) { opacity: 0.78; }

.game-card.selected {
  z-index: 2;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.94), 0 18px 38px rgba(22, 126, 138, 0.2);
  opacity: 1;
  transform: scale(1.055);
}

.edge-control {
  position: relative;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 48px;
  height: 78px;
  margin: auto;
  border: 0;
  border-radius: 14px;
  color: #4c4f55;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 8px 20px rgba(43, 46, 51, 0.12);
  cursor: pointer;
  font-size: 31px;
  transition: color 160ms ease, transform 180ms var(--ease-out), background 160ms ease;
}

.edge-control:hover { color: var(--accent-dark); background: #fff; transform: scale(1.05); }
.edge-control:active { transform: scale(0.96); }

.selected-game {
  min-height: 74px;
  padding: 0 32px;
  text-align: center;
}

.selected-game h1 {
  margin: 0;
  font-size: clamp(25px, 2.3vw, 36px);
  letter-spacing: -0.035em;
  line-height: 1.15;
}

.selected-game p { margin: 8px 0 0; color: var(--text-soft); font-size: 14px; font-weight: 650; }

.all-games-view {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  padding: 28px clamp(34px, 5vw, 92px) 34px;
  overflow: hidden;
}

.all-games-view[hidden],
.console-home[hidden] { display: none; }

.all-games-header,
.all-games-heading {
  display: flex;
  align-items: center;
}

.all-games-header {
  justify-content: space-between;
  gap: 24px;
  padding: 0 4px 24px;
  border-bottom: 1px solid rgba(42, 49, 52, 0.13);
}

.all-games-heading { gap: 18px; }

.all-games-back {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 54px;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid rgba(48, 56, 59, 0.12);
  border-radius: 50%;
  color: #364044;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 8px 22px rgba(43, 46, 51, 0.09);
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, transform 180ms var(--ease-out), background 160ms ease;
}

.all-games-back i { font-size: 25px; }
.all-games-back:hover { color: #17383b; border-color: var(--accent); background: #fff; transform: translateX(-2px); }
.all-games-back:active { transform: translateX(-2px) scale(.96); }

.all-games-kicker {
  display: block;
  margin-bottom: 3px;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .16em;
}

.all-games-heading h1 {
  margin: 0;
  font-size: clamp(30px, 3vw, 46px);
  letter-spacing: -.045em;
  line-height: 1;
}

.all-games-sort {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 9px 14px;
  border: 1px solid rgba(72, 184, 189, .18);
  border-radius: 999px;
  color: #566164;
  background: rgba(255, 255, 255, .52);
  font-size: 13px;
  font-weight: 750;
}

.all-games-sort i { color: var(--accent-dark); font-size: 18px; }

.all-games-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-content: start;
  gap: clamp(18px, 2.1vw, 34px) clamp(14px, 1.6vw, 26px);
  min-height: 0;
  padding: 30px 8px 42px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-color: rgba(72, 184, 189, .55) transparent;
  scrollbar-width: thin;
}

.all-games-tile {
  display: grid;
  min-width: 0;
  padding: 0;
  border: 0;
  color: var(--text);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.all-games-cover {
  display: block;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 4px solid transparent;
  border-radius: 12px;
  background: #dfe1e4;
  box-shadow: 0 9px 24px rgba(44, 47, 52, .14);
  transition: border-color 160ms ease, box-shadow 220ms ease, transform 220ms var(--ease-out);
}

.all-games-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.all-games-tile strong {
  margin: 10px 3px 0;
  overflow: hidden;
  font-size: clamp(14px, 1.1vw, 18px);
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.all-games-tile small {
  margin: 5px 3px 0;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.all-games-tile:hover .all-games-cover,
.all-games-tile.selected .all-games-cover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .96), 0 14px 30px rgba(22, 126, 138, .2);
  transform: translateY(-5px);
}

.all-games-tile.selected strong { color: #167e86; }

.toast {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: 88px;
  padding: 11px 18px;
  border-radius: 999px;
  color: #fff;
  background: rgba(31, 33, 36, 0.92);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
  font-size: 12px;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 180ms ease, transform 220ms var(--ease-out);
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 760px) {
  .library-shell { grid-template-rows: minmax(0, 1fr); }
  .console-home { grid-template-rows: clamp(390px, 60vh, 470px) auto; }
  .game-picker { transform: translateY(20px); }
  .game-rail {
    padding: 18px calc(50vw - clamp(160px, 15.5vw, 230px)) 22px;
  }
  .game-card { flex-basis: clamp(320px, 31vw, 460px); }
  .all-games-card { flex-basis: clamp(126px, 11vw, 170px); }
}

@media (max-width: 900px) {
  .console-topbar { padding-inline: 24px; }
  .console-wordmark { width: 118px; }
  .player-presence { max-width: 150px; }
  .player-chip { width: 40px; height: 40px; }
  .console-room { padding-inline: 11px; }
  .game-picker { grid-template-columns: 52px minmax(0, 1fr) 52px; }
  .edge-control { width: 40px; height: 66px; }
  .all-games-view { padding-inline: 26px; }
  .all-games-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 901px) and (max-width: 1400px) {
  .all-games-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

.deployment-notice {
  position: fixed; z-index: 1200; top: max(14px, env(safe-area-inset-top)); left: 50%;
  width: min(680px, calc(100vw - 32px)); transform: translateX(-50%); padding: 12px 18px;
  border: 1px solid rgba(255, 183, 77, .7); border-radius: 10px; color: #fff3dd;
  background: rgba(38, 28, 14, .94); box-shadow: 0 10px 32px rgba(0, 0, 0, .28);
  text-align: center; font-size: 14px;
}
