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

:root {
  --bg:          #0a0a18;
  --bg-card:     #13132a;
  --bg-card2:    #1a1a35;
  --border:      rgba(108,99,255,.18);
  --primary:     #6c63ff;
  --primary-dim: rgba(108,99,255,.14);
  --secondary:   #ff6b9d;
  --success:     #00d4aa;
  --warning:     #ffd93d;
  --danger:      #ff4757;
  --text:        #e4e4f8;
  --muted:       #6868a0;
  --radius:      12px;
  --radius-lg:   20px;
  --shadow:      0 8px 40px rgba(0,0,0,.5);
  --glow-p:      0 0 20px rgba(108,99,255,.3);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: 'Vazirmatn', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ─────────────────────────────────── */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.lobby-page {
  justify-content: flex-start;
  padding-top: 20px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow);
}

/* ── Typography ──────────────────────────────── */
h1 { font-size: 1.8rem; font-weight: 800; }
h2 { font-size: 1.4rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 600; }

.logo {
  text-align: center;
  margin-bottom: 32px;
}
.logo-emoji { font-size: 2.4rem; margin-bottom: 6px; display: block; }
.logo-img   { height: 72px; width: auto; display: block; margin: 0 auto 10px; }
.logo-title {
  font-size: 1.9rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -.5px;
}
.logo-sub {
  font-size: .82rem;
  color: var(--muted);
  margin-top: 4px;
}

/* ── Form ────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
label {
  display: block;
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}
input[type=text], input[type=email], input[type=password] {
  width: 100%;
  padding: 13px 16px;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108,99,255,.12);
}

/* ── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 24px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  text-decoration: none;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff;
  width: 100%;
  box-shadow: 0 4px 16px rgba(108,99,255,.3);
}
.btn-primary:hover  { opacity: .92; transform: translateY(-1px); box-shadow: 0 6px 24px rgba(108,99,255,.4); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 7px 14px; font-size: .82rem; }

/* ── Tabs ────────────────────────────────────── */
.tabs {
  display: flex;
  background: var(--bg-card2);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 24px;
  gap: 4px;
}
.tab {
  flex: 1; padding: 10px; text-align: center;
  border-radius: 9px; cursor: pointer;
  font-weight: 700; font-size: .9rem;
  color: var(--muted); transition: all .2s;
}
.tab.active { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(108,99,255,.3); }

/* ── Alert ───────────────────────────────────── */
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: .9rem; margin-bottom: 16px; display: none;
}
.alert.show { display: block; }
.alert-error   { background: rgba(255,71,87,.12);  color: var(--danger);  border: 1px solid rgba(255,71,87,.25); }
.alert-success { background: rgba(0,212,170,.12);  color: var(--success); border: 1px solid rgba(0,212,170,.25); }

