/* The Seerah Atlas · the gate.
   A full-bleed field, a floating bone index sheet, one verdigris survey light.
   Every door is a plate: number, field note, name, and a lit threshold. */

:root {
  --ink: #0b100e;
  --ink-deep: #070b09;
  --bone: #ece5d3;
  --bone-soft: #ded5c0;
  --bone-dim: rgba(236, 229, 211, 0.64);
  --muted: #a9a291;
  --muted-ink: #5a5447;
  --accent: #9bc4ae;
  --accent-deep: #3a6250;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: "Archivo", "Cormorant Garamond", "Helvetica Neue", sans-serif;
  --arabic: "Amiri", "Cormorant Garamond", serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --edge: clamp(20px, 3.4vw, 52px);
  --sheet-edge: clamp(12px, 1.7vw, 26px);
  --head: 96px;
}

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

html { background: var(--ink); }

body {
  margin: 0;
  min-height: 100svh;
  background: var(--ink);
  color: var(--bone);
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 400;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img { display: block; max-width: 100%; height: auto; }
a { color: inherit; text-decoration: none; }
h1, p { margin: 0; }
svg { display: block; }
::selection { background: var(--accent); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.skip {
  position: fixed;
  top: -120px;
  left: var(--edge);
  z-index: 100;
  padding: 12px 16px;
  background: var(--bone);
  color: var(--ink);
  font-size: 16px;
  transition: top 0.2s var(--ease);
}
.skip:focus { top: 12px; }

/* ------------------------------ masthead, laid on the field */

.masthead {
  position: fixed;
  inset: 0 0 auto;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  height: calc(var(--head) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) var(--edge) 0;
  background: none;
}

.masthead-lockup {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  min-width: 0;
}

.masthead-mark {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: 12px;
  min-height: 34px;
  font-family: var(--serif);
  font-size: clamp(32px, 2.8vw, 40px);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.015em;
  color: var(--bone);
}

.masthead-sigil {
  width: 17px;
  height: 19px;
  flex: none;
  fill: var(--accent);
}

.masthead-sub {
  display: block;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: 0.012em;
  color: rgba(236, 229, 211, 0.8);
  white-space: nowrap;
}

.masthead-sub .hon {
  display: inline-block;
  padding-inline: 0.14em;
  margin: 0 0.1em 0 0.04em;
  font-family: var(--arabic);
  font-size: 1.5em;
  line-height: 1;
  vertical-align: -0.06em;
  color: var(--bone);
}

.masthead-side {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  text-align: right;
}

.masthead-ar {
  font-family: var(--arabic);
  font-size: 18px;
  line-height: 1.2;
  color: var(--bone);
}

.masthead-note {
  font-size: 13px;
  line-height: 1.2;
  letter-spacing: 0.02em;
  color: rgba(236, 229, 211, 0.72);
  white-space: nowrap;
}

/* ------------------------------ the gate */

.gate {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 100svh;
  padding: 0 var(--sheet-edge) var(--sheet-edge);
  background: var(--ink);
}

/* ------------------------------ the field */

.stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  min-height: 280px;
  overflow: hidden;
  background: var(--ink-deep);
}

.stage-track {
  position: absolute;
  inset: 0;
}

/* the grade: a top scrim for the masthead, a vignette, a grounded bottom */
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(7, 11, 9, 0.72) 0%, rgba(7, 11, 9, 0.26) 22%, rgba(7, 11, 9, 0) 46%, rgba(7, 11, 9, 0) 66%, rgba(7, 11, 9, 0.48) 100%), /* taste-skill-ignore: the field grade */
    radial-gradient(130% 100% at 50% 44%, rgba(7, 11, 9, 0) 46%, rgba(7, 11, 9, 0.4) 100%); /* taste-skill-ignore: the field grade */
}

/* a little grain so the render sits in the sheet, not on top of it */
.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0.055;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>");
}

.stage-layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  transform: scale(1);
  transition: opacity 0.8s var(--ease);
}

