/* ══════════════════════════════════════════════════
   ساموراي عبر الزمن — نظام التصميم
   ══════════════════════════════════════════════════ */
:root {
  --void:        #07080d;
  --ink:         #0c0e17;
  --ink-2:       #12141f;
  --glass:       rgba(255,255,255,.045);
  --glass-2:     rgba(255,255,255,.07);
  --border:      rgba(255,255,255,.09);
  --border-2:    rgba(255,255,255,.18);

  --text:        #f1f4fb;
  --muted:       #8b93a7;
  --dim:         #5c6478;

  --red:         #e11d2e;
  --red-soft:    #ff5a5f;
  --ember:       #ff8a1f;
  --jade:        #2fbf71;
  --gold:        #e8c15a;
  --violet:      #7c5cff;

  --grad-fire:   linear-gradient(135deg, #ff8a1f, #e11d2e);
  --grad-jade:   linear-gradient(135deg, #2fbf71, #7ce0a5);
  --grad-royal:  linear-gradient(135deg, #7c5cff, #3aa0ff);

  --r-sm: 8px;
  --r:    14px;
  --r-lg: 22px;
  --shadow:    0 10px 40px rgba(0,0,0,.55);
  --shadow-lg: 0 24px 80px rgba(0,0,0,.7);

  --font-ar: 'Cairo', system-ui, sans-serif;
  --font-ui: 'Orbitron', 'Cairo', sans-serif;
}

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

html, body { height: 100%; }

body {
  background: var(--void);
  color: var(--text);
  font-family: var(--font-ar);
  line-height: 1.6;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.bg-glow {
  position: fixed; inset: -30% -10% auto -10%; height: 80vh; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse 55% 60% at 25% 0%, rgba(225,29,46,.22), transparent 65%),
    radial-gradient(ellipse 50% 55% at 80% 5%, rgba(124,92,255,.18), transparent 65%);
}
.bg-grid {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .35;
  background-image:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 30%, #000 20%, transparent 85%);
  -webkit-mask-image: radial-gradient(ellipse 80% 70% at 50% 30%, #000 20%, transparent 85%);
}

/* ── Layout shell ── */
.app {
  position: relative; z-index: 1;
  min-height: 100dvh;
  display: flex; flex-direction: column;
  max-width: 1120px; margin: 0 auto; padding: 0 1rem 1.5rem;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem .35rem .85rem;
}
.brand { display: flex; align-items: center; gap: .65rem; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: var(--grad-fire);
  box-shadow: 0 0 0 1px rgba(255,255,255,.14), 0 8px 26px rgba(225,29,46,.45);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 7px 6px;
  background: linear-gradient(180deg, #fff, rgba(255,255,255,.55));
  clip-path: polygon(46% 0, 100% 0, 58% 44%, 92% 44%, 34% 100%, 44% 56%, 12% 56%);
}
.brand-name {
  font-family: var(--font-ui); font-weight: 800; font-size: 1rem;
  letter-spacing: .01em;
}
.brand-name em {
  font-style: normal; display: block;
  font-size: .62rem; letter-spacing: .22em; color: var(--muted); font-weight: 600;
}
.topbar-actions { display: flex; gap: .5rem; }

.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 12px; cursor: pointer; color: var(--muted);
  background: var(--glass); border: 1px solid var(--border);
  transition: transform .18s ease, color .18s ease, background .18s ease, border-color .18s;
}
.icon-btn:hover { color: var(--text); background: var(--glass-2); border-color: var(--border-2); transform: translateY(-2px); }
.icon-btn.is-off { color: var(--red-soft); }
.icon-btn svg { width: 19px; height: 19px; }

/* ── Stage ── */
.stage-wrap { flex: 1; display: flex; align-items: center; justify-content: center; }
.stage {
  position: relative; width: 100%; max-width: 1040px;
  aspect-ratio: 16 / 9;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #05060a;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg), inset 0 0 120px rgba(225,29,46,.08);
  isolation: isolate;
}
#game { display: block; width: 100%; height: 100%; touch-action: none; }

/* ── Screens & panels ── */
.screen {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  padding: 1.25rem;
  background: radial-gradient(ellipse at 50% 40%, rgba(10,12,20,.86), rgba(4,5,9,.97));
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  opacity: 0; visibility: hidden; transition: opacity .3s ease, visibility .3s;
  overflow-y: auto;
}
.screen.is-on { opacity: 1; visibility: visible; }

.panel {
  width: 100%; max-width: 640px;
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 2rem 1.85rem;
  box-shadow: var(--shadow);
  animation: riseIn .45s cubic-bezier(.2,.8,.25,1) both;
}
.panel-narrow { max-width: 460px; text-align: center; }
.panel-title { text-align: center; max-width: 660px; }
.panel-h { font-size: 1.5rem; font-weight: 800; margin-bottom: 1rem; letter-spacing: -.01em; }

.eyebrow {
  display: inline-block; font-size: .7rem; font-weight: 700; letter-spacing: .16em;
  color: var(--ember); text-transform: uppercase; margin-bottom: 1rem;
  border: 1px solid rgba(255,138,31,.32); background: rgba(255,138,31,.09);
  padding: .3rem .8rem; border-radius: 999px;
}
.title {
  font-family: var(--font-ui); font-weight: 900; line-height: 1.05;
  font-size: clamp(2rem, 6vw, 3.3rem); letter-spacing: -.02em; margin-bottom: 1.1rem;
}
.title span { display: block; }
.title-accent {
  background: var(--grad-fire);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 6px 26px rgba(225,29,46,.5));
}
.lede { color: var(--muted); font-size: .98rem; max-width: 520px; margin: 0 auto 1.6rem; }
.lede strong { color: var(--red-soft); font-weight: 800; }
.muted { color: var(--muted); font-size: .92rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .72rem 1.4rem; border-radius: 999px;
  font-family: var(--font-ar); font-size: .92rem; font-weight: 700;
  cursor: pointer; border: 1px solid transparent; color: var(--text);
  transition: transform .16s ease, box-shadow .16s ease, background .16s, border-color .16s;
}
.btn svg { width: 17px; height: 17px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
  background: var(--grad-fire); color: #fff;
  box-shadow: 0 10px 34px rgba(225,29,46,.4);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 16px 44px rgba(225,29,46,.55); }
.btn-ghost { background: var(--glass); border-color: var(--border-2); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--glass-2); transform: translateY(-2px); }
.btn.wide { width: 100%; }

.cta-row { display: flex; gap: .7rem; justify-content: center; flex-wrap: wrap; }
.cta-row.col { flex-direction: column; align-items: stretch; margin-top: 1.25rem; }

.facts {
  list-style: none; display: flex; justify-content: center; gap: .6rem;
  margin-top: 1.6rem; flex-wrap: wrap;
}
.facts li {
  font-size: .78rem; color: var(--muted);
  background: var(--glass); border: 1px solid var(--border);
  padding: .35rem .85rem; border-radius: 999px;
}
.facts strong { color: var(--gold); font-family: var(--font-ui); font-weight: 800; }

/* ── Story screen ── */
.panel-story { max-width: 700px; }
.story-head { border-bottom: 1px solid var(--border); padding-bottom: 1rem; margin-bottom: 1.15rem; }
.chapter-tag {
  display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .14em;
  color: var(--red-soft); margin-bottom: .35rem;
}
#storyTitle { font-family: var(--font-ui); font-size: clamp(1.5rem, 4vw, 2.1rem); font-weight: 800; }
.story-body p { color: #cfd6e6; font-size: 1rem; margin-bottom: .85rem; }
.story-body p:last-child { margin-bottom: 0; }
.objective {
  display: flex; align-items: center; gap: .6rem; margin: 1.25rem 0 .4rem;
  background: rgba(47,191,113,.08); border: 1px solid rgba(47,191,113,.28);
  border-radius: var(--r); padding: .75rem 1rem;
  color: #9ff0c4; font-size: .9rem; font-weight: 600;
}
.objective svg { width: 18px; height: 18px; flex: none; color: var(--jade); }

/* ── Help screen ── */
.keys { display: flex; flex-direction: column; gap: .45rem; margin-bottom: 1.4rem; }
.key-row {
  display: flex; align-items: center; gap: .9rem;
  background: var(--glass); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: .55rem .85rem; font-size: .88rem;
}
.kb {
  font-family: var(--font-ui); font-size: .72rem; font-weight: 700; letter-spacing: .04em;
  color: var(--gold); background: rgba(232,193,90,.1);
  border: 1px solid rgba(232,193,90,.28); border-radius: 6px;
  padding: .25rem .5rem; min-width: 84px; text-align: center; flex: none;
}
.key-row span:last-child { color: #cfd6e6; }
.tips h3 { font-size: .95rem; font-weight: 800; margin-bottom: .5rem; color: var(--ember); }
.tips ul { list-style: none; display: flex; flex-direction: column; gap: .45rem; margin-bottom: 1.4rem; }
.tips li {
  position: relative; padding-inline-start: 1.15rem;
  font-size: .88rem; color: var(--muted);
}
.tips li::before {
  content: ""; position: absolute; inset-inline-start: 0; top: .62em;
  width: 6px; height: 6px; border-radius: 50%; background: var(--red);
}

/* ── Result screen ── */
.verdict {
  width: 68px; height: 68px; margin: 0 auto 1rem; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.8rem;
}
.verdict.win {
  background: rgba(47,191,113,.13); border: 1px solid rgba(47,191,113,.4);
  color: var(--jade); box-shadow: 0 0 46px rgba(47,191,113,.28);
}
.verdict.lose {
  background: rgba(225,29,46,.13); border: 1px solid rgba(225,29,46,.4);
  color: var(--red-soft); box-shadow: 0 0 46px rgba(225,29,46,.28);
}
.verdict svg { width: 34px; height: 34px; }
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin-top: 1.25rem;
}
.stat {
  background: var(--glass); border: 1px solid var(--border);
  border-radius: var(--r); padding: .7rem .5rem; text-align: center;
}
.stat b { display: block; font-family: var(--font-ui); font-size: 1.3rem; font-weight: 800; color: var(--gold); }
.stat span { font-size: .72rem; color: var(--muted); }

.spinner {
  width: 40px; height: 40px; margin: 0 auto 1rem; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.1); border-top-color: var(--red);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes riseIn { from { opacity: 0; transform: translateY(22px) scale(.98); } to { opacity: 1; transform: none; } }

/* ── HUD ── */
.hud {
  position: absolute; inset: 0; z-index: 4; pointer-events: none;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 10px;
}
.hud-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.hud-card {
  display: flex; align-items: center; gap: .55rem;
  background: rgba(6,8,14,.62); border: 1px solid var(--border);
  border-radius: 999px; padding: .4rem .8rem;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.hud-card .ic { width: 17px; height: 17px; flex: none; }
.ic.red { color: var(--red-soft); }
.ic.gold { color: var(--gold); }
.hud-val { font-family: var(--font-ui); font-weight: 800; font-size: .85rem; min-width: 2ch; }
.hud-sub { font-size: .65rem; color: var(--dim); }
.bar { height: 9px; border-radius: 999px; background: rgba(255,255,255,.1); overflow: hidden; }
.bar-hp { width: clamp(80px, 18vw, 190px); }
.bar-hp span {
  display: block; height: 100%; width: 100%; border-radius: 999px;
  background: var(--grad-jade); transition: width .18s ease, background .3s;
}
.bar-hp span.low { background: var(--grad-fire); }
.hud-mid { display: flex; flex-direction: column; gap: .3rem; align-items: center; }
.chip {
  font-size: .72rem; font-weight: 700; letter-spacing: .02em;
  background: rgba(225,29,46,.14); border: 1px solid rgba(225,29,46,.34);
  color: #ffb3b8; padding: .2rem .7rem; border-radius: 999px; white-space: nowrap;
}
.chip.ghost { background: rgba(255,255,255,.05); border-color: var(--border); color: var(--muted); }

.boss-wrap {
  align-self: center; width: min(560px, 82%); text-align: center;
  background: rgba(6,8,14,.6); border: 1px solid rgba(225,29,46,.3);
  border-radius: var(--r); padding: .5rem .8rem;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.boss-name { font-size: .74rem; font-weight: 800; color: var(--red-soft); letter-spacing: .08em; }
.bar-boss { margin-top: .3rem; height: 12px; }
.bar-boss span {
  display: block; height: 100%; width: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #ff8a1f, #e11d2e); transition: width .2s ease;
}
.combo {
  position: absolute; inset-inline-end: 20px; top: 92px;
  font-family: var(--font-ui); font-weight: 900; font-size: 1.5rem;
  color: var(--gold); text-shadow: 0 0 22px rgba(232,193,90,.6);
  animation: pop .9s ease;
}
@keyframes pop { 0% { transform: scale(.6); opacity: 0 } 30% { transform: scale(1.15); opacity: 1 } 100% { transform: scale(1); opacity: .9 } }

/* ── Touch controls ── */
.touch { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
.stick {
  position: absolute; left: 22px; bottom: 22px;
  width: 122px; height: 122px; border-radius: 50%;
  background: rgba(255,255,255,.05); border: 1px solid var(--border-2);
  pointer-events: auto; touch-action: none;
}
.stick-knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px;
  margin: -26px 0 0 -26px; border-radius: 50%;
  background: rgba(255,255,255,.16); border: 1px solid var(--border-2);
}
.touch-btns {
  position: absolute; right: 22px; bottom: 26px;
  display: flex; align-items: flex-end; gap: 14px; pointer-events: auto;
}
.tbtn {
  width: 74px; height: 74px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; color: #fff;
  background: rgba(255,255,255,.07); border: 1px solid var(--border-2);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: transform .12s ease, background .12s;
}
.tbtn:active { transform: scale(.92); background: rgba(255,255,255,.16); }
.tbtn svg { width: 26px; height: 26px; }
.tbtn-atk { background: rgba(225,29,46,.28); border-color: rgba(225,29,46,.5); width: 88px; height: 88px; }
.tbtn-dash { background: rgba(124,92,255,.22); border-color: rgba(124,92,255,.45); }

/* ── Responsive ── */
@media (max-width: 900px) {
  .app { padding: 0 .6rem 1rem; }
  .panel { padding: 1.5rem 1.15rem; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .hud { padding: 10px; }
}
@media (max-width: 640px) {
  .brand-name em { display: none; }
  .stage { border-radius: var(--r); }
  .hud-val, .hud-sub { font-size: .72rem; }
  .chip { font-size: .62rem; padding: .16rem .5rem; }
  .bar-hp { width: 74px; }
  .screen { padding: .6rem; align-items: flex-start; padding-top: 1.2rem; }
  .keys { font-size: .82rem; }
  .kb { min-width: 62px; font-size: .64rem; }
  .title { font-size: clamp(1.7rem, 9vw, 2.4rem); }
}
@media (max-width: 420px) {
  .stick { width: 104px; height: 104px; }
  .tbtn { width: 62px; height: 62px; }
  .tbtn-atk { width: 74px; height: 74px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* إخفاء موثوق للعناصر ذات display مُخصَّص */
[hidden] { display: none !important; }
button:focus-visible, .icon-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* حالة الزر الملموس أثناء الضغط */
.tbtn.on {
  transform: scale(.92);
  background: rgba(255,255,255,.2);
  box-shadow: 0 0 0 4px rgba(255,255,255,.08);
}
.tbtn-atk.on { background: rgba(225,29,46,.5); }
.tbtn-dash.on { background: rgba(124,92,255,.45); }
#resultText p { margin: 0 0 .55rem; }
#resultText p:last-child { margin-bottom: 0; }
