:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --ink: #16171c;
  --muted: #6a6e78;
  --line: #e4e2dc;
  --brand: #2f2fd8;
  --brand-ink: #ffffff;
  --brand-soft: #e7e7fb;
  --ok: #0e9f4f;
  --warn-bg: #fff3d6;
  --warn-ink: #7a4b00;
  --danger: #d23333;
  --free-bg: #dcf5e6;
  --free-ink: #0a6b36;
  --turn: #0e9f4f;
  --turn-2: #0b7d3e;
  --radius: 18px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px rgb(0 0 0 / 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111216;
    --surface: #1b1c22;
    --ink: #f1f1f3;
    --muted: #a0a3ad;
    --line: #2c2e36;
    --brand: #7b7bff;
    --brand-ink: #0d0d1a;
    --brand-soft: #24244a;
    --warn-bg: #3a2e12;
    --warn-ink: #ffd88a;
    --free-bg: #12341f;
    --free-ink: #7fe0a6;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1 { font-size: 1.9rem; line-height: 1.15; margin: 0.2em 0 0.4em; letter-spacing: -0.02em; }
.muted { color: var(--muted); font-weight: 400; }
.lead { color: var(--muted); font-size: 1.05rem; }
.hint { color: var(--muted); font-size: 0.92rem; text-align: center; margin-top: 18px; }
.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.wrap {
  max-width: 460px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.wrap > section { flex: 1; display: flex; flex-direction: column; }
.center { justify-content: center; text-align: center; align-items: center; }
.topbar { padding: 4px 0 20px; }
.logo { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.logo b { color: var(--brand); }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
label { display: block; font-weight: 600; margin-bottom: 8px; }
input {
  width: 100%;
  font: inherit;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  margin-bottom: 16px;
}
input:focus { outline: none; border-color: var(--brand); }

.btn {
  font: inherit;
  font-weight: 650;
  border: 0;
  border-radius: 14px;
  padding: 14px 20px;
  cursor: pointer;
  transition: transform 0.08s, opacity 0.15s;
}
a.btn { display: inline-block; text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; color: var(--muted); text-decoration: underline; }
.btn.light { background: #fff; color: var(--turn-2); }
.btn.big { width: 100%; padding: 18px 20px; font-size: 1.1rem; }

.status {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 10px;
  margin: 8px 0 22px;
}
.status-text { flex-basis: 100%; color: var(--muted); }
.status.free {
  flex-direction: column;
  align-items: flex-start;
  background: var(--free-bg);
  color: var(--free-ink);
  border-radius: var(--radius);
  padding: 22px 20px;
}
.status.free .status-title { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.02em; }
.status.free .status-text { color: inherit; font-size: 1.15rem; font-weight: 600; }
.stat-n { font-size: 2.6rem; font-weight: 750; letter-spacing: -0.03em; }
.stat-label { color: var(--muted); font-size: 1.1rem; }
#join-anyway { align-self: center; }

/* Waiting screen */
.ticket {
  margin: 14px 0 18px;
  background: var(--brand);
  color: var(--brand-ink);
  border-radius: 24px;
  padding: 24px 20px 26px;
  text-align: center;
  display: flex;
  flex-direction: column;
}
.ticket-label { font-size: 0.85rem; font-weight: 600; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.08em; }
.ticket-number { font-size: 6rem; font-weight: 800; line-height: 1; letter-spacing: -0.04em; margin-top: 6px; }
.ticket-name { opacity: 0.85; min-height: 1.2em; margin-top: 6px; }
.ahead {
  text-align: center;
  margin: 0 0 16px;
  font-size: 1.2rem;
  font-weight: 650;
}
.banner {
  display: block;
  width: 100%;
  border: 0;
  font: inherit;
  font-weight: 600;
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
  text-align: center;
}
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner.action { background: var(--brand-soft); color: var(--brand); cursor: pointer; }
.banner.ok { background: var(--free-bg); color: var(--free-ink); }
.push { margin-bottom: 12px; padding: 16px 18px; }
.push-title { margin: 0 0 4px; font-weight: 700; }
.push-text { margin: 0 0 12px; color: var(--muted); font-size: 0.95rem; }
.push .btn { width: 100%; }
.push-steps { margin: 0; padding-left: 22px; font-size: 0.98rem; display: grid; gap: 8px; }
.push-steps .share {
  width: 18px; height: 18px; vertical-align: -3px;
  fill: none; stroke: var(--brand); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.keep-open {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 0.95rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}
.keep-open svg { flex: none; width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
#leave { margin-top: auto; padding-top: 24px; }

/* "Your turn" full screen */
.turn {
  position: fixed;
  inset: 0;
  z-index: 10;
  color: #fff;
  background: var(--turn);
  animation: pulse 1.2s ease-in-out infinite alternate;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}
.turn-inner { width: 100%; max-width: 420px; }
.turn-title { font-size: 2.4rem; font-weight: 800; margin: 0; letter-spacing: -0.02em; }
.turn-number { font-size: 8rem; font-weight: 850; line-height: 1; margin: 12px 0; letter-spacing: -0.05em; }
.turn-name { font-size: 1.3rem; font-weight: 600; margin: -4px 0 12px; opacity: 0.9; min-height: 1em; }
.turn-text { font-size: 1.3rem; font-weight: 600; margin: 0 0 8px; }
.turn-timer { font-size: 1.05rem; opacity: 0.9; margin: 0 0 28px; font-variant-numeric: tabular-nums; }
@keyframes pulse { from { background: var(--turn); } to { background: var(--turn-2); } }
@media (prefers-reduced-motion: reduce) { .turn { animation: none; } }

.net {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--ink);
  color: var(--bg);
  text-align: center;
  font-size: 0.9rem;
  padding: 8px;
}

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
