/* ═══════════════════════════════════════════════════════
   main.css — Knipars Chess Ledger
   Warm mahogany × gold palette, Playfair Display typography
   ═══════════════════════════════════════════════════════ */

/* ── CSS Variables: Dark theme (default) ── */
:root {
  --bg:           #0f0906;
  --bg-card:      #1e1008;
  --bg-surface:   #2a1710;
  --gold:         #c9922a;
  --gold-light:   #e8b84b;
  --gold-dim:     #7a5318;
  --cream:        #f2ddb5;
  --cream-dim:    #b09070;
  --burgundy:     #7c1f1f;
  --burgundy-lt:  #a83232;
  --text:         #f0ddb8;
  --text-dim:     #9a8060;
  --border:       #3d2410;
  --border-gold:  #6b4e20;

  --font-display: 'Playfair Display', Georgia, serif;
  --font-body:    'Crimson Pro', Georgia, serif;

  --radius-sm:    8px;
  --radius-md:    16px;
  --radius-lg:    24px;
  --radius-pill:  999px;

  --shadow-gold:  0 0 30px rgba(201,146,42,0.25);
  --shadow-card:  0 8px 40px rgba(0,0,0,0.6);

  --transition:   0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Light Theme ── */
[data-theme="light"] {
  --bg:           #f5e5c0;
  --bg-card:      #fdf3dc;
  --bg-surface:   #ede0be;
  --gold:         #9a6a10;
  --gold-light:   #c08820;
  --gold-dim:     #b08830;
  --cream:        #2d1a04;
  --cream-dim:    #5a3818;
  --burgundy:     #7c1f1f;
  --burgundy-lt:  #a83232;
  --text:         #2d1a04;
  --text-dim:     #7a5530;
  --border:       #d4b880;
  --border-gold:  #c09850;

  --shadow-gold:  0 0 30px rgba(154,106,16,0.2);
  --shadow-card:  0 8px 40px rgba(100,60,0,0.18);

  background-image:
    repeating-linear-gradient(
      90deg,
      rgba(255,255,255,0.06) 0px,
      transparent 1px,
      transparent 60px
    ),
    radial-gradient(ellipse at 20% 0%, rgba(220,170,80,0.25) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(200,140,40,0.2) 0%, transparent 60%);
}

/* ── Red Theme (black bg, yellow text, red accents) ── */
[data-theme="red"] {
  --bg:           #000000;
  --bg-card:      #0d0000;
  --bg-surface:   #1a0000;
  --gold:         #cc0000;
  --gold-light:   #ff2222;
  --gold-dim:     #770000;
  --cream:        #f5d400;
  --cream-dim:    #c4a800;
  --burgundy:     #550000;
  --burgundy-lt:  #880000;
  --text:         #f5d400;
  --text-dim:     #b89800;
  --border:       #2a0000;
  --border-gold:  #550000;

  --shadow-gold:  0 0 30px rgba(204,0,0,0.35);
  --shadow-card:  0 8px 40px rgba(0,0,0,0.8);
}

[data-theme="red"] body {
  background-image: none;
}

[data-theme="red"] .topbar {
  background: rgba(0,0,0,0.92);
}

/* ── White Theme (pure white, minimal, dark text) ── */
[data-theme="white"] {
  --bg:           #ffffff;
  --bg-card:      #f5f5f5;
  --bg-surface:   #ebebeb;
  --gold:         #333333;
  --gold-light:   #111111;
  --gold-dim:     #666666;
  --cream:        #111111;
  --cream-dim:    #555555;
  --burgundy:     #444444;
  --burgundy-lt:  #222222;
  --text:         #111111;
  --text-dim:     #888888;
  --border:       #dddddd;
  --border-gold:  #cccccc;

  --shadow-gold:  0 0 20px rgba(0,0,0,0.1);
  --shadow-card:  0 4px 20px rgba(0,0,0,0.12);
}

[data-theme="white"] body {
  background-image: none;
}

[data-theme="white"] .topbar {
  background: rgba(255,255,255,0.95);
}

/* ── Green Theme (forest green, warm cream text) ── */
[data-theme="green"] {
  --bg:           #071a0f;
  --bg-card:      #0d2b17;
  --bg-surface:   #143d22;
  --gold:         #4caf76;
  --gold-light:   #6dd196;
  --gold-dim:     #2d6b44;
  --cream:        #d4f0df;
  --cream-dim:    #8abfa0;
  --burgundy:     #1f4d2f;
  --burgundy-lt:  #2e7044;
  --text:         #c8ead8;
  --text-dim:     #6a9e7f;
  --border:       #1c4028;
  --border-gold:  #2d6b44;

  --shadow-gold:  0 0 30px rgba(76,175,118,0.25);
  --shadow-card:  0 8px 40px rgba(0,0,0,0.6);
}

[data-theme="green"] body {
  background-image: none;
}

/* ── Yellow Theme (golden amber, dark bg) ── */
[data-theme="yellow"] {
  --bg:           #100d00;
  --bg-card:      #1f1900;
  --bg-surface:   #2d2400;
  --gold:         #e8b800;
  --gold-light:   #ffd700;
  --gold-dim:     #8a6e00;
  --cream:        #fff3a0;
  --cream-dim:    #c9b850;
  --burgundy:     #4a3900;
  --burgundy-lt:  #6b5200;
  --text:         #fff3a0;
  --text-dim:     #b09820;
  --border:       #3a2e00;
  --border-gold:  #6b5200;

  --shadow-gold:  0 0 30px rgba(232,184,0,0.3);
  --shadow-card:  0 8px 40px rgba(0,0,0,0.7);
}

[data-theme="yellow"] body {
  background-image: none;
}

/* ── Purple Theme (deep violet, silver accents) ── */
[data-theme="purple"] {
  --bg:           #0a0514;
  --bg-card:      #140a28;
  --bg-surface:   #1e1038;
  --gold:         #9b59d4;
  --gold-light:   #bf7fff;
  --gold-dim:     #5d2d8a;
  --cream:        #e8d4ff;
  --cream-dim:    #a080c8;
  --burgundy:     #3d1b6e;
  --burgundy-lt:  #5a28a0;
  --text:         #e0ccff;
  --text-dim:     #8060a8;
  --border:       #2a1050;
  --border-gold:  #5d2d8a;

  --shadow-gold:  0 0 30px rgba(155,89,212,0.3);
  --shadow-card:  0 8px 40px rgba(0,0,0,0.7);
}

[data-theme="purple"] body {
  background-image: none;
}

/* ── Wood Theme (classic chess board warm oak) ── */
[data-theme="wood"] {
  --bg:           #3b2005;
  --bg-card:      #4e2c08;
  --bg-surface:   #5e360d;
  --gold:         #c8860a;
  --gold-light:   #e8a820;
  --gold-dim:     #7a5010;
  --cream:        #fdf0d0;
  --cream-dim:    #c8a870;
  --burgundy:     #8b3a00;
  --burgundy-lt:  #b05010;
  --text:         #fdf0d0;
  --text-dim:     #b09060;
  --border:       #6b4018;
  --border-gold:  #a06020;

  --shadow-gold:  0 0 30px rgba(200,134,10,0.3);
  --shadow-card:  0 8px 40px rgba(0,0,0,0.5);
}

[data-theme="wood"] body {
  background-image:
    repeating-linear-gradient(
      90deg,
      rgba(255,220,150,0.04) 0px,
      transparent 1px,
      transparent 80px
    ),
    repeating-linear-gradient(
      0deg,
      rgba(0,0,0,0.04) 0px,
      transparent 1px,
      transparent 80px
    );
}

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

html {
  font-size: 14px; /* default −20% (0.8 × 18px); JS slider overrides via style attribute */
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 300;
  min-height: 100dvh;
  overflow-x: hidden;
  max-width: 100vw;
  transition: background 0.4s ease, color 0.4s ease;

  background-image:
    repeating-linear-gradient(
      90deg,
      rgba(255,255,255,0.01) 0px,
      transparent 1px,
      transparent 60px
    ),
    radial-gradient(ellipse at 20% 0%, rgba(100,40,10,0.4) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(80,20,5,0.3) 0%, transparent 60%);
}

img { display: block; max-width: 100%; }
a   { color: var(--gold); text-decoration: none; }
em  { font-style: italic; color: var(--gold-light); }

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Preloader ── */
.preloader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

.preloader.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.preloader__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
}

