/*
 * The Cluster (הקלאסטר) theme.
 * Flat and deliberate: solid surfaces, hairline rules, square-ish corners,
 * condensed scoreboard numerals, cyan from the logo used only where it means
 * something, amber for first place.
 */
:root {
  --bg: #0b2530;
  --bg-deep: #081c25;
  --surface: #0f3140;
  --surface-2: #143c4d;
  --line: #1f4a5c;
  --line-strong: #2d6177;
  --text: #f1f8f9;
  --text-2: #a6c3ca;
  --text-3: #6f929b;
  --accent: #5fe6f4;
  --accent-hover: #8beef8;
  --accent-ink: #062530;
  --accent-tint: #123f4e;
  --gold: #f2b640;
  --gold-ink: #2a1c00;
  --good: #34c98a;
  --good-ink: #03251a;
  --good-tint: #0f3d34;
  --bad: #ef6a6a;
  --bad-ink: #2b0808;
  --bad-tint: #3b1f27;
  --radius: 4px;
  --font: Rubik, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --num: "Barlow Condensed", Rubik, ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { color-scheme: dark; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--text); background: var(--bg);
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.86em;
  color: var(--accent); background: var(--bg-deep); border-radius: 3px; padding: 0.05em 0.35em;
}

/* ---------- type ---------- */
.eyebrow, .label {
  font-family: var(--num); font-size: 15px; font-weight: 600; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-3);
}
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.small { font-size: 14px; }
.error { color: var(--bad); min-height: 1.3em; font-size: 14px; }
.h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.h2 { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.num { font-family: var(--num); font-weight: 700; letter-spacing: 0.01em; }

/* ---------- app shell ---------- */
.appbar {
  height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 max(24px, env(safe-area-inset-right)) 0 max(24px, env(safe-area-inset-left));
  background: var(--bg-deep); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; flex: none; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand-mark { height: 32px; width: auto; }
.brand .sub { font-weight: 400; color: var(--text-3); }
.brand-logo { display: block; margin: 0 auto; height: auto; }
.appbar-right { display: flex; align-items: center; gap: 12px; color: var(--text-2); font-size: 15px; }
.appbar-right b { color: var(--text); }
.chip-info { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--radius); }

/* Full-viewport screens for the projector: body + bottom bar. */
.fill { height: calc(100vh - 60px); height: calc(100dvh - 60px); display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.fill-body { min-height: 0; padding: clamp(24px, 4vh, 48px) clamp(24px, 4vw, 64px); }
.bar {
  position: sticky; bottom: 0; z-index: 6; display: flex; align-items: center; gap: 16px; padding: 14px clamp(24px, 4vw, 64px);
  background: var(--bg-deep); border-top: 1px solid var(--line);
}
.bar .spacer { flex: 1; }

.page { max-width: 720px; margin: 0 auto; padding: 40px 20px 60px; }
.center { display: grid; place-items: center; text-align: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card-pad { padding: 28px; }
.stack > * + * { margin-top: 18px; }
.stack-sm > * + * { margin-top: 8px; }

/* ---------- forms ---------- */
label.field { display: block; font-size: 14px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
input[type="text"], input[type="password"] { -webkit-appearance: none; appearance: none; }
input[type="text"], input[type="password"], select {
  width: 100%; padding: 12px 14px; font: 500 16px var(--font); color: var(--text);
  background: var(--bg-deep); border: 1px solid var(--line-strong); border-radius: var(--radius); outline: none;
}
select option { background: var(--surface); color: var(--text); }
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-3); }
input.pin { font-family: var(--num); font-size: 34px; font-weight: 700; letter-spacing: 0.3em; text-align: center; padding: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 44px;
  padding: 12px 22px; font: 600 15px/1 var(--font); border-radius: var(--radius);
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); cursor: pointer;
  -webkit-appearance: none; appearance: none; transition: background 0.15s, border-color 0.15s, transform 0.12s;
}
button { touch-action: manipulation; }
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.lg { padding: 15px 26px; font-size: 17px; }
.btn.sm { min-height: 36px; padding: 7px 12px; font-size: 14px; }
.sound { display: inline-flex; align-items: center; gap: 10px; }
.sound input[type="range"] { width: 90px; accent-color: var(--accent); }
@media (max-width: 700px) { .sound input[type="range"] { display: none; } }
.btn.secondary { background: transparent; color: var(--text); border-color: var(--line-strong); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--bad-tint); }
.btn.danger:hover { border-color: var(--bad); }
.btn kbd { font: 600 11px/1 var(--font); padding: 3px 5px; border-radius: 2px; border: 1px solid currentColor; opacity: 0.55; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.toggle-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; user-select: none;
  border: 1px solid var(--line-strong); border-radius: var(--radius); font-size: 14px; color: var(--text-2);
}
.toggle-chip input { accent-color: var(--accent); margin: 0; }
.toggle-chip:has(input:checked) { border-color: var(--accent); color: var(--text); background: var(--accent-tint); }
.toggle-chip .n { color: var(--text-3); font-family: var(--num); font-size: 14px; }
.grid-3 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 15px; color: var(--text-2); user-select: none; }
.switch input { -webkit-appearance: none; appearance: none; width: 38px; height: 22px; border-radius: 11px; background: var(--line-strong); position: relative; cursor: pointer; transition: background 0.15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--text); transition: transform 0.15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); background: var(--accent-ink); }