.gate[data-battle="badr"] .stage-layer--badr,
.gate[data-battle="uhud"] .stage-layer--uhud,
.gate[data-battle="khandaq"] .stage-layer--khandaq,
.gate[data-battle="khaybar"] .stage-layer--khaybar,
.gate[data-battle="mutah"] .stage-layer--mutah,
.gate[data-battle="hunayn"] .stage-layer--hunayn {
  opacity: 1;
  transform: scale(1.025);
}

/* the field keeps its own weather: a slow drift over the capture */
@media (min-width: 901px) and (prefers-reduced-motion: no-preference) {
  .gate .stage-layer { animation: field-drift 44s ease-in-out infinite alternate; }
}

@keyframes field-drift {
  from { transform: scale(1.008) translate3d(0, 0, 0); }
  to { transform: scale(1.042) translate3d(-0.7%, -0.4%, 0); }
}

.stage-layer img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 48%;
  filter: saturate(0.86) contrast(1.05) brightness(0.94);
}

.stage-layer--uhud img { object-position: 50% 46%; }
.stage-layer--khandaq img { object-position: 50% 45%; }
.stage-layer--khaybar img { object-position: 50% 46%; }
.stage-layer--mutah img { object-position: 50% 52%; }
.stage-layer--hunayn img { object-position: 50% 50%; }

.day-frame {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 1.1s linear;
}

.day-frame.is-on { opacity: 1; }

/* ------------------------------ the plate, tabbed to the sheet */

.field-plate {
  position: absolute;
  left: 0;
  bottom: calc(100% + 12px);
  z-index: 2;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 16px;
  padding: 10px 18px 11px 15px;
  background: var(--bone);
  color: var(--ink);
  transition: opacity 0.18s ease;
}

.field-plate::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--accent-deep);
}

.field-plate.is-swapping { opacity: 0; }

.field-plate-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* the active field's survey plan, carried by the plate */
.field-plate-plan {
  width: 90px;
  height: 48px;
  flex: none;
  color: var(--accent-deep);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
  opacity: 0.9;
}

.field-plate-plan .plate-plan {
  opacity: 0;
  transition: opacity 0.3s var(--ease);
}

.field-plate-plan .dash { stroke-dasharray: 2 3.2; }
.field-plate-plan .draw { stroke-dasharray: none; }
.field-plate-plan circle { fill: currentColor; stroke: none; }

.field-plate[data-field="badr"] .plan--badr,
.field-plate[data-field="uhud"] .plan--uhud,
.field-plate[data-field="khandaq"] .plan--khandaq,
.field-plate[data-field="khaybar"] .plan--khaybar,
.field-plate[data-field="mutah"] .plan--mutah,
.field-plate[data-field="hunayn"] .plan--hunayn { opacity: 1; }

.field-plate-year {
  font-size: 13px;
  line-height: 1.2;
  letter-spacing: 0.02em;
  color: var(--muted-ink);
}

.field-plate-name {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.012em;
}

.field-plate-place {
  margin-left: 0.4em;
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.01em;
  color: var(--muted-ink);
}

/* ------------------------------ the index sheet */

.band {
  position: relative;
  z-index: 5;
  width: 100%;
  background: var(--bone);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* paper grain beneath the plates, never over the type */
.band::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.035;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>");
}

.doors {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: field;
}

.door-cell { display: contents; }

.door { counter-increment: field; }

.door {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  min-height: clamp(248px, 27svh, 286px);
  padding: clamp(20px, 2vw, 28px) clamp(18px, 1.8vw, 26px) clamp(16px, 1.5vw, 21px);
  overflow: hidden;
  color: var(--ink);
  cursor: pointer;
}

.door-cell:first-child .door { padding-left: calc(var(--edge) - var(--sheet-edge)); }
.door-cell:last-child .door { padding-right: calc(var(--edge) - var(--sheet-edge)); }

/* the five plates share one sheet: space and the active wash do the dividing */

/* the active plate holds a shallow verdigris wash */
.gate[data-battle="badr"] .door--badr,
.gate[data-battle="uhud"] .door--uhud,
.gate[data-battle="khandaq"] .door--khandaq,
.gate[data-battle="khaybar"] .door--khaybar,
.gate[data-battle="mutah"] .door--mutah,
.gate[data-battle="hunayn"] .door--hunayn {
  background: rgba(58, 98, 80, 0.06);
}