.preloader__rook {
  width: 90px;
  height: 90px;
  animation: rookBob 1.4s ease-in-out infinite, rookGlow 1.4s ease-in-out infinite;
  filter: drop-shadow(0 0 12px var(--gold));
}

@keyframes rookBob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%       { transform: translateY(-12px) rotate(3deg); }
}
@keyframes rookGlow {
  0%, 100% { filter: drop-shadow(0 0 8px var(--gold)); }
  50%       { filter: drop-shadow(0 0 24px var(--gold-light)); }
}

.preloader__text {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: 0.25em;
  color: var(--gold);
  text-transform: uppercase;
  animation: pulse 1.4s ease-in-out infinite;
}

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

/* ── Page Content ── */
.page-content {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  animation: fadeUp 0.5s ease both;
  overflow-x: hidden;
  max-width: 100%;
}

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

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  text-decoration: none;
}

.btn--primary {
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-light) 100%);
  color: var(--bg);
  padding: 0.65rem 1.6rem;
  border-radius: var(--radius-pill);
  font-size: 1rem;
  box-shadow: var(--shadow-gold), inset 0 1px 0 rgba(255,255,255,0.2);
  letter-spacing: 0.04em;
}
.btn--primary:hover  { filter: brightness(1.12); transform: translateY(-2px); }
.btn--primary:active { transform: translateY(1px); filter: brightness(0.95); }
.btn--primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; filter: none; }

