/* شاشة التلفزيون: لوحة 1920×1080 تتمدد على أي شاشة. 1rem = 16px على 1920. */
html { font-size: min(calc(100vw / 120), calc(100vh / 67.5)); }
html, body { height: 100%; overflow: hidden; }
body.tv { font-size: 1.625rem; background-color: var(--deep); }

.frame {
  position: relative; height: 100vh; max-width: calc(100vh * 16 / 9); margin: 0 auto;
  display: flex; flex-direction: column; background: var(--navy) var(--pattern); background-size: 5.625rem 4.125rem;
}
.band { height: 1.75rem; background-size: 12.5rem 1.75rem; margin: 1.25rem 2rem 0; flex: none; }
.area { flex: 1; min-height: 0; padding: 1.5rem 4.5rem 0; position: relative; }
.area > section { height: 100%; display: flex; flex-direction: column; }
.connecting { text-align: center; margin-top: 30vh; }
.center { text-align: center; }
.err { color: var(--accent-text); min-height: 1.6em; font-size: 1.375rem; margin: .4em 0; }
.small { font-size: 1.25rem; }
.title { font-size: 3rem; margin: 0; }
.actions { display: flex; gap: 1rem; justify-content: center; align-items: center; padding: .75rem 0 0; flex-wrap: wrap; }
.btn { font-size: 1.5rem; }
.btn.big { font-size: 2rem; padding: .45em 1.8em; }

/* ---------- setup ---------- */
.setup-head { display: flex; align-items: center; gap: 2rem; margin-bottom: 1.25rem; }
.setup-head p { margin: 0; font-size: 1.5rem; }
.setup-body { flex: 1; min-height: 0; display: flex; gap: 2rem; }
.stage-groups { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 1.25rem 1.75rem; overflow-y: auto; padding: .25rem; }
.group { flex: 1 1 auto; }
.group-head { display: flex; align-items: center; gap: 1rem; margin-bottom: .6rem; }
.group-head .name { color: var(--accent-text); font-size: 1.375rem; font-weight: 600; }
.group-head .btn { font-size: 1.125rem; padding: .2em .9em; }
.group-cards { display: flex; flex-wrap: wrap; gap: .75rem; }
.stage-card {
  width: 10.5rem; min-height: 9.5rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .35rem;
  background: var(--up); color: var(--wool); border: 0; border-radius: var(--r); padding: .9rem .6rem; cursor: pointer; position: relative;
  font-family: "Readex", sans-serif;
}
.stage-card .stage-icon { color: var(--accent-text); line-height: 0; }
.stage-card .nm { font-size: 1.375rem; font-weight: 600; line-height: 1.25; text-align: center; }
.stage-card small { font-size: 1rem; color: var(--wool-dim); }
.stage-card.on { background: var(--saffron); color: var(--on-accent); }
.stage-card.on .stage-icon, .stage-card.on small { color: var(--on-accent); }
.stage-card .tick { position: absolute; top: .4rem; left: .6rem; font-family: "Lalezar"; font-size: 1.5rem; }
.stage-card:disabled { opacity: .4; cursor: default; }
.stage-card:focus-visible { outline: 3px solid var(--wool); outline-offset: 3px; }

.setup-side { width: 30rem; flex: none; padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: .9rem; align-self: flex-start; }
.opt { display: flex; flex-direction: column; gap: .4rem; font-size: 1.25rem; }
.opt.row { flex-direction: row; align-items: center; justify-content: space-between; }
.seg { display: flex; gap: .4rem; flex-wrap: wrap; }
.seg .btn, .toggle { background: var(--navy); font-size: 1.25rem; padding: .3em .9em; }
.seg .btn.on, .toggle.on { background: var(--saffron); color: var(--on-accent); }
.setup-side .btn.big { margin-top: .4rem; }