/* ---------- answers: a solid letter block + the answer text ---------- */
.answers { display: grid; gap: 8px; }
.answer {
  position: relative; overflow: hidden; display: flex; align-items: stretch; width: 100%; padding: 0;
  text-align: left; font: 500 17px/1.35 var(--font); color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  transition: background 0.15s, border-color 0.15s, opacity 0.25s, transform 0.12s;
}
.answer > * { position: relative; }
.answer .badge {
  flex: none; width: 52px; display: grid; place-items: center;
  font-family: var(--num); font-size: 24px; font-weight: 700; color: var(--accent);
  background: var(--bg-deep); border-right: 1px solid var(--line);
}
.answer .answer-text { flex: 1; min-width: 0; padding: 14px 16px; align-self: center; overflow-wrap: anywhere; }
.answer .answer-meta { flex: none; align-self: center; padding: 0 18px; text-align: right; font-family: var(--num); font-size: 1.25em; font-weight: 700; color: var(--text-2); }
.answer .answer-meta small { display: block; font-family: var(--font); font-size: 0.55em; font-weight: 400; color: var(--text-3); }
.answer .answer-fill { position: absolute; inset: 0 auto 0 0; width: var(--pct, 0%); background: var(--surface-2); animation: grow 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) 0.1s backwards; }

button.answer { cursor: pointer; -webkit-appearance: none; appearance: none; }
button.answer:active { transform: scale(0.985); }
button.answer:hover { border-color: var(--line-strong); background: var(--surface-2); }
.answer.chosen { border-color: var(--accent); }
.answer.chosen .badge { background: var(--accent); color: var(--accent-ink); border-right-color: var(--accent); }
.answers.locked .answer:not(.chosen) { opacity: 0.4; }
.answers.locked .answer { pointer-events: none; }

.answer.correct { border-color: var(--good); }
.answer.correct .badge { background: var(--good); color: var(--good-ink); border-right-color: var(--good); }
.answer.correct .answer-fill { background: var(--good-tint); }
.answer.correct .answer-meta { color: var(--good); }
.answer.wrong { color: var(--text-2); }
.answer.wrong .badge { color: var(--text-3); }

/* ---------- timer bar ---------- */
.timebar { height: 4px; background: var(--line); overflow: hidden; }
.timebar > i { display: block; height: 100%; width: 100%; background: var(--accent); transform-origin: left; transition: background 0.3s; }
.timebar.low > i { background: var(--bad); }
.bar > .timebar { position: absolute; top: -1px; left: 0; right: 0; height: 3px; background: transparent; }

/* ---------- ranking list: hairline rows ---------- */
.rank-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.rank-row {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) auto 140px; align-items: center; gap: 16px;
  padding: 10px 4px; border-bottom: 1px solid var(--line); animation: rise 0.3s ease-out both;
}
.rank-row .rank { font-family: var(--num); font-size: 1.5em; font-weight: 700; color: var(--text-3); text-align: center; }
.rank-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .delta { font-family: var(--num); font-weight: 600; color: var(--good); }
.rank-row .score { font-family: var(--num); font-size: 1.3em; font-weight: 700; text-align: right; }
.rank-row { position: relative; }
.flip .rank-row { animation: none; }
.rank-row.first .rank { color: var(--gold); }
.rank-row.first .name, .rank-row.first .score { color: var(--gold); }

/* ---------- misc ---------- */
.pill {
  display: inline-block; font-family: var(--num); font-size: 15px; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--accent);
}
.pill.gray { color: var(--text-3); }
.dot-loader { display: inline-flex; gap: 6px; }
.dot-loader i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: pulse 1.2s ease-in-out infinite; }
.dot-loader i:nth-child(2) { animation-delay: 0.15s; }
.dot-loader i:nth-child(3) { animation-delay: 0.3s; }
.rows { border-top: 1px solid var(--line); }
.rows > div { display: flex; justify-content: space-between; gap: 16px; padding: 12px 2px; font-size: 15px; border-bottom: 1px solid var(--line); }
.rows .k { color: var(--text-2); }
.rows .v { font-weight: 600; text-align: right; }

html { scroll-behavior: smooth; }
.screen-enter { animation: screenIn 0.34s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
@keyframes screenIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes grow { from { width: 0; } }
@keyframes okpulse { 0% { transform: scale(1); } 35% { transform: scale(1.025); } 100% { transform: scale(1); } }
@keyframes dim { to { opacity: 0.6; } }
@keyframes bump { 40% { transform: scale(1.18); } }
.answer.correct { animation: okpulse 0.6s ease-out 0.15s; }
.answer.wrong { animation: dim 0.5s ease 0.2s both; }
.bump { display: inline-block; animation: bump 0.3s ease-out; }
.player.leaving { opacity: 0; transform: scale(0.8); transition: opacity 0.18s, transform 0.18s; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }
.rise { animation: rise 0.3s ease-out both; }
.pop { animation: rise 0.3s ease-out both; }

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