/* ── Topbar ──────────────────────────────────── */
.topbar {
  width: 100%; max-width: 720px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; margin-bottom: 20px; flex-wrap: wrap; gap: 10px;
}
.topbar .brand {
  font-size: 1.4rem; font-weight: 900;
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.brand-logo { height: 56px; width: auto; flex-shrink: 0; }
.topbar .user-info { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* User chip */
.user-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 50px; padding: 5px 12px 5px 6px;
  text-decoration: none; color: inherit;
  cursor: pointer; transition: border-color .2s;
}
.user-chip:hover { border-color: rgba(108,99,255,.45); }
.user-chip-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--bg-card2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.05rem; font-weight: 800; color: #fff; flex-shrink: 0;
}
.user-chip-name { font-weight: 700; font-size: .88rem; }
.user-chip-admin {
  font-size: .68rem; font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

/* Admin link */
.admin-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 14px; border-radius: var(--radius);
  font-size: .8rem; font-weight: 700;
  background: linear-gradient(135deg, #f59e0b, #f97316);
  color: #fff !important;
  border: none; text-decoration: none;
  box-shadow: 0 2px 10px rgba(245,158,11,.4);
  transition: all .2s;
}
.admin-badge:hover { opacity: .9; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(245,158,11,.55); }

/* Ready sent message */
.ready-sent-msg {
  margin-top: 18px;
  padding: 14px 24px;
  background: rgba(0,212,170,.1);
  border: 1px solid rgba(0,212,170,.25);
  border-radius: var(--radius);
  color: var(--success);
  font-size: 1rem;
  font-weight: 700;
  animation: fadeIn .3s ease;
}

/* ── Stats bar ───────────────────────────────── */
.stats-bar {
  display: flex; gap: 10px;
  width: 100%; max-width: 720px; margin-bottom: 22px; flex-wrap: wrap;
}
.stat-item {
  flex: 1; min-width: 70px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  transition: border-color .2s;
}
.stat-item:hover { border-color: rgba(108,99,255,.35); }
.stat-value { font-size: 1.5rem; font-weight: 900; line-height: 1; }
.stat-label { font-size: .7rem; color: var(--muted); margin-top: 4px; font-weight: 500; }
.stat-item.wins     .stat-value { color: var(--success); }
.stat-item.losses   .stat-value { color: var(--danger); }
.stat-item.draws    .stat-value { color: var(--warning); }
.stat-item.winrate  .stat-value { color: var(--primary); }

/* ── Rooms ───────────────────────────────────── */
.rooms-header { width: 100%; max-width: 720px; margin-bottom: 14px; }
.rooms-header h2 { font-size: 1rem; color: var(--muted); font-weight: 500; }

.rooms-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px; width: 100%; max-width: 720px;
}
.room-card {
  aspect-ratio: 10/7;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; cursor: pointer; transition: all .22s; position: relative; overflow: hidden;
}
.room-card::before {
  content: ''; position: absolute; inset: 0;
  border-radius: inherit; opacity: 0; transition: opacity .22s;
}
.room-card:hover::before        { opacity: 1; background: radial-gradient(circle at 50% 50%, rgba(108,99,255,.08), transparent 70%); }
.room-card:hover                { border-color: var(--primary); transform: translateY(-3px); box-shadow: 0 6px 24px rgba(108,99,255,.2); }

/* waiting — زرد/کهربایی */
.room-card.waiting {
  border-color: rgba(255,217,61,.6);
  background: linear-gradient(145deg, rgba(255,217,61,.07), rgba(255,180,0,.04));
  box-shadow: 0 0 0 0 rgba(255,217,61,.4);
  animation: waitingPulse 2.5s ease-in-out infinite;
}
.room-card.waiting:hover { transform: translateY(-3px); box-shadow: 0 6px 20px rgba(255,217,61,.25); animation: none; }

/* playing — قرمز */
.room-card.playing {
  border-color: rgba(255,71,87,.5);
  background: linear-gradient(145deg, rgba(255,71,87,.07), rgba(200,0,30,.03));
  cursor: not-allowed; opacity: .7;
}
.room-card.playing:hover { transform: none; box-shadow: none; }

.room-card.joining { border-color: var(--primary); animation: pulse 1s infinite; }

.room-number { font-size: 1.4rem; font-weight: 900; transition: transform .2s; }
.room-card:hover .room-number { transform: scale(1.1); }
/* shrink letter when names are shown */
.room-card.waiting .room-number,
.room-card.playing .room-number { font-size: 1.1rem; }

/* player names — prominent */
.room-players {
  max-width: 92%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-align: center; line-height: 1.2; min-height: 0;
  font-size: .7rem; font-weight: 700;
}
.room-players:empty { display: none; }
.room-card.waiting .room-players { color: var(--warning); font-size: .75rem; }
.room-card.playing .room-players { color: rgba(255,71,87,.9); font-size: .68rem; }

/* status label — subtitle */
.room-status { font-size: .56rem; font-weight: 600; letter-spacing: .3px; }
.room-card.empty   .room-status { color: var(--muted); text-transform: uppercase; }
.room-card.waiting .room-status { color: rgba(255,217,61,.65); }
.room-card.playing .room-status { color: rgba(255,71,87,.65); }

.room-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.room-card.waiting .room-dot { background: var(--warning); box-shadow: 0 0 6px var(--warning); animation: dotBlink 1.2s ease-in-out infinite; }
.room-card.playing .room-dot { background: var(--danger);  box-shadow: 0 0 6px var(--danger); }