.btn--ghost {
  background: transparent;
  color: var(--gold);
  border: 1.5px solid var(--border-gold);
  padding: 0.7rem 1.5rem;
  border-radius: var(--radius-pill);
  font-size: 0.9rem;
  letter-spacing: 0.05em;
}
.btn--ghost:hover { background: rgba(201,146,42,0.1); border-color: var(--gold); }

.btn--claim {
  background: linear-gradient(135deg, #2a6a2a 0%, #3d9a3d 100%);
  color: #e8f8e8;
  padding: 0.65rem 1.3rem;
  border-radius: var(--radius-pill);
  font-size: 0.9rem;
  font-weight: 700;
  font-family: var(--font-display);
  border: none;
  cursor: pointer;
  box-shadow: 0 0 16px rgba(60,160,60,0.3);
  transition: var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn--claim:hover { filter: brightness(1.1); transform: translateY(-2px); }

.btn--bet {
  background: linear-gradient(135deg, var(--burgundy) 0%, var(--burgundy-lt) 100%);
  color: #fde8e8;
  padding: 0.65rem 1.3rem;
  border-radius: var(--radius-pill);
  font-size: 0.9rem;
  font-weight: 700;
  font-family: var(--font-display);
  border: none;
  cursor: pointer;
  box-shadow: 0 0 16px rgba(160,50,50,0.3);
  transition: var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn--bet:hover { filter: brightness(1.1); transform: translateY(-2px); }

.btn--scan {
  background: linear-gradient(160deg, var(--bg-surface) 0%, var(--bg-card) 100%);
  border: 2px solid var(--border-gold);
  color: var(--gold-light);
  padding: 0.9rem 1.6rem;
  border-radius: var(--radius-lg);
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  box-shadow: var(--shadow-card), inset 0 1px 0 rgba(201,146,42,0.1);
  width: 100%;
  max-width: 360px;
  position: relative;
  overflow: hidden;
}
.btn--scan::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(201,146,42,0.08) 0%, transparent 60%);
  opacity: 0;
  transition: var(--transition);
}
.btn--scan:hover::before { opacity: 1; }
.btn--scan:hover  { border-color: var(--gold-light); transform: translateY(-3px); box-shadow: var(--shadow-card), var(--shadow-gold); }
.btn--scan:active { transform: translateY(1px); }

/* Big ledger button on profile page */
.btn--ledger {
  background: linear-gradient(160deg, var(--bg-surface) 0%, var(--bg-card) 100%);
  border: 2px solid var(--border-gold);
  color: var(--gold-light);
  padding: 1rem 1.6rem;
  border-radius: var(--radius-lg);
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  box-shadow: var(--shadow-card);
  width: 100%;
  position: relative;
  overflow: hidden;
}
.btn--ledger:hover { border-color: var(--gold-light); transform: translateY(-3px); box-shadow: var(--shadow-card), var(--shadow-gold); }

.btn--block { width: 100%; }
.btn--sm    { padding: 0.5rem 1rem; font-size: 0.8rem; }

.btn__icon {
  width: 1.4em;
  height: 1.4em;
  flex-shrink: 0;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--burgundy);
  color: var(--cream);
  padding: 0.9rem 1.6rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  z-index: 8000;
  box-shadow: var(--shadow-card);
  max-width: 90vw;
  text-align: center;
  animation: toastIn 0.3s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Shared Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 58px 0.6rem 1rem;
  min-height: 54px;
  height: auto;
  border-bottom: 1px solid var(--border);
  background: rgba(15,9,6,0.82);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 0.6rem;
}

