/* ═══════════════════════════════════════════════
   Spyfall Webapp — TgPlay Dark Theme
   Accent: Gold (#d4af37)
   ═══════════════════════════════════════════════ */

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

:root {
  --bg: #0a0a0f;
  --bg-soft: #111119;
  --card: #16161f;
  --surface: #1c1c28;
  --text: #e8e6df;
  --dim: #8a8880;
  --muted: #5a5850;
  --accent: #d4af37;
  --accent-dim: #8a7126;
  --accent-glow: rgba(212, 175, 55, 0.15);
  --green: #3fb950;
  --red: #c23b3b;
  --blue: #58a6ff;
  --border: rgba(212, 175, 55, 0.12);
  --border-subtle: rgba(255, 255, 255, 0.06);
  --font: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', 'Menlo', monospace;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body {
  background-image:
    radial-gradient(ellipse at 15% 5%, rgba(212,175,55,0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 90%, rgba(194,59,59,0.04) 0%, transparent 50%);
  background-attachment: fixed;
}

/* ── App Container ────────────────────────────── */
#app {
  position: relative;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ── Screens ──────────────────────────────────── */
.screen {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 20px 16px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.active {
  opacity: 1;
  pointer-events: auto;
  z-index: 1;
}

/* ── Typography ───────────────────────────────── */
h1 { font-size: 28px; font-weight: 900; color: var(--accent); letter-spacing: -0.5px; }
h2 { font-size: 20px; font-weight: 800; color: var(--text); }
h3 { font-size: 16px; font-weight: 700; color: var(--text); }
.subtitle { font-size: 13px; color: var(--dim); font-family: var(--mono); letter-spacing: 1px; text-transform: uppercase; }
.meta { font-size: 12px; color: var(--muted); }
.gold { color: var(--accent); }
.green { color: var(--green); }
.red { color: var(--red); }

/* ── Header Bar ───────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-top: 8px;
}
.header .back-btn {
  width: 36px; height: 36px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--accent);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.header .back-btn:hover { background: var(--card); }
.header h2 { flex: 1; }

/* ── Cards ────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  transition: border-color 0.15s;
}
.card:hover { border-color: rgba(212,175,55,0.25); }
.card-flat {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 10px;
}

/* ── Buttons ──────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border-radius: 12px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s;
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: #1a1408;
  box-shadow: 0 4px 16px rgba(212,175,55,0.3);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 6px 20px rgba(212,175,55,0.4); }

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent-dim);
}
.btn-outline:hover:not(:disabled) { background: var(--accent-glow); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1.5px solid rgba(194,59,59,0.3);
}

.btn-green {
  background: var(--green);
  color: #0a1a0a;
}

.btn-block { display: flex; width: 100%; }
.btn-sm { padding: 10px 16px; font-size: 13px; border-radius: 10px; }
.btn-lg { padding: 18px 32px; font-size: 17px; }

/* ── Stats Chips ──────────────────────────────── */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 16px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  text-align: center;
  min-width: 90px;
  flex-shrink: 0;
}
.chip-value {
  font-size: 20px;
  font-weight: 900;
  color: var(--accent);
  line-height: 1.2;
}
.chip-label {
  font-size: 11px;
  color: var(--dim);
  margin-top: 2px;
}

/* ── Player List ──────────────────────────────── */
.player-list { list-style: none; }
.player-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  transition: border-color 0.15s;
}
.player-item.is-you { border-color: var(--accent-dim); }
.player-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: #1a1408;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}
.player-name { flex: 1; font-weight: 600; }
.player-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 600;
}
.badge-creator { background: var(--accent-glow); color: var(--accent); }
.badge-spy { background: rgba(194,59,59,0.15); color: var(--red); }
.badge-voted { background: rgba(63,185,80,0.15); color: var(--green); }

/* ── Role Card ────────────────────────────────── */
.role-card {
  background: linear-gradient(135deg, var(--card) 0%, var(--surface) 100%);
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 28px 20px;
  text-align: center;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}