.legend {
  display: flex; gap: 20px; margin-top: 18px;
  font-size: .8rem; color: var(--muted);
  width: 100%; max-width: 720px; flex-wrap: wrap;
}
.legend span { display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

/* ── Game page ───────────────────────────────── */
.game-page {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  padding: 14px 16px; max-width: 560px; margin: 0 auto;
}

.game-header {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; margin-bottom: 14px;
}
.game-header .room-tag {
  font-size: .78rem; background: var(--primary-dim); color: var(--primary);
  padding: 4px 14px; border-radius: 20px; font-weight: 700;
}
.q-counter { font-size: .85rem; color: var(--muted); font-weight: 600; }

/* ── Scores bar ──────────────────────────────── */
.scores-bar {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px 18px;
  margin-bottom: 14px; gap: 8px;
}
.player-side {
  display: flex; align-items: center; gap: 10px; flex: 1;
}
.opp-side { flex-direction: row-reverse; }

.player-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.45rem; font-weight: 900; color: #fff; flex-shrink: 0;
  border: 2px solid transparent;
}
.player-avatar.me  {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-color: rgba(108,99,255,.4);
  box-shadow: 0 0 16px rgba(108,99,255,.3);
}
.player-avatar.opp {
  background: linear-gradient(135deg, var(--secondary), #f97316);
  border-color: rgba(255,107,157,.4);
  box-shadow: 0 0 16px rgba(255,107,157,.3);
}

.player-info { min-width: 0; }
.player-name {
  font-size: 1rem; font-weight: 800;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 110px;
}
.player-tag { font-size: .68rem; color: var(--muted); font-weight: 500; margin-top: 1px; }

.player-score-val {
  font-size: 2.2rem; font-weight: 900; line-height: 1;
  min-width: 36px; text-align: center; flex-shrink: 0;
  transition: transform .2s;
}
.player-score-val.score-bump {
  animation: scoreBump .35s ease;
}

.vs-divider {
  font-size: .9rem; color: var(--muted); font-weight: 700;
  padding: 0 4px; flex-shrink: 0;
}

/* ── Timer ───────────────────────────────────── */
.timer-wrap { width: 100%; margin-bottom: 14px; }
.timer-bar-bg {
  height: 7px; background: var(--bg-card2);
  border-radius: 4px; overflow: hidden;
}
.timer-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--success), #00b4d8);
  border-radius: 4px;
  transition: width .05s linear;
  width: 100%;
}
.timer-bar.low { background: linear-gradient(90deg, var(--danger), #ff6b4a); }
.timer-label {
  text-align: center; font-size: .85rem;
  color: var(--muted); margin-top: 5px; font-weight: 600;
  transition: color .3s;
}
.timer-label.urgent { color: var(--danger); font-size: 1rem; font-weight: 800; }

/* ── Question card ───────────────────────────── */
.question-card {
  width: 100%; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 22px 20px; margin-bottom: 14px;
}
.question-meta { margin-bottom: 10px; }
.q-num {
  font-size: .75rem; color: var(--primary); font-weight: 700;
  background: var(--primary-dim); padding: 3px 10px; border-radius: 20px;
  display: inline-block;
}
.question-text {
  font-size: 1.15rem; line-height: 1.8; font-weight: 600;
}

/* ── Options ─────────────────────────────────── */
.options { width: 100%; display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }

.option-btn {
  width: 100%; padding: 14px 16px;
  background: var(--bg-card); border: 1.5px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-family: inherit;
  font-size: .95rem; font-weight: 500; cursor: pointer;
  text-align: right; display: flex; align-items: center; gap: 12px;
  transition: all .15s; position: relative; overflow: hidden;
}
.option-btn:hover:not(:disabled) {
  border-color: var(--primary); background: var(--primary-dim);
  transform: translateX(-2px);
}
.option-btn:disabled { cursor: default; }

.option-btn.selected {
  border-color: var(--primary);
  background: var(--primary-dim);
}
.option-btn.correct {
  border-color: var(--success);
  background: rgba(0,212,170,.12);
  color: var(--success);
  font-weight: 700;
}
.option-btn.wrong {
  border-color: var(--danger);
  background: rgba(255,71,87,.15);
  color: var(--danger);
  font-weight: 700;
  animation: wrongShake .4s ease;
}

.option-label {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--bg-card2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .8rem; flex-shrink: 0;
  transition: background .15s;
}
.option-btn.correct .option-label { background: rgba(0,212,170,.25); color: var(--success); }
.option-btn.wrong   .option-label { background: rgba(255,71,87,.25);  color: var(--danger); }
.option-btn.selected .option-label { background: rgba(108,99,255,.3); color: var(--primary); }

.option-text { flex: 1; text-align: right; }

/* جواب حریف */
.opp-badge {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-size: .72rem; background: var(--bg-card2);
  border: 1px solid var(--border); border-radius: 20px; padding: 2px 8px;
  white-space: nowrap;
}

/* وضعیت پاسخ */
.answer-status {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .82rem; margin-bottom: 10px;
}
.status-me  { color: var(--success); font-weight: 600; }
.status-opp { color: var(--muted); }
.blinking { animation: blink 1s step-end infinite; }

/* ── Waiting ─────────────────────────────────── */
.waiting-box {
  width: 100%; text-align: center; padding: 44px 20px;
}
.waiting-icon { font-size: 2.8rem; margin-bottom: 14px; }
.waiting-box h2 { margin-bottom: 8px; }
.waiting-box p  { color: var(--muted); font-size: .9rem; }
.dot-loader { display: flex; gap: 6px; justify-content: center; margin-top: 22px; }
.dot-loader span {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--primary); animation: bounce 1.2s infinite;
}
.dot-loader span:nth-child(2) { animation-delay: .2s; }
.dot-loader span:nth-child(3) { animation-delay: .4s; }

.ready-wait-msg {
  color: var(--success); font-size: .85rem; margin-top: 14px; font-weight: 600;
}
.ready-wait-msg.hidden { display: none; }

/* ── Overlays ────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(10,10,24,.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 100; backdrop-filter: blur(8px);
}
.overlay.hidden { display: none; }
.countdown-number {
  font-size: 8rem; font-weight: 900;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  animation: pop .75s ease;
}
.overlay-title { font-size: 1.2rem; color: var(--muted); margin-top: 6px; }

/* Result overlay */
.result-banner {
  position: fixed; inset: 0;
  background: rgba(10,10,24,.96);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 100; backdrop-filter: blur(10px);
  text-align: center; padding: 32px;
}
.result-banner.hidden { display: none; }
.result-emoji { font-size: 5.5rem; margin-bottom: 16px; animation: pop .5s ease; }
.result-title { font-size: 2.2rem; font-weight: 900; margin-bottom: 10px; }
.result-score-detail { font-size: 1.05rem; margin-bottom: 6px; font-weight: 600; }
.result-score { font-size: .95rem; color: var(--muted); margin-bottom: 8px; }
.result-tiebreak { font-size: .82rem; color: var(--muted); margin-bottom: 20px; padding: 6px 14px; background: rgba(255,255,255,.05); border-radius: 20px; }

/* Pause overlay */
.pause-overlay {
  position: fixed; inset: 0;
  background: rgba(10,10,24,.93);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 100; backdrop-filter: blur(8px); text-align: center; padding: 24px;
}
.pause-overlay.hidden { display: none; }
.pause-countdown { font-size: 3.5rem; font-weight: 900; color: var(--warning); margin: 12px 0; }

/* ── Animations ──────────────────────────────── */
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-14px); }
}
@keyframes pop {
  0%   { transform: scale(.4); opacity: 0; }
  65%  { transform: scale(1.12); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(108,99,255,.4); }
  50%       { box-shadow: 0 0 0 10px rgba(108,99,255,0); }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes scoreBump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.35); color: var(--success); }
  100% { transform: scale(1); }
}
@keyframes wrongShake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-5px); }
  40%     { transform: translateX(5px); }
  60%     { transform: translateX(-3px); }
  80%     { transform: translateX(3px); }
}
@keyframes blink {
  50% { opacity: .3; }
}
@keyframes waitingPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,217,61,.3); }
  50%       { box-shadow: 0 0 0 6px rgba(255,217,61,0); }
}
@keyframes dotBlink {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}
.fade-in { animation: fadeIn .3s ease forwards; }