/* ---------- lobby ---------- */
.lobby-body { flex: 1; min-height: 0; display: flex; gap: 3rem; }
.lobby-players { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lobby-players .sub { margin: .2rem 0 1.25rem; font-size: 1.5rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 1rem; align-content: start; overflow: hidden; }
.tiles.many { grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr)); gap: .6rem; font-size: 1.25rem; }
.tile {
  background: var(--up); border-radius: var(--r); padding: 1rem .6rem .8rem; display: flex; flex-direction: column; align-items: center; gap: .4rem;
  position: relative; text-align: center; min-width: 0;
}
.tile .avatar { font-size: 1.75rem; }
.tiles.many .tile .avatar { font-size: 1.25rem; }
.tile .nm { font-family: "Lalezar"; font-size: 1.5rem; line-height: 1.2; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tiles.many .tile .nm { font-size: 1.25rem; }
/* A crowd (over 30, up to 50 on the owner's nights): each player is a short row, so everyone fits on one screen. */
.tiles.crowd { grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: .45rem; }
.tiles.crowd .tile { flex-direction: row; justify-content: flex-start; padding: .45rem .7rem; gap: .5rem; }
.tiles.crowd .tile .avatar { font-size: 1rem; flex: none; }
.tiles.crowd .tile .nm { font-size: 1.15rem; flex: 1; text-align: right; }
.tiles.crowd .tile .tools { flex: none; }
.tiles.crowd .tile .tools .btn { font-size: .8rem; padding: .1em .45em; }
.tiles.crowd .tile.empty { min-height: 0; justify-content: center; }
.tile.off { opacity: .45; }
.tile.empty { background: none; box-shadow: inset 0 0 0 2px var(--wool-faint); color: var(--wool-dim); justify-content: center; min-height: 8.5rem; border-radius: var(--r); }
.tile .tools { display: flex; gap: .3rem; }
.tile .tools .btn { font-size: 1rem; padding: .15em .6em; background: var(--navy); }
.team-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1.25rem; overflow: hidden; }
.team-col { display: flex; flex-direction: column; gap: .7rem; }
.team-col .head { display: flex; align-items: center; gap: .6rem; }
.team-col .head .team { font-size: 1.5rem; }
.team-col .head .btn { font-size: 1rem; padding: .2em .8em; }
.team-col .tiles { grid-template-columns: 1fr 1fr; }

.join { width: 30rem; flex: none; padding: 1.75rem; display: flex; flex-direction: column; align-items: center; text-align: center; align-self: flex-start; }
.join .qr { width: 21rem; height: 21rem; background: var(--paper); border-radius: var(--r); padding: .8rem; }
.join .qr svg { width: 100%; height: 100%; display: block; }
.join p { margin: .8rem 0 0; font-size: 1.375rem; }
.join .code { font-size: 5.5rem; letter-spacing: .12em; line-height: 1; margin-top: .3rem; }
.join .small { font-size: 1.125rem; }

/* ---------- question ---------- */
.q-head { display: flex; align-items: center; gap: 1.5rem; }
.stage-pill { font-size: 1.375rem; padding: .2em 1em; }
.stage-pill .stage-icon { line-height: 0; }
.q-head > .dim { font-size: 1.375rem; }
.ring { margin-right: auto; position: relative; width: 6.5rem; height: 6.5rem; flex: none; }
.ring svg { width: 100%; height: 100%; }
.ring-bg { fill: var(--up); stroke: var(--up); stroke-width: 8; }
.ring-fill { fill: none; stroke: var(--saffron); stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset .2s linear; }
.ring span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 2.75rem; }
.ring.low span { color: var(--accent-text); }
.q-text { font-size: 3.5rem; margin: .4rem 0 1.25rem; max-width: 95rem; }
.q-text.small { font-size: 2.75rem; margin-bottom: .75rem; }

.visual { position: relative; flex: 1; min-height: 0; padding: 1.25rem 2rem 3.25rem; }
.visual.short { flex: 0 0 19rem; }
.visual canvas { width: 100%; height: 100%; display: block; }
.labels { position: absolute; left: 2rem; right: 2rem; bottom: .9rem; height: 2.2rem; }
.lbl { position: absolute; transform: translateX(-50%); white-space: nowrap; font-size: 1.5rem; font-weight: 600; }
.lbl.target { color: var(--accent-text); }
/* Who took the real photos, shown small at the reveal (photos are public domain or freely licensed). */
.photo-credit { position: absolute; top: .6rem; left: 1rem; font-size: .95rem; color: var(--wool-dim); }

.choices { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-content: start; }
.choice { background: var(--up); border-radius: var(--r); padding: 1.25rem 1.5rem; font-size: 2.25rem; display: flex; flex-wrap: wrap; align-items: center; gap: .3rem 1rem; position: relative; }
.choice .letter { font-family: "Lalezar"; color: var(--accent-text); font-size: 2.25rem; width: 3rem; height: 3rem; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; box-shadow: inset 0 0 0 2px var(--saffron); line-height: 1; }
.choice .pickers { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: .4rem; font-size: 1.125rem; }
.choice .pickers .avatar { font-size: 1.125rem; }
.choice.right { box-shadow: inset 0 0 0 4px var(--truth); }
.choice.right::after { content: "الصح"; position: absolute; top: -1rem; left: 1.25rem; background: var(--truth); color: var(--wool); font-family: "Lalezar"; font-size: 1.375rem; padding: 0 .8em; border-radius: 99px; }
.choice.wrong { opacity: .45; }