.role-card.spy {
  border-color: rgba(194,59,59,0.3);
  background: linear-gradient(135deg, #1a1015 0%, #1c1020 100%);
}
.role-emoji { font-size: 56px; line-height: 1; margin-bottom: 12px; }
.role-title { font-size: 22px; font-weight: 900; margin-bottom: 4px; }
.role-sub { font-size: 14px; color: var(--dim); }

/* ── Timer ────────────────────────────────────── */
.timer {
  text-align: center;
  margin: 16px 0;
}
.timer-value {
  font-size: 48px;
  font-weight: 900;
  font-family: var(--mono);
  color: var(--accent);
  letter-spacing: 2px;
}
.timer-value.danger { color: var(--red); animation: pulse 1s infinite; }
.timer-label { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: 2px; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ── Locations Grid ───────────────────────────── */
.loc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}
.loc-item {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.loc-item:hover { border-color: var(--accent-dim); background: var(--card); }
.loc-item.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.loc-item.correct { border-color: var(--green); background: rgba(63,185,80,0.1); }
.loc-item.wrong { border-color: var(--red); background: rgba(194,59,59,0.1); }

/* ── Achievements ─────────────────────────────── */
.ach-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.ach-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 6px 8px;
  text-align: center;
  transition: border-color 0.15s;
}
.ach-item:not(.locked) { border-color: rgba(212,175,55,0.25); }
.ach-item.locked { opacity: 0.35; }
.ach-emoji { font-size: 22px; display: block; margin-bottom: 6px; }
.ach-name { font-size: 11px; font-weight: 700; line-height: 1.3; }
.ach-desc { font-size: 10px; color: var(--dim); margin-top: 3px; line-height: 1.3; }

/* ── Leaderboard ──────────────────────────────── */
.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
}
.lb-row:last-child { border-bottom: none; }
.lb-rank {
  width: 28px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 14px;
  color: var(--accent-dim);
  text-align: center;
  flex-shrink: 0;
}
.lb-rank.top { color: var(--accent); font-size: 16px; }
.lb-name { flex: 1; font-weight: 600; }
.lb-value { font-family: var(--mono); font-weight: 600; color: var(--accent); }

/* ── Vote Bar ─────────────────────────────────── */
.vote-bar {
  height: 6px;
  background: var(--surface);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}
.vote-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* ── Toast ─────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  z-index: 100;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  box-shadow: var(--shadow);
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Loading Spinner ──────────────────────────── */
.spinner-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 16px;
}
.spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Auth Screen ──────────────────────────────── */
.auth-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  text-align: center;
  gap: 16px;
}
.auth-emoji { font-size: 80px; line-height: 1; filter: drop-shadow(0 0 24px rgba(212,175,55,0.3)); }
.auth-title { font-size: 42px; font-weight: 900; color: var(--accent); letter-spacing: -1px; }
.auth-sub { color: var(--dim); font-family: var(--mono); font-size: 13px; letter-spacing: 2px; text-transform: uppercase; }

/* ── Menu Screen ──────────────────────────────── */
.menu-hero {
  text-align: center;
  padding: 24px 0 16px;
}
.menu-avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dim) 100%);
  color: #1a1408;
  display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 26px; font-weight: 900;
  margin-bottom: 10px;
}
.menu-name { font-size: 20px; font-weight: 800; }
.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}
.menu-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  text-decoration: none;
  color: var(--text);
}
.menu-btn:hover { border-color: rgba(212,175,55,0.3); }
.menu-btn:active { transform: scale(0.97); }
.menu-btn-icon { font-size: 28px; display: block; margin-bottom: 6px; }
.menu-btn-label { font-size: 13px; font-weight: 700; }

/* ── Game Code Input ──────────────────────────── */
.code-input {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}
.code-input input {
  flex: 1;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 18px;
  padding: 14px 16px;
  text-align: center;
  letter-spacing: 3px;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.15s;
}
.code-input input:focus { border-color: var(--accent); }
.code-input input::placeholder {
  color: var(--muted);
  letter-spacing: 1px;
  font-size: 14px;
}

/* ── Invite Link ──────────────────────────────── */
.invite-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}
.invite-box code {
  flex: 1;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  word-break: break-all;
}
.invite-box .copy-btn {
  background: var(--accent-glow);
  border: none;
  color: var(--accent);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Result Screen ────────────────────────────── */
.result-hero {
  text-align: center;
  padding: 32px 0 16px;
}
.result-emoji { font-size: 64px; line-height: 1; margin-bottom: 12px; }
.result-title { font-size: 24px; font-weight: 900; margin-bottom: 4px; }
.result-sub { color: var(--dim); font-size: 14px; }

/* ── Section Divider ──────────────────────────── */
.section-title {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent-dim);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin: 20px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Rules Screen ─────────────────────────────── */
.rule-step {
  display: flex;
  gap: 14px;
  margin-bottom: 16px;
}
.rule-num {
  width: 32px; height: 32px;
  background: var(--accent-glow);
  border: 1px solid var(--accent-dim);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--accent);
  font-size: 14px;
  flex-shrink: 0;
}
.rule-text { flex: 1; }
.rule-text strong { color: var(--accent); }

/* ── Mobile ───────────────────────────────────── */
@media (max-width: 480px) {
  .screen { padding: 16px 14px 24px; }
  h1 { font-size: 24px; }
  .auth-title { font-size: 36px; }
  .auth-emoji { font-size: 64px; }
  .timer-value { font-size: 40px; }
  .menu-grid { gap: 8px; }
  .menu-btn { padding: 16px 10px; }
}

/* ── Safe area (notch) ────────────────────────── */
@supports (padding-top: env(safe-area-inset-top)) {
  .screen { padding-top: calc(16px + env(safe-area-inset-top)); }
}