/* the flood: on hover the plate becomes a lit field */
.door::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.55s var(--ease);
}

.door:hover::before,
.door:focus-visible::before { transform: scaleX(1); }

/* the threshold: a verdigris line on the field edge */
.door::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  height: 3px;
  background: var(--accent-deep);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.55s var(--ease), background 0.3s var(--ease);
}

.gate[data-battle="badr"] .door--badr::after,
.gate[data-battle="uhud"] .door--uhud::after,
.gate[data-battle="khandaq"] .door--khandaq::after,
.gate[data-battle="khaybar"] .door--khaybar::after,
.gate[data-battle="mutah"] .door--mutah::after,
.gate[data-battle="hunayn"] .door--hunayn::after {
  transform: scaleX(1);
}

.door:hover::after,
.door:focus-visible::after { background: var(--accent); }

.door-top,
.door-cta {
  position: relative;
  z-index: 1;
}

.door-top {
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.1vw, 14px);
  min-width: 0;
}

.door-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.door-id {
  display: flex;
  align-items: baseline;
  gap: 9px;
  min-width: 0;
}

.door-num {
  flex: none;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.02em;
  color: rgba(11, 16, 14, 0.4);
  font-variant-numeric: tabular-nums;
  transition: color 0.2s var(--ease) 0.32s;
}

.door-num::before { content: counter(field, decimal-leading-zero); } /* taste-skill-ignore: the folio number orders the register */

.door-meta {
  display: block;
  font-size: 13px;
  line-height: 1.4;
  letter-spacing: 0.01em;
  color: var(--muted-ink);
  transition: color 0.2s var(--ease) 0.32s;
}

.door-meta::before {
  content: "·";
  margin-right: 0.5em;
  opacity: 0.55;
}

.gate[data-battle="badr"] .door--badr:not(:hover):not(:focus-visible) .door-num,
.gate[data-battle="uhud"] .door--uhud:not(:hover):not(:focus-visible) .door-num,
.gate[data-battle="khandaq"] .door--khandaq:not(:hover):not(:focus-visible) .door-num,
.gate[data-battle="khaybar"] .door--khaybar:not(:hover):not(:focus-visible) .door-num,
.gate[data-battle="mutah"] .door--mutah:not(:hover):not(:focus-visible) .door-num,
.gate[data-battle="hunayn"] .door--hunayn:not(:hover):not(:focus-visible) .door-num {
  color: var(--accent-deep);
}

/* the plan mark: a surveyor's line of the field this door opens */
.door-plan {
  flex: none;
  width: 96px;
  height: 50px;
  margin-top: -4px;
  color: rgba(11, 16, 14, 0.46);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
  opacity: 0.9;
  transition: color 0.2s var(--ease) 0.32s, opacity 0.35s var(--ease);
}

.door-plan .dash { stroke-dasharray: 2 3.2; }
.door-plan .draw { stroke-dasharray: 1; stroke-dashoffset: 0; }
.door-plan circle { fill: currentColor; stroke: none; }

.gate[data-battle="badr"] .door--badr:not(:hover):not(:focus-visible) .door-plan,
.gate[data-battle="uhud"] .door--uhud:not(:hover):not(:focus-visible) .door-plan,
.gate[data-battle="khandaq"] .door--khandaq:not(:hover):not(:focus-visible) .door-plan,
.gate[data-battle="khaybar"] .door--khaybar:not(:hover):not(:focus-visible) .door-plan,
.gate[data-battle="mutah"] .door--mutah:not(:hover):not(:focus-visible) .door-plan,
.gate[data-battle="hunayn"] .door--hunayn:not(:hover):not(:focus-visible) .door-plan {
  color: rgba(58, 98, 80, 0.72);
}

.door:hover .door-plan,
.door:focus-visible .door-plan {
  color: var(--bone);
  opacity: 1;
  transition-delay: 0.06s, 0s;
}

.door-name {
  display: flex;
  align-items: flex-end;
  gap: clamp(9px, 1vw, 16px);
  min-width: 0;
}