.big-note { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; font-family: "Lalezar"; font-size: 3.5rem; color: var(--wool-dim); }
.chips { display: flex; flex-wrap: wrap; gap: .6rem; padding: 1rem 0 .5rem; min-height: 4rem; margin-top: auto; }
.chip { display: inline-flex; align-items: center; gap: .5rem; background: var(--up); border-radius: 99px; padding: .25rem 1rem .25rem .3rem; font-size: 1.25rem; opacity: .5; }
.chip .avatar { font-size: .9rem; }
.chip.done { opacity: 1; box-shadow: inset 0 0 0 2px var(--saffron); }
.chips.many .chip { padding: .2rem; }
.chips.many .chip .nm { display: none; }

/* ---------- reveal: the ruler, the red thread and the needle ---------- */
.ruler-wrap { flex: none; padding: 0 1rem; margin-top: auto; }
.ruler { position: relative; height: 19rem; }
.ruler .bar {
  position: absolute; left: 0; right: 0; bottom: 1.6rem; height: 2.6rem; border-radius: .6rem; box-shadow: inset 0 0 0 3px var(--wool);
  background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 3px), var(--wool) calc(10% - 3px) 10%) 0 0 / 100% 45% no-repeat;
}
.mark { position: absolute; bottom: 4.4rem; transform: translateX(-50%); direction: rtl; display: flex; flex-direction: column; align-items: center; opacity: 0; transition: opacity .35s, transform .35s; }
.mark.shown { opacity: 1; }
.mark:not(.actual) { z-index: 1; }
.mark .who, .mark .val { background: var(--navy); border-radius: .4rem; padding: 0 .3rem; }
.mark .who { font-size: 1.25rem; font-weight: 600; white-space: nowrap; }
.mark .val { font-size: 1.05rem; color: var(--wool-dim); white-space: nowrap; }
.mark .avatar { font-size: 1.05rem; margin-top: .2rem; }
.mark.exact .avatar { box-shadow: inset 0 0 0 3px var(--saffron); }
.mark.exact .who::after { content: " · بالضبط!"; color: var(--accent-text); }
.mark.up { bottom: 10.2rem; }
.ruler.dense .mark .val { display: none; }
.ruler.dense .mark.up { bottom: 8.6rem; }
/* A crowd: pictures only, names stay for whoever got it exactly. */
.ruler.crowd .mark .who, .ruler.crowd .mark .val { display: none; }
.ruler.crowd .mark.exact .who { display: block; }
.ruler.crowd .mark.up { bottom: 6.4rem; }
.mark.actual { bottom: 1.6rem; z-index: 0; }
.mark.actual .tag { background: var(--truth); color: var(--wool); font-family: "Lalezar"; font-size: 1.75rem; padding: .05em .9em; border-radius: 99px; white-space: nowrap; }
/* The «الصح» tag sits above both rows of players, so it never covers a name. */
.mark.actual svg { display: block; width: 2.4rem; height: 14.6rem; overflow: visible; }
.mark.actual .thread { fill: none; stroke: var(--truth); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 140; stroke-dashoffset: 140; }
.mark.actual.shown .thread { animation: sew 1s ease-out forwards; }
.mark.actual .needle { fill: var(--wool); opacity: 0; }
.mark.actual.shown .needle { animation: appear .2s 1s forwards; }
@keyframes sew { to { stroke-dashoffset: 0; } }
@keyframes appear { to { opacity: 1; } }
.ends { display: flex; justify-content: space-between; font-size: 1.25rem; color: var(--wool-dim); margin-top: -1.4rem; padding: 0 .3rem; }
.fact { padding: .8rem 1.5rem; margin: 1rem 0 0; font-size: 1.5rem; text-align: center; }
#rNotes { font-size: 1.25rem; margin: .6rem 0 auto; }

