/* ===== TOKENS ===== */
:root {
  --bg:            #09090f;
  --surface:       #111119;
  --border:        #272736;
  --border-bright: #3a3a55;
  --fg:            #e8e8f2;
  --muted:         #5a5a72;
  --accent:        #d32f2f;
  --accent-dim:    #5c1615;
  --accent-text:   #ff8a80;
  --green:         #39d98a;
  --green-dim:     #1a6640;
  --danger:        #ff5454;
  --danger-dim:    #7a2020;
  --shadow:        3px 3px 0px #04040a;
  --shadow-deep:   5px 5px 0px #04040a;
  --radius:        8px;
  --font:          'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'SFMono-Regular', Consolas, monospace;
}

/* ===== RESET ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Critical: prevent CSS display from overriding [hidden] */
[hidden] {
  display: none !important;
}

/* ===== BASE ===== */
html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  padding: 2rem 1rem;
  background-image: radial-gradient(circle, #1a1a2e 1px, transparent 1px);
  background-size: 28px 28px;
}

body::before,
body::after {
  content: "";
  flex: 1;
}

#app {
  width: 100%;
  max-width: 640px;
  flex-shrink: 0;
}

/* ===== VIEWS ===== */
.view {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  animation: fadein 0.2s ease-out both;
}

@keyframes fadein {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}

/* ===== TYPOGRAPHY ===== */
h1, h2, h3 {
  font-weight: 800;
  letter-spacing: 0.03em;
  line-height: 1.1;
}

p { line-height: 1.55; }

.logo {
  font-size: clamp(1.8rem, 6vw, 2.8rem);
  text-align: center;
  color: var(--accent-text);
  padding-bottom: 2px;
}

.tagline {
  text-align: center;
  color: var(--muted);
  font-size: clamp(0.8rem, 2.5vw, 0.95rem);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  margin-top: -0.5rem;
}

.muted { color: var(--muted); }

.small {
  font-size: 0.82rem;
  word-break: break-all;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.5rem 0.75rem;
  background: rgba(255,84,84,0.08);
  border: 1px solid rgba(255,84,84,0.3);
  border-radius: var(--radius);
  text-align: center;
}

/* ===== CARD ===== */
.card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-deep);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card h2 {
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.65rem;
}

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

/* ===== INPUTS ===== */
.input {
  width: 100%;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 0.75rem 1rem;
  background: var(--bg);
  color: var(--fg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  text-align: center;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input::placeholder {
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 0.04em;
}

.input:focus {
  border-color: var(--accent-text);
  box-shadow: 0 0 0 3px rgba(255,138,128,0.2);
}

select.input {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e8e8f2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 1em;
  padding-right: 2.5rem;
  text-align: left;
}

select.input option {
  background: var(--surface);
  color: var(--fg);
}

/* ===== BUTTONS ===== */
.btn {
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  color: var(--fg);
  border: 1.5px solid var(--border-bright);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  min-height: 44px;
  transition: transform 0.07s ease-out, box-shadow 0.07s ease-out, opacity 0.12s;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent-text);
}

.btn-green:hover:not(:disabled) {
  border-color: var(--green);
}

.btn:active:not(:disabled) {
  transform: translate(3px, 3px);
  box-shadow: none;
}

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

#btn-fullscreen {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 9999;
  padding: 0.5rem 0.75rem;
  min-height: unset;
}

@media (max-width: 768px) {
  #btn-fullscreen {
    display: none !important;
  }
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-dim);
  box-shadow: 3px 3px 0px var(--accent-dim);
}

.btn-primary:active:not(:disabled) {
  box-shadow: none;
}

.btn-green {
  background: var(--green);
  color: #051410;
  border-color: var(--green-dim);
  box-shadow: 3px 3px 0px var(--green-dim);
}

.btn-green:active:not(:disabled) {
  box-shadow: none;
}

.btn-big {
  width: 100%;
  font-size: 1rem;
  padding: 1rem 1.5rem;
}

.btn-square {
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
  padding: 0;
  line-height: 1;
}

/* ===== GAME CODE / QR ===== */
.game-code {
  font-size: clamp(3rem, 14vw, 5rem);
  font-weight: 900;
  letter-spacing: 0.25em;
  color: var(--accent-text);
  text-shadow: 0 0 28px rgba(211,47,47,0.55);
  line-height: 1;
}

.qrcode {
  background: #fff;
  padding: 8px;
  border-radius: var(--radius);
  border: 2px solid var(--border-bright);
  display: inline-block;
  box-shadow: var(--shadow);
}

