/* Viva La Trivia - 2026 theme */

@font-face {
  font-family: "Rubik";
  font-style: normal;
  font-display: swap;
  font-weight: 300 900;
  src: url(../fonts/rubik-hebrew-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0307-0308, U+0590-05FF, U+200C-2010, U+20AA, U+25CC, U+FB1D-FB4F;
}
@font-face {
  font-family: "Rubik";
  font-style: normal;
  font-display: swap;
  font-weight: 300 900;
  src: url(../fonts/rubik-latin-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light dark;
  --bg: #f5f3ff;
  --bg-2: #ede9fe;
  --surface: #ffffff;
  --surface-2: #f8f7fc;
  --text: #1c1530;
  --muted: #6b6488;
  --border: #e4e0f2;
  --primary: #6d28d9;
  --primary-2: #8b5cf6;
  --primary-text: #ffffff;
  --accent: #f59e0b;
  --pink: #ec4899;
  --success: #059669;
  --success-bg: #d1fae5;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info-bg: #ede9fe;
  --shadow: 0 1px 2px rgb(28 21 48 / 6%), 0 8px 24px rgb(28 21 48 / 8%);
  --shadow-lg: 0 12px 40px rgb(76 29 149 / 18%);
  --radius: 20px;
  --radius-sm: 12px;
  --gradient: linear-gradient(135deg, #6d28d9 0%, #a855f7 50%, #ec4899 100%);
  --font: "Rubik", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0b1d;
    --bg-2: #181130;
    --surface: #1a1430;
    --surface-2: #221a3d;
    --text: #f2effc;
    --muted: #a59fc2;
    --border: #2f2652;
    --primary: #8b5cf6;
    --primary-2: #a78bfa;
    --success: #34d399;
    --success-bg: rgb(5 150 105 / 18%);
    --warning: #fbbf24;
    --warning-bg: rgb(245 158 11 / 16%);
    --danger: #f87171;
    --danger-bg: rgb(220 38 38 / 18%);
    --info-bg: rgb(139 92 246 / 16%);
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 30%);
    --shadow-lg: 0 12px 40px rgb(0 0 0 / 45%);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 100% -10%, rgb(168 85 247 / 18%), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgb(236 72 153 / 10%), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

a { color: var(--primary); text-decoration: none; }
svg:not([width]) { width: 1em; height: 1em; vertical-align: -0.125em; flex: none; }
.page-title svg { color: var(--primary); }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
img, svg { max-width: 100%; }

:focus-visible { outline: 3px solid var(--primary-2); outline-offset: 2px; border-radius: 6px; }

/* ---------- Layout ---------- */

.container {
  width: 100%;
  max-width: 1040px;
  margin-inline: auto;
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
}

main.container { flex: 1; padding-block: 24px 48px; }

.page-title { margin-block: 4px 20px; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.app-header .container { display: flex; align-items: center; gap: 12px; min-height: 64px; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-logo {
  width: 36px; height: 36px;
  border-radius: 11px;
  background: var(--gradient);
  display: grid; place-items: center;
  color: #fff;
  font-weight: 900;
  font-size: 1.15rem;
  box-shadow: 0 6px 16px rgb(139 92 246 / 35%);
}

.nav { display: flex; gap: 4px; margin-inline-start: auto; align-items: center; }
.nav a {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--info-bg); color: var(--primary); }
.nav svg { width: 18px; height: 18px; flex: none; }

.nav-more { position: relative; }
.nav-more > summary { list-style: none; cursor: pointer; }
.nav-more > summary::-webkit-details-marker { display: none; }
.nav-more .menu {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 8px);
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: flex; flex-direction: column;
}
.nav-more .menu a { border-radius: 8px; }

.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding-block: 4px;
  padding-inline: 4px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: .9rem;
  max-width: 180px;
}
.user-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  width: 28px; height: 28px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: .85rem;
  background: var(--gradient);
}
.avatar.lg { width: 44px; height: 44px; font-size: 1.1rem; }

.app-header .nav-toggle { display: none; margin-inline-start: auto; }

.drawer {
  border: 0;
  padding: 0;
  margin: 0;
  margin-inline-start: auto;
  height: 100dvh;
  max-height: 100dvh;
  width: min(320px, 86vw);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.drawer::backdrop { background: rgb(15 11 29 / 45%); backdrop-filter: blur(2px); }
.drawer-inner { display: flex; flex-direction: column; gap: 4px; padding: calc(16px + env(safe-area-inset-top)) 16px 24px; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.drawer a {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--text);
  font-weight: 500;
}
.drawer a:hover, .drawer a.active { background: var(--info-bg); text-decoration: none; }
.drawer a svg { width: 20px; height: 20px; color: var(--primary); }
.drawer hr { border: 0; border-top: 1px solid var(--border); margin: 8px 0; width: 100%; }

@media (max-width: 860px) {
  .nav { display: none; }
  .app-header .nav-toggle { display: inline-flex; }
}

.app-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .875rem;
  padding-block: 20px calc(20px + env(safe-area-inset-bottom));
}
.app-footer .container { display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: space-between; align-items: center; }
.app-footer a { color: var(--muted); }

/* ---------- Building blocks ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
@media (min-width: 640px) { .card { padding: 28px; } }
.card > :last-child { margin-bottom: 0; }
.card-title { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-title svg { width: 22px; height: 22px; color: var(--primary); }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.nowrap { white-space: nowrap; }

/* ---------- Buttons ---------- */

.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-border: var(--border);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: transform .08s ease, box-shadow .2s ease, background .2s ease, opacity .2s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:hover { text-decoration: none; filter: brightness(1.04); }
.btn:active { transform: scale(.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn svg { width: 18px; height: 18px; flex: none; }

.btn-primary {
  --btn-bg: var(--gradient);
  --btn-fg: #fff;
  --btn-border: transparent;
  background: var(--gradient);
  box-shadow: 0 8px 20px rgb(139 92 246 / 35%);
}
.btn-accent { --btn-bg: var(--accent); --btn-fg: #1c1530; --btn-border: transparent; }
.btn-danger { --btn-bg: var(--danger-bg); --btn-fg: var(--danger); --btn-border: transparent; }
.btn-success { --btn-bg: var(--success-bg); --btn-fg: var(--success); --btn-border: transparent; }
.btn-warning { --btn-bg: var(--warning-bg); --btn-fg: var(--warning); --btn-border: transparent; }
.btn-ghost { --btn-bg: transparent; --btn-border: transparent; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: .875rem; }
.btn-lg { min-height: 56px; padding: 14px 28px; font-size: 1.1rem; }
.btn-block { width: 100%; }
.btn-icon { width: 44px; padding: 0; }
.btn-icon.btn-sm { width: 34px; }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > label, .label { font-weight: 600; font-size: .925rem; }
.field .hint { color: var(--muted); font-size: .85rem; }

input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input:not([type]), select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* Prevents zooming on iOS */
  transition: border-color .15s, box-shadow .15s, background .15s;
}
textarea { min-height: 140px; resize: vertical; }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-inline-end: 40px;
}
[dir=rtl] select { background-position: 20px 50%, 14px 50%; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-2);
  box-shadow: 0 0 0 4px rgb(139 92 246 / 20%);
  background: var(--surface);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }

.check { display: flex; align-items: center; gap: 12px; padding: 8px 0; cursor: pointer; font-weight: 500; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); flex: none; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); }
.seg label { flex: 1 1 auto; text-align: center; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block;
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.seg input:checked + span { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 3px solid var(--primary-2); }

.input-group { display: flex; gap: 8px; }
.input-group input { flex: 1; min-width: 0; }

.code-input { text-transform: uppercase; letter-spacing: .25em; font-weight: 700; text-align: center; font-size: 1.3rem !important; }

/* ---------- Alerts & badges ---------- */

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--info-bg);
  color: var(--text);
  margin-bottom: 16px;
  border: 1px solid transparent;
  font-weight: 500;
}
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-warning { background: var(--warning-bg); color: var(--warning); }
.alert a { color: inherit; text-decoration: underline; font-weight: 700; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success); border-color: transparent; }
.badge-warning { background: var(--warning-bg); color: var(--warning); border-color: transparent; }
.badge-danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.badge-primary { background: var(--info-bg); color: var(--primary); border-color: transparent; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td .row { flex-wrap: nowrap; }

.pager { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 16px; }

/* ---------- Dialogs ---------- */

dialog.modal {
  border: 0;
  padding: 0;
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgb(15 11 29 / 55%); backdrop-filter: blur(3px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 0; }
.modal-head h3 { margin: 0; }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 0 20px 20px; flex-wrap: wrap; }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  inset-inline: 0;
  bottom: calc(20px + env(safe-area-inset-bottom));
  margin-inline: auto;
  width: fit-content;
  max-width: calc(100vw - 32px);
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: none; }

