/* وصلة — Wasla v1. Dark, gold, Islamic-geometric. */
@font-face {
  font-family: 'Cairo';
  src: url('../fonts/cairo-arabic.woff2') format('woff2');
  font-weight: 200 1000; font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('../fonts/cairo-latin.woff2') format('woff2');
  font-weight: 200 1000; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F;
}

:root {
  --bg0: #0b0e24;
  --bg1: #141838;
  --panel: #1b2148;
  --panel2: #232a5c;
  --gold: #e6c15c;
  --gold2: #f5d98b;
  --teal: #39c2a5;
  --text: #f2ecdc;
  --muted: #9aa0c3;
  --cell: #262d5e;
  --cell-border: #3a438a;
  --danger: #e0685c;
  --radius: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Cairo', system-ui, sans-serif;
  background: radial-gradient(120% 100% at 50% 0%, var(--bg1), var(--bg0));
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
#bg { position: fixed; inset: 0; z-index: 0; opacity: .5; }
#fx { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
#app { position: relative; z-index: 1; height: 100dvh; display: flex; flex-direction: column; }

/* top bar */
#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 8px;
}
#top-title { flex: 1; text-align: center; font-weight: 900; font-size: 20px; color: var(--gold2); letter-spacing: .5px; }
#coin-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--cell-border);
  border-radius: 999px; padding: 4px 12px; font-weight: 700; font-size: 15px;
  min-width: 74px; justify-content: center;
}
.coin-ico {
  width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe9a8, var(--gold) 60%, #a97f22);
  box-shadow: 0 0 6px rgba(230,193,92,.6);
  display: inline-block;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--cell-border);
  background: var(--panel); color: var(--text); font-size: 22px; line-height: 1;
  cursor: pointer;
}
.hidden { display: none !important; }

#main { flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; }
.screen { min-height: 100%; display: flex; flex-direction: column; padding: 6px 16px 24px; }

/* home */
#hero { text-align: center; padding: 26px 0 18px; }
#hero-logo {
  font-size: 64px; font-weight: 900; line-height: 1.1;
  background: linear-gradient(180deg, var(--gold2), var(--gold) 55%, #9c7420);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 4px 30px rgba(230,193,92,.25);
}
#hero-sub { color: var(--muted); font-size: 15px; margin-top: 4px; }
#chapters { display: flex; flex-direction: column; gap: 14px; }
.chapter-card {
  background: linear-gradient(160deg, var(--panel), var(--panel2));
  border: 1px solid var(--cell-border); border-radius: var(--radius);
  padding: 14px 16px;
}
.chapter-card.locked { opacity: .45; filter: saturate(.4); }
.chapter-head { display: flex; align-items: baseline; justify-content: space-between; }
.chapter-name { font-weight: 900; font-size: 21px; color: var(--gold2); }
.chapter-prog { color: var(--muted); font-size: 13px; font-weight: 700; }
.prog-bar { height: 6px; border-radius: 3px; background: #10143a; margin: 10px 0 12px; overflow: hidden; }
.prog-fill { height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--teal), var(--gold)); transition: width .5s ease; }
.level-dots { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.dot {
  aspect-ratio: 1; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; background: #10143a; color: var(--muted);
  border: 1px solid transparent; cursor: pointer;
}
.dot.done { background: rgba(57,194,165,.18); color: var(--teal); border-color: rgba(57,194,165,.4); }
.dot.current { background: var(--gold); color: #1a1405; box-shadow: 0 0 10px rgba(230,193,92,.55); }
.dot.locked { opacity: .35; cursor: default; }
#home-footer { display: flex; gap: 8px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }
.pill-btn {
  background: var(--panel); color: var(--text); border: 1px solid var(--cell-border);
  border-radius: 999px; padding: 8px 16px; font-family: inherit; font-weight: 700; font-size: 13px; cursor: pointer;
}
.pill-btn.danger { color: var(--danger); }

/* game */
#level-head { display: flex; justify-content: center; gap: 10px; color: var(--muted); font-weight: 700; font-size: 14px; padding: 2px 0 8px; }
#level-head #level-num { color: var(--gold2); }
#grid-wrap { flex: 1; min-height: 120px; display: flex; align-items: center; justify-content: center; }
#grid { position: relative; }
.cell {
  position: absolute; border-radius: 9px;
  background: var(--cell); border: 1px solid var(--cell-border);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.25);
}
.cell .glyph {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-weight: 900; color: #fff; opacity: 0; transform: scale(.4);
  transition: opacity .18s ease, transform .18s cubic-bezier(.2,1.6,.4,1);
}
.cell.revealed { background: linear-gradient(160deg, #3b3480, #4a3f9e); border-color: #6b5fd0; }
.cell.revealed .glyph { opacity: 1; transform: scale(1); }
.cell.hinted { animation: hintPulse 1s ease 2; }
@keyframes hintPulse { 50% { box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(230,193,92,.8); } }
#grid.shake { animation: shake .4s ease; }
@keyframes shake { 20%,60% { transform: translateX(-7px); } 40%,80% { transform: translateX(7px); } }

#toast {
  position: absolute; left: 50%; top: 34%; transform: translateX(-50%);
  background: rgba(14,18,48,.92); border: 1px solid var(--cell-border);
  border-radius: 999px; padding: 8px 20px; font-weight: 700; font-size: 15px;
  z-index: 20; pointer-events: none; white-space: nowrap;
  animation: toastIn .25s ease;
}
#toast.good { color: var(--teal); border-color: var(--teal); }
#toast.bad { color: var(--danger); border-color: var(--danger); }
#toast.gold { color: var(--gold2); border-color: var(--gold); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }

#preview {
  text-align: center; font-size: 30px; font-weight: 900; min-height: 44px;
  color: var(--gold2); letter-spacing: 2px; padding: 2px 0;
  text-shadow: 0 2px 14px rgba(230,193,92,.3);
}
#preview.bad { color: var(--danger); animation: shake .4s ease; }

#wheel-zone { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 6px); }
#bonus-chip {
  background: rgba(57,194,165,.15); color: var(--teal); border: 1px solid rgba(57,194,165,.45);
  border-radius: 999px; font-size: 12px; font-weight: 700; padding: 3px 12px;
}
#wheel {
  position: relative; border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, #2a3273, #171c46 75%);
  border: 2px solid var(--cell-border);
  box-shadow: 0 12px 40px rgba(0,0,0,.5), inset 0 2px 12px rgba(255,255,255,.06);
  touch-action: none;
}
#wheel-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#wheel-lines polyline { fill: none; stroke: var(--gold); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.wletter {
  position: absolute; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #f7f3e8, #d8d2bd);
  color: #22264a; font-weight: 900;
  box-shadow: 0 4px 10px rgba(0,0,0,.4);
  transition: transform .12s ease, background .12s ease;
  pointer-events: none;
}
.wletter.sel {
  background: linear-gradient(160deg, var(--gold2), var(--gold));
  transform: scale(1.18);
  box-shadow: 0 0 16px rgba(230,193,92,.8);
}
#wheel.shuffling .wletter { transition: left .35s ease, top .35s ease, transform .12s ease, background .12s ease; }
#wheel-actions { display: flex; gap: 12px; }
.action-btn {
  display: flex; align-items: center; gap: 7px;
  background: var(--panel); border: 1px solid var(--cell-border); color: var(--text);
  border-radius: 999px; padding: 9px 18px; font-family: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
}
.action-btn:active { transform: scale(.95); }
.action-btn.disabled { opacity: .45; }
.a-cost { color: var(--gold2); font-size: 13px; }
.a-cost::before { content: '🪙'; margin-inline-end: 3px; font-size: 11px; }