.lobby-card {
  cursor: pointer;
}

/* ===== QR OVERLAY ===== */
.qr-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.qr-overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface);
  border: 1.5px solid var(--border-bright);
  border-radius: var(--radius);
  box-shadow: var(--shadow-deep);
  padding: 3rem;
  max-width: min(90vw, 480px);
  text-align: center;
}

.qrcode-big {
  padding: 16px;
}

.qrcode-big canvas,
.qrcode-big img {
  width: min(70vw, 320px);
  height: min(70vw, 320px);
}

/* ===== CARDS & GRID ===== */

.lobby-card {
  padding: 2rem;
}

.join-url-big {
  font-size: clamp(1.2rem, 4vw, 1.8rem);
  font-weight: 800;
  color: var(--accent-text);
  word-break: break-all;
}

.game-code-small {
  font-size: 1rem;
  color: var(--muted);
}

.players-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  width: 100%;
  list-style: none;
}

.players-grid li {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  font-size: 1.1rem;
  gap: 0.8rem;
  font-weight: 700;
}

/* ===== LISTS ===== */
.result-list, .scoreboard-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.result-list li,
.scoreboard-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  font-size: clamp(0.85rem, 3.5vw, 1.05rem);
  gap: 0.75rem;
}

/* ===== ROUND COUNTER ===== */
.counter {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
}

.counter-value {
  font-size: 2.5rem;
  font-weight: 900;
  min-width: 3ch;
  text-align: center;
  color: var(--accent-text);
}

/* ===== ROUND VIEW ===== */
.round-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.round-header h1 {
  font-size: clamp(1.1rem, 3.5vw, 1.6rem);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.timer {
  font-size: clamp(1.5rem, 5.5vw, 2.4rem);
  font-weight: 900;
  background: var(--surface);
  border: 1.5px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 0.3rem 0.9rem;
  box-shadow: var(--shadow);
  min-width: 5ch;
  text-align: center;
  letter-spacing: 0.05em;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}

.timer.urgent {
  color: var(--danger);
  border-color: var(--danger-dim);
  animation: pulse-danger 0.5s ease-in-out infinite alternate;
}

@keyframes pulse-danger {
  from { box-shadow: 3px 3px 0 #04040a; }
  to   { box-shadow: 3px 3px 0 var(--danger-dim), 0 0 12px rgba(255,84,84,0.3); }
}

.scenario {
  border-left: 3px solid var(--accent);
}

.scenario p {
  font-size: clamp(1rem, 3vw, 1.35rem);
  line-height: 1.6;
}

.big-counter {
  font-size: clamp(2.5rem, 9vw, 4rem);
  font-weight: 900;
  color: var(--accent-text);
  line-height: 1;
}

#guess-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(57,217,138,0.2);
}

/* ===== ROUND RESULT ===== */
.answer {
  font-size: clamp(1.8rem, 7vw, 2.8rem);
  font-weight: 900;
  color: var(--green);
  letter-spacing: 0.06em;
  text-shadow: 0 0 20px rgba(57,217,138,0.4);
  word-break: break-all;
  line-height: 1.1;
}

.score-pill {
  background: var(--accent-dim);
  color: var(--accent-text);
  font-size: 0.78rem;
  font-weight: 800;
  padding: 0.18rem 0.5rem;
  border-radius: 4px;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.score-pill.high {
  background: var(--green-dim);
  color: var(--green);
}

/* ===== SCOREBOARD ===== */
.scoreboard-list li {
  font-size: clamp(1.2rem, 4vw, 1.5rem);
}

.scoreboard-list li .rank-num {
  color: var(--muted);
  font-size: clamp(1rem, 3.5vw, 1.3rem);
  min-width: 2.5rem;
}

.scoreboard-list li.rank-1 {
  border-color: var(--accent);
  background: rgba(211,47,47,0.07);
  color: var(--accent-text);
  font-weight: 800;
}

.scoreboard-list li.rank-1 .rank-num {
  color: var(--accent-text);
}

/* ===== MISC ===== */
.blink {
  text-align: center;
  letter-spacing: 0.04em;
  animation: blink 1.8s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

.submitted-banner {
  text-align: center;
  color: var(--green);
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 0.9rem;
  padding: 0.6rem;
  background: rgba(57,217,138,0.07);
  border: 1px solid rgba(57,217,138,0.25);
  border-radius: var(--radius);
}

#waiting-nickname-status {
  font-size: 0.85rem;
  color: var(--green);
}

/* ===== CONFETTI ===== */
#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 999;
}
