/* ── Design tokens ── */
:root {
  --bg:            #0F172A;
  --bg-deep:       #0B1120;
  --bg-card:       rgba(255,255,255,.05);
  --bg-hover:      rgba(255,255,255,.09);
  --border:        rgba(255,255,255,.08);
  --border-strong: rgba(255,255,255,.18);
  --text:          #F8FAFC;
  --text-muted:    #94A3B8;
  --primary:       #DC2626;
  --secondary:     #2563EB;
  --accent:        #22C55E;
  --shadow:        0 4px 24px rgba(0,0,0,.45);
  --shadow-lg:     0 18px 60px rgba(0,0,0,.55);
  --radius-sm:     8px;
  --radius:        14px;
  --radius-lg:     20px;

  /* LCD screen (classic handheld green) */
  --lcd-bg:        #9BBC0F;
  --lcd-bg-alt:    #8AA80E;
  --lcd-ink:       #0F380F;
  --lcd-ink-soft:  #2F5B2F;
  --lcd-frame:     #4B5D0C;

  /* Phone body */
  --phone-body:    #2B3345;
  --phone-edge:    #171E2C;
  --phone-key:     #3C4658;
  --phone-key-hi:  #4E5A70;

  --font-pixel: 'Press Start 2P', monospace;
  --font-lcd:   'VT323', monospace;
  --font-ar:    'Cairo', ui-sans-serif, system-ui, sans-serif;
}

body.theme-amber {
  --lcd-bg:       #F0B000;
  --lcd-bg-alt:   #DDA200;
  --lcd-ink:      #2A1A00;
  --lcd-ink-soft: #5C3A00;
  --lcd-frame:    #7A5600;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100dvh;
  overscroll-behavior: none;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font-ar);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
}