[data-theme="light"] .topbar {
  background: rgba(245,229,192,0.88);
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  flex: 1;
}

.topbar__greeting {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--cream);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.topbar__title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--cream);
  flex: 1;
  text-align: center;
  white-space: normal;
  line-height: 1.25;
  word-break: break-word;
}

.topbar__player {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--gold-light);
}

.topbar__profile-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--border-gold);
  background: var(--bg-surface);
  color: var(--gold);
  flex-shrink: 0;
  transition: var(--transition);
}
.topbar__profile-btn svg { width: 18px; height: 18px; }
.topbar__profile-btn:hover { border-color: var(--gold); background: rgba(201,146,42,0.15); }

.topbar__back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--border-gold);
  background: var(--bg-surface);
  color: var(--gold);
  flex-shrink: 0;
  transition: var(--transition);
}
.topbar__back-btn svg { width: 20px; height: 20px; }
.topbar__back-btn:hover { border-color: var(--gold); background: rgba(201,146,42,0.15); }

/* ── Camera Modal (shared) ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
}
.modal__box {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: var(--bg-card);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 1.4rem;
  animation: slideUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.modal__title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gold-light);
}
.modal__close {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.modal__close:hover { color: var(--cream); border-color: var(--border-gold); }

/* Scanner viewport */
.scanner-wrap {
  position: relative;
  width: 100%;
  height: 60vw;
  max-height: 320px;
  background: #000;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1.5px solid var(--border-gold);
}
#qr-reader { width: 100% !important; height: 100% !important; border: none !important; }
#qr-reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
#qr-reader__dashboard,
#qr-reader__status_span,
#qr-reader__camera_selection,
#qr-reader__header_message { display: none !important; }

.scanner-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.scanner-frame {
  width: 55%; aspect-ratio: 1;
  border: 3px solid var(--gold);
  border-radius: 12px;
  position: relative;
  box-shadow: 0 0 0 2000px rgba(0,0,0,0.45);
  overflow: hidden;
}
.scanner-laser {
  position: absolute; inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold-light), transparent);
  animation: scanLaser 2s ease-in-out infinite;
  box-shadow: 0 0 8px var(--gold);
}
@keyframes scanLaser {
  0%   { top: 0%; }
  50%  { top: calc(100% - 2px); }
  100% { top: 0%; }
}
.scanner-timer {
  position: absolute; bottom: 0.6rem; right: 0.8rem;
  font-family: var(--font-display);
  font-size: 1.4rem; font-weight: 900;
  color: var(--gold-light);
  text-shadow: 0 0 10px rgba(201,146,42,0.8);
}
.modal__hint {
  text-align: center; color: var(--text-dim);
  font-size: 0.85rem; margin-top: 0.9rem; letter-spacing: 0.04em;
}

/* ── Hint pulse animation (first visit) ── */
@keyframes hintPulse {
  0%   { box-shadow: 0 0 0 0 rgba(201,146,42,0.7); }
  50%  { box-shadow: 0 0 0 12px rgba(201,146,42,0); }
  100% { box-shadow: 0 0 0 0 rgba(201,146,42,0); }
}

.hint-active {
  animation: hintPulse 1s ease 0.4s 3 !important;
}

/* ── App version stamp ── */
.app-version {
  text-align: center;
  font-size: 0.55rem;
  color: var(--border-gold);
  padding: 0.8rem 0 0.4rem;
  letter-spacing: 0.15em;
  font-family: 'Courier New', monospace;
  opacity: 0.5;
  user-select: none;
}

/* ═══════════════════════════════════════════
   Hamburger button & Side Drawer
   ═══════════════════════════════════════════ */

/* ── Hamburger button ── */
.hamburger-btn {
  position: fixed;
  top: clamp(6px, 2.5vmin, 18px);
  right: clamp(6px, 2.5vmin, 18px);
  z-index: 6000;
  width: 44px;
  height: 44px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-gold);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  padding: 0;
  transition: var(--transition);
  box-shadow: var(--shadow-card);
  -webkit-tap-highlight-color: transparent;
}

.hamburger-btn:hover {
  border-color: var(--gold);
  background: var(--bg-surface);
}

.hamburger-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--gold);
  border-radius: 2px;
  transition: var(--transition);
}

/* ── Backdrop ── */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(3px);
  z-index: 7000;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Drawer ── */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(320px, 85vw);
  background: var(--bg-card);
  border-left: 1px solid var(--border-gold);
  z-index: 8000;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -8px 0 40px rgba(0,0,0,0.6);
}

.drawer--open {
  transform: translateX(0);
}

