:root {
  /* Dark theme (default) */
  --bg: radial-gradient(circle at top right, #1e1b4b, #0f172a 60%);
  --panel: rgba(30, 41, 59, 0.45);
  --panel-2: rgba(15, 23, 42, 0.55);
  --line: rgba(255, 255, 255, 0.08);
  --text: #f8fafc;
  --text-dim: #94a3b8;
  --teal: #10b981;
  --teal-glow: rgba(16, 185, 129, 0.25);
  --coral: #ef4444;
  --amber: #f59e0b;
  --primary: #6366f1;
  --primary-glow: rgba(99, 102, 241, 0.3);
  --primary-grad: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  --btn-shadow: 0 4px 14px 0 rgba(99, 102, 241, 0.35);
  --radius: 20px;
  --inner-radius: 12px;
  --shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.5);
  --font-main: 'Outfit', system-ui, sans-serif;
}

[data-theme="light"] {
  /* Light theme */
  --bg: radial-gradient(circle at top right, #e2e8f0, #f8fafc 70%);
  --panel: rgba(255, 255, 255, 0.7);
  --panel-2: rgba(241, 245, 249, 0.8);
  --line: rgba(0, 0, 0, 0.08);
  --text: #0f172a;
  --text-dim: #64748b;
  --teal: #059669;
  --teal-glow: rgba(5, 150, 105, 0.15);
  --coral: #dc2626;
  --amber: #d97706;
  --primary: #4f46e5;
  --primary-glow: rgba(79, 70, 229, 0.15);
  --primary-grad: linear-gradient(135deg, #4f46e5 0%, #3730a3 100%);
  --btn-shadow: 0 4px 14px 0 rgba(79, 70, 229, 0.2);
  --shadow: 0 20px 40px -15px rgba(148, 163, 184, 0.15);
}

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

body {
  min-height: 100vh;
  background: var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-main);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px 16px;
  transition: background 0.3s ease, color 0.3s ease;
}

.wrap {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Header/Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  margin-bottom: 5px;
}

.topbar .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 12px var(--teal);
}

.topbar h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--text) 50%, var(--text-dim) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.topbar .sub {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-left: 10px;
  padding: 4px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 99px;
}

/* Screen animations */
.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Card layout */
.card {
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 30px 24px;
  box-shadow: var(--shadow);
  transition: background 0.3s ease, border-color 0.3s ease;
}

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

/* Field label */
.field-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--text-dim);
  margin: 0 0 10px 4px;
  font-weight: 700;
  display: block;
  text-align: left;
}

.card.center .field-label {
  text-align: center;
}

/* Inputs */
input[type="text"], input[type="number"] {
  width: 100%;
  background: var(--panel-2);
  border: 1.5px solid var(--line);
  color: var(--text);
  padding: 14px 16px;
  border-radius: var(--inner-radius);
  font-size: 16px;
  font-family: inherit;
  font-weight: 500;
  margin-bottom: 18px;
  outline: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
  background: var(--panel);
}

.mono-input {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: .25em;
  text-align: center;
  text-transform: uppercase;
  padding-left: 20px; /* offset letter-spacing on right */
}

/* Divider */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* Buttons */
.stack {
  display: flex;
  flex-direction: column;
}

.btn {
  border: none;
  border-radius: var(--inner-radius);
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.1s ease, filter 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary-grad);
  color: #ffffff;
  box-shadow: var(--btn-shadow);
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: var(--btn-shadow), 0 0 15px var(--primary-glow);
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--line);
}

.btn-outline:hover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.05);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-dim);
  border: 1px solid var(--line);
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--line-focus);
}

/* Theme Toggle Button */
.btn-theme {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background-color 0.15s, transform 0.1s;
  margin-left: auto;
}

.btn-theme:hover {
  color: var(--text);
  background: var(--panel);
  transform: rotate(15deg);
}

.sun-icon { display: none; }
.moon-icon { display: block; }

[data-theme="light"] .sun-icon { display: block; }
[data-theme="light"] .moon-icon { display: none; }

/* Text helper styles */
.error-text {
  color: var(--coral);
  font-size: 13px;
  font-weight: 600;
  min-height: 18px;
  margin-top: 12px;
  text-align: center;
}

.hint-text {
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 500;
  margin: 6px 0 16px;
  line-height: 1.4;
}

/* Spinner */
.spinner {
  width: 28px;
  height: 28px;
  border: 3.5px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 8px auto 20px;
  animation: spin 0.8s cubic-bezier(0.5, 0.1, 0.4, 0.9) infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Setup Room Code Display */
.room-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 46px;
  font-weight: 800;
  letter-spacing: .2em;
  background: linear-gradient(135deg, var(--teal) 30%, #00f2fe 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 10px 0 18px;
  text-shadow: 0 0 20px var(--teal-glow);
  padding-left: 10px;
}

/* Setup big digit inputs */
.big-number-input {
  font-family: 'JetBrains Mono', monospace;
  font-size: 38px;
  font-weight: 800;
  text-align: center;
  padding: 16px;
  border-radius: var(--inner-radius);
  max-width: 180px;
  margin: 0 auto 18px;
  letter-spacing: 0.05em;
}

/* Scoreboard */
.scoreboard {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.player-chip {
  flex: 1;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--inner-radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#chip-me.active-turn {
  border-color: var(--primary);
  box-shadow: 0 0 15px var(--primary-glow);
  background: rgba(99, 102, 241, 0.06);
}

#chip-opp.active-turn {
  border-color: var(--amber);
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.3);
  background: rgba(245, 158, 11, 0.06);
}