/* ── Backdrop: glow + pixel grid + scanlines ── */
.glow {
  position: fixed; inset: -30% -20% auto -20%; height: 75vh; pointer-events: none;
  background: radial-gradient(ellipse at 50% 0%, rgba(34,197,94,.20), transparent 58%),
              radial-gradient(ellipse at 15% 10%, rgba(37,99,235,.25), transparent 55%),
              radial-gradient(ellipse at 85% 5%, rgba(220,38,38,.20), transparent 50%);
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .35;
  background-image: linear-gradient(rgba(255,255,255,.045) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(ellipse at 50% 0%, #000 20%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at 50% 0%, #000 20%, transparent 75%);
}
.scanlines {
  position: fixed; inset: 0; pointer-events: none; z-index: 60; opacity: .16;
  background: repeating-linear-gradient(180deg, rgba(0,0,0,.5) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
}

/* ── Topbar ── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: calc(.6rem + env(safe-area-inset-top)) 1.25rem .6rem;
  background: rgba(11,17,32,.82); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .7rem; }
.brand__mark { image-rendering: pixelated; filter: drop-shadow(0 0 10px rgba(34,197,94,.45)); }
.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__text strong { font-size: 1.05rem; font-weight: 800; letter-spacing: -.02em; }
.brand__text span {
  font-family: var(--font-pixel); font-size: .48rem; color: var(--accent);
  letter-spacing: .08em; text-transform: uppercase;
}
.topbar__actions { display: flex; gap: .5rem; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer;
  color: var(--text-muted); background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 11px; transition: transform .15s ease, color .15s ease, background .15s ease;
}
.icon-btn:hover { color: var(--text); background: var(--bg-hover); transform: translateY(-2px); }
.icon-btn.is-off { color: var(--primary); }
.icon-btn svg { width: 19px; height: 19px; }

/* ── Layout ── */
.wrap {
  position: relative; z-index: 1;
  max-width: 1060px; margin: 0 auto; padding: 1.75rem 1.25rem 2.5rem;
  display: grid; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: 1.75rem;
  align-items: start;
}
.stage { display: flex; flex-direction: column; gap: 1.1rem; }
.side { display: flex; flex-direction: column; gap: 1.1rem; }

/* ── Phone shell ── */
.phone {
  background: linear-gradient(160deg, var(--phone-body), var(--phone-edge) 78%);
  border: 2px solid rgba(255,255,255,.07);
  border-radius: 36px; padding: 1rem .95rem 1.1rem;
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,.12);
  animation: fadeUp .5s ease both;
}
.phone__top { display: flex; align-items: center; justify-content: space-between; padding: 0 .35rem .6rem; }
.phone__speaker { width: 54px; height: 6px; border-radius: 99px; background: rgba(0,0,0,.5); box-shadow: inset 0 1px 2px rgba(0,0,0,.6); }
.phone__brand { font-family: var(--font-pixel); font-size: .5rem; color: rgba(255,255,255,.35); letter-spacing: .12em; }

/* ── LCD screen ── */
.lcd {
  position: relative; padding: 7px; border-radius: 12px;
  background: var(--lcd-bg-alt);
  box-shadow: inset 0 0 0 3px rgba(0,0,0,.28), 0 0 22px rgba(155,188,15,.14);
  transition: background .25s ease;
}
.lcd__hud {
  display: flex; justify-content: space-between; gap: .4rem; padding: 0 4px 3px;
  font-family: var(--font-lcd); font-size: .82rem; text-transform: uppercase;
  color: var(--lcd-ink-soft); letter-spacing: .04em;
}
.lcd__cell { display: flex; align-items: baseline; gap: .25rem; }
.lcd__cell b { font-size: 1.15rem; color: var(--lcd-ink); }
#lcd {
  display: block; width: 100%; height: auto; touch-action: none;
  image-rendering: pixelated; image-rendering: crisp-edges; border-radius: 4px;
  background: var(--lcd-bg);
}
.lcd__flash {
  position: absolute; inset: 7px; border-radius: 4px; pointer-events: none;
  background: var(--lcd-ink); opacity: 0; transition: opacity .07s linear;
}
.lcd__overlay {
  position: absolute; inset: 7px; border-radius: 4px; display: grid; place-items: center;
  padding: .5rem; text-align: center;
  background: var(--lcd-bg);
  background: color-mix(in srgb, var(--lcd-bg) 94%, transparent);
  color: var(--lcd-ink);
}
.lcd__overlay.hidden { display: none; }

/* ── On-screen LCD screens ── */
.scr { display: flex; flex-direction: column; align-items: center; gap: .55rem; animation: fadeUp .25s ease both; }
.scr__title { font-family: var(--font-pixel); font-size: .95rem; line-height: 1.5; }
.scr__title--sm { font-size: .7rem; }
.scr__big { font-family: var(--font-lcd); font-size: 2.6rem; line-height: 1; }
.scr__row { font-family: var(--font-lcd); font-size: 1.05rem; color: var(--lcd-ink-soft); }
.scr__row b { color: var(--lcd-ink); font-size: 1.3rem; }
.scr__btns { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; margin-top: .2rem; }
.btn-lcd {
  display: inline-flex; align-items: center; gap: .35rem; cursor: pointer;
  font-family: var(--font-pixel); font-size: .55rem; padding: .6rem .8rem;
  color: var(--lcd-bg); background: var(--lcd-ink);
  border: 2px solid var(--lcd-ink); border-radius: 3px;
  transition: transform .12s ease, opacity .15s ease;
}
.btn-lcd:hover { transform: translateY(-2px); opacity: .86; }
.btn-lcd--ghost { background: transparent; color: var(--lcd-ink); }
.btn-lcd svg { width: 13px; height: 13px; }
.blink { animation: blink 1s steps(2, start) infinite; }
.rec-badge {
  font-family: var(--font-pixel); font-size: .5rem; padding: .35rem .5rem;
  background: var(--lcd-ink); color: var(--lcd-bg); border-radius: 3px;
}

/* ── Phone keypad ── */
.phone__keys { display: flex; flex-direction: column; align-items: center; gap: .4rem; padding-top: .85rem; }
.key--mid { display: flex; align-items: center; gap: .4rem; }
.key {
  display: grid; place-items: center; cursor: pointer; color: rgba(255,255,255,.75);
  background: linear-gradient(180deg, var(--phone-key-hi), var(--phone-key));
  border: 1px solid rgba(0,0,0,.45); border-radius: 12px;
  box-shadow: 0 2px 0 rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.14);
  transition: transform .1s ease, box-shadow .1s ease, color .15s ease;
}
.key:hover { color: #fff; }
.key:active { transform: translateY(2px); box-shadow: 0 0 0 rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.1); }
.key--rock { width: 130px; height: 34px; }
.key--side { width: 62px; height: 44px; }
.key--ok {
  width: 74px; height: 44px; border-radius: 22px;
  font-family: var(--font-pixel); font-size: .55rem; color: #0B1120;
  background: linear-gradient(180deg, #E2E8F0, #A8B3C4);
}
.key svg { width: 18px; height: 18px; }

/* ── Control panel ── */
.panel {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  backdrop-filter: blur(12px); box-shadow: var(--shadow); padding: 1.1rem;
  display: flex; flex-direction: column; gap: .7rem;
  animation: fadeUp .5s ease .1s both;
}
.panel__label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--text-muted); }
.tabs { display: flex; gap: .25rem; padding: .25rem; background: rgba(255,255,255,.05); border: 1px solid var(--border); border-radius: 999px; }
.tab {
  flex: 1; padding: .45rem .3rem; cursor: pointer; border: none; border-radius: 999px;
  background: transparent; color: var(--text-muted); font-family: inherit; font-size: .82rem; font-weight: 700;
  transition: background .2s ease, color .2s ease, transform .15s ease;
}
.tab:hover { color: var(--text); }
.tab.active { background: linear-gradient(135deg, var(--accent), #4ADE80); color: #06210F; transform: translateY(-1px); }
.panel__actions { display: flex; gap: .6rem; }
.panel__actions .btn { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; cursor: pointer;
  padding: .7rem 1.1rem; border: none; border-radius: 12px;
  font-family: inherit; font-size: .9rem; font-weight: 700; color: var(--text);
  transition: transform .15s ease, box-shadow .15s ease, opacity .2s ease, background .2s ease;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #16A34A); color: #052012; box-shadow: 0 8px 26px rgba(34,197,94,.28); }
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 12px 34px rgba(34,197,94,.42); }
.btn-ghost { background: rgba(255,255,255,.05); border: 1.5px solid var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); transform: translateY(-2px); }
.btn--sm { padding: .5rem .85rem; font-size: .8rem; align-self: flex-start; }
.hint {
  display: flex; align-items: center; gap: .5rem; font-size: .78rem; color: var(--text-muted);
  border-top: 1px dashed var(--border); padding-top: .65rem;
}
.hint svg { width: 16px; height: 16px; flex: none; color: var(--accent); }

/* ── Side cards ── */
.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  backdrop-filter: blur(12px); box-shadow: var(--shadow); padding: 1.15rem 1.2rem;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
  animation: fadeUp .5s ease both;
}
.card:nth-child(1) { animation-delay: .1s; }
.card:nth-child(2) { animation-delay: .18s; }
.card:nth-child(3) { animation-delay: .26s; }
.card:hover { transform: translateY(-3px); border-color: var(--border-strong); box-shadow: var(--shadow-lg); }
.card__head { display: flex; align-items: center; gap: .6rem; margin-bottom: .8rem; }
.card__head h2 { font-size: 1rem; font-weight: 800; letter-spacing: -.01em; }
.card__ico {
  width: 34px; height: 34px; display: grid; place-items: center; flex: none;
  border-radius: 10px; color: var(--accent); background: rgba(34,197,94,.13);
}
.card__ico svg { width: 18px; height: 18px; }
.card__note { font-size: .78rem; color: var(--text-muted); margin-top: .7rem; }
.rows { list-style: none; display: flex; flex-direction: column; gap: .55rem; }
.rows li { display: flex; gap: .6rem; font-size: .85rem; color: var(--text-muted); }
.rows svg { width: 16px; height: 16px; flex: none; margin-top: .25rem; color: var(--secondary); }
.rows b, .steps b { color: var(--text); }
.steps { list-style: none; display: flex; flex-direction: column; gap: .6rem; }
.steps li { display: flex; gap: .65rem; font-size: .85rem; color: var(--text-muted); align-items: flex-start; }
.steps__n {
  width: 22px; height: 22px; flex: none; display: grid; place-items: center;
  border-radius: 6px; font-size: .72rem; font-weight: 800; color: #052012; background: var(--accent);
}
.inline-ico { width: 14px; height: 14px; vertical-align: -2px; color: var(--accent); }
.records { list-style: none; display: flex; flex-direction: column; gap: .35rem; margin-bottom: .8rem; }
.records li {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .45rem .6rem; border-radius: var(--radius-sm);
  background: rgba(255,255,255,.04); border: 1px solid var(--border); font-size: .82rem;
}
.records .r-rank { font-family: var(--font-pixel); font-size: .5rem; color: var(--accent); }
.records .r-score { font-family: var(--font-lcd); font-size: 1.25rem; }
.records .r-meta { color: var(--text-muted); font-size: .74rem; }
.records__empty { color: var(--text-muted); font-size: .82rem; padding: .5rem 0; }