/* ---------- leaderboard ---------- */
#leaderboard .title { margin-bottom: 1rem; }
.answer { padding: .8rem 1.5rem; margin-bottom: 1rem; text-align: center; font-size: 1.5rem; }
.answer .truth { display: inline-block; background: var(--truth); color: var(--wool); font-family: "Lalezar"; font-size: 1.75rem; padding: 0 .9em; border-radius: 99px; }
.answer .dim { display: block; margin-top: .4rem; }
.board, .teams-board { list-style: none; margin: 0 auto; padding: 0; width: 100%; max-width: 70rem; display: flex; flex-direction: column; gap: .6rem; }
.board.cols { max-width: none; display: grid; grid-auto-flow: column; grid-template-rows: repeat(var(--rows), auto); grid-template-columns: repeat(var(--cols), 1fr); column-gap: 1.25rem; }
.board li, .teams-board li { display: flex; align-items: center; gap: 1rem; background: var(--up); border-radius: var(--r); padding: .55rem 1.25rem; font-size: 1.75rem; }
.board.cols li { font-size: 1.25rem; padding: .3rem .8rem; gap: .6rem; }
.board .rk, .teams-board .rk { font-family: "Lalezar"; color: var(--accent-text); width: 2.2rem; text-align: center; }
.board .avatar { font-size: 1.125rem; }
.board.cols .avatar { font-size: .85rem; }
.board .nm, .teams-board .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.board .delta, .teams-board .delta { color: var(--accent-text); font-family: "Lalezar"; }
.board .sc, .teams-board .sc { font-family: "Lalezar"; min-width: 4rem; text-align: left; }
.board li.first { box-shadow: inset 0 0 0 3px var(--saffron); }
.teams-board { margin-bottom: 1.25rem; }
.teams-board .members { display: block; font-size: 1.125rem; color: var(--wool-dim); font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
.teams-board .team { font-size: 1.5rem; }

/* ---------- awards ---------- */
.award-grid { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(24rem, 1fr)); gap: 1.25rem; align-content: center; }
.award { background: var(--up); border-radius: var(--r); padding: 1.5rem; display: flex; flex-direction: column; gap: .5rem; opacity: 0; transform: translateY(1rem); transition: opacity .5s, transform .5s; }
.award.shown { opacity: 1; transform: none; }
.award .icon { font-size: 2.5rem; line-height: 1; }
.award .ttl { font-family: "Lalezar"; font-size: 2.25rem; color: var(--accent-text); line-height: 1.2; }
.award .who { display: flex; align-items: center; gap: .6rem; font-size: 1.5rem; font-weight: 600; }
.award .who .avatar { font-size: 1.125rem; }
.award .line { color: var(--wool-dim); font-size: 1.25rem; }

/* ---------- final ---------- */
.final-teams { display: flex; justify-content: center; gap: 1rem; margin: .8rem 0 0; }
.final-teams .team { font-size: 1.5rem; }
.final-teams .team .sc { font-family: "Lalezar"; margin-right: .4em; }
.final-body { flex: 1; min-height: 0; display: flex; gap: 2.5rem; align-items: flex-end; }
.final-awards { width: 26rem; flex: none; display: flex; flex-direction: column; gap: .8rem; align-self: center; }
.final-awards .award { opacity: 1; transform: none; padding: .9rem 1.25rem; gap: .2rem; }
.final-awards .award .ttl { font-size: 1.625rem; }
.final-awards .award .icon { display: none; }
.final-awards .award .line { font-size: 1.125rem; }
.podium { flex: 1; display: flex; justify-content: center; align-items: flex-end; gap: 1rem; height: 100%; }
.pod { width: 13rem; display: flex; flex-direction: column; align-items: center; gap: .4rem; }
.pod .avatar { font-size: 2.25rem; }
.pod .nm { font-family: "Lalezar"; font-size: 2rem; line-height: 1.1; text-align: center; }
.pod .pts { color: var(--wool-dim); font-size: 1.25rem; }
.pod .block { width: 100%; background: var(--up); border-radius: var(--r) var(--r) 0 0; display: flex; justify-content: center; padding-top: .8rem; font-family: "Lalezar"; font-size: 4rem; line-height: 1; }
.pod.p1 .block { background: var(--saffron); color: var(--on-accent); }
.pod.p1 .avatar { box-shadow: inset 0 0 0 4px var(--saffron); }
#finalRest { font-size: 1.25rem; margin: .6rem 0 0; }

/* ---------- controls, reactions, dialogs ---------- */
.controls { flex: none; display: flex; align-items: center; gap: .6rem; padding: .8rem 2rem; background: var(--deep); }
.controls .btn { font-size: 1.25rem; padding: .35em 1em; }
.controls .spacer { flex: 1; }
.controls .room-tag { font-size: 1.25rem; }
.controls .icon { font-family: system-ui, "Segoe UI Emoji", sans-serif; }

.react-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 40; }
.react-float { position: absolute; bottom: 5rem; display: flex; flex-direction: column; align-items: center; gap: .2rem; animation: float 3.2s ease-out forwards; }
.react-float .e { font-size: 4rem; line-height: 1; font-family: system-ui, "Segoe UI Emoji", sans-serif; }
.react-float .who { background: var(--up); color: var(--wool); border-radius: 99px; padding: 0 .8em; font-size: 1.125rem; font-weight: 600; }
@keyframes float { 0% { transform: translateY(0); opacity: 0; } 10% { opacity: 1; } 80% { opacity: 1; } 100% { transform: translateY(-55vh); opacity: 0; } }