.chip-name {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.chip-role {
  font-size: 12px;
  color: var(--text-dim);
}

.vs {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 800;
  background: var(--panel-2);
  border: 1px solid var(--line);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Turn Banner */
.turn-banner {
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--primary);
  font-weight: 700;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: var(--inner-radius);
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  transition: background 0.3s ease;
}

.turn-banner.waiting {
  color: var(--text-dim);
  background: var(--panel-2);
}

/* Digit Display */
.digit-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: 700;
}

.digit-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 64px;
  font-weight: 800;
  background: var(--panel-2);
  border: 1.5px solid var(--line);
  border-radius: var(--inner-radius);
  padding: 16px 0;
  margin-bottom: 16px;
  color: var(--text);
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.2);
}

/* Feedback badge */
.feedback-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 auto 20px;
  padding: 8px 20px;
  border-radius: 99px;
  font-weight: 800;
  font-size: 13.5px;
  letter-spacing: .05em;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.feedback-badge.up {
  background: rgba(245, 158, 11, 0.15);
  color: var(--amber);
  border: 1px solid rgba(245, 158, 11, 0.25);
}

.feedback-badge.down {
  background: rgba(239, 68, 68, 0.15);
  color: var(--coral);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.feedback-badge.correct {
  background: rgba(16, 185, 129, 0.15);
  color: var(--teal);
  border: 1px solid rgba(16, 185, 129, 0.25);
}

/* Guess Row Input Form */
.guess-row {
  display: flex;
  gap: 10px;
}

.guess-row input {
  margin-bottom: 0;
  text-align: center;
  font-weight: 700;
}

/* Waiting for opponent turn container */
.waiting-turn-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--panel-2);
  border: 1.5px solid var(--line);
  padding: 13px 14px;
  border-radius: var(--inner-radius);
  color: var(--text-dim);
  font-size: 14.5px;
  font-weight: 600;
  animation: pulse 2s infinite ease-in-out;
}

.spinner-small {
  width: 16px;
  height: 16px;
  border: 2.5px solid var(--line);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Split History Container & Column Variants */
.history-split {
  display: flex;
  gap: 12px;
  margin-top: 22px;
}

.history-col {
  flex: 1;
  border: 1.5px solid var(--line);
  border-radius: var(--inner-radius);
  padding: 14px 12px;
  transition: border-color 0.3s, background 0.3s;
}

.history-col-mine {
  border-color: rgba(99, 102, 241, 0.2);
  background: rgba(99, 102, 241, 0.02);
}

.history-col-mine .history-col-title {
  color: var(--primary);
  border-bottom: 1.5px solid rgba(99, 102, 241, 0.15);
}

.history-col-opp {
  border-color: rgba(245, 158, 11, 0.2);
  background: rgba(245, 158, 11, 0.02);
}

.history-col-opp .history-col-title {
  color: var(--amber);
  border-bottom: 1.5px solid rgba(245, 158, 11, 0.15);
}

.history-col-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 0 0 12px;
  font-weight: 800;
  text-align: center;
  padding-bottom: 8px;
}

.history-col .history {
  margin-top: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.history-chip {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text-dim);
  transition: all 0.2s ease;
}

.history-chip.mine {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(99, 102, 241, 0.08);
}

.history-chip.opp {
  border-color: var(--amber);
  color: var(--amber);
  background: rgba(245, 158, 11, 0.08);
}

/* Detailed feedback information */
.feedback-detail {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.45;
  margin: -10px auto 18px;
  max-width: 320px;
  text-align: center;
  padding: 0 10px;
}

.feedback-detail.up {
  color: var(--amber);
}

.feedback-detail.down {
  color: var(--coral);
}

.feedback-detail.correct {
  color: var(--teal);
}

/* Victory Popup overlay */
.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 999;
}

.popup-overlay.active {
  display: flex;
}

.popup-card {
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 24px;
  padding: 40px 28px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.popup-emoji {
  font-size: 52px;
  margin-bottom: 12px;
  animation: float 2s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.popup-card h2 {
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--text) 60%, var(--primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.popup-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

.popup-actions .btn {
  flex: 1;
}

/* Responsiveness on Phone Screens */
@media (max-width: 480px) {
  body {
    padding: 24px 12px;
  }
  
  .card {
    padding: 24px 18px;
  }

  .room-code {
    font-size: 38px;
  }

  .digit-display {
    font-size: 52px;
  }

  .history-split {
    flex-direction: column;
    gap: 12px;
  }
}