/* overlay */
#overlay {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: rgba(6,8,22,.78); backdrop-filter: blur(4px);
}
#overlay-card {
  background: linear-gradient(165deg, var(--panel2), var(--panel));
  border: 1px solid var(--cell-border); border-radius: 22px;
  padding: 30px 40px; text-align: center; min-width: 270px;
  animation: popIn .35s cubic-bezier(.2,1.5,.4,1);
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
@keyframes popIn { from { opacity: 0; transform: scale(.7); } }
#ov-stars { font-size: 40px; letter-spacing: 8px; color: #3a3f6e; }
#ov-stars span.lit { color: var(--gold); text-shadow: 0 0 18px rgba(230,193,92,.9); animation: starPop .4s cubic-bezier(.2,1.6,.4,1) both; }
#ov-stars span.lit:nth-child(2) { animation-delay: .15s; } #ov-stars span.lit:nth-child(3) { animation-delay: .3s; }
@keyframes starPop { from { transform: scale(0) rotate(-40deg); } }
#ov-title { font-size: 26px; font-weight: 900; color: var(--gold2); margin: 6px 0 10px; }
#ov-reward, #ov-bonus { color: var(--muted); font-weight: 700; font-size: 15px; margin: 3px 0; }
#ov-bonus { color: var(--teal); }
.big-btn {
  margin-top: 18px; background: linear-gradient(160deg, var(--gold2), var(--gold));
  color: #241c05; border: none; border-radius: 999px; padding: 13px 38px;
  font-family: inherit; font-size: 17px; font-weight: 900; cursor: pointer;
  box-shadow: 0 6px 22px rgba(230,193,92,.4);
}
.big-btn:active { transform: scale(.96); }

/* coin fly animation */
.fly-coin {
  position: fixed; width: 18px; height: 18px; border-radius: 50%; z-index: 60;
  background: radial-gradient(circle at 35% 30%, #ffe9a8, var(--gold) 60%, #a97f22);
  pointer-events: none; transition: transform .6s cubic-bezier(.3,.7,.4,1), opacity .6s ease;
}