.door-en {
  font-family: var(--serif);
  font-size: clamp(36px, 4vw, 58px);
  font-weight: 400;
  line-height: 0.8;
  letter-spacing: -0.045em;
  color: var(--ink);
  transition: color 0.2s var(--ease) 0.32s;
}

.door-ar {
  display: inline-block;
  margin-bottom: clamp(2px, 0.3vw, 5px);
  font-family: var(--arabic);
  font-size: clamp(21px, 1.9vw, 29px);
  font-weight: 400;
  line-height: 1.2;
  color: var(--ink);
  transition: color 0.2s var(--ease) 0.32s;
}

/* the field window: each plate carries the ground it opens onto */
.door-media {
  position: relative;
  z-index: 1;
  display: block;
  flex: none;
  height: clamp(44px, 5.2vw, 68px);
  margin-top: clamp(8px, 0.9vw, 12px);
  overflow: hidden;
  background: var(--bone-soft);
}

.door-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.9) contrast(1.08) brightness(1.03);
  opacity: 0.95;
  transition:
    transform 0.8s var(--ease),
    filter 0.35s var(--ease),
    opacity 0.35s var(--ease);
}

.door-media::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(11, 16, 14, 0.17); /* taste-skill-ignore: the mounted print edge */
}

.door--badr .door-media img { object-position: 50% 72%; }
.door--uhud .door-media img { object-position: 50% 54%; }
.door--khandaq .door-media img { object-position: 50% 52%; }
.door--khaybar .door-media img { object-position: 50% 58%; }
.door--mutah .door-media img { object-position: 50% 70%; }
.door--hunayn .door-media img { object-position: 50% 52%; }

/* the field on show is the one whose ground is fully lit */
.gate[data-battle="badr"] .door--badr .door-media img,
.gate[data-battle="uhud"] .door--uhud .door-media img,
.gate[data-battle="khandaq"] .door--khandaq .door-media img,
.gate[data-battle="khaybar"] .door--khaybar .door-media img,
.gate[data-battle="mutah"] .door--mutah .door-media img,
.gate[data-battle="hunayn"] .door--hunayn .door-media img {
  opacity: 1;
  filter: saturate(0.96) contrast(1.06) brightness(1.05);
}

.door:hover .door-media img,
.door:focus-visible .door-media img {
  opacity: 1;
  filter: saturate(1) contrast(1.05) brightness(1.08);
  transform: scale(1.035);
}

.door-cta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  margin-top: auto;
  padding-top: clamp(12px, 1.4vw, 16px);
}

.door-arrow {
  flex: none;
  color: var(--ink);
  transition: transform 0.45s var(--ease), color 0.2s var(--ease);
  transition-delay: 0s, 0.06s;
}

/* the flood flips the plate */
.door:hover .door-en,
.door:hover .door-ar,
.door:focus-visible .door-en,
.door:focus-visible .door-ar {
  color: var(--bone);
  transition-delay: 0.06s;
}

.door:hover .door-meta,
.door:focus-visible .door-meta {
  color: var(--bone-dim);
  transition-delay: 0.06s;
}

.door:hover .door-num,
.door:focus-visible .door-num {
  color: var(--accent);
  transition-delay: 0.06s;
}

.gate[data-battle="badr"] .door--badr:not(:hover):not(:focus-visible) .door-arrow,
.gate[data-battle="uhud"] .door--uhud:not(:hover):not(:focus-visible) .door-arrow,
.gate[data-battle="khandaq"] .door--khandaq:not(:hover):not(:focus-visible) .door-arrow,
.gate[data-battle="khaybar"] .door--khaybar:not(:hover):not(:focus-visible) .door-arrow,
.gate[data-battle="mutah"] .door--mutah:not(:hover):not(:focus-visible) .door-arrow,
.gate[data-battle="hunayn"] .door--hunayn:not(:hover):not(:focus-visible) .door-arrow {
  color: var(--accent-deep);
}

.door:hover .door-arrow,
.door:focus-visible .door-arrow {
  color: var(--accent);
  transform: translateX(6px);
  transition-delay: 0s, 0.32s;
}

