:root {
  --ivory: #fbf6ea; --paper: #fffdf7; --ink: #15323a; --muted: #5d6f73;
  --gold: #c9971c; --gold-2: #f1c75b; --gold-deep: #9a6f0c;
  --t0: #d9a21b; --t1: #138a7e; --t2: #c8506a; --t3: #2f63c4;   /* answer tiles: gold, teal, rose, royal blue */
  --ok: #1f9d5b; --no: #c0443a;
  --radius: 22px; --shadow: 0 10px 30px rgba(120, 84, 10, .18);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--ivory); color: var(--ink);
  font-family: 'Nunito', system-ui, sans-serif; font-size: 18px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
.ar { font-family: 'Amiri Quran', 'Amiri', serif; direction: rtl; font-size: 1.35em; line-height: 1.9; }
h1, h2, h3 { font-family: 'Fredoka', 'Nunito', sans-serif; margin: 0 0 .4em; line-height: 1.15; }
a { color: var(--gold-deep); }
button { font: inherit; cursor: pointer; border: 0; }
.wrap { max-width: 880px; margin: 0 auto; padding: 16px; }

/* pattern background (pure geometry, no pictures) */
.pattern { position: fixed; inset: 0; z-index: -1; opacity: .5; pointer-events: none;
  background-image: radial-gradient(circle at 20% 10%, #fff7da 0, transparent 45%), radial-gradient(circle at 90% 90%, #fbe7b3 0, transparent 40%); }

/* buttons: each has its own character */
.btn-gold { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #3b2a00; font-weight: 800;
  padding: 16px 28px; border-radius: 999px; box-shadow: 0 6px 0 var(--gold-deep), var(--shadow); transition: transform .1s; }
.btn-gold:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--gold-deep); }
.btn-ghost { background: transparent; color: var(--ink); font-weight: 700; padding: 12px 20px; border-radius: 14px; border: 2px solid rgba(21,50,58,.2); }
.btn-ghost:hover { border-color: var(--gold); }
.btn-ink { background: var(--ink); color: #fff; font-weight: 800; padding: 14px 26px; border-radius: 16px; }
.mute { position: fixed; top: 12px; right: 12px; z-index: 50; background: var(--paper); border-radius: 50%; width: 44px; height: 44px;
  box-shadow: var(--shadow); font-size: 20px; }

.card { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.center { text-align: center; }
.hidden { display: none !important; }
input[type=text], input[type=email], input[type=password] {
  width: 100%; font: inherit; padding: 14px 16px; border-radius: 14px; border: 2px solid #e7dcc2; background: #fff; margin: 6px 0 12px; }
input:focus { outline: none; border-color: var(--gold); }
label.check { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; color: var(--muted); margin: 6px 0 14px; }
label.check input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--gold); }
.err { color: var(--no); font-weight: 700; min-height: 1.4em; }
.small { font-size: 14px; color: var(--muted); }

/* ---------- intro (scroll-played) ---------- */
.intro { height: 260vh; position: relative; }
.intro-stage { position: sticky; top: 0; height: 100vh; overflow: hidden; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 45%, #fff6d8 0, #f7e2a4 40%, #e8c56a 75%, #c9971c 100%); }
.intro-stage canvas, .intro-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.intro-title { position: relative; text-align: center; padding: 16px; color: #3b2a00; text-shadow: 0 2px 18px rgba(255,248,220,.9); }
.intro-title h1 { font-size: clamp(34px, 8vw, 72px); }
.intro-title p { font-size: clamp(16px, 3.5vw, 22px); margin: 0; }
.scroll-hint { position: absolute; bottom: 22px; left: 0; right: 0; text-align: center; font-weight: 700; color: #5a4100; animation: bob 1.6s infinite; }
@keyframes bob { 50% { transform: translateY(8px); } }

.games { display: grid; gap: 18px; margin: 30px 0 60px; }
.game-card { display: grid; gap: 10px; }
.game-card .row { display: flex; gap: 10px; flex-wrap: wrap; }
.pin-join { display: flex; gap: 8px; }
.pin-join input { margin: 0; font-size: 22px; letter-spacing: 4px; text-align: center; max-width: 180px; }

/* ---------- play ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-weight: 800; margin: 4px 50px 10px 0; }
.pill { background: var(--paper); border-radius: 999px; padding: 6px 14px; box-shadow: var(--shadow); }
.streak { color: #d4520f; }
.timer { height: 12px; border-radius: 999px; background: #efe3c3; overflow: hidden; margin: 8px 0 16px; }
.timer > i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--gold), var(--gold-2)); transform-origin: left; }
.timer.low > i { background: linear-gradient(90deg, #d9542f, #f08a4b); }
.count { font-family: 'Fredoka'; font-size: 34px; text-align: center; }
.qtext { font-size: clamp(22px, 4.5vw, 32px); font-weight: 800; text-align: center; margin: 8px 0 18px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .tiles { grid-template-columns: 1fr; } }
.tile { position: relative; color: #fff; border-radius: 18px; padding: 16px 16px 16px 58px; min-height: 84px; text-align: left;
  font-weight: 800; font-size: 20px; box-shadow: 0 6px 0 rgba(0,0,0,.18); transition: transform .12s, opacity .3s, filter .3s; }
.tile:active { transform: translateY(3px); }
.tile .shape { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); font-size: 28px; opacity: .9; }
.tile .ar { display: block; font-size: 1.3em; font-weight: 400; text-align: right; }
.tile .tr { display: block; font-style: italic; font-weight: 700; opacity: .95; }
.tile .en { display: block; }
.tile .tr + .en { font-weight: 600; opacity: .95; font-size: .92em; }
.tile.c0 { background: var(--t0); } .tile.c1 { background: var(--t1); } .tile.c2 { background: var(--t2); } .tile.c3 { background: var(--t3); }
.tile.dim { opacity: .35; filter: grayscale(.4); }
.tile.right { outline: 5px solid #fff; box-shadow: 0 0 0 9px var(--ok), 0 6px 0 rgba(0,0,0,.18); }
.tile.picked { outline: 5px solid #fff; }
.tiles.locked .tile { pointer-events: none; }

.verdict { text-align: center; padding: 26px; border-radius: var(--radius); color: #fff; animation: pop .35s ease-out; }
.verdict.ok { background: linear-gradient(160deg, #2fbf73, var(--ok)); }
.verdict.no { background: linear-gradient(160deg, #e36a5d, var(--no)); }
.verdict h2 { font-size: 40px; }
.verdict .pts { font-family: 'Fredoka'; font-size: 30px; }
@keyframes pop { 0% { transform: scale(.7); opacity: 0; } 70% { transform: scale(1.05); } 100% { transform: scale(1); opacity: 1; } }

.board { list-style: none; padding: 0; margin: 10px 0; }
.board li { display: flex; justify-content: space-between; background: var(--paper); margin: 8px 0; padding: 12px 16px; border-radius: 14px;
  box-shadow: var(--shadow); font-weight: 800; animation: slide .4s ease-out both; }
.board li.me { outline: 3px solid var(--gold); }
.board li:nth-child(2) { animation-delay: .06s } .board li:nth-child(3) { animation-delay: .12s } .board li:nth-child(4) { animation-delay: .18s } .board li:nth-child(5) { animation-delay: .24s }
@keyframes slide { from { transform: translateX(-30px); opacity: 0; } }
.rankbig { font-family: 'Fredoka'; font-size: clamp(40px, 10vw, 70px); color: var(--gold-deep); line-height: 1; }

.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin: 24px 0; min-height: 250px; }
.podium .step { width: 30%; max-width: 180px; text-align: center; font-weight: 800; }
.podium .block { border-radius: 16px 16px 0 0; color: #fff; font-family: 'Fredoka'; font-size: 40px; display: grid; place-items: center;
  animation: rise .8s cubic-bezier(.2,1.4,.4,1) both; }
.podium .p1 .block { height: 180px; background: linear-gradient(180deg, var(--gold-2), var(--gold)); animation-delay: .9s; }
.podium .p2 .block { height: 130px; background: linear-gradient(180deg, #d7dde3, #9aa6b2); animation-delay: .5s; }
.podium .p3 .block { height: 95px; background: linear-gradient(180deg, #e9b48a, #b86f3c); animation-delay: .2s; }
@keyframes rise { from { transform: scaleY(0); transform-origin: bottom; } }
.podium .name { margin-bottom: 6px; animation: pop .4s ease-out both; }

.bars { display: flex; gap: 12px; align-items: flex-end; height: 160px; justify-content: center; margin: 12px 0; }
.bars div { width: 60px; border-radius: 12px 12px 0 0; color: #fff; font-weight: 800; display: flex; align-items: flex-start; justify-content: center;
  padding-top: 6px; min-height: 30px; transition: height .5s; }

.lobby-pin { font-family: 'Fredoka'; font-size: clamp(54px, 14vw, 110px); letter-spacing: 8px; color: var(--gold-deep); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chips span { background: var(--paper); padding: 8px 14px; border-radius: 999px; box-shadow: var(--shadow); font-weight: 800; animation: pop .35s ease-out both; }

table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--paper); }
th, td { padding: 8px; border-bottom: 1px solid #eee2c7; text-align: left; }
th { background: #f5e9c8; position: sticky; top: 0; }
.tablewrap { overflow: auto; max-height: 70vh; border-radius: 14px; box-shadow: var(--shadow); }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