.dialog-back { position: fixed; inset: 0; background: rgba(22, 27, 63, .82); display: flex; align-items: center; justify-content: center; z-index: 60; }
.dialog { width: min(46rem, 90vw); padding: 2rem 2.5rem; text-align: center; }
.dialog h2 { font-size: 2.5rem; margin: 0 0 .6rem; }
.dialog .opt { margin: 1rem 0; text-align: right; }
.dialog input { width: 100%; padding: .6em .9em; border-radius: var(--r); border: 0; background: var(--navy); color: var(--wool); font-size: 1.5rem; margin: .6rem 0; }
.suggest { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; }
.suggest .btn { background: var(--navy); font-size: 1.25rem; padding: .25em .9em; }

/* "+99" reads left to right even inside Arabic text. */
.delta, .ltr-num { direction: ltr; unicode-bidi: isolate; }
#leaderboard { justify-content: center; padding-bottom: 3rem; }

/* ---------- the host's phone ---------- */
.control-card { display: flex; align-items: center; gap: 1rem; background: var(--up); border-radius: var(--r); padding: .8rem 1.1rem; }
.control-card .mini-qr { width: 7.5rem; height: 7.5rem; flex: none; background: var(--paper); border-radius: .6rem; padding: .35rem; }
.control-card .mini-qr svg { width: 100%; height: 100%; display: block; }
.control-card .txt { display: flex; flex-direction: column; gap: .25rem; text-align: right; }
.control-card b { font-family: "Lalezar"; font-weight: 400; font-size: 1.5rem; color: var(--accent-text); line-height: 1.2; }
.control-card .dim { font-size: 1.125rem; margin: 0; }
.control-card .btn { font-size: 1.125rem; padding: .25em .9em; background: var(--navy); align-self: flex-start; }
#ctlSetup { margin-right: auto; }
.join .control-card, #ctlSettings .control-card { background: var(--navy); margin-top: 1.25rem; }
.join .control-card .btn, #ctlSettings .control-card .btn { background: var(--up); }
.lobby-stages { display: flex; flex-wrap: wrap; gap: .5rem; margin: -.4rem 0 1.25rem; }
.lobby-stages .pill { font-size: 1.125rem; }
.lobby-stages .stage-icon { line-height: 0; }
.join .control-card { width: 100%; justify-content: center; }
.dialog .opt > .toggle { align-self: flex-start; }

/* ---------- linking the TV to an account ---------- */
#acctSetup .control-card .link-code { font-family: "Lalezar"; font-size: 2rem; letter-spacing: .18em; color: var(--wool); line-height: 1.1; }
#acctSetup .control-card.linked { padding: 1rem 1.25rem; }
#acctSetup .control-card .site { font-size: 1rem; text-align: right; }

/* ---------- the room's plan ---------- */
.plan-line { margin: 0; font-size: 1.125rem; color: var(--wool-dim); }
.lobby-players .plan-line { margin: -.6rem 0 1rem; }
.stage-card.locked { opacity: .5; }
.stage-card.locked small { color: var(--accent-text); }
.seg .btn.locked { opacity: .35; }
.toggle:disabled { opacity: .35; }
.upsell { font-family: "Lalezar"; font-size: 1.75rem; color: var(--accent-text); margin: .4rem 0 0; }

/* The setup panel holds more now (the plan line, the names switch): tighter spacing so it fits above the control bar. */
.setup-side { gap: .5rem; padding: 1rem 1.25rem; }
.setup-side .opt { gap: .25rem; font-size: 1.125rem; }
.setup-side .seg .btn, .setup-side .toggle { font-size: 1.125rem; padding: .2em .8em; }
.setup-side .btn.big { margin-top: .2rem; font-size: 1.75rem; }

/* Join QR over the game (a guest who arrives late). It sits at the side, so the question stays readable. */
.join-over { position: fixed; top: 5.5rem; left: 2rem; z-index: 50; }
.join-over .join { width: 24rem; padding: 1.4rem; box-shadow: 0 0 0 .3rem var(--saffron); }
.join-over .join h2 { margin: 0 0 .6rem; font-size: 2.2rem; font-weight: 400; color: var(--accent-text); }
.join-over .join .qr { width: 17rem; height: 17rem; }
.join-over .join .code { font-size: 4rem; }

/* Secondary buttons inside a dialog card take the darker navy, so «لا» reads as a button. */
.dialog .btn:not(.primary) { background: var(--navy); color: var(--wool); }
