:root{
  --ivory:#FAF7F2;
  --paper:#FFFCF7;
  --lilac:#C9B6E4;
  --peach:#F6C9A8;
  --mint:#B8E0CF;
  --gold:#D9A93E;
  --ink:#3A3348;
  --ink-2:#6B6178;
  --line:rgba(58,51,72,.10);
  --shadow:0 8px 24px rgba(58,51,72,.10);
  --shadow-sm:0 2px 8px rgba(58,51,72,.07);
  --r-lg:24px;
  --r-md:16px;
  --r-sm:12px;
  --font-head:'Noto Kufi Arabic',system-ui,-apple-system,'Segoe UI',sans-serif;
  --font-body:'IBM Plex Sans Arabic',system-ui,-apple-system,'Segoe UI',sans-serif;
}

*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{height:100%;margin:0}
body{
  background:var(--ivory);
  color:var(--ink);
  font-family:var(--font-body);
  -webkit-font-smoothing:antialiased;
  overscroll-behavior:none;
  overflow:hidden;
}
body::after{
  content:'';position:fixed;inset:0;pointer-events:none;z-index:9999;opacity:.035;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}
button{font-family:inherit;color:inherit;border:none;background:none;cursor:pointer;user-select:none}
h1,h2,h3{font-family:var(--font-head);margin:0;line-height:1.35}
p{margin:0}
.num{font-variant-numeric:tabular-nums;font-feature-settings:"tnum" 1;letter-spacing:.01em}
.hidden{display:none !important}

/* ---------- root ---------- */
.game-root{
  position:relative;
  display:flex;
  flex-direction:column;
  height:100%;
  min-height:100dvh;
  overflow:hidden;
  background:var(--ivory);
}

