/* FIREWORKS — UI styles. Every visual element (buttons, panels, icons, digits)
   comes from the kit's assets/ui folder; only text is rendered by the browser. */
:root {
  --night: #06142d;
  --ink: #051b25;
  --emerald: #13ba83;
  --mint: #82ffc4;
  --gold: #ffd475;
  --ivory: #fff3d1;
  --red: #ff625d;
  --violet: #c28aff;
  --muted: #9cbab9;
  --panel: #0b1f33;
  --font-ar: "Segoe UI", Tahoma, "Noto Naskh Arabic", "Noto Sans Arabic", "Geeza Pro", "Helvetica Neue", Arial, sans-serif;
  --font-en: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: "Courier New", Consolas, monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--night) radial-gradient(ellipse at 50% 20%, #0d2a4a 0, #06142d 55%, #030a16 100%);
  color: var(--ivory);
  font-family: var(--font-en);
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
}
body.lang-ar { font-family: var(--font-ar); }
/* Arabic letters must join: no tracking / monospace on Arabic labels */
body.lang-ar .eyebrow, body.lang-ar .hud-label, body.lang-ar .load-text, body.lang-ar .share-title,
body.lang-ar .result-score .label, body.lang-ar .menu-foot, body.lang-ar .combo, body.lang-ar .btn, body.lang-ar .ctl-fire { letter-spacing: 0; }
body.lang-ar .load-text, body.lang-ar .combo { font-family: var(--font-ar); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
img { image-rendering: pixelated; image-rendering: crisp-edges; -webkit-user-drag: none; -webkit-touch-callout: none; }
button, .ctl { -webkit-touch-callout: none; }
.noscript { padding: 40px; text-align: center; font-size: 18px; }

/* ------------------------------------------------------------ stage / viewport (360x640 logical, scaled) */
.stage { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
.viewport {
  position: absolute; left: 0; top: 0; width: 360px; height: 640px;
  transform-origin: 0 0; overflow: hidden; background: var(--night);
  box-shadow: 0 0 0 1px rgba(130,255,196,.08), 0 30px 80px rgba(0,0,0,.6);
}
#game { position: absolute; left: 0; top: 0; width: 360px; height: 640px; display: block; image-rendering: pixelated; image-rendering: crisp-edges; }

/* ------------------------------------------------------------ 9-slice helpers (kit PNGs, 12px insets) */
.panel {
  border: 12px solid transparent;
  border-image: url("../assets/ui/panels/modal.png") 12 fill / 12px stretch;
  background: transparent;
}
.panel-card { border: 12px solid transparent; border-image: url("../assets/ui/panels/card.png") 12 fill / 12px stretch; }
.panel-hud  { border: 10px solid transparent; border-image: url("../assets/ui/panels/hud.png") 12 fill / 10px stretch; }
.panel-toast{ border: 12px solid transparent; border-image: url("../assets/ui/panels/toast.png") 12 fill / 12px stretch; }
.row-panel  { border: 10px solid transparent; border-image: url("../assets/ui/panels/leaderboard_row.png") 12 fill / 10px stretch; }

.btn {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; width: 100%; padding: 4px 14px;
  border: 12px solid transparent;
  border-image: url("../assets/ui/buttons/primary_normal.png") 12 fill / 12px stretch;
  color: var(--ivory); font-weight: 700; font-size: 17px; letter-spacing: .3px;
  text-shadow: 0 2px 0 rgba(0,0,0,.45);
  transition: transform .08s ease;
}
.btn img { width: 22px; height: 22px; }
.btn:hover { border-image-source: url("../assets/ui/buttons/primary_hover.png"); }
.btn:active, .btn.is-pressed { border-image-source: url("../assets/ui/buttons/primary_pressed.png"); transform: translateY(2px); }
.btn:disabled, .btn.is-disabled { border-image-source: url("../assets/ui/buttons/primary_disabled.png"); color: var(--muted); cursor: default; transform: none; }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.btn.secondary { border-image-source: url("../assets/ui/buttons/secondary_normal.png"); color: var(--gold); }
.btn.secondary:hover { border-image-source: url("../assets/ui/buttons/secondary_hover.png"); color: var(--ivory); }
.btn.secondary:active, .btn.secondary.is-pressed { border-image-source: url("../assets/ui/buttons/secondary_pressed.png"); }
.btn.secondary:disabled { border-image-source: url("../assets/ui/buttons/secondary_disabled.png"); }

.btn.danger { border-image-source: url("../assets/ui/buttons/danger_normal.png"); color: var(--red); }
.btn.danger:hover { border-image-source: url("../assets/ui/buttons/danger_hover.png"); }
.btn.danger:active { border-image-source: url("../assets/ui/buttons/danger_pressed.png"); }

.btn.big { min-height: 60px; font-size: 19px; }
.btn.small { min-height: 44px; font-size: 14px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1 1 0; min-width: 0; width: auto; }
.btn.small img { width: 18px; height: 18px; }

.sq-btn {
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  border: 12px solid transparent;
  border-image: url("../assets/ui/buttons/square_normal.png") 12 fill / 12px stretch;
}
.sq-btn img { width: 22px; height: 22px; }
.sq-btn:hover { border-image-source: url("../assets/ui/buttons/square_hover.png"); }
.sq-btn:active { border-image-source: url("../assets/ui/buttons/square_pressed.png"); }

/* ------------------------------------------------------------ pixel digits */
.digits { display: inline-flex; gap: 2px; direction: ltr; align-items: center; height: 24px; }
.digits img { width: 16px; height: 24px; }
.digits.lg img { width: 24px; height: 36px; }
.digits.lg { height: 36px; gap: 3px; }
.digits.xl img { width: 32px; height: 48px; }
.digits.xl { height: 48px; gap: 4px; }

/* ------------------------------------------------------------ loading */
.loading {
  position: absolute; inset: 0; z-index: 40; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(ellipse at 50% 30%, #0d2a4a 0, var(--night) 60%, #030a16 100%);
}
.load-logo { width: 240px; height: 48px; }
.track { position: relative; height: 24px; width: 224px; border: 8px solid transparent; border-image: url("../assets/ui/panels/progress_track.png") 12 fill / 8px stretch; }
.track .fill { height: 100%; width: 0%; background: url("../assets/ui/progress_fill.png") left center / auto 100% repeat-x; transition: width .2s ease; }
.load-text { font-family: var(--mono); color: var(--mint); font-size: 14px; letter-spacing: 2px; }
.loading.done { opacity: 0; pointer-events: none; transition: opacity .5s ease; }

/* ------------------------------------------------------------ screens (DOM overlays) */
.screen { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
.screen > * { pointer-events: auto; }
.screen:empty { display: none; }

.lang-pill {
  position: absolute; top: 14px; inset-inline-end: 14px; z-index: 5;
  display: flex; gap: 2px; padding: 2px; border-radius: 999px;
  background: rgba(5,27,37,.75); border: 1px solid rgba(130,255,196,.35);
}
.lang-pill button { padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; color: var(--muted); }
.lang-pill button.on { background: var(--emerald); color: #04251b; }

.menu { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; padding: 52px 24px 26px; text-align: center; }
.eyebrow { font-size: 11px; letter-spacing: 3px; color: var(--mint); text-transform: uppercase; font-weight: 700; margin-bottom: 8px; }
.logo { width: 300px; height: 60px; filter: drop-shadow(0 4px 0 rgba(0,0,0,.5)); animation: float 3.6s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.tagline { margin: 10px 0 0; color: var(--gold); font-size: 16px; font-weight: 700; text-shadow: 0 2px 0 rgba(0,0,0,.5); }
.menu-actions { margin-top: 18px; width: 100%; display: flex; flex-direction: column; gap: 10px; }
.menu-actions .btn-row .btn { white-space: nowrap; padding-inline: 4px; font-size: 13px; gap: 6px; }
.menu-actions .btn-row .btn.icon-only { flex: 0 0 58px; }
.menu-foot { position: absolute; bottom: 14px; left: 0; right: 0; font-size: 11px; color: var(--muted); letter-spacing: 1px; text-shadow: 0 1px 0 rgba(0,0,0,.6); }
.challenge {
  margin-top: 14px; padding: 8px 16px; font-size: 13px; color: var(--ivory);
  border: 10px solid transparent; border-image: url("../assets/ui/panels/toast.png") 12 fill / 10px stretch;
}
.challenge b { color: var(--gold); }
.welcome { margin-top: 12px; font-size: 13px; color: var(--muted); }
.welcome b { color: var(--mint); }
.welcome button { color: var(--gold); text-decoration: underline; font-size: 12px; margin-inline-start: 6px; }

.modal-wrap { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 18px; background: rgba(3,10,22,.55); }
.modal { width: 100%; max-height: 100%; display: flex; flex-direction: column; gap: 12px; padding: 10px 6px; overflow: hidden; }
.modal h2 { margin: 0; font-size: 22px; color: var(--ivory); text-align: center; text-shadow: 0 2px 0 rgba(0,0,0,.5); }
.modal .sub { margin: -4px 0 0; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.5; }
.modal .body { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.result-body { display: flex; flex-direction: column; gap: 10px; padding: 2px 2px 4px; }
.modal.result .sub { font-size: 12px; }

.guide { display: flex; flex-direction: column; gap: 8px; }
.guide div { display: flex; align-items: center; gap: 10px; font-size: 13px; line-height: 1.45; text-align: start; }
.guide img { width: 28px; height: 28px; flex: 0 0 28px; }
.guide .anim { width: 44px; height: 44px; flex: 0 0 44px; image-rendering: pixelated; }

.field { display: flex; flex-direction: column; gap: 5px; text-align: start; }
.field label { font-size: 12px; color: var(--mint); font-weight: 700; letter-spacing: .5px; }
.field input {
  width: 100%; height: 46px; padding: 0 12px; border-radius: 6px; font-size: 16px;
  background: #061a2a; border: 2px solid #23444b; color: var(--ivory); outline: none;
}
.field input:focus { border-color: var(--mint); box-shadow: 0 0 0 3px rgba(130,255,196,.15); }
.field input.bad { border-color: var(--red); }
.field .err { min-height: 14px; font-size: 11px; color: var(--red); }
.privacy { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.5; }
.optin { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); text-align: start; padding: 0 2px; }
.optin input { width: 18px; height: 18px; accent-color: var(--emerald); flex: 0 0 auto; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 4px; font-size: 15px; border-bottom: 1px solid rgba(130,255,196,.12); }
.setting img { width: 24px; height: 24px; margin-inline-end: 8px; vertical-align: middle; }
.toggle { position: relative; width: 52px; height: 28px; border-radius: 999px; background: #23444b; transition: background .2s; flex: 0 0 auto; }
.toggle::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--ivory); transition: transform .2s; }
.toggle.on { background: var(--emerald); }
.toggle.on::after { transform: translateX(24px); }
[dir="rtl"] .toggle.on::after { transform: translateX(-24px); }
.seg { display: flex; gap: 4px; }
.seg button { padding: 6px 12px; border-radius: 6px; background: #0a2436; color: var(--muted); font-weight: 700; font-size: 13px; }
.seg button.on { background: var(--emerald); color: #04251b; }

/* result */
.result-score { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.result-score .label { font-size: 11px; letter-spacing: 2px; color: var(--mint); text-transform: uppercase; }
.newbest { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: rgba(255,212,117,.15); color: var(--gold); font-size: 12px; font-weight: 700; animation: pulse 1.2s ease-in-out infinite; }
.newbest img { width: 16px; height: 16px; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.rankline { text-align: center; font-size: 14px; color: var(--ivory); }
.rankline b { color: var(--gold); font-size: 18px; }
.stats { display: flex; justify-content: center; gap: 6px; }
.stat { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; border: 10px solid transparent; border-image: url("../assets/ui/panels/card.png") 12 fill / 10px stretch; }
.stat b { font-family: var(--mono); font-size: 16px; color: var(--gold); }
.stat span { font-size: 10px; color: var(--muted); }
.share-title { text-align: center; font-size: 12px; color: var(--mint); letter-spacing: 1px; margin-top: 2px; }
.share-row { display: flex; gap: 6px; justify-content: center; }
.share-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 52px; padding: 4px 2px;
  border: 10px solid transparent; border-image: url("../assets/ui/buttons/secondary_normal.png") 12 fill / 10px stretch;
  color: var(--ivory); font-size: 10px; font-weight: 700;
}
.share-btn:active { border-image-source: url("../assets/ui/buttons/secondary_pressed.png"); }
.share-btn svg { width: 20px; height: 20px; fill: var(--gold); }
.share-btn img { width: 20px; height: 20px; }
.share-btn.x { color: var(--ivory); }

/* leaderboard */
.lb { display: flex; flex-direction: column; gap: 5px; }
.lb-row { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 6px; font-size: 13px; border: 10px solid transparent; border-image: url("../assets/ui/panels/leaderboard_row.png") 12 fill / 10px stretch; }
.lb-row .pos { width: 26px; font-family: var(--mono); font-weight: 700; color: var(--mint); text-align: center; }
.lb-row .pos img { width: 18px; height: 18px; vertical-align: middle; }
.lb-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .sc { font-family: var(--mono); font-weight: 700; color: var(--gold); direction: ltr; }
.lb-row.me { border-image-source: url("../assets/ui/buttons/primary_normal.png"); }
.lb-row.me .nm { color: var(--mint); font-weight: 700; }
.lb-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 12px; }
.lb-total { text-align: center; color: var(--muted); font-size: 11px; }

/* ------------------------------------------------------------ HUD */
.hud { position: absolute; inset: 0 0 auto 0; z-index: 10; padding: 12px 12px 0; padding-top: calc(12px + env(safe-area-inset-top, 0px)); pointer-events: none; }
.hud-row { display: flex; align-items: center; gap: 8px; }
.hud-top { justify-content: space-between; }
.hud-box { display: flex; flex-direction: column; gap: 3px; padding: 6px 10px; border: 10px solid transparent; border-image: url("../assets/ui/panels/hud.png") 12 fill / 10px stretch; }
.hud-label { font-size: 9px; letter-spacing: 1.5px; color: var(--mint); text-transform: uppercase; font-weight: 700; }
.hud-score { min-width: 140px; }
.hud-time { min-width: 72px; align-items: center; }
.hud-time.warn .digits img { filter: drop-shadow(0 0 4px var(--red)) sepia(1) saturate(4) hue-rotate(-30deg); }
.hud .sq-btn { pointer-events: auto; }
.hud-second { margin-top: 6px; justify-content: space-between; }
.energy { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.energy .track { width: 100%; height: 20px; border-width: 7px; }
.lives { display: flex; gap: 2px; }
.lives img { width: 22px; height: 22px; }
.lives img.off { opacity: .22; filter: grayscale(1); }
.combo { position: absolute; top: 118px; inset-inline-end: 14px; font-family: var(--mono); font-weight: 700; font-size: 15px; color: var(--gold); text-shadow: 0 2px 0 rgba(0,0,0,.6); animation: combopop .25s ease; }
@keyframes combopop { from { transform: scale(1.5); } to { transform: scale(1); } }
.banner { position: absolute; top: 200px; left: 0; right: 0; text-align: center; font-size: 20px; font-weight: 800; color: var(--gold); text-shadow: 0 3px 0 rgba(0,0,0,.7); pointer-events: none; }
.power-tag { position: absolute; top: 118px; inset-inline-start: 14px; display: flex; gap: 4px; }
.power-tag span { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: rgba(5,27,37,.8); color: var(--mint); font-size: 11px; font-weight: 700; }
.power-tag img { width: 14px; height: 14px; }

/* ------------------------------------------------------------ controls */
.controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 12; height: 96px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 12px 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); height: calc(96px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(3,10,22,.9), rgba(3,10,22,0));
  direction: ltr;
}
.ctl { display: flex; align-items: center; justify-content: center; touch-action: none; }
.ctl-move {
  width: 78px; height: 66px;
  border: 12px solid transparent; border-image: url("../assets/ui/buttons/secondary_normal.png") 12 fill / 12px stretch;
}
.ctl-move img { width: 30px; height: 30px; }
.ctl-move:active, .ctl-move.is-pressed { border-image-source: url("../assets/ui/buttons/secondary_pressed.png"); }
.ctl-fire {
  position: relative; flex: 1; height: 74px; flex-direction: column; gap: 0;
  border: 12px solid transparent; border-image: url("../assets/ui/buttons/primary_normal.png") 12 fill / 12px stretch;
  color: var(--ivory); font-weight: 800; font-size: 16px; letter-spacing: 1px; text-shadow: 0 2px 0 rgba(0,0,0,.5);
}
.ctl-fire .fire-icon { width: 24px; height: 24px; margin-bottom: -2px; }
.ctl-fire:active, .ctl-fire.is-pressed { border-image-source: url("../assets/ui/buttons/primary_pressed.png"); }
.ctl-fire.charging { border-image-source: url("../assets/ui/buttons/secondary_pressed.png"); color: var(--gold); }
.ctl-fire.ready { border-image-source: url("../assets/ui/buttons/secondary_hover.png"); color: #04251b; }
.charge-ring { position: absolute; left: 8px; right: 8px; bottom: -3px; height: 5px; background: rgba(0,0,0,.45); border-radius: 3px; overflow: hidden; }
.charge-ring i { display: block; height: 100%; width: 0%; background: var(--gold); }
.ctl-fire.ready .charge-ring i { background: var(--ivory); }

/* ------------------------------------------------------------ toast / flash / rotate */
.toast {
  position: absolute; left: 50%; top: 150px; transform: translateX(-50%); z-index: 30; max-width: 300px;
  padding: 6px 16px; font-size: 14px; font-weight: 700; color: var(--ivory); text-align: center;
  border: 12px solid transparent; border-image: url("../assets/ui/panels/toast.png") 12 fill / 12px stretch;
  animation: toastin .25s ease; pointer-events: none;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.flash { position: absolute; inset: 0; pointer-events: none; }
.rotate { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: var(--night); color: var(--ivory); font-size: 16px; }
.rotate img { width: 48px; height: 48px; animation: spin 2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.fade-in { animation: fadein .3s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
[hidden] { display: none !important; }