.door:active .door-arrow { transform: translateX(9px); color: var(--accent); }

.door:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: -4px;
  box-shadow: inset 0 0 0 2px var(--bone); /* taste-skill-ignore: dual tone focus ring */
}

/* ------------------------------ ahead: three fields not yet modelled */

.ahead {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: baseline;
  gap: clamp(12px, 1.4vw, 20px);
  padding: 10px calc(var(--edge) - var(--sheet-edge)) 11px;
  background: rgba(11, 16, 14, 0.03);
}

.ahead-title {
  flex: none;
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.005em;
  color: rgba(11, 16, 14, 0.7);
}

.ahead-mark {
  width: 18px;
  height: 9px;
  flex: none;
  color: rgba(11, 16, 14, 0.4);
}

.ahead-line {
  min-width: 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted-ink);
}

.ahead-field {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.005em;
  color: rgba(11, 16, 14, 0.78);
}

.ahead-ar {
  margin-left: 0.35em;
  font-family: var(--arabic);
  font-size: 13px;
  color: var(--muted-ink);
}

.ahead-sep {
  margin: 0 0.4em;
  color: rgba(11, 16, 14, 0.32);
}

/* the last register rides as one unit, so the separator never strands at a line end */
.ahead-tail { display: inline-block; }
.ahead--orphan .ahead-sep { display: none; }

/* ------------------------------ the desk reading: one plan, stacked names */

@media (min-width: 901px) {
  .door-name {
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
  }

  .door-ar {
    margin-bottom: 0;
    font-size: clamp(18px, 1.55vw, 22px);
    line-height: 1;
  }

  /* the plate carries the plan on a desk; the phone register keeps the small one */
  .door-plan { display: none; }
}

@media (min-width: 901px) and (max-width: 1180px) {
  .door-cta { gap: 8px; }
  .door-arrow svg { width: 22px; height: 15px; }
}

/* ------------------------------ entrance */

@media (prefers-reduced-motion: no-preference) {
  .js .stage { animation: settle 1.8s var(--ease) both; }
  .js .masthead { animation: fade-in 0.7s var(--ease) both; }
  .js .band { animation: sheet-rise 1s var(--ease) both 0.08s; }
  .js .door-top,
  .js .door-cta { animation: door-rise 0.8s var(--ease) both; }
  .js .door--badr .door-top { animation-delay: 0.16s; }
  .js .door--badr .door-cta { animation-delay: 0.24s; }
  .js .door--uhud .door-top { animation-delay: 0.22s; }
  .js .door--uhud .door-cta { animation-delay: 0.3s; }
  .js .door--khandaq .door-top { animation-delay: 0.28s; }
  .js .door--khandaq .door-cta { animation-delay: 0.36s; }
  .js .door--khaybar .door-top { animation-delay: 0.34s; }
  .js .door--khaybar .door-cta { animation-delay: 0.42s; }
  .js .door--mutah .door-top { animation-delay: 0.4s; }
  .js .door--mutah .door-cta { animation-delay: 0.48s; }
  .js .door--hunayn .door-top { animation-delay: 0.46s; }
  .js .door--hunayn .door-cta { animation-delay: 0.54s; }
}

.door:hover .door-plan .draw,
.door:focus-visible .door-plan .draw { animation: plan-draw 1.1s var(--ease) both; }