/* ---------- HUD ---------- */
.hud{
  flex:0 0 auto;
  padding:8px 10px 0;
  background:rgba(250,247,242,.96);
  border-bottom:1px solid var(--line);
  z-index:5;
}
.hud-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:6px;
  min-width:0;
}
.hud-cluster{display:flex;align-items:center;gap:5px;min-width:0;flex:1 1 0}
.hud-cluster.hud-end{justify-content:flex-start;direction:ltr}
.hud-end .chip{direction:rtl}
.chip{
  display:flex;flex-direction:column;line-height:1.05;
  background:var(--paper);
  border:1px solid var(--line);
  border-radius:12px;
  padding:4px 9px;
  box-shadow:var(--shadow-sm);
  min-width:0;
}
.chip-label{font-size:9px;color:var(--ink-2);font-weight:500;white-space:nowrap}
.chip-value{font-size:15px;font-weight:700;color:var(--ink);white-space:nowrap}
.chip-value .sep{opacity:.4;margin:0 1px;font-weight:500}
.chip-streak{background:linear-gradient(180deg,#FBE9D3,#F7DCC0);border-color:rgba(217,169,62,.45)}
.chip-streak .chip-value{color:#8A6614}
.chip-score .chip-value{color:var(--ink)}

.icon-btn{
  width:42px;height:42px;border-radius:12px;
  display:grid;place-items:center;
  background:var(--paper);
  border:1px solid var(--line);
  box-shadow:var(--shadow-sm);
  color:var(--ink);
  flex:0 0 auto;
  transition:transform .12s ease, background .18s ease;
}
.icon-btn:active{transform:scale(.93);background:#F2ECE2}
.icon-btn svg{width:22px;height:22px}
.icon-btn[aria-pressed="true"] .wave{opacity:0}
.icon-btn[aria-pressed="false"] .mute-x{opacity:0}

.timer{
  position:relative;flex:0 0 auto;width:52px;height:52px;
  display:grid;place-items:center;
}
.timer svg{position:absolute;inset:0;width:100%;height:100%;transform:rotate(-90deg)}
.timer-track{fill:rgba(255,252,247,.85);stroke:rgba(58,51,72,.10);stroke-width:4.5}
.timer-arc{
  fill:none;stroke:var(--mint);stroke-width:4.5;stroke-linecap:round;
  stroke-dasharray:125.66;stroke-dashoffset:0;
  transition:stroke .4s ease;
}
.timer.warn .timer-arc{stroke:#E39B6B}
.timer.danger .timer-arc{stroke:#D86A5B}
.timer.danger{animation:tick 1s ease-in-out infinite}
@keyframes tick{0%,100%{transform:scale(1)}50%{transform:scale(1.06)}}
.timer-num{position:relative;font-size:16px;font-weight:700;font-family:var(--font-head);color:var(--ink)}

.hud-progress{
  height:5px;border-radius:99px;background:rgba(58,51,72,.08);
  margin:8px 2px 7px;overflow:hidden;
}
#progressFill{
  height:100%;width:0%;border-radius:99px;
  background:linear-gradient(90deg,var(--mint),var(--gold));
  transition:width .55s cubic-bezier(.3,.9,.35,1);
}

/* ---------- stage ---------- */
.stage{
  position:relative;
  flex:1 1 auto;
  min-height:0;
  overflow:hidden;
  background:#FDF3E3;
}
#scene{display:block;width:100%;height:100%}

/* ---------- controls dock ---------- */
.controls{
  flex:0 0 auto;
  display:flex;
  align-items:stretch;
  gap:10px;
  padding:9px 12px 12px;
  background:rgba(250,247,242,.98);
  border-top:1px solid var(--line);
  z-index:5;
}
.dock-btn{
  display:flex;align-items:center;justify-content:center;gap:9px;
  min-height:54px;
  border-radius:18px;
  font-family:var(--font-head);
  font-weight:700;font-size:15px;
  transition:transform .12s ease, box-shadow .18s ease, background .18s ease;
}
.dock-btn-hint{
  flex:1 1 auto;
  background:linear-gradient(180deg,#FBEAD6,#F6D6B6);
  color:#7A4F2A;
  border:1.5px solid rgba(217,169,62,.45);
  box-shadow:0 3px 0 rgba(217,169,62,.28);
}
.dock-btn-hint:active{transform:translateY(2px);box-shadow:0 1px 0 rgba(217,169,62,.28)}
.dock-btn-icon{
  flex:0 0 66px;width:66px;
  background:var(--paper);
  color:var(--ink);
  border:1.5px solid var(--line);
  box-shadow:0 3px 0 rgba(58,51,72,.10);
}
.dock-btn-icon:active{transform:translateY(2px);box-shadow:0 1px 0 rgba(58,51,72,.10)}
.dock-icon{width:24px;height:24px;flex:0 0 auto}
.dock-text{display:flex;align-items:center;gap:8px}
.dock-cost{
  font-size:12px;font-weight:600;
  background:rgba(255,255,255,.7);
  border-radius:99px;padding:1px 8px;color:#8A5A22;
}

/* ---------- overlays ---------- */
.overlay{
  position:absolute;inset:0;z-index:50;
  display:flex;align-items:center;justify-content:center;
  padding:14px;
  background:rgba(58,51,72,.30);
  -webkit-backdrop-filter:blur(5px);
  backdrop-filter:blur(5px);
  overflow-y:auto;
  overscroll-behavior:contain;
}
#pauseOverlay{z-index:70;background:rgba(58,51,72,.42)}
#boardOverlay{z-index:80;background:rgba(58,51,72,.46)}
.end-overlay{align-items:flex-end;padding-bottom:16px}

.card{
  width:100%;max-width:520px;
  background:var(--paper);
  border-radius:var(--r-lg);
  box-shadow:var(--shadow);
  border:1px solid rgba(58,51,72,.06);
  padding:18px;
  position:relative;
  animation:cardIn .32s cubic-bezier(.25,.9,.3,1) both;
}
@keyframes cardIn{from{opacity:0;transform:translateY(18px) scale(.97)}to{opacity:1;transform:none}}
.card.shake{animation:shake .42s cubic-bezier(.36,.07,.19,.97) both}
@keyframes shake{
  10%,90%{transform:translateX(-2px)}
  20%,80%{transform:translateX(4px)}
  30%,50%,70%{transform:translateX(-7px)}
  40%,60%{transform:translateX(7px)}
}

.sadu{
  height:12px;margin:-4px 0 14px;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='12'%3E%3Cpath d='M0 12 L6.5 0 L13 12 Z' fill='%23B8E0CF'/%3E%3Cpath d='M13 12 L19.5 0 L26 12 Z' fill='%23F6C9A8'/%3E%3C/svg%3E");
  background-repeat:repeat-x;
  background-size:26px 12px;
  border-radius:3px;
  opacity:.9;
}

/* ---------- menu ---------- */
.menu-card{text-align:center;padding-top:16px}
.menu-arch{
  margin:0 auto 12px;
  width:100%;max-width:280px;
  background:linear-gradient(160deg,var(--mint),var(--lilac) 55%,var(--peach));
  border-radius:140px 140px 20px 20px;
  padding:5px;
}
.arch-inner{
  background:var(--paper);
  border-radius:136px 136px 16px 16px;
  padding:16px 12px 12px;
  display:flex;align-items:center;justify-content:center;gap:12px;direction:ltr;
}
.hero-year{font-family:var(--font-head);font-weight:700;font-size:22px;color:var(--ink)}
.hero-arrow{color:var(--gold);font-size:20px;font-weight:700}
.menu-title{font-size:30px;font-weight:700;color:var(--ink);letter-spacing:-.4px}
.menu-sub{font-size:14.5px;color:var(--ink-2);margin-top:5px;line-height:1.6}
.how-list{
  list-style:none;margin:16px 0 14px;padding:0;
  text-align:right;display:flex;flex-direction:column;gap:9px;
}
.how-list li{
  display:flex;align-items:flex-start;gap:9px;
  font-size:14px;color:var(--ink);line-height:1.5;
}
.dot{width:9px;height:9px;border-radius:99px;flex:0 0 auto;margin-top:6px}
.dot-mint{background:var(--mint)}
.dot-peach{background:var(--peach)}
.dot-gold{background:var(--gold)}
.menu-stats{display:flex;gap:10px;margin-bottom:14px}
.mini-stat{
  flex:1 1 0;min-width:0;
  background:#F7F2EA;
  border:1px solid var(--line);
  border-radius:var(--r-md);
  padding:9px 6px;
  display:flex;flex-direction:column;gap:2px;
}
.mini-label{font-size:11px;color:var(--ink-2);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.mini-value{font-size:19px;font-weight:700;font-family:var(--font-head);color:var(--ink)}
.menu-links{margin-top:10px;display:flex;justify-content:center}
.fine{font-size:11.5px;color:#9A93A5;margin-top:12px;line-height:1.5}

/* ---------- buttons ---------- */
.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:8px;
  min-height:48px;padding:0 20px;
  border-radius:16px;
  font-family:var(--font-head);
  font-weight:700;font-size:15.5px;
  transition:transform .12s ease, box-shadow .18s ease, background .18s ease, opacity .18s ease;
}
.btn-primary{
  background:linear-gradient(180deg,#E4B94F,var(--gold));
  color:#2E2517;
  box-shadow:0 4px 0 #B98A24;
  width:100%;
}
.btn-primary:active{transform:translateY(3px);box-shadow:0 1px 0 #B98A24}
.btn-primary:disabled{opacity:.5;box-shadow:0 4px 0 rgba(185,138,36,.4);cursor:default}
.btn-lg{min-height:56px;font-size:17px}
.btn-sm{min-height:42px;font-size:13.5px;padding:0 16px;border-radius:13px}
.btn-ghost{
  background:#F4EFE6;color:var(--ink);
  border:1px solid var(--line);
  box-shadow:0 2px 0 rgba(58,51,72,.07);
}
.btn-ghost:active{transform:translateY(2px);box-shadow:none}

/* ---------- info card ---------- */
.info-card{padding-top:16px}
.info-top{display:flex;gap:14px;align-items:flex-start;margin-bottom:12px}
.portrait-wrap{
  width:92px;height:114px;flex:0 0 auto;
  border-radius:70px 70px 16px 16px;
  overflow:hidden;
  background:linear-gradient(180deg,var(--mint),var(--lilac));
  border:2px solid rgba(217,169,62,.42);
  box-shadow:var(--shadow-sm);
  display:grid;place-items:center;
}
.portrait-wrap img{width:100%;height:100%;object-fit:cover;object-position:top center;display:block}
.portrait-wrap .emblem{width:56px;height:56px;color:#5D7F70}
.info-meta{min-width:0;flex:1 1 auto;padding-top:2px}
.year-badge{
  display:inline-block;
  background:linear-gradient(180deg,#E4B94F,var(--gold));
  color:#2E2517;
  font-family:var(--font-head);font-weight:700;font-size:14px;
  padding:2px 12px;border-radius:99px;
  box-shadow:0 2px 6px rgba(217,169,62,.35);
}
.info-title{font-size:19px;margin-top:8px;color:var(--ink);line-height:1.4}
.info-sub{font-size:12.5px;color:var(--ink-2);margin-top:4px}
.info-lines{display:flex;flex-direction:column;gap:9px;margin-bottom:16px}
.info-lines p{
  font-size:14.5px;line-height:1.75;color:#4B4358;
  background:#F8F4EC;border-radius:var(--r-sm);padding:10px 12px;
  border-right:3px solid var(--mint);
}
.info-actions{display:flex;gap:9px;align-items:center}
.info-actions .btn-primary{flex:1 1 auto}

/* ---------- puzzle ---------- */
.puzzle-card{max-width:540px}
.puzzle-top{display:flex;gap:8px;margin-bottom:12px;flex-wrap:wrap}
.pill{
  font-size:11.5px;font-weight:600;
  background:#EFEAF6;color:#5A4B78;
  padding:4px 11px;border-radius:99px;
  border:1px solid rgba(201,182,228,.6);
}
.pill-gold{background:#FBEFD5;color:#8A6614;border-color:rgba(217,169,62,.45)}
.puzzle-q{font-size:17px;line-height:1.6;color:var(--ink);margin-bottom:14px;font-weight:700}

.opt-list{display:flex;flex-direction:column;gap:9px}
.opt{
  display:flex;align-items:center;gap:11px;
  width:100%;text-align:right;
  min-height:54px;padding:10px 13px;
  background:#F8F4EC;
  border:1.5px solid rgba(58,51,72,.09);
  border-radius:var(--r-md);
  font-size:15px;font-weight:500;color:var(--ink);
  line-height:1.45;
  transition:transform .12s ease, background .16s ease, border-color .16s ease, opacity .2s ease;
}
.opt:active{transform:scale(.985)}
.opt .opt-key{
  width:26px;height:26px;flex:0 0 auto;border-radius:9px;
  display:grid;place-items:center;
  background:#EDE6DA;color:#6B6178;
  font-family:var(--font-head);font-weight:700;font-size:12.5px;
}
.opt.correct{background:#DDF2E7;border-color:#7CC4A2;color:#1F5C42}
.opt.correct .opt-key{background:#7CC4A2;color:#fff}
.opt.wrong{background:#FBE3DE;border-color:#E09B8D;color:#8A3527}
.opt.wrong .opt-key{background:#E09B8D;color:#fff}
.opt.removed{opacity:.35;text-decoration:line-through;pointer-events:none}
.opt.locked{pointer-events:none}
.opt.dim{opacity:.55;pointer-events:none}

/* order puzzle */
.order-list{display:flex;flex-direction:column;gap:8px}
.order-row{
  display:flex;align-items:center;gap:10px;
  background:#F8F4EC;
  border:1.5px solid rgba(58,51,72,.09);
  border-radius:var(--r-md);
  padding:9px 11px;
  min-height:52px;
  touch-action:none;
  transition:box-shadow .16s ease, background .16s ease, transform .18s ease;
}
.order-row.dragging{
  background:#FFF9EE;
  box-shadow:0 10px 22px rgba(58,51,72,.18);
  border-color:rgba(217,169,62,.6);
  cursor:grabbing;
}
.order-row.drop-target{border-color:var(--gold);border-style:dashed}
.order-row.locked{background:#FBF3E0;border-color:rgba(217,169,62,.55)}
.order-num{
  width:24px;height:24px;flex:0 0 auto;border-radius:8px;
  display:grid;place-items:center;
  background:#EDE6DA;color:#6B6178;
  font-family:var(--font-head);font-weight:700;font-size:12px;
}
.order-text{flex:1 1 auto;font-size:14px;line-height:1.45;color:var(--ink)}
.order-btns{display:flex;flex-direction:column;gap:3px;flex:0 0 auto}
.mini{
  width:32px;height:24px;border-radius:7px;
  background:#EFE9DE;color:#6B6178;
  font-size:10px;line-height:1;
  display:grid;place-items:center;
  transition:background .15s ease, transform .1s ease;
}
.mini:active{background:#E2D9CA;transform:scale(.94)}

/* match puzzle */
.match-wrap{display:flex;gap:9px;align-items:stretch}
.match-col{flex:1 1 0;min-width:0;display:flex;flex-direction:column;gap:8px}
.match-col-head{
  font-size:11px;color:var(--ink-2);font-weight:600;text-align:center;
  padding-bottom:2px;
}
.match-item{
  width:100%;min-height:54px;
  display:flex;align-items:center;justify-content:center;gap:7px;
  padding:8px 9px;
  background:#F8F4EC;
  border:1.5px solid rgba(58,51,72,.09);
  border-radius:var(--r-md);
  font-size:13.5px;font-weight:500;color:var(--ink);
  line-height:1.35;
  text-align:center;
  transition:transform .12s ease, background .16s ease, border-color .16s ease;
}
.match-item:active{transform:scale(.98)}
.match-item.selected{background:#F1ECFA;border-color:var(--lilac);box-shadow:0 0 0 2px rgba(201,182,228,.4)}
.match-item.linked{background:#FFF8EC;border-color:rgba(217,169,62,.6)}
.match-item .tag{
  width:19px;height:19px;border-radius:99px;flex:0 0 auto;
  display:grid;place-items:center;
  font-size:10px;font-weight:700;color:#fff;font-family:var(--font-head);
}
.match-item.correct{background:#DDF2E7;border-color:#7CC4A2}
.match-item.wrong{background:#FBE3DE;border-color:#E09B8D}
.match-hint{font-size:11.5px;color:var(--ink-2);text-align:center;margin-top:9px}

.feedback{
  margin-top:12px;padding:11px 13px;border-radius:var(--r-sm);
  font-size:13.5px;line-height:1.65;
  background:#FBEEE0;color:#7A4A20;border:1px solid rgba(217,169,62,.4);
}
.feedback.good{background:#E4F5EC;color:#1F5C42;border-color:rgba(124,196,162,.6)}
.puzzle-actions{margin-top:14px;display:flex;gap:8px}
.puzzle-actions .btn-primary{width:100%}

/* ---------- pause / end ---------- */
.pause-card{text-align:center;padding-top:16px}
.pause-title{font-size:21px;margin-bottom:6px}
.pause-sub{font-size:13px;color:var(--ink-2);margin-bottom:16px}
.pause-card .btn-ghost{width:100%;margin-top:9px}

.end-card{text-align:center;padding-top:14px;max-height:88vh;overflow-y:auto}
.end-medal-wrap{display:flex;justify-content:center;margin-bottom:8px}
.medal{width:78px;height:78px;filter:drop-shadow(0 6px 12px rgba(217,169,62,.35))}
.medal.dim{filter:grayscale(1) opacity(.32);}
.medal.pop{animation:medalPop .7s cubic-bezier(.2,1.5,.4,1) both}
@keyframes medalPop{0%{transform:scale(.3) rotate(-18deg);opacity:0}100%{transform:scale(1) rotate(0);opacity:1}}
.end-title{font-size:22px;margin-bottom:5px}
.end-sub{font-size:13.5px;color:var(--ink-2);line-height:1.6;margin-bottom:14px}
.end-grid{display:flex;gap:9px;margin-bottom:12px}
.end-sync{font-size:11.5px;color:#9A93A5;min-height:16px;margin-bottom:10px;line-height:1.5}
.end-card .btn-ghost{width:100%;margin-top:9px}

/* ---------- leaderboard ---------- */
.board-card{max-width:480px}
.board-head{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:12px}
.board-title{font-size:19px}
.board-body{display:flex;flex-direction:column;gap:7px;max-height:52vh;overflow-y:auto}
.board-row{
  display:flex;align-items:center;gap:10px;
  background:#F8F4EC;border-radius:var(--r-sm);
  padding:9px 12px;font-size:14px;
  border:1px solid var(--line);
}
.board-row.me{background:#FBF1DA;border-color:rgba(217,169,62,.5)}
.board-rank{
  width:24px;height:24px;border-radius:99px;flex:0 0 auto;
  display:grid;place-items:center;
  background:#EDE6DA;color:#6B6178;font-size:11.5px;font-weight:700;font-family:var(--font-head);
}
.board-row:nth-child(1) .board-rank{background:var(--gold);color:#2E2517}
.board-row:nth-child(2) .board-rank{background:#D8D2C8;color:#3A3348}
.board-row:nth-child(3) .board-rank{background:var(--peach);color:#7A4A20}
.board-name{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.board-score{font-weight:700;font-family:var(--font-head);font-size:14.5px}
.board-note{font-size:13px;color:var(--ink-2);text-align:center;line-height:1.7;padding:14px 6px}
.board-note .btn{margin-top:12px}

/* ---------- toast ---------- */
.toast{
  position:absolute;top:78px;left:50%;transform:translateX(-50%);
  z-index:90;
  background:rgba(58,51,72,.94);color:#FFF7E8;
  font-size:13.5px;font-weight:600;font-family:var(--font-head);
  padding:9px 18px;border-radius:99px;
  box-shadow:0 8px 24px rgba(58,51,72,.3);
  pointer-events:none;
  white-space:nowrap;max-width:88vw;overflow:hidden;text-overflow:ellipsis;
  animation:toastIn .26s cubic-bezier(.2,1.4,.4,1) both;
}
.toast.gold{background:linear-gradient(180deg,#E4B94F,#D9A93E);color:#2E2517}
@keyframes toastIn{from{opacity:0;transform:translate(-50%,-10px)}to{opacity:1;transform:translate(-50%,0)}}

/* ---------- small screens ---------- */
@media (max-width:430px){
  .hud{padding:6px 8px 0}
  .chip{padding:3px 7px;border-radius:10px}
  .chip-label{font-size:8px}
  .chip-value{font-size:13.5px}
  .icon-btn{width:38px;height:38px;border-radius:11px}
  .icon-btn svg{width:19px;height:19px}
  .timer{width:46px;height:46px}
  .timer-num{font-size:14px}
  .hud-progress{margin:6px 2px 6px}
  .card{padding:15px;border-radius:20px}
  .menu-title{font-size:26px}
  .menu-arch{max-width:230px}
  .arch-inner{padding:12px 8px 10px}
  .hero-year{font-size:18px}
  .puzzle-q{font-size:15.5px}
  .opt{font-size:14px;min-height:50px}
  .match-item{font-size:12px;min-height:50px}
  .controls{padding:8px 10px 10px;gap:8px}
  .dock-btn{min-height:52px;font-size:14px;border-radius:16px}
  .dock-btn-icon{flex:0 0 58px;width:58px}
  .info-title{font-size:17px}
  .portrait-wrap{width:78px;height:98px}
}

@media (max-height:560px){
  .menu-arch{margin-bottom:8px;max-width:200px}
  .arch-inner{padding:8px 10px}
  .menu-title{font-size:22px}
  .how-list{margin:10px 0;gap:6px}
  .how-list li{font-size:12.5px}
  .card{padding:13px}
  .sadu{margin-bottom:10px}
  .end-medal-wrap .medal{width:56px;height:56px}
}

@media (prefers-reduced-motion:reduce){
  *{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important}
}