@font-face { font-family: "Reem Kufi"; src: url(assets/fonts/ReemKufi-Var.ttf) format("truetype"); font-weight: 400 700; font-display: block; }
@font-face { font-family: "Plex"; src: url(assets/fonts/IBMPlexSansArabic-SemiBold.ttf) format("truetype"); font-weight: 600; font-display: block; }
@font-face { font-family: "Plex"; src: url(assets/fonts/IBMPlexSansArabic-Bold.ttf) format("truetype"); font-weight: 700; font-display: block; }

:root {
  --sand: #f3dcb4;
  --panel: #2a1b10;
  --panel-2: #3a2616;
  --line: #5e3f25;
  --accent: #e2802f;
  --accent-d: #9c4d16;
  --bad: #c0392b;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #1d140c;
  overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
body { font-family: "Plex", system-ui, sans-serif; font-weight: 600; color: var(--sand); }
canvas { position: fixed; inset: 0; display: block; }
#sat { position: fixed; top: 0; height: var(--sat); width: 1px; visibility: hidden; }
#sab { position: fixed; bottom: 0; height: var(--sab); width: 1px; visibility: hidden; }

#app { position: fixed; top: 0; bottom: 0; left: 0; width: 100%; pointer-events: none; }

.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(var(--sat) + 12px) 14px calc(var(--sab) + 14px);
  box-sizing: border-box;
  opacity: 0; transition: opacity .25s ease;
}
.screen.show { opacity: 1; pointer-events: auto; }

.panel {
  width: min(100%, 380px); box-sizing: border-box;
  background: rgba(34, 21, 12, .96); border: 1px solid var(--line); border-radius: 20px;
  padding: 16px 16px 12px; text-align: center;
  box-shadow: 0 10px 28px rgba(20, 10, 3, .4);
}
.panel h2 { margin: 0 0 12px; font-family: "Reem Kufi", serif; font-weight: 700; font-size: 21px; color: #fff1da; }

/* ---------- menu ---------- */
#menu { justify-content: flex-end; }
.logo { text-align: center; margin: 2px 0 12px; }
.logo h1 {
  margin: 0; font-family: "Reem Kufi", serif; font-weight: 700;
  font-size: clamp(30px, 9.4vw, 44px); line-height: 1.25; color: #fff6e6;
  text-shadow: 0 3px 0 #8a4416;
}
.logo p {
  margin: 14px 0 0; font: 700 11px/1 system-ui, sans-serif; letter-spacing: .38em;
  color: #fff6e6; opacity: .85; direction: ltr; padding-left: .38em;
}
.how { display: flex; gap: 8px; margin-bottom: 14px; }
.how div {
  flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--panel-2); border-radius: 14px; padding: 8px 4px 9px; font-size: 14px; color: #f1dfc2;
}
.how img { height: 46px; width: auto; }
.how div:last-child { box-shadow: inset 0 0 0 2px rgba(192, 57, 43, .55); }

.btn {
  display: block; width: 100%; margin: 0 0 10px; padding: 13px 10px;
  border: 0; border-radius: 14px; cursor: pointer;
  font: 700 20px/1.2 "Plex", system-ui, sans-serif;
  background: var(--panel-2); color: var(--sand); box-shadow: 0 4px 0 #1a0f07;
}
.btn.primary { background: var(--accent); color: #1c0e05; box-shadow: 0 4px 0 var(--accent-d); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #1a0f07; }
.btn.primary:active { box-shadow: 0 1px 0 var(--accent-d); }
.best { margin: 2px 0 2px; font-size: 14px; color: #d6bb93; }
.best b { color: #fff1da; font-size: 16px; }

/* ---------- in-game HUD ---------- */
#hud {
  position: absolute; top: calc(var(--sat) + 10px); right: 10px;
  display: flex; justify-content: space-between; align-items: flex-start;
  opacity: 0; transition: opacity .2s;
}
#hud.show { opacity: 1; }
.hud-r { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
#scoreBox {
  display: flex; align-items: center; gap: 6px;
  background: rgba(34, 21, 12, .92); border: 1px solid var(--line); border-radius: 14px;
  padding: 2px 12px 3px;
}
#score { font-family: "Reem Kufi", serif; font-weight: 700; font-size: 30px; line-height: 1.2; color: #fff6e6; display: inline-block; }
#score.pop { animation: pop .18s ease-out; }
@keyframes pop { 50% { transform: scale(1.2); } }
#combo { display: none; font: 700 15px/1 "Plex", sans-serif; color: #1c0e05; background: #f2c14b; border-radius: 999px; padding: 4px 8px 5px; }
#combo.show { display: inline-block; }
#hearts { display: flex; gap: 4px; padding: 0 4px; }
#hearts svg { width: 24px; height: 24px; display: block; filter: drop-shadow(0 1px 0 rgba(30, 12, 4, .7)); }
#hearts svg path { fill: #d9443a; stroke: #4a160f; stroke-width: 1.4; }
#hearts svg.off path { fill: #4a3a2c; stroke: #241810; }
#hearts svg.hit { animation: hit .5s ease-out; }
@keyframes hit { 20% { transform: scale(1.4); } 40% { transform: scale(.8) rotate(-10deg); } 70% { transform: rotate(8deg); } }
#lvl {
  margin-top: 0; padding: 5px 12px 6px; border-radius: 999px;
  background: rgba(34, 21, 12, .92); border: 1px solid var(--line);
  font-size: 15px; color: #fff1da;
}

#timer {
  position: absolute; left: 12px; right: 12px; height: 10px; top: 0;
  background: rgba(34, 21, 12, .9); border: 1px solid var(--line); border-radius: 999px;
  overflow: hidden; opacity: 0; transition: opacity .2s;
}
#timer.show { opacity: 1; }
#timer i { position: absolute; inset: 1px; border-radius: 999px; background: var(--accent); transform-origin: right center; }
#timer.low i { background: #d9443a; animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .55; } }

