/* =========================================================
   AlGzawy Auto — Medieval War Theme
   ========================================================= */
:root {
  --night: #0b0806;
  --night-2: #140e0a;
  --wood: #2a1c11;
  --wood-2: #3b2716;
  --gold: #d9ab52;
  --gold-hi: #ffe2a0;
  --gold-lo: #8a6326;
  --ember: #ff7a2b;
  --ember-2: #ffb347;
  --blood: #8e1c1c;
  --blood-hi: #c9302c;
  --parch: #ecdcb8;
  --parch-2: #cdb689;
  --ink: #2a1a0e;
  --steel: #9aa3ad;
  --ok: #6fbf5a;
  --warn: #e7b23c;
  --bad: #e0503c;
  --radius: 14px;
  --font-title: "Reem Kufi", "Cairo", serif;
  --font-body: "Cairo", system-ui, sans-serif;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; overflow-x: clip; }
body {
  font-family: var(--font-body);
  background: var(--night);
  color: var(--parch);
  min-height: 100dvh;
  overflow-x: clip;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--gold); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
img, svg { display: block; }

/* ---------- Atmospheric background layers ---------- */
.sky {
  position: fixed; inset: 0; z-index: -5;
  background:
    radial-gradient(120% 70% at 50% 110%, #5a2a10 0%, transparent 55%),
    radial-gradient(80% 50% at 80% 0%, #1d1530 0%, transparent 60%),
    linear-gradient(180deg, #07050a 0%, #120b08 55%, #1c100a 100%);
}
.sky::after { /* stars */
  content: ""; position: absolute; inset: 0 0 40% 0;
  background-image:
    radial-gradient(1px 1px at 12% 18%, #fff8 50%, transparent),
    radial-gradient(1px 1px at 28% 8%, #fff6 50%, transparent),
    radial-gradient(1.5px 1.5px at 47% 22%, #ffe9b8aa 50%, transparent),
    radial-gradient(1px 1px at 66% 12%, #fff7 50%, transparent),
    radial-gradient(1px 1px at 84% 26%, #fff5 50%, transparent),
    radial-gradient(1px 1px at 92% 6%, #fff8 50%, transparent),
    radial-gradient(1px 1px at 6% 34%, #fff4 50%, transparent),
    radial-gradient(1.5px 1.5px at 74% 38%, #fff6 50%, transparent);
  animation: twinkle 6s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .45 } to { opacity: 1 } }

.moon {
  position: fixed; top: 7vh; inset-inline-start: 10vw; z-index: -4;
  width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff6dd, #e9d29a 55%, #b8955a 100%);
  box-shadow: 0 0 60px 18px #ffdf9a33, 0 0 160px 60px #ffb34711;
  opacity: .85;
}

#embers { position: fixed; inset: 0; z-index: -2; pointer-events: none; }

.fog {
  position: fixed; inset-inline: -50%; bottom: -10vh; height: 45vh; z-index: -1;
  pointer-events: none; opacity: .5;
  background:
    radial-gradient(40% 60% at 20% 70%, #ffffff10, transparent 70%),
    radial-gradient(35% 55% at 60% 80%, #ffffff0d, transparent 70%),
    radial-gradient(30% 50% at 90% 75%, #ffffff0c, transparent 70%);
  animation: fog 38s linear infinite;
}
.fog.f2 { animation-duration: 60s; animation-direction: reverse; opacity: .35; bottom: -16vh; }
@keyframes fog { from { transform: translateX(0) } to { transform: translateX(25%) } }

.skyline {
  position: fixed; inset-inline: 0; bottom: 0; z-index: -3; height: 34vh;
  pointer-events: none; color: #0a0705;
}
.skyline svg { width: 100%; height: 100%; }

/* ---------- Layout ---------- */
.wrap { width: min(1100px, 100% - 32px); margin-inline: auto; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(180deg, #0b0806ee, #0b080600);
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-title); font-size: 1.25rem; color: var(--gold-hi); }
.brand .crest { width: 38px; height: 38px; filter: drop-shadow(0 0 8px #ffb34766); }
.brand small { display: block; font-family: var(--font-body); font-size: .7rem; color: var(--parch-2); letter-spacing: .08em; }

/* ---------- Gold title text ---------- */
.gold-text {
  font-family: var(--font-title);
  background: linear-gradient(180deg, var(--gold-hi) 0%, var(--gold) 45%, var(--gold-lo) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 0 #00000088) drop-shadow(0 0 18px #ffb34733);
}
.shine { position: relative; display: inline-block; }
.shine::after {
  content: attr(data-text); position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 35%, #fff8 50%, transparent 65%);
  background-size: 250% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shine 4.5s ease-in-out infinite;
}
@keyframes shine { 0%, 60% { background-position: 150% 0 } 100% { background-position: -50% 0 } }

/* ---------- Buttons ---------- */
.btn {
  --c1: #f2c66b; --c2: #b07d2c; --c3: #6e4914;
  position: relative; isolation: isolate; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 26px; border: 0; cursor: pointer;
  font-family: var(--font-title); font-size: 1.08rem; color: #2a1606;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--c1), var(--c2) 60%, var(--c3));
  box-shadow: inset 0 1px 0 #fff6, inset 0 -3px 0 #0005, 0 6px 0 #3a2408, 0 10px 24px #0009, 0 0 0 1px #000a;
  transition: transform .18s var(--ease-spring), box-shadow .18s, filter .2s;
  text-shadow: 0 1px 0 #ffe7b088;
  -webkit-tap-highlight-color: transparent;
}
.btn::before { /* sweeping glint */
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(110deg, transparent 30%, #fff7 48%, transparent 66%);
  transform: translateX(120%); transition: transform .7s var(--ease-out);
}
.btn:hover::before { transform: translateX(-120%); }
.btn:hover { filter: brightness(1.08) saturate(1.1); }
.btn:active { transform: translateY(4px); box-shadow: inset 0 1px 0 #fff6, inset 0 -2px 0 #0005, 0 2px 0 #3a2408, 0 4px 12px #0009, 0 0 0 1px #000a; }
.btn:disabled { filter: grayscale(.7) brightness(.7); cursor: not-allowed; }
.btn.red   { --c1: #e0544a; --c2: #9a1f1c; --c3: #571010; color: #ffe9d6; text-shadow: 0 1px 0 #000a; }
.btn.steel { --c1: #c4ccd4; --c2: #6c757e; --c3: #3a4148; color: #111; }
.btn.green { --c1: #8fd36f; --c2: #3f8a2c; --c3: #1f4a14; color: #0d2208; }
.btn.ghost {
  background: #ffffff08; color: var(--parch); text-shadow: none;
  box-shadow: inset 0 0 0 1px #d9ab5255;
}
.btn.block { width: 100%; }
.btn .spin { width: 20px; height: 20px; border: 3px solid #2a160655; border-top-color: #2a1606; border-radius: 50%; animation: rot .8s linear infinite; display: none; }
.btn.loading .spin { display: block; }
.btn.loading .label { opacity: .7; }
@keyframes rot { to { transform: rotate(1turn) } }

.spark { /* click sparks */
  position: fixed; width: 5px; height: 5px; border-radius: 50%; pointer-events: none; z-index: 999;
  background: radial-gradient(circle, #fff, var(--ember-2) 40%, var(--ember) 70%, transparent);
  box-shadow: 0 0 8px var(--ember);
}

/* ---------- Panels (carved wood + gold trim) ---------- */
.panel {
  position: relative; border-radius: var(--radius);
  background:
    linear-gradient(180deg, #ffffff07, #00000030),
    repeating-linear-gradient(92deg, #2c1e12 0 6px, #2a1c10 6px 9px, #2f2014 9px 15px),
    var(--wood);
  border: 1px solid #000;
  box-shadow: inset 0 0 0 2px #6b4a1e, inset 0 0 0 3px #000a, inset 0 0 40px #000a, 0 18px 40px #000b;
  padding: 20px;
}
.panel::before { /* corner rivets */
  content: ""; position: absolute; inset: 8px; pointer-events: none; border-radius: 10px;
  background:
    radial-gradient(circle at 6px 6px, var(--gold) 0 3px, transparent 4px) top left / 14px 14px no-repeat,
    radial-gradient(circle at 8px 6px, var(--gold) 0 3px, transparent 4px) top right / 14px 14px no-repeat,
    radial-gradient(circle at 6px 8px, var(--gold) 0 3px, transparent 4px) bottom left / 14px 14px no-repeat,
    radial-gradient(circle at 8px 8px, var(--gold) 0 3px, transparent 4px) bottom right / 14px 14px no-repeat;
}
.panel h2, .panel h3 { font-family: var(--font-title); color: var(--gold-hi); font-weight: 500; }
.panel h3 { font-size: 1.1rem; display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }

.parchment {
  position: relative; color: var(--ink); border-radius: 10px; padding: 18px;
  background:
    radial-gradient(120% 90% at 50% 50%, transparent 55%, #8a6a3a55 100%),
    radial-gradient(circle at 20% 30%, #ffffff40, transparent 40%),
    linear-gradient(135deg, #f1e3c2, #dfc794 60%, #d4b97f);
  box-shadow: inset 0 0 30px #7a552455, 0 8px 24px #0008;
}

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-size: .9rem; color: var(--parch-2); display: flex; align-items: center; gap: 6px; }
.input {
  width: 100%; min-height: 50px; padding: 0 14px; border-radius: 10px;
  background: #0c0806cc; border: 1px solid #5b3f1a;
  box-shadow: inset 0 2px 8px #000c, 0 1px 0 #ffffff10;
  color: var(--parch); font-size: 1rem; outline: none;
  transition: border-color .25s, box-shadow .25s;
}
.input::placeholder { color: #8d7a5c; }
.input:focus { border-color: var(--gold); box-shadow: inset 0 2px 8px #000c, 0 0 0 3px #d9ab5233, 0 0 22px #ffb34733; }
.input-wrap { position: relative; }
.input-wrap .eye { position: absolute; inset-inline-end: 8px; top: 50%; translate: 0 -50%; background: none; border: 0; padding: 8px; cursor: pointer; color: var(--parch-2); }
.hint { font-size: .78rem; color: #a99372; }

.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; position: absolute; inset: 0; cursor: pointer; z-index: 1; }
.switch span {
  position: absolute; inset: 0; border-radius: 99px; background: #1a110b;
  box-shadow: inset 0 2px 6px #000, 0 0 0 1px #5b3f1a; transition: background .3s;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3d0, var(--gold) 55%, var(--gold-lo));
  box-shadow: 0 2px 4px #000a; transition: transform .35s var(--ease-spring);
}
.switch input:checked + span { background: linear-gradient(90deg, #4f2a0c, #9a5414); box-shadow: inset 0 2px 6px #000, 0 0 12px #ff7a2b66; }
[dir="rtl"] .switch input:checked + span::after { transform: translateX(-22px); }
[dir="ltr"] .switch input:checked + span::after { transform: translateX(22px); }

/* ---------- Toast ---------- */
#toasts { position: fixed; z-index: 1000; inset-inline: 0; bottom: 18px; display: grid; justify-items: center; gap: 8px; pointer-events: none; }
.toast {
  pointer-events: auto; max-width: min(92vw, 460px); padding: 12px 18px; border-radius: 12px;
  background: linear-gradient(180deg, #2b1d11, #1a120b); border: 1px solid #6b4a1e;
  box-shadow: 0 10px 30px #000c, 0 0 0 1px #000; color: var(--parch);
  display: flex; gap: 10px; align-items: center;
  animation: toastIn .5s var(--ease-spring) both;
}
.toast.bad { border-color: var(--blood-hi); }
.toast.ok { border-color: #3f8a2c; }
.toast.out { animation: toastOut .35s ease-in both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(30px) scale(.9) } }
@keyframes toastOut { to { opacity: 0; transform: translateY(20px) scale(.95) } }

/* ---------- Page transition: castle gates ---------- */
.gates { position: fixed; inset: 0; z-index: 900; pointer-events: none; display: flex; }
.gate {
  flex: 1; height: 100%;
  background:
    repeating-linear-gradient(90deg, #2a1a0e 0 22px, #22150b 22px 24px, #301e10 24px 46px),
    #2a1a0e;
  box-shadow: inset 0 0 80px #000;
  position: relative;
  transition: transform .9s var(--ease-out);
}
.gate::before, .gate::after { /* iron bands */
  content: ""; position: absolute; inset-inline: 0; height: 26px;
  background: linear-gradient(180deg, #555c63, #2a2e33);
  box-shadow: 0 2px 6px #000, inset 0 1px 0 #ffffff33;
}
.gate::before { top: 18%; } .gate::after { bottom: 18%; }
.gate.l { transform-origin: left; } .gate.r { transform-origin: right; }
.gates.open .gate.l { transform: translateX(-102%); }
.gates.open .gate.r { transform: translateX(102%); }
.gates .seal {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%; width: 110px; height: 110px; z-index: 2;
  transition: opacity .3s, transform .6s var(--ease-spring);
  filter: drop-shadow(0 0 20px #ffb34788);
}
.gates.open .seal { opacity: 0; transform: scale(1.6) rotate(25deg); }

/* ---------- Reveal on load ---------- */
.reveal { opacity: 0; transform: translateY(24px); filter: blur(4px); }
.reveal.in { opacity: 1; transform: none; filter: none; transition: opacity .9s var(--ease-out), transform .9s var(--ease-out), filter .9s; }

/* ---------- Torch glow ---------- */
.torch {
  position: absolute; width: 220px; height: 220px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, #ff9a3c44, #ff7a2b11 45%, transparent 70%);
  animation: flicker 2.2s infinite;
  mix-blend-mode: screen;
}
@keyframes flicker {
  0%, 100% { opacity: .85; transform: scale(1) }
  20% { opacity: 1; transform: scale(1.04) }
  45% { opacity: .7; transform: scale(.97) }
  70% { opacity: .95; transform: scale(1.02) }
}

/* ---------- Utilities ---------- */
.row { display: flex; gap: 12px; align-items: center; }
.between { justify-content: space-between; }
.wrapflex { flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.muted { color: #a99372; }
.center { text-align: center; }
.hidden { display: none !important; }

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