@keyframes settle {
  from { transform: scale(1.02); }
  to { transform: scale(1); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes sheet-rise {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: none; }
}

@keyframes door-rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

@keyframes plan-draw {
  from { stroke-dashoffset: 1; }
  to { stroke-dashoffset: 0; }
}

/* ------------------------------ tablet and phone: the field above the register */

@media (max-width: 900px) {
  :root { --head: 84px; }

  .gate {
    padding: 0;
    justify-content: flex-start;
  }

  .stage {
    position: relative;
    inset: auto;
    flex: 1 1 auto;
    min-height: 260px;
  }

  .band { box-shadow: none; } /* taste-skill-ignore: flattens the mount on touch */

  /* touch has no hover: the field is a gallery you swipe, the plate is its caption.
     The register below still enters on one tap. */
  .stage-track {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .stage-track::-webkit-scrollbar { display: none; }

  .gate .stage .stage-layer {
    position: relative;
    flex: 0 0 100%;
    height: 100%;
    opacity: 1;
    transform: none;
    transition: none;
    scroll-snap-align: center;
    scroll-snap-stop: always;
  }

  /* the plate is a caption tab on the field's own corner, clear of the register's names */
  .field-plate { left: auto; right: 0; }

  .field-plate { padding-left: 20px; }

  .doors { grid-template-columns: 1fr; }

  /* the row is a register line: what, when, which field; the arrow is the door */
  .door {
    position: relative;
    display: block;
    min-height: 0;
    padding: 13px var(--edge) 15px;
  }

  .door-cell:first-child .door,
  .door-cell:last-child .door { padding-right: var(--edge); padding-left: var(--edge); }

  /* on a row the threshold is the binding edge, not the top rule */
  .door::after {
    top: 0;
    bottom: 0;
    left: 0;
    right: auto;
    width: 3px;
    height: auto;
    transform: scaleY(0);
    transform-origin: top center;
  }

  .gate[data-battle="badr"] .door--badr::after,
  .gate[data-battle="uhud"] .door--uhud::after,
  .gate[data-battle="khandaq"] .door--khandaq::after,
  .gate[data-battle="khaybar"] .door--khaybar::after,
  .gate[data-battle="mutah"] .door--mutah::after,
  .gate[data-battle="hunayn"] .door--hunayn::after {
    transform: scaleY(1);
  }

  .door-top { gap: 3px; }
  .door-head { align-items: center; }
  .door-id { gap: 8px; }

  .door-plan {
    width: 54px;
    height: 29px;
    margin-top: 0;
  }

  .door-name { gap: 9px; margin-top: 4px; }
  .door-en { font-size: clamp(42px, 6.4vw, 58px); }
  .door-ar { font-size: clamp(20px, 2.6vw, 26px); }

  .door-cta {
    position: absolute;
    right: var(--edge);
    bottom: 15px;
    flex-direction: row-reverse;
    gap: 10px;
    padding-top: 0;
    border-top: 0;
  }

  .door-arrow svg { width: 26px; height: 24px; }

  /* on touch the field window is a stamp: top right on a tablet, bottom right on a phone */
  .door-media {
    position: absolute;
    top: 13px;
    right: var(--edge);
    width: clamp(98px, 15vw, 128px);
    height: 48px;
    margin: 0;
  }

  .door-media img {
    filter: saturate(0.78) contrast(1.04) brightness(0.92);
    opacity: 0.94;
  }

  .door-plan { display: none; }

  .ahead {
    display: block;
    padding: 7px var(--edge) 8px;
    font-size: 13px;
    line-height: 1.45;
  }

  .ahead-title {
    display: inline;
    margin-right: 8px;
    font-size: 16px;
  }

  .ahead-mark {
    display: inline-block;
    width: 15px;
    height: 8px;
    margin-right: 6px;
    vertical-align: 1px;
  }

  .ahead-line {
    display: inline;
    line-height: 1.4;
  }

  .ahead-field {
    font-size: 16px;
    line-height: 1.25;
  }
}

/* the tablet row is deep enough for a field stamp above the enter line */
@media (min-width: 701px) and (max-width: 900px) {
  .door { min-height: 106px; }
}

/* the small plan stays with the phone register; the desk plate carries the larger one */
@media (max-width: 700px) {
  :root {
    --head: 76px;
    --edge: 20px;
  }

  .masthead-mark { font-size: 27px; gap: 9px; }
  .masthead-sigil { width: 14px; height: 16px; }
  .masthead-sub { font-size: 13px; }
  .masthead-ar { font-size: 18px; }
  .masthead-note { display: none; }

  .stage { min-height: 270px; }

  .field-plate {
    gap: 12px;
    padding: 8px 13px 9px 20px;
  }

  .field-plate-name { font-size: 20px; }
  .field-plate-plan { width: 64px; height: 34px; }

  .door {
    padding-top: 12px;
    padding-bottom: 14px;
  }

  .door-meta { font-size: 13px; }
  .door-en { font-size: clamp(40px, 10.6vw, 47px); }
  .door-ar { font-size: clamp(19px, 5.1vw, 23px); }
  .door-plan { display: none; }
  .door-arrow svg { width: 26px; height: 24px; }
  .door-cta { top: 13px; bottom: auto; }

  .door-media {
    top: auto;
    bottom: 7px;
    width: clamp(54px, 15vw, 64px);
    height: 34px;
  }

  .ahead { padding: 7px var(--edge) 8px; }
  .ahead-title { font-size: 16px; }
  .ahead-ar { display: none; }
}

@media (max-width: 380px) {
  :root { --head: 72px; }

  .masthead-ar { display: none; }
  .masthead-sub { font-size: 13px; }
  .masthead-mark { font-size: 26px; }

  .stage { min-height: 230px; }

  .door {
    padding-top: 10px;
    padding-bottom: 12px;
  }

  .door-plan { display: none; }
  .door-num { font-size: 13px; }
  .door-meta { font-size: 13px; }
  .door-en { font-size: 40px; }
  .door-arrow svg { width: 28px; height: 24px; }
  .door-cta { top: 13px; bottom: auto; }
}

/* a landscape phone is an index card, not a stack */
@media (max-width: 900px) and (max-height: 560px) and (orientation: landscape) {
  :root {
    --head: 64px;
    --sheet-edge: 10px;
    --edge: 18px;
  }

  .gate {
    padding: 0 var(--sheet-edge) var(--sheet-edge);
    justify-content: flex-end;
  }

  .stage {
    position: absolute;
    inset: 0;
    min-height: 0;
  }

  .band {
    box-shadow: none; /* taste-skill-ignore: flattens the mount in landscape */
  }

  .masthead-mark { font-size: 24px; gap: 8px; }
  .masthead-sigil { width: 12px; height: 14px; }
  .masthead-sub { font-size: 13px; }
  .masthead-ar { font-size: 15px; }
  .masthead-note { display: none; }

  .doors { grid-template-columns: repeat(6, minmax(0, 1fr)); }

  .door {
    display: flex;
    min-height: 0;
    padding: 11px 14px 24px;
  }

  .door-cell:first-child .door { padding-left: 14px; }
  .door-cell:last-child .door { padding-right: 14px; }

  .door::after {
    top: 0;
    bottom: auto;
    left: 0;
    right: 0;
    width: auto;
    height: 2px;
    transform: scaleX(0);
    transform-origin: left center;
  }

  .gate[data-battle="badr"] .door--badr::after,
  .gate[data-battle="uhud"] .door--uhud::after,
  .gate[data-battle="khandaq"] .door--khandaq::after,
  .gate[data-battle="khaybar"] .door--khaybar::after,
  .gate[data-battle="mutah"] .door--mutah::after,
  .gate[data-battle="hunayn"] .door--hunayn::after {
    transform: scaleX(1);
  }

  .door-plan { display: none; }
  .door-meta { font-size: 13px; line-height: 1.35; }
  .door-name { margin-top: 4px; gap: 7px; }
  .door-en { font-size: clamp(22px, 3vw, 28px); }
  .door-ar { font-size: 15px; }
  .door-cta { position: static; flex-direction: row; padding-top: 9px; }
  .door-arrow svg { width: 20px; height: 24px; }

  .door-media {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 22px;
    -webkit-mask-image: none;
    mask-image: none;
  }
}

/* short phones: five rows and a field still fit one screen */
@media (max-width: 700px) and (max-height: 700px) {
  .stage { min-height: 150px; }

  .door { padding-top: 9px; padding-bottom: 11px; }
  .door-en { font-size: clamp(34px, 9.6vw, 40px); }

  .door-cta { top: 9px; }
  .door-arrow svg { width: 22px; height: 20px; }
  .door-media { bottom: 3px; }

  .ahead { padding-top: 5px; padding-bottom: 6px; }
}

@media (max-width: 700px) and (max-height: 620px) {
  .field-plate { display: none; }
}

/* ------------------------------ reduced motion */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .stage-layer { transform: none !important; }
}