/* ── Lobby footer ────────────────────────────── */
.lobby-footer {
  width: 100%; max-width: 720px;
  padding: 20px 0 32px;
  text-align: center;
  font-size: .72rem;
  color: rgba(148,163,184,.35);
  letter-spacing: .04em;
}

/* ── Match history (lobby) ───────────────────── */
.history-section {
  width: 100%; max-width: 720px;
  margin-top: 28px; padding-bottom: 12px;
}
.history-title {
  font-size: .78rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .6px;
  margin-bottom: 14px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.history-list { display: flex; flex-direction: column; gap: 5px; }
.history-empty {
  text-align: center; color: var(--muted); font-size: .9rem;
  padding: 36px 0; border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}

/* ── Compact single-line match card ──────────────────────── */
.match-card {
  display: grid;
  grid-template-columns: 68px 1fr 52px 1fr 72px;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-right: 3px solid var(--muted);
  overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}
.match-card:hover   { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0,0,0,.28); }
.match-card.win     { border-right-color: var(--success); }
.match-card.loss    { border-right-color: var(--danger); }
.match-card.draw    { border-right-color: #64748b; }
.match-card.cancelled { opacity: .7; }

.match-badge { font-size:.72rem; font-weight:800; display:flex; align-items:center; gap:3px; white-space:nowrap; flex-shrink:0; }
.match-badge.win  { color: var(--success); }
.match-badge.loss { color: var(--danger); }
.match-badge.draw { color: #94a3b8; }
.match-badge.cancelled { color: var(--muted); }

.mc-player { display:flex; align-items:center; gap:3px; font-size:.82rem; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; min-width:0; }
.mc-player.me  { color:var(--text); justify-content:flex-end; text-align:right; }
.mc-player.opp { color:rgba(228,228,248,.6); }
.mc-score { display:flex; align-items:center; justify-content:center; }
.mc-time  { font-size:.63rem; color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; text-align:left; padding-right:2px; }
.match-avatar { font-size:.9rem; line-height:1; flex-shrink:0; }

.score-num { font-size:1rem; font-weight:900; line-height:1; min-width:16px; text-align:center; }
.score-num.mine.win  { color: var(--success); }
.score-num.mine.loss { color: var(--danger); }
.score-num.mine.draw { color: #94a3b8; }
.score-num.mine.cancelled { color: var(--muted); }
.score-num.theirs { color: var(--muted); }
.score-sep { font-size:.85rem; color:rgba(255,255,255,.3); padding:0 4px; line-height:1; }

/* ── Responsive / Mobile ─────────────────────── */

/* ─ Tablet ─ */
@media (max-width: 768px) {
  /* Lobby */
  .lobby-page { padding: 12px; }
  .topbar { padding: 10px 14px; gap: 8px; }
  .brand  { font-size: 1rem; }
  .user-chip { padding: 4px 12px 4px 5px; }
  .user-chip-name { font-size: .92rem; }
  .stats-bar { gap: 6px; padding: 10px 12px; }
  .stat-value { font-size: 1.3rem; }
  .stat-label { font-size: .6rem; }
  .rooms-header h2 { font-size: .9rem; }
  .rooms-grid { gap: 8px; }
  .legend { gap: 12px; font-size: .72rem; }

  /* Match cards — tablet */
  .match-card { grid-template-columns: 64px 1fr 48px 1fr 68px; gap: 5px; padding: 6px 10px; }
  .mc-player { font-size: .76rem; }
  .score-num { font-size: .9rem; }
  .mc-time   { font-size: .58rem; }

  /* Game page */
  .game-header { padding: 10px 14px; }
  .scores-bar  { padding: 10px 14px; gap: 8px; }
  .player-score-val { font-size: 2rem; }
  .player-name { font-size: .9rem; max-width: 90px; }
  .question-card { padding: 16px; }
  .question-text { font-size: 1rem; line-height: 1.6; }
  .option-btn { padding: 13px 14px; gap: 10px; font-size: .92rem; }
  .option-label { width: 26px; height: 26px; font-size: .78rem; }
}

/* ─ Mobile (≤480 px) ─ */
@media (max-width: 480px) {
  /* viewport & layout */
  html { -webkit-text-size-adjust: 100%; }
  body { overscroll-behavior-y: contain; }

  /* Lobby */
  .lobby-page { padding: 10px; padding-bottom: 32px; }
  .topbar { padding: 8px 12px; border-radius: var(--radius); margin-bottom: 10px; gap: 6px; }
  .brand  { font-size: .9rem; }
  .brand-text { display: none; }
  .admin-badge { padding: 5px 10px; font-size: .72rem; }
  .user-chip { padding: 4px 12px 4px 5px; }
  .user-chip-name { font-size: .9rem; font-weight: 700; }
  /* Leaderboard: shrink chips so all 3 fit in one row */
  .leaderboard-box { flex-wrap: nowrap; gap: 4px; padding: 8px 10px; overflow: hidden; }
  .lb-chip { font-size: .62rem; padding: 2px 5px; gap: 2px; }
  .lb-label { font-size: .6rem; white-space: nowrap; }
  .stats-bar { padding: 8px 10px; gap: 5px; border-radius: var(--radius); }
  .stat-item { min-width: 44px; padding: 6px 4px; }
  .stat-value { font-size: 1.2rem; }
  .stat-label { font-size: .55rem; }
  .rooms-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .room-number { font-size: 1rem; }
  .room-status { font-size: .5rem; }
  .room-players { font-size: .58rem; }
  .room-card.waiting .room-number,
  .room-card.playing .room-number { font-size: .85rem; }
  .legend { gap: 10px; font-size: .68rem; margin-top: 12px; }

  /* Match history — mobile */
  .history-section { margin-top: 20px; }
  .match-card { grid-template-columns: 56px 1fr 44px 1fr 60px; gap: 4px; padding: 5px 8px; }
  .match-badge { font-size: .6rem; }
  .mc-player { font-size: .7rem; }
  .score-num { font-size: .82rem; min-width: 13px; }
  .score-sep { padding: 0 2px; font-size: .75rem; }
  .mc-time   { font-size: .55rem; }

  /* Game page */
  .game-page { padding: 10px 12px; }
  .game-header { padding: 8px 12px; border-radius: var(--radius); }
  .game-header .btn { font-size: .75rem; padding: 6px 10px; }
  .room-tag { font-size: .72rem; padding: 4px 10px; }
  .scores-bar { padding: 8px 12px; gap: 6px; border-radius: var(--radius); }
  .player-avatar { width: 34px; height: 34px; font-size: .9rem; }
  .player-name { font-size: .8rem; max-width: 72px; }
  .player-score-val { font-size: 1.8rem; }
  .vs-divider { font-size: .75rem; }
  .timer-wrap { margin: 8px 0; }
  .question-card { padding: 14px 12px; border-radius: var(--radius); }
  .question-meta { margin-bottom: 8px; }
  .question-text { font-size: .95rem; line-height: 1.65; }
  .options { gap: 8px; margin-top: 10px; }
  .option-btn {
    padding: 12px 12px; gap: 8px; font-size: .88rem;
    min-height: 48px;             /* WCAG touch target */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .option-label { width: 24px; height: 24px; font-size: .72rem; flex-shrink: 0; }
  .result-banner { padding: 28px 16px; border-radius: var(--radius-lg); }
  .result-emoji  { font-size: 3rem; }
  .result-title  { font-size: 1.6rem; }

  /* Login card */
  .card { padding: 24px 16px; }
  .logo-emoji { font-size: 2.8rem; }
  .logo-title { font-size: 1.6rem; }

  /* Profile */
  .profile-hero { flex-direction: column; text-align: center; gap: 12px; padding: 20px 16px; }
  .profile-meta { text-align: center; }
  .profile-since { justify-content: center; }
  .profile-stats { grid-template-columns: repeat(2, 1fr); padding: 0 16px 20px; gap: 8px; }
  .card-wide { padding: 20px 16px !important; }
}
