:root {
  color-scheme: dark;
  --bg: #0b1020;
  --panel: #151c31;
  --panel-soft: #1b2440;
  --primary: #4f46e5;
  --accent: #16a34a;
  --danger: #dc2626;
  --text: #f8fafc;
  --muted: #94a3b8;
  --border: #334155;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(circle at top, #1e293b 0%, var(--bg) 45%);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
}

.card {
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.75), rgba(21, 28, 49, 0.92));
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.2rem;
  box-shadow: 0 15px 45px rgba(2, 6, 23, 0.35);
}

#auth-card {
  max-width: 460px;
  margin: 10vh auto 0;
}

h1, h2, h3, p {
  margin: 0;
}

h1 {
  font-size: 2rem;
}

h2 {
  font-size: 1.3rem;
}

.subtle {
  color: var(--muted);
  margin-top: 0.4rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 1rem;
}

label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
}

input {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 0.8rem 0.9rem;
  font-size: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

#room-code {
  text-align: center;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 1.2rem;
}

.tab {
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
  border-radius: 12px;
  padding: 0.7rem;
  cursor: pointer;
}

.tab.active {
  background: var(--primary);
  border-color: var(--primary);
}

.pane {
  margin-top: 1rem;
}

.hidden {
  display: none !important;
}

.btn {
  width: 100%;
  border: 0;
  border-radius: 999px;
  color: white;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.9rem 1rem;
  cursor: pointer;
  margin-top: 0.8rem;
  transition: transform 0.14s ease, filter 0.2s ease, opacity 0.2s ease;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn:active {
  transform: translateY(1px) scale(0.99);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--primary);
}

.btn.accent {
  background: var(--accent);
}

.btn.danger {
  background: var(--danger);
}

.btn.secondary {
  background: #475569;
}

.layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
}

.scoreboard-wrap {
  height: fit-content;
}

.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  border-radius: 12px;
  padding: 0.55rem 0.75rem;
  margin-top: 0.6rem;
}

.score-row.buzzed {
  border-color: var(--primary);
}

.score-name {
  font-weight: 700;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.room-code-display {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  color: var(--text);
  line-height: 1;
}

.room-code-frame {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem 1rem 0.8rem;
  background: rgba(15, 23, 42, 0.45);
  display: inline-block;
}

.room-code-label {
  position: absolute;
  top: -0.48rem;
  left: 0.7rem;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--muted);
  background: #111827;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
}

.host-top {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}

.host-open-wrap {
  margin-top: 1rem;
  text-align: center;
}

.host-open-wrap .subtle {
  margin-top: 0.75rem;
}

.host-open-buzzer {
  width: min(92vw, 340px);
  height: min(92vw, 340px);
  margin: 0 auto;
  border-radius: 50%;
  border: 10px solid #312e81;
  box-shadow: 0 16px 36px rgba(79, 70, 229, 0.4);
  display: grid;
  place-items: center;
  font-size: clamp(1.1rem, 2.7vw, 1.5rem);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.host-open-buzzer:active {
  transform: translateY(1px) scale(0.98);
}

.buzzer {
  width: 270px;
  height: 270px;
  border-radius: 50%;
  border: 10px solid #0f172a;
  margin: 1.2rem auto;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.buzzer.ready {
  background: #dc2626;
}

.buzzer.winner {
  background: var(--accent);
}

.buzzer.locked {
  background: #334155;
}

.player-center {
  text-align: center;
}

.top-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.top-actions .btn {
  width: auto;
  margin-top: 0;
  padding: 0.65rem 1rem;
}

.icon-btn {
  width: 46px !important;
  height: 46px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.mobile-nav {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: min(94vw, 460px);
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem;
  z-index: 30;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  display: none;
  gap: 0.35rem;
}

.mobile-nav-btn {
  flex: 1;
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 0.8rem;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.mobile-nav-btn.active {
  background: var(--primary);
  color: #fff;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #020617;
  border: 1px solid var(--border);
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  max-width: 300px;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 40;
  animation: modal-fade-in 0.18s ease;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.7);
}

.modal-card {
  position: relative;
  width: min(92vw, 440px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.9rem;
  z-index: 1;
  max-height: min(86vh, 560px);
  overflow: hidden;
  animation: modal-slide-up 0.2s ease;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.modal-close-btn {
  width: auto;
  margin-top: 0;
  padding: 0.5rem 0.9rem;
}

.invite-qr-wrap {
  margin-top: 0.75rem;
  padding: 0.55rem;
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: grid;
  place-items: center;
}

.invite-qr {
  width: min(100%, 210px);
  height: auto;
  border-radius: 10px;
  background: #fff;
  padding: 0.35rem;
}

.copy-row {
  position: relative;
  display: block;
}

.copy-row input {
  width: 100%;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-align: center;
  padding-right: 3rem;
}

.copy-btn {
  width: 42px;
  height: 42px;
  margin-top: 0;
  padding: 0;
}

.icon-inside-input {
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  border-radius: 10px;
}

.icon-inside-input svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.no-scroll {
  overflow: hidden;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-slide-up {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 850px) {
  .app {
    padding: 0.7rem 0.7rem 1.1rem;
  }

  .card {
    border-radius: 16px;
    padding: 1rem;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .layout.show-score-mobile #main-view {
    display: none;
  }

  .layout.show-main-mobile #score-panel {
    display: none;
  }

  .room-code-display {
    font-size: 2.3rem;
  }

  .top-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .top-actions .btn {
    width: 100%;
  }

  .top-actions .btn:last-child {
    grid-column: 1 / -1;
  }

  .mobile-nav {
    display: flex;
  }

  .host-open-buzzer {
    width: min(88vw, 300px);
    height: min(88vw, 300px);
  }
}