/* ── Drawer header ── */
.drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.4rem 1.2rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer__title {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--gold-light);
  letter-spacing: 0.05em;
}

.drawer__close {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.drawer__close:hover { color: var(--cream); border-color: var(--border-gold); }

/* ── Prefs row ── */
.drawer__prefs {
  display: flex;
  gap: 0.5rem;
  padding: 0.8rem 1rem;
}

.drawer__pref-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--bg-surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.5rem;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--cream);
  -webkit-tap-highlight-color: transparent;
}
.drawer__pref-btn:hover { border-color: var(--border-gold); background: rgba(201,146,42,0.1); }
.drawer__pref-btn:active { transform: scale(0.96); }

.drawer__pref-label {
  font-size: 0.68rem;
  color: var(--text-dim);
}

/* ── Language flags row ── */
.drawer__flags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem 1rem 0.8rem;
}

.drawer__flag-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  background: var(--bg-surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.45rem;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
  min-width: 44px;
  min-height: 44px;
  justify-content: center;
}

.drawer__flag-btn span {
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  font-family: var(--font-display);
}

.drawer__flag-btn:hover {
  border-color: var(--border-gold);
  background: rgba(201,146,42,0.08);
}

.drawer__flag-btn--active {
  border-color: var(--gold);
  background: rgba(201,146,42,0.18);
}

.drawer__flag-btn--active span {
  color: var(--gold);
}

/* ── Divider ── */
.drawer__divider {
  height: 1px;
  background: var(--border);
  margin: 0.3rem 0;
  flex-shrink: 0;
}

/* ── Nav links ── */
.drawer__nav {
  list-style: none;
  padding: 0.3rem 0;
}

.drawer__link {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.85rem 1.2rem;
  color: var(--cream);
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  text-decoration: none;
  transition: var(--transition);
  letter-spacing: 0.03em;
  -webkit-tap-highlight-color: transparent;
}
.drawer__link:hover { background: rgba(201,146,42,0.08); color: var(--gold-light); }
.drawer__link:active { background: rgba(201,146,42,0.15); }

.drawer__link--action { color: var(--gold-light); }
.drawer__link--action:hover { background: rgba(201,146,42,0.12); }

.drawer__link--danger { color: #f0a0a0; }
.drawer__link--danger:hover { background: rgba(168,50,50,0.15); }

.drawer__link--dim { color: var(--text-dim); }
.drawer__link--dim:hover { color: var(--cream); }

.drawer__link-icon {
  font-size: 1.1rem;
  width: 1.4rem;
  text-align: center;
  flex-shrink: 0;
}

/* ── Version ── */
/* ── Keyboard hints (desktop drawer bottom) ── */
.drawer__kb-hints {
  padding: 0.7rem 1.2rem 0.5rem;
  border-top: 1px solid var(--border);
  display: none;
}
@media (min-width: 900px) {
  .drawer__kb-hints { display: block; }
}
.drawer__kb-title {
  font-size: 0.6rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 0.4rem;
}
.drawer__kb-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.drawer__kb-row span {
  font-size: 0.65rem;
  color: var(--text-dim);
}
kbd {
  font-family: 'Courier New', monospace;
  font-size: 0.6rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-gold);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  color: var(--gold-light);
  line-height: 1.4;
  flex-shrink: 0;
}

.drawer__version {
  margin-top: auto;
  padding: 1rem 1.2rem 1.4rem;
  font-size: 0.6rem;
  color: var(--border-gold);
  font-family: 'Courier New', monospace;
  letter-spacing: 0.1em;
  opacity: 0.5;
}

/* ── Font-size slider in drawer ── */
.drawer__font-section {
  padding: 0.8rem 1.2rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.drawer__font-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.55rem;
}
.drawer__font-label {
  font-size: 0.68rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.drawer__font-value {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--gold-light);
  min-width: 3.5em;
  text-align: right;
}
.drawer__font-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
  accent-color: var(--gold);
}
.drawer__font-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
  border: 2px solid var(--gold-light);
}
.drawer__font-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
  border: 2px solid var(--gold-light);
}
.drawer__font-reset {
  display: block;
  width: 100%;
  margin-top: 0.45rem;
  padding: 0.2rem 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.62rem;
  text-align: center;
  cursor: pointer;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
  transition: color 0.2s, opacity 0.2s;
}
.drawer__font-reset:hover { color: var(--gold); opacity: 1; }