/* ── Footer & toasts ── */
.foot {
  position: relative; z-index: 1; display: flex; flex-wrap: wrap; justify-content: center;
  gap: .5rem; padding: 1.25rem; font-size: .78rem; color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.foot__dot { color: var(--accent); }
.toast-wrap { position: fixed; z-index: 90; inset-inline-start: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: .5rem; }
.toast {
  padding: .7rem 1rem; border-radius: 10px; font-size: .84rem; font-weight: 700;
  box-shadow: var(--shadow-lg); animation: fadeUp .28s ease both;
  background: rgba(11,17,32,.94); border: 1px solid var(--border-strong); color: var(--text);
}
.toast.success { border-color: rgba(34,197,94,.45); color: #86EFAC; }
.toast.info { border-color: rgba(37,99,235,.45); color: #BFDBFE; }

/* ── Animations ── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: .15; } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.lcd.shake { animation: shake .32s ease; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .wrap { grid-template-columns: 1fr; padding: 1.25rem 1rem 2rem; gap: 1.4rem; }
  .stage { max-width: 400px; width: 100%; margin: 0 auto; }
}
@media (max-width: 400px) {
  .phone { border-radius: 28px; padding: .8rem .7rem .9rem; }
  .icon-btn { width: 36px; height: 36px; }
  .brand__text span { font-size: .42rem; }
  .key--rock { width: 110px; }
  .key--side { width: 54px; }
}

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

/* ── سلامة الشاشات الصغيرة ── */
.lcd__overlay { overflow: hidden; }
.scr { max-width: 100%; }
.scr__big { font-size: clamp(1.9rem, 11vw, 2.6rem); }
.scr__title { font-size: clamp(.62rem, 3.4vw, .95rem); }
.scr__row { font-size: clamp(.85rem, 4.4vw, 1.05rem); }
.btn-lcd { font-size: clamp(.44rem, 2.4vw, .55rem); }

/* ── ضبط الخطوط داخل الشاشة: عربي واضح + أرقام LCD ── */
.lcd__hud { font-family: var(--font-ar); font-weight: 700; font-size: .62rem; letter-spacing: 0; }
.lcd__cell b { font-family: var(--font-lcd); font-size: 1.25rem; }
.scr__row {
  font-family: var(--font-ar); font-weight: 700;
  font-size: clamp(.74rem, 3.4vw, .9rem); line-height: 1.5;
}
.scr__row b { font-family: var(--font-lcd); font-weight: 400; font-size: 1.35rem; }
.btn-lcd {
  font-family: var(--font-ar); font-weight: 800; letter-spacing: 0;
  font-size: clamp(.68rem, 3.2vw, .8rem); border-radius: 6px;
}
.rec-badge { font-family: var(--font-ar); font-weight: 800; font-size: .72rem; letter-spacing: 0; }
.key--ok { font-family: var(--font-ar); font-weight: 800; font-size: .68rem; }