#bubble {
  position: absolute; top: 0; left: 0; max-width: 46%;
  background: #fffaf0; color: #2a1505; border: 2px solid #2a1b10; border-radius: 16px;
  padding: 6px 14px 8px; font: 700 19px/1.3 "Reem Kufi", serif; white-space: nowrap;
  transform: translateY(-50%) scale(.6); opacity: 0; transition: opacity .15s, transform .15s;
}
#bubble::after {
  content: ""; position: absolute; top: 50%; right: -11px; margin-top: -7px;
  border-width: 7px 0 7px 11px; border-style: solid; border-color: transparent transparent transparent #2a1b10;
}
#bubble::before {
  content: ""; position: absolute; top: 50%; right: -7px; margin-top: -5px; z-index: 1;
  border-width: 5px 0 5px 8px; border-style: solid; border-color: transparent transparent transparent #fffaf0;
}
#bubble.show { opacity: 1; transform: translateY(-50%) scale(1); }
#bubble.bad { background: #ffe9e2; }
#bubble.bad::before { border-left-color: #ffe9e2; }

#banner {
  position: absolute; left: 50%; top: 0; transform: translate(-50%, -50%) scale(.8);
  min-width: 190px; text-align: center; white-space: nowrap;
  background: rgba(34, 21, 12, .95); border: 1px solid var(--line); border-radius: 18px;
  padding: 10px 22px 12px; opacity: 0; transition: opacity .2s, transform .2s;
}
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#banner b { display: block; font: 700 30px/1.3 "Reem Kufi", serif; color: #fff6e6; }
#banner span { display: block; font-size: 15px; color: #e9cfa6; }
#banner span:empty { display: none; }

/* ---------- game over ---------- */
#over { justify-content: center; background: rgba(20, 12, 6, .35); }
#over .panel { padding: 20px 18px 10px; }
#over h2 { font-size: 32px; margin-bottom: 14px; }
.stats { display: flex; gap: 10px; margin-bottom: 10px; }
.stats div { flex: 1; background: var(--panel-2); border-radius: 14px; padding: 10px 6px 8px; display: flex; flex-direction: column; gap: 2px; }
.stats span { font-size: 14px; color: #d6bb93; }
.stats b { font-family: "Reem Kufi", serif; font-size: 40px; line-height: 1.1; color: #fff6e6; }
.reached { margin: 0 0 12px; font-size: 15px; color: #d6bb93; }
.reached b { color: #fff1da; }
#newBest {
  display: none; margin: -2px auto 14px; padding: 5px 14px; width: fit-content;
  border-radius: 999px; background: #f2c14b; color: #2a1505; font-weight: 700; font-size: 15px;
}
#newBest.show { display: block; }
#over .btn.locked { pointer-events: none; opacity: .55; }

.icon-btn {
  position: absolute; z-index: 5; top: calc(var(--sat) + 10px); left: 12px; pointer-events: auto;
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(34, 21, 12, .92); color: var(--sand); padding: 10px; cursor: pointer;
}
.icon-btn svg { width: 100%; height: 100%; fill: currentColor; display: block; }
#icoOff { display: none; }
.icon-btn.off #icoOn { display: none; }
.icon-btn.off #icoOff { display: block; }