/* ── Name editor in drawer ── */
.drawer__name-section {
  padding: 0.7rem 1.2rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
.drawer__name-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.drawer__name-label {
  flex: 1;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--cream);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drawer__name-edit-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.15rem 0.3rem;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background 0.2s;
  flex-shrink: 0;
}
.drawer__name-edit-btn:hover { color: var(--gold); background: rgba(201,146,42,0.1); }

.drawer__name-edit-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.45rem;
}
.drawer__name-input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-sm);
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 0.82rem;
  padding: 0.3rem 0.55rem;
  outline: none;
  min-width: 0;
}
.drawer__name-input:focus { border-color: var(--gold-light); }
.drawer__name-save-btn {
  background: var(--gold);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--bg);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.drawer__name-save-btn:hover { background: var(--gold-light); }
.drawer__name-save-btn:disabled { opacity: 0.5; cursor: default; }
.drawer__name-cancel-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.75rem;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
  flex-shrink: 0;
}
.drawer__name-cancel-btn:hover { color: var(--cream); border-color: var(--border-gold); }

.drawer__name-feedback {
  font-size: 0.7rem;
  margin-top: 0.35rem;
  padding: 0.25rem 0.4rem;
  border-radius: var(--radius-sm);
}
.drawer__name-feedback--error   { color: #f0a0a0; background: rgba(168,50,50,0.15); }
.drawer__name-feedback--success { color: #7de0a0; background: rgba(39,174,96,0.12); }

/* ── Register page: name mismatch warning ── */
#register-name-warning {
  display: none;
  margin-top: 0.5rem;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  border-left: 3px solid #c0392b;
  background: rgba(192,57,43,0.12);
  color: #f0a0a0;
  font-size: 0.82rem;
  line-height: 1.45;
}
#register-name-warning strong { color: #f5c0c0; }

/* ── Name field shake on mismatch ── */
@keyframes name-shake {
  0%   { transform: translateX(0); }
  10%  { transform: translateX(-9px); }
  25%  { transform: translateX(8px); }
  40%  { transform: translateX(-7px); }
  55%  { transform: translateX(5px); }
  70%  { transform: translateX(-3px); }
  85%  { transform: translateX(2px); }
  100% { transform: translateX(0); }
}
.name-shake {
  animation: name-shake 0.5s ease;
  border-color: #c0392b !important;
  box-shadow: 0 0 0 2px rgba(192,57,43,0.35) !important;
}

/* ── Drawer consent banner ── */
@keyframes consent-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(168,50,50,0.7); }
  50%       { box-shadow: 0 0 0 8px rgba(168,50,50,0); }
}
.drawer__consent-banner {
  margin: 0;
  padding: 1rem 1.2rem;
  background: linear-gradient(135deg, #3a0a0a 0%, #5c1212 100%);
  border-bottom: 2px solid #a83232;
  animation: consent-pulse 1.8s ease-in-out infinite;
}
.drawer__consent-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: #f0a0a0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 0.3rem;
}
.drawer__consent-desc {
  font-size: 0.82rem;
  color: var(--cream-dim);
  margin-bottom: 0.75rem;
  line-height: 1.4;
}
.drawer__consent-desc strong {
  color: var(--cream);
}
.drawer__consent-btn {
  display: block;
  width: 100%;
  padding: 0.7rem 1rem;
  background: #a83232;
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.drawer__consent-btn:hover   { background: #c0392b; }
.drawer__consent-btn:active  { transform: scale(0.97); }
.drawer__consent-btn:disabled { opacity: 0.6; cursor: default; transform: none; }

/* ── Drawer consent codes strip ── */
.drawer__codes-section {
  padding: 0.65rem 1.2rem 0.7rem;
  border-bottom: 1px solid var(--border);
}
.drawer__codes-header {
  margin-bottom: 0.45rem;
}
.drawer__codes-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.drawer__codes-strip {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.15rem;
  scrollbar-width: none;
}
.drawer__codes-strip::-webkit-scrollbar { display: none; }
.drawer__code-chip {
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--gold-light);
  background: var(--bg-card);
  border: 1.5px solid var(--border-gold);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.65rem;
  white-space: nowrap;
  user-select: all;
  flex-shrink: 0;
}
.drawer__codes-loading,
.drawer__codes-empty {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-style: italic;
}

/* ═══════════════════════════════════════════
   Desktop shell — centered on tablet, 3-col on desktop
   ═══════════════════════════════════════════ */

.app-shell {
  width: 100%;
  min-height: 100dvh;
}

/* ── Tablet (600–899px): centered 520px shell ── */
@media (min-width: 600px) and (max-width: 899px) {
  body {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background-image:
      repeating-linear-gradient(45deg, rgba(201,146,42,0.03) 0px, transparent 1px, transparent 28px),
      radial-gradient(ellipse at 20% 10%, rgba(100,40,10,0.55) 0%, transparent 55%),
      radial-gradient(ellipse at 80% 90%, rgba(80,20,5,0.45) 0%, transparent 55%);
    background-attachment: fixed;
  }
  [data-theme="light"] body {
    background-image:
      repeating-linear-gradient(45deg, rgba(154,106,16,0.04) 0px, transparent 1px, transparent 28px),
      radial-gradient(ellipse at 20% 10%, rgba(220,170,80,0.35) 0%, transparent 55%),
      radial-gradient(ellipse at 80% 90%, rgba(200,140,40,0.28) 0%, transparent 55%);
    background-attachment: fixed;
  }
  [data-theme="red"] body,
  [data-theme="white"] body { background-image: none; background-color: #111; }
  [data-theme="white"] body { background-color: #d0d0d0; }

  .app-shell {
    width: 520px;
    flex-shrink: 0;
    background: var(--bg);
    box-shadow: 0 0 0 1px var(--border-gold), 0 0 80px rgba(0,0,0,0.75);
    position: relative;
    overflow: hidden;
  }
  .topbar { position: sticky; }
  .drawer  { right: calc((100vw - 520px) / 2); }
  .hamburger-btn { right: calc((100vw - 520px) / 2 + 10px); }
}

/* ── Desktop (≥900px): 3-column layout ── */
@media (min-width: 900px) {
  :root {
    --nav-w:   230px;
    --board-w: 220px;
  }

  body {
    display: grid;
    grid-template-columns: var(--nav-w) 1fr var(--board-w);
    grid-template-rows: 1fr;
    align-items: start;
    min-height: 100dvh;
    background-image:
      repeating-linear-gradient(45deg, rgba(201,146,42,0.03) 0px, transparent 1px, transparent 28px),
      radial-gradient(ellipse at 20% 10%, rgba(100,40,10,0.55) 0%, transparent 55%),
      radial-gradient(ellipse at 80% 90%, rgba(80,20,5,0.45) 0%, transparent 55%);
    background-attachment: fixed;
  }
  [data-theme="light"] body {
    background-image:
      repeating-linear-gradient(45deg, rgba(154,106,16,0.04) 0px, transparent 1px, transparent 28px),
      radial-gradient(ellipse at 20% 10%, rgba(220,170,80,0.35) 0%, transparent 55%),
      radial-gradient(ellipse at 80% 90%, rgba(200,140,40,0.28) 0%, transparent 55%);
    background-attachment: fixed;
  }
  [data-theme="red"] body,
  [data-theme="white"] body { background-image: none; background-color: #111; }
  [data-theme="white"] body { background-color: #d0d0d0; }

  /* Center shell */
  .app-shell {
    grid-column: 2;
    grid-row: 1;
    width: 100%;
    max-width: 600px;
    justify-self: center;
    background: var(--bg);
    min-height: 100dvh;
    box-shadow: 0 0 0 1px var(--border-gold), 0 0 60px rgba(0,0,0,0.6);
    overflow: hidden;
  }

  /* Left nav — drawer becomes permanent sidebar */
  .drawer {
    grid-column: 1;
    grid-row: 1;
    position: sticky !important;
    top: 0;
    left: 0;
    right: auto !important;
    width: var(--nav-w) !important;
    height: 100dvh;
    transform: none !important;
    display: flex !important;
    border-left: none;
    border-right: 1px solid var(--border-gold);
    box-shadow: none;
    overflow-y: auto;
  }
  .drawer--open { transform: none !important; }
  .drawer__close { display: none; }
  .drawer-backdrop { display: none !important; }
  .hamburger-btn  { display: none !important; }

  /* Right leaderboard panel */
  .desktop-board {
    grid-column: 3;
    grid-row: 1;
    position: sticky;
    top: 0;
    height: 100dvh;
    overflow-y: auto;
    background: var(--bg-card);
    border-left: 1px solid var(--border-gold);
    display: flex;
    flex-direction: column;
  }

  .topbar { position: sticky; top: 0; }
}

/* ── Right leaderboard panel styles ── */
.desktop-board { display: none; }

@media (min-width: 900px) {
  .desktop-board { display: flex; }
}

.desktop-board__title {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 1rem 1rem 0.6rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.desktop-board__list {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-gold) transparent;
}

.desktop-board__row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  text-decoration: none;
  transition: background 0.15s;
  cursor: pointer;
}
.desktop-board__row:hover { background: rgba(201,146,42,0.08); }

.desktop-board__rank {
  font-size: 0.6rem;
  color: var(--text-dim);
  font-family: 'Courier New', monospace;
  width: 1.4rem;
  flex-shrink: 0;
  text-align: right;
}

.desktop-board__name {
  flex: 1;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--cream);
  font-family: var(--font-display);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.desktop-board__val {
  font-size: 0.72rem;
  font-family: var(--font-display);
  font-weight: 900;
  color: var(--gold-light);
  flex-shrink: 0;
}

.desktop-board__empty {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-align: center;
  padding: 2rem 1rem;
  font-style: italic;
}

.desktop-board__footer {
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.desktop-board__footer a {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-decoration: none;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.desktop-board__footer a:hover { color: var(--gold); }

/* ═══════════════════════════════════════════
   Accessibility — High Contrast
   ═══════════════════════════════════════════ */

[data-contrast="high"] {
  --bg:          #000000;
  --bg-card:     #0d0d0d;
  --bg-surface:  #1a1a1a;
  --gold:        #ffee00;
  --gold-light:  #ffff66;
  --gold-dim:    #ccbb00;
  --cream:       #ffffff;
  --cream-dim:   #dddddd;
  --text:        #ffffff;
  --text-dim:    #cccccc;
  --border:      #555555;
  --border-gold: #ffee00;
  --shadow-gold: 0 0 20px rgba(255,238,0,0.5);
  --shadow-card: 0 4px 20px rgba(0,0,0,0.9);
}

[data-contrast="high"] body {
  background-image: none !important;
}

[data-contrast="high"] .topbar {
  background: #000 !important;
  border-bottom-color: #ffee00 !important;
}

[data-contrast="high"] .hamburger-btn {
  border-color: #ffee00 !important;
  background: #000 !important;
}

[data-contrast="high"] .hamburger-btn span {
  background: #ffee00 !important;
}

/* ═══════════════════════════════════════════
   Accessibility — Line Spacing
   ═══════════════════════════════════════════ */

[data-linespace="wide"] body {
  line-height: 2.0;
}

[data-linespace="wide"] p,
[data-linespace="wide"] li,
[data-linespace="wide"] label,
[data-linespace="wide"] .drawer__link,
[data-linespace="wide"] .consent-codes-hint,
[data-linespace="wide"] .privacy-body p,
[data-linespace="wide"] .privacy-body li {
  line-height: 2.0;
}

/* ═══════════════════════════════════════════
   Accessibility drawer section
   ═══════════════════════════════════════════ */

.drawer__access-section {
  padding: 0.7rem 1rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

.drawer__access-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.45rem;
  display: block;
}

.drawer__access-row {
  display: flex;
  gap: 0.4rem;
}

.drawer__access-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  background: var(--bg-surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.3rem;
  cursor: pointer;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.drawer__access-btn:hover {
  border-color: var(--border-gold);
  background: rgba(201,146,42,0.08);
}

.drawer__access-btn--on {
  border-color: var(--gold);
  background: rgba(201,146,42,0.15);
}

.drawer__access-icon { font-size: 1.1rem; line-height: 1; }

.drawer__access-text {
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: center;
}

/* ── Drawer button-style link ── */
.drawer__link--btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.8rem 1.2rem;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.85rem;
  text-align: left;
  transition: background var(--transition);
  border-radius: 0;
}
.drawer__link--btn:hover { background: var(--bg-surface); }

/* ── Unread badge ── */
.drawer__unread-badge {
  margin-left: auto;
  background: var(--burgundy-lt);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 1.4rem;
  height: 1.4rem;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.35rem;
}

/* ── QR Share Modal ── */
.qr-share-modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
}
.qr-share-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
}
.qr-share-modal__box {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-card);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  padding: 2rem 2rem 1.6rem;
  text-align: center;
  box-shadow: var(--shadow-card);
  min-width: 260px;
  animation: fadeUp 0.25s ease;
}
.qr-share-modal__close {
  position: absolute;
  top: 0.8rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}
.qr-share-modal__title {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--gold);
  margin-bottom: 1rem;
  font-weight: 700;
}
.qr-share-modal__img {
  width: 200px;
  height: 200px;
  border-radius: var(--radius-sm);
  display: block;
  margin: 0 auto 0.8rem;
}
.qr-share-modal__hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}
