/* Chai Chaos — Apple-keynote-style design system.
   Mobile first. Pure black, big type, gradient accents, smooth fades. */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

:root {
  --bg: #000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --text: #f5f5f7;
  --muted: #a1a1a6;
  --line: rgba(255, 255, 255, 0.1);
  --accent: #ff9f0a; /* per-game accent may override this */
  --grad: linear-gradient(90deg, #ff2d92 0%, #ff6a3d 45%, #ffd60a 100%);
  --radius: 28px;
  --radius-sm: 16px;
  --tap: 48px;
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 40px;
  --space-5: 64px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Inter',
    'Helvetica Neue', Helvetica, Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Layout ---------- */

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding:
    calc(var(--space-4) + var(--safe-top))
    calc(var(--space-3) + var(--safe-right))
    calc(var(--space-4) + var(--safe-bottom))
    calc(var(--space-3) + var(--safe-left));
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-2);
  padding: var(--space-5) 0 var(--space-4);
}

/* ---------- Type ---------- */

.title {
  margin: 0;
  font-size: clamp(40px, 11vw, 96px);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -0.045em;
}

/* Gradient-clipped accent text: <span class="title"><span class="grad">Chaos</span></span>
   or simply .title.grad */
.grad,
.title em {
  font-style: normal;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.subtitle {
  margin: 0;
  font-size: clamp(19px, 4.6vw, 28px);
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.015em;
  color: var(--muted);
  max-width: 34ch;
}

/* ---------- Surfaces ---------- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  border: 1px solid var(--line);
}

.card h2,
.card h3 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.card p { margin: 0; color: var(--muted); }

a.card,
button.card {
  color: inherit;
  text-decoration: none;
  text-align: left;
  cursor: pointer;
  transition: transform 0.35s var(--ease), background 0.35s var(--ease);
}
a.card:hover,
button.card:hover { background: var(--surface-2); }
a.card:active,
button.card:active { transform: scale(0.97); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr));
  gap: var(--space-2);
}
@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: 56px;
  min-width: var(--tap);
  padding: 0 32px;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: transform 0.25s var(--ease), opacity 0.25s var(--ease), background 0.25s var(--ease);
}
.btn:active { transform: scale(0.96); }
.btn:disabled,
.btn[aria-disabled='true'] { opacity: 0.35; cursor: not-allowed; transform: none; }
.btn:focus-visible,
.choice:focus-visible,
.card:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.btn-primary { background: #fff; color: #000; }
.btn-primary:hover { background: #e8e8ed; }

.btn-ghost {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.2); }

.btn-block { width: 100%; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0;
  white-space: nowrap;
}

/* ---------- Game bits ---------- */

@property --p { syntax: '<number>'; inherits: true; initial-value: 1; }

/* Big circular countdown. Set --p (0–1 remaining) inline to drive the ring:
   <div class="timer" style="--p:.6">12</div> */
.timer {
  --p: 1;
  --size: min(56vw, 220px);
  width: var(--size);
  height: var(--size);
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
  isolation: isolate;
  font-size: calc(var(--size) * 0.36);
  font-weight: 800;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  background:
    conic-gradient(var(--accent) calc(var(--p) * 360deg), var(--surface) 0);
  transition: --p 1s linear;
}
.timer::before {
  content: '';
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: var(--bg);
  z-index: -1;
}
.timer.urgent { --accent: #ff453a; animation: pulse 1s var(--ease) infinite; }

.player-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 6px 18px 6px 6px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-weight: 600;
  max-width: 100%;
}
.player-chip .emoji {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 20px;
  line-height: 1;
  flex: none;
}
.player-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.big-code {
  font-size: clamp(64px, 22vw, 160px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  text-align: center;
  text-transform: uppercase;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  user-select: all;
}

.choice {
  appearance: none;
  width: 100%;
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: 22px;
  background: var(--surface);
  border: 2px solid transparent;
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: left;
  cursor: pointer;
  transition: transform 0.25s var(--ease), background 0.25s var(--ease), border-color 0.25s var(--ease);
}
.choice:hover { background: var(--surface-2); }
.choice:active { transform: scale(0.98); }
.choice.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
}
.choice.selected::after { content: '✓'; margin-left: auto; color: var(--accent); font-weight: 800; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--space-3) + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 1000;
  max-width: calc(100% - 2 * var(--space-3));
  padding: 14px 22px;
  border-radius: 999px;
  background: rgba(44, 44, 46, 0.92);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.5s var(--ease) both;
}

/* ---------- Motion ---------- */

.fade-in { animation: fade-in 0.7s var(--ease) both; }
.fade-in:nth-child(2) { animation-delay: 0.06s; }
.fade-in:nth-child(3) { animation-delay: 0.12s; }
.fade-in:nth-child(4) { animation-delay: 0.18s; }
.fade-in:nth-child(5) { animation-delay: 0.24s; }
.fade-in:nth-child(n + 6) { animation-delay: 0.3s; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(24px); filter: blur(4px); }
  to { opacity: 1; transform: none; filter: none; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes pulse {
  50% { transform: scale(1.04); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .fade-in { transform: none; filter: none; }
}

/* Lobby game-picker category tabs: one horizontally scrollable row of pills */
.cat-tabs {
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
  scrollbar-width: none;
  margin-bottom: var(--space-2);
  -webkit-overflow-scrolling: touch;
}
.cat-tabs::-webkit-scrollbar { display: none; }
.cat-tabs .pill {
  flex: none;
  min-height: var(--tap);
  padding: 0 var(--space-2);
  border: 1px solid var(--line);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s var(--ease), color 0.3s var(--ease);
}
.cat-tabs .pill.selected {
  background: var(--text);
  color: var(--bg);
  border-color: transparent;
}

/* Lobby game search, sits above the game grid */
.game-search {
  display: block;
  width: 100%;
  min-height: 52px;
  margin-bottom: var(--space-2);
  padding: 0 var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 17px;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.3s var(--ease);
}
.game-search::placeholder { color: var(--muted); }
.game-search:focus { outline: none; border-color: var(--muted); }
.game-search-empty { grid-column: 1 / -1; text-align: center; }
