/* لعبة القوافي — night-sky teal with gold accents. Right-to-left throughout. */
:root {
  --bg: #0b1d2e;
  --bg2: #123047;
  --panel: rgba(18, 48, 71, .55);
  --line: rgba(255, 255, 255, .12);
  --text: #fff4dc;
  --muted: #a9c3d6;
  --gold: #f7b538;
  --gold2: #ffcd6b;
  --red: #e8434f;
  --ok: #3ddc97;
  --pa: #ff6b6b;
  --pb: #5ec8ff;
  --display: "Lalezar", "Cairo", system-ui, sans-serif;
  --ui: "Cairo", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
[hidden] { display: none !important; }
body {
  background: radial-gradient(1000px 520px at 50% -12%, rgba(247, 181, 56, .16), transparent 70%), linear-gradient(180deg, var(--bg2), var(--bg) 60%);
  background-attachment: fixed;
  color: var(--text); font: 15px/1.6 var(--ui); font-synthesis-weight: none;
}
body.playing { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
h2 { margin: 0; font: 400 24px/1.3 var(--display); }
a { color: var(--muted); }
bdi { unicode-bidi: isolate; }

/* ---------- Buttons & inputs ---------- */
.btn { background: rgba(255, 255, 255, .08); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; cursor: pointer; font-weight: 700; white-space: nowrap; }
.btn:hover { background: rgba(255, 255, 255, .14); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 9px; unicode-bidi: plaintext; }
.btn.primary { background: var(--gold); color: #1c1300; border-color: transparent; }
.btn.primary:hover { background: var(--gold2); }
.btn.ghost { background: rgba(0, 0, 0, .2); }
.btn.big { font: 400 24px/1.3 var(--display); padding: 12px 26px; border-radius: 16px; }
input[type=text], input[type=email], input[type=number], select {
  background: rgba(4, 16, 26, .6); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; min-width: 0; width: 100%;
}
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--gold); }
select { width: auto; }

/* ---------- Home ---------- */
#home { max-width: 1120px; margin: 0 auto; padding: 22px max(16px, env(safe-area-inset-right)) 40px max(16px, env(safe-area-inset-left)); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-bottom: 18px; }
.logo { position: relative; display: inline-flex; flex-direction: column; align-items: center; padding-bottom: 14px; }
.logo-title { font: 400 50px/1.15 var(--display); text-shadow: 0 3px 0 #04101a, 0 6px 0 #04101a, 0 12px 24px rgba(0, 0, 0, .4); }
.logo-tag { position: absolute; left: -18px; bottom: -4px; transform: rotate(-4deg); background: var(--red); color: #fff; font: 400 14px/1.5 var(--display); padding: 1px 12px; border-radius: 99px; box-shadow: 0 0 0 2px var(--text); }
.topbtns { display: flex; gap: 8px; flex-wrap: wrap; }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: linear-gradient(90deg, rgba(247, 181, 56, .22), rgba(232, 67, 79, .2)); border: 1px solid rgba(247, 181, 56, .5); border-radius: 14px; padding: 12px 16px; margin-bottom: 14px; }
.banner b { font: 400 20px var(--display); }
.banner span { color: var(--muted); }

.modes, .tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.modes button, .tabs button { background: rgba(0, 0, 0, .25); border: 1px solid var(--line); border-radius: 999px; padding: 8px 18px; cursor: pointer; font-weight: 700; }
.modes button { font: 400 19px/1.4 var(--display); padding: 8px 22px; }
.modes button[aria-selected=true], .tabs button[aria-selected=true] { background: var(--gold); color: #1c1300; border-color: transparent; }

.grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 14px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; backdrop-filter: blur(4px); }
#dailyPanel, #battlePanel, .panel.go { grid-column: 1 / -1; }
#beatPanel { grid-row: span 2; }
@media (max-width: 820px) { .grid { grid-template-columns: minmax(0, 1fr); } #beatPanel { grid-row: auto; } .logo-title { font-size: 40px; } }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lead { margin: 0; color: var(--muted); }
.help { margin: 0; color: var(--muted); font-size: 13.5px; }
.msg { margin: 0; font-size: 14px; color: var(--muted); }
.msg.err { color: #ffb4a8; } .msg.ok { color: var(--ok); }
.row { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.col { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; color: var(--muted); font-weight: 600; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two label { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; color: var(--muted); font-weight: 600; }
.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inline input { flex: 1 1 180px; width: auto; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: rgba(0, 0, 0, .25); border: 1px solid var(--line); border-radius: 12px; padding: 6px 16px; cursor: pointer; font: 400 19px/1.4 var(--display); }
.chip[aria-checked=true] { background: var(--text); color: var(--bg); }

.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: rgba(0, 0, 0, .22); border-radius: 14px; padding: 10px; text-align: center; display: flex; flex-direction: column; }
.stat b { font: 400 28px/1.3 var(--display); color: var(--gold); }
.stat span { font-size: 13px; color: var(--muted); }

.beats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 380px; overflow-y: auto; }
.beats li { display: flex; align-items: center; gap: 6px; }
.pick { flex: 1; min-width: 0; text-align: start; background: rgba(4, 16, 26, .45); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; cursor: pointer; display: flex; flex-direction: column; }
.pick:hover { background: rgba(255, 255, 255, .07); }
.beats li.active .pick { border-color: var(--gold); background: rgba(247, 181, 56, .12); box-shadow: inset -3px 0 0 var(--gold); }
.bname { font-weight: 700; display: flex; align-items: center; gap: 8px; overflow: hidden; white-space: nowrap; }
.bmeta { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: plaintext; text-align: start; }
.badge { font-size: 11px; font-weight: 700; padding: 0 8px; border-radius: 99px; background: rgba(255, 80, 80, .18); color: #ffc0c0; }
.badge.ok { background: rgba(61, 220, 151, .15); color: var(--ok); }
.beats .yt { text-decoration: none; padding: 4px 8px; }

.go { flex-direction: row !important; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.go-main { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.start { font: 400 30px/1.2 var(--display); padding: 14px 52px; border-radius: 18px; box-shadow: 0 8px 0 #a86f0b, 0 14px 30px rgba(247, 181, 56, .25); transition: transform .08s, box-shadow .08s; }
.start:active { transform: translateY(5px); box-shadow: 0 3px 0 #a86f0b; }
.rec { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 700; background: rgba(232, 67, 79, .14); border: 1px solid rgba(232, 67, 79, .4); padding: 8px 14px; border-radius: 12px; }
.stats { color: var(--muted); font-size: 14px; }
.keys { display: flex; flex-wrap: wrap; gap: 6px 16px; list-style: none; margin: 0; padding: 0; color: var(--muted); font-size: 13px; width: 100%; }
kbd { font: 700 12px var(--ui); background: rgba(255, 255, 255, .1); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 0 6px; color: var(--text); }
.foot { text-align: center; color: var(--muted); font-size: 13px; padding-top: 22px; }

/* ---------- Dialogs ---------- */
dialog.sheet { width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow-y: auto; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 20px; padding: 20px; }
dialog.sheet::backdrop { background: rgba(2, 8, 14, .72); backdrop-filter: blur(3px); }
.sheet-body { display: flex; flex-direction: column; gap: 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; min-height: 120px; }
.board li { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 12px; background: rgba(255, 255, 255, .05); }
.board li.me { background: rgba(247, 181, 56, .16); box-shadow: inset -3px 0 0 var(--gold); }
.board li.empty { justify-content: center; color: var(--muted); background: none; }
.board .rank { width: 30px; text-align: center; font-weight: 800; }
.board .who { flex: 1; font-weight: 700; }
.board .score { color: var(--gold); font-weight: 800; unicode-bidi: plaintext; }
.ytbox { width: 100%; aspect-ratio: 16/9; background: #000; border-radius: 12px; overflow: hidden; }
.ytbox iframe, .ytslot iframe { width: 100%; height: 100%; border: 0; display: block; }

/* ---------- Stage ---------- */
#stageWrap { position: fixed; inset: 0; background: #07121d; display: grid; place-items: center; overflow: hidden; }
#stageWrap.idle { cursor: none; }
#stageCanvas { display: block; }
.ytslot { position: absolute; left: 14px; bottom: 14px; width: 220px; aspect-ratio: 16/9; border-radius: 12px; overflow: hidden; background: #000; display: none; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); }
#stageWrap.has-yt .ytslot { display: block; }
.chrome { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); display: flex; gap: 8px; align-items: center; transition: opacity .3s; }
.chrome .btn { background: rgba(4, 16, 26, .6); backdrop-filter: blur(6px); }
#stageWrap.idle .chrome { opacity: 0; pointer-events: none; }
.recdot { display: none; color: #fff; background: var(--red); border-radius: 99px; padding: 2px 10px; font-size: 12px; font-weight: 800; direction: ltr; animation: blink 1.2s infinite; }
#stageWrap.recording .recdot { display: inline-block; }
@keyframes blink { 50% { opacity: .45; } }
#toast { position: absolute; top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); background: rgba(4, 16, 26, .85); border: 1px solid var(--line); border-radius: 10px; padding: 6px 14px; opacity: 0; transition: opacity .3s; pointer-events: none; unicode-bidi: plaintext; }
#toast.show { opacity: 1; transition: none; }
#stageMsg { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(4, 16, 26, .9); border: 1px solid var(--line); border-radius: 14px; padding: 14px 20px; font-size: 18px; font-weight: 700; max-width: 90%; text-align: center; }
#stageMsg.clickable { cursor: pointer; border-color: var(--gold); }
.overlay { position: absolute; inset: 0; background: rgba(2, 8, 14, .6); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 16px; }
.card { background: var(--bg); border: 1px solid var(--line); border-radius: 20px; padding: 22px; width: min(480px, 100%); max-height: calc(100% - 32px); overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.card.video video { width: 100%; max-height: 60vh; border-radius: 12px; background: #000; }
.sync { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.sync b { min-width: 70px; text-align: center; unicode-bidi: plaintext; }
.endcard { position: absolute; left: 0; right: 0; bottom: 6%; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 0 16px; animation: rise .5s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } }
.endcard .xp { margin: 0; font: 400 26px/1.4 var(--display); color: var(--gold); text-align: center; }
.endlink { color: var(--gold); font-weight: 700; word-break: break-all; text-align: center; background: rgba(4, 16, 26, .7); padding: 4px 12px; border-radius: 10px; }
.vote { text-align: center; }
.vote p { margin: 0 0 8px; font: 400 26px var(--display); }
.btn.pa { background: var(--pa); color: #2a0606; border: 0; }
.btn.pb { background: var(--pb); color: #03202f; border: 0; }
@media (prefers-reduced-motion: reduce) { .endcard, .recdot { animation: none; } }
.topbtns .btn { display: inline-flex; align-items: center; gap: 8px; }
.pill { background: rgba(247, 181, 56, .16); color: var(--gold); border-radius: 99px; padding: 0 8px; font-size: 13px; }

/* ---------- Progression ---------- */
.levelbar { display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px; margin-bottom: 14px; }
.lv { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--gold); color: #1c1300; font: 400 24px/1 var(--display); box-shadow: 0 0 0 3px rgba(247, 181, 56, .3); }
.lvtext { display: flex; flex-direction: column; line-height: 1.3; }
.lvtext b { font: 400 20px var(--display); }
.lvtext span { font-size: 12.5px; color: var(--muted); }
.xpbar { height: 10px; border-radius: 99px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.xpbar i { display: block; height: 100%; width: 0; background: linear-gradient(270deg, var(--gold2), var(--gold)); border-radius: 99px; transition: width .6s; margin-inline-start: 0; }
.toggle { align-items: flex-start; }
.toggle input { margin-top: 4px; }
.toggle small { display: block; color: var(--muted); font-size: 12.5px; }
.toggle.locked { opacity: .55; }
.lock { font-style: normal; font-size: 12px; font-weight: 700; color: var(--gold); background: rgba(247, 181, 56, .12); border-radius: 99px; padding: 1px 8px; margin-inline-start: auto; white-space: nowrap; }
.skins { display: flex; gap: 8px; flex-wrap: wrap; }
.skin { width: 38px; height: 38px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; position: relative; }
.skin[aria-checked=true] { border-color: var(--text); box-shadow: 0 0 0 3px rgba(255, 244, 220, .25); }
.skin.locked::after { content: '🔒'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 15px; background: rgba(4, 16, 26, .55); border-radius: 50%; }
.chip.locked, .pick.locked { opacity: .6; }
.adbox { margin-top: 16px; min-height: 90px; border-radius: 14px; overflow: hidden; }