/* ---------- Landing ---------- */

.hero { text-align: center; padding-block: clamp(16px, 5vw, 48px) clamp(24px, 5vw, 40px); }
.hero h1 { font-size: clamp(2.2rem, 7vw, 3.8rem); font-weight: 800; margin-bottom: 12px; }
.hero h1 .grad { background: var(--gradient); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { font-size: clamp(1.05rem, 2.5vw, 1.25rem); color: var(--muted); max-width: 620px; margin-inline: auto; }

.feature-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); margin-top: 8px; }
.feature { display: flex; gap: 12px; align-items: flex-start; }
.feature svg { width: 26px; height: 26px; color: var(--primary); flex: none; margin-top: 2px; }

.stat { display: flex; flex-direction: column; }
.stat strong { font-size: 1.8rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .9rem; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
a.list-item:hover { text-decoration: none; border-color: var(--primary-2); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { text-align: center; color: var(--muted); padding: 24px 12px; }

/* ---------- Game ---------- */

.game { display: grid; gap: 16px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 900px) { .game { grid-template-columns: minmax(0, 1fr) 300px; } }

.lobby-share { display: grid; gap: 20px; grid-template-columns: 1fr; align-items: center; }
@media (min-width: 640px) { .lobby-share { grid-template-columns: auto 1fr; } }

.qr {
  width: 220px; height: 220px;
  margin-inline: auto;
  padding: 12px;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.qr svg { width: 100%; height: 100%; display: block; }

.join-code {
  font-size: clamp(2rem, 8vw, 2.8rem);
  font-weight: 800;
  letter-spacing: .18em;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}

.q-card { position: relative; overflow: hidden; }
.q-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 6px;
  background: var(--gradient);
}
.q-head { display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 18px; }
.q-num { font-weight: 700; color: var(--muted); }
.q-text {
  font-size: clamp(1.35rem, 4.5vw, 2rem);
  font-weight: 700;
  line-height: 1.3;
  margin: 8px 0 24px;
  overflow-wrap: anywhere;
}

.timer { position: relative; width: 64px; height: 64px; flex: none; }
.timer svg { transform: rotate(-90deg); width: 64px; height: 64px; }
.timer circle { fill: none; stroke-width: 6; }
.timer .track { stroke: var(--surface-2); }
.timer .bar { stroke: var(--primary); stroke-linecap: round; transition: stroke-dashoffset 1s linear, stroke .3s; }
.timer.low .bar { stroke: var(--danger); }
.timer span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums; }

.answer-form { display: flex; gap: 10px; }
.answer-form input { flex: 1; min-width: 0; min-height: 56px; font-size: 1.15rem !important; }
.answer-form .btn { min-height: 56px; }

.feedback { min-height: 0; margin-top: 14px; }
.feedback .alert { margin: 0; animation: pop .25s ease; }

.tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.reveal { text-align: center; padding-block: 12px; }
.reveal .answer { font-size: clamp(1.4rem, 5vw, 2rem); font-weight: 800; margin: 8px 0 16px; }
.reveal-msg { color: var(--muted); }

.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 20px; }
.progress > div { height: 100%; width: 0; background: var(--gradient); border-radius: inherit; transition: width .9s linear; }

.players .list-item { padding: 10px 12px; }
.players .points { font-weight: 800; font-variant-numeric: tabular-nums; }
.players .me { border-color: var(--primary-2); background: var(--info-bg); }

.winner { text-align: center; padding-block: 8px; }
.winner .trophy { width: 72px; height: 72px; color: var(--accent); margin: 0 auto 8px; animation: pop .5s ease; }
.winner h2 { font-size: clamp(1.6rem, 5vw, 2.2rem); }

.rank { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .85rem; background: var(--surface); border: 1px solid var(--border); flex: none; }
.rank-1 { background: #fbbf24; color: #1c1530; border-color: transparent; }
.rank-2 { background: #d1d5db; color: #1c1530; border-color: transparent; }
.rank-3 { background: #d97706; color: #fff; border-color: transparent; }

@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pulse { 50% { opacity: .55; } }
.pulse { animation: pulse 1.6s ease-in-out infinite; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Content ---------- */

.system { background: var(--warning-bg); padding: 8px 12px; border-radius: 8px; }
