/* Keystone Homes — interaction layer (motion, saved homes, listing view, Arabic/RTL).
   Every animation here has a reduced-motion fallback at the bottom, and every
   reveal has an "is-done" end state that JS forces, so nothing can stay hidden
   in a browser that pauses CSS animations. */

:root {
  --ar-sans: "IBM Plex Sans Arabic", "Inter", system-ui, sans-serif;
  --ar-serif: "Noto Naskh Arabic", "Fraunces", Georgia, serif;
  --accent-soft: #F1E6DA;
}

/* ---------- Utilities ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Skip link ---------- */
.skip {
  position: fixed; inset-inline-start: 16px; top: -60px; z-index: 100;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; text-decoration: none;
  transition: top .2s;
}
.skip:focus { top: 12px; }

/* ---------- Sticky header ---------- */
.nav {
  position: fixed; max-width: none; padding-inline: max(var(--gutter), calc((100vw - var(--max)) / 2 + var(--gutter)));
  transition: background .35s ease, box-shadow .35s ease, height .35s ease, backdrop-filter .35s ease;
}
.nav.is-solid {
  background: rgba(247, 245, 241, .82);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  box-shadow: 0 1px 0 rgba(28, 28, 28, .08);
  height: 64px;
}
.nav__links { position: relative; margin-left: 0; margin-inline-start: auto; }
.nav__links a { padding: 6px 0; position: relative; }
.nav__links a.is-active { color: var(--ink); }
.nav__ink {
  position: absolute; bottom: -2px; left: 0; height: 1.5px; width: 0; background: var(--accent-ink);
  transition: transform .45s var(--ease), width .45s var(--ease), opacity .3s; opacity: 0; pointer-events: none;
}
.nav__tools { display: flex; align-items: center; gap: 10px; }
.nav__burger { margin-left: 0; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px; background: transparent; cursor: pointer; font-size: 14px;
  transition: border-color .2s, background .2s;
}
.chip-btn:hover { border-color: var(--ink); }
.chip-btn svg { flex: none; }
.saved-count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--ink); color: var(--bg);
  font-size: 12px; font-weight: 600; display: inline-grid; place-items: center;
}
.saved-count.bump { animation: bump .45s var(--ease); }
@keyframes bump { 40% { transform: scale(1.35); } }
.lang-btn { font-weight: 600; min-width: 44px; justify-content: center; }
@media (max-width: 959px) {
  .nav__tools { margin-inline-start: auto; }
  .chip-btn .chip-label { display: none; }
}

/* ---------- Hero entrance + parallax ---------- */
.hero h1 { text-shadow: 0 2px 24px rgba(20, 16, 12, .35); }
.hero h1 .line { display: block; overflow: hidden; padding-bottom: .06em; }
.hero h1 .line > span { display: block; animation: line-up 1s var(--ease) both; }
.hero h1 .line:nth-child(2) > span { animation-delay: .12s; }
@keyframes line-up { from { transform: translateY(105%); } }
.search { animation: card-rise .9s var(--ease) .35s both; }
@keyframes card-rise { from { opacity: 0; translate: 0 28px; } }
.hero__media img { inset: -8% 0 auto; height: 116%; translate: 0 var(--py, 0px); will-change: translate; }
/* Safety: after load the entrance is forced to its end state */
.intro-done .hero h1 .line > span, .intro-done .search { animation: none; opacity: 1; translate: none; transform: none; }
@media (min-width: 1100px) { .intro-done .search { transform: translateY(-50%); } }

/* ---------- Section heads + drawn dividers ---------- */
.reveal-up { opacity: 0; transform: translateY(18px); transition: opacity .8s ease, transform .9s var(--ease); }
.reveal-up.is-in { opacity: 1; transform: none; }
.section--rule { border-top: 0; position: relative; }
.section--rule::before {
  content: ""; position: absolute; top: 0; inset-inline: var(--gutter); height: 1px; background: var(--line);
  transform: scaleX(0); transform-origin: left; transition: transform 1.4s var(--ease);
}
[dir="rtl"] .section--rule::before { transform-origin: right; }
.section--rule.is-in::before { transform: scaleX(1); }
.reveal-up.is-done { opacity: 1; transform: none; transition: none; }
.section--rule.is-done::before { transform: scaleX(1); transition: none; }

/* ---------- Map: coastline draws in, pins pulse ---------- */
.map__land { stroke: #CFC6B8; stroke-width: 1.2; fill-opacity: 0; stroke-dasharray: 1; stroke-dashoffset: 1;
  transition: stroke-dashoffset 2.2s var(--ease), fill-opacity 1s ease 1.2s; }
.map__road { stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset 2s var(--ease) .6s; }
.map__lbl { opacity: 0; transition: opacity .8s ease 1.4s; }
.map__pins .pin { opacity: 0; translate: 0 8px; transition: opacity .5s ease, translate .6s var(--ease), background .2s, color .2s, transform .25s var(--ease); }
.map.is-in .map__land, .map.is-in .map__road { stroke-dashoffset: 0; fill-opacity: 1; }
.map.is-in .map__lbl { opacity: 1; }
.map.is-in .map__pins .pin { opacity: 1; translate: 0 0; transition-delay: calc(1.3s + var(--i) * 90ms), calc(1.3s + var(--i) * 90ms), 0s, 0s, 0s; }
.map.is-in .map__pins .pin.is-off { opacity: .25; }
.map.is-done .map__land, .map.is-done .map__road, .map.is-done .map__lbl { transition: none !important; }
.map.is-done .pin { transition: background .2s, color .2s, transform .25s var(--ease) !important; transition-delay: 0s !important; }
.map.is-done .map__land, .map.is-done .map__road { stroke-dashoffset: 0; fill-opacity: 1; }
.map.is-done .map__lbl { opacity: 1; }
.map.is-done .pin { opacity: 1; translate: 0 0; }
.map.is-done .pin.is-off { opacity: .25; }
.pin.pulse::before {
  content: ""; position: absolute; inset: -1px; border: 2px solid var(--accent); border-radius: 2px;
  animation: pin-ring .9s ease-out forwards; pointer-events: none;
}
@keyframes pin-ring { from { opacity: .9; transform: scale(1); } to { opacity: 0; transform: scale(1.5); } }
.card.flash .media { outline: 2px solid var(--accent); outline-offset: 4px; animation: flash 1.4s ease; }
@keyframes flash { 0%, 100% { outline-color: transparent; } 15%, 60% { outline-color: var(--accent); } }

/* ---------- Result count odometer ---------- */
.odo { display: inline-flex; vertical-align: bottom; height: 1.6em; overflow: hidden; font-weight: 600; color: var(--ink); }
.odo__digit { display: block; height: 1.6em; overflow: hidden; }
.odo__strip { display: flex; flex-direction: column; transition: transform .7s var(--ease); }
.odo__strip span { height: 1.6em; line-height: 1.6em; text-align: center; }

/* ---------- Cards: save button ---------- */
.card { will-change: transform; }
.save-btn {
  position: absolute; top: 10px; inset-inline-end: 10px; z-index: 3; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: rgba(247, 245, 241, .92); display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 4px 14px -6px rgba(28,28,28,.35); transition: transform .2s var(--ease), background .2s;
}
.save-btn:hover { transform: scale(1.08); }
.save-btn svg path { fill: transparent; stroke: var(--ink); stroke-width: 1.7; transition: fill .25s, stroke .25s; }
.save-btn[aria-pressed="true"] svg path { fill: #B4472E; stroke: #B4472E; }
.save-btn.pop { animation: heart-pop .5s var(--ease); }
.save-btn.pop::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid #B4472E; animation: heart-ring .55s ease-out forwards;
}
@keyframes heart-pop { 30% { transform: scale(1.3); } 60% { transform: scale(.92); } }
@keyframes heart-ring { from { opacity: .8; transform: scale(.7); } to { opacity: 0; transform: scale(1.5); } }
.card__tags { inset-inline-start: 12px; left: auto; }
[dir="ltr"] .card__tags { left: 12px; }

/* ---------- Cursor "View" label ---------- */
.cursor {
  position: fixed; top: 0; left: 0; z-index: 60; pointer-events: none;
  padding: 10px 16px; border-radius: 999px; background: var(--ink); color: var(--bg);
  font-size: 13px; font-weight: 500; letter-spacing: .04em;
  opacity: 0; scale: .6; transition: opacity .25s ease, scale .35s var(--ease);
}
.cursor.is-on { opacity: 1; scale: 1; }
@media (hover: none), (pointer: coarse) { .cursor { display: none; } }

/* ---------- Listing view ---------- */
.detail[open] { animation: none; }
.detail.fallback-in[open] { animation: rise .45s var(--ease); }
::view-transition-old(listing-photo), ::view-transition-new(listing-photo) {
  animation-duration: .55s; animation-timing-function: cubic-bezier(.2, .7, .1, 1); height: 100%; object-fit: cover;
}
::view-transition-group(listing-photo) { animation-duration: .55s; animation-timing-function: cubic-bezier(.2, .7, .1, 1); }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .35s; }

.detail__main { touch-action: pan-y; user-select: none; }
.detail__main img { transition: opacity .45s ease; }
.detail__main img.is-leaving { opacity: 0; }
.detail__main .img-next { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .45s ease; }
.detail__main .img-next.is-in { opacity: 1; }
.gal-btn {
  position: absolute; top: 50%; z-index: 3; width: 46px; height: 46px; margin-top: -23px; border-radius: 50%; border: 0;
  background: rgba(247, 245, 241, .9); cursor: pointer; display: grid; place-items: center;
  box-shadow: 0 6px 20px -8px rgba(28,28,28,.4); transition: transform .2s var(--ease), opacity .2s;
}
.gal-btn:hover { transform: scale(1.06); }
.gal-btn--prev { inset-inline-start: 14px; }
.gal-btn--next { inset-inline-end: 14px; }
[dir="rtl"] .gal-btn svg { transform: scaleX(-1); }
.gal-count {
  position: absolute; bottom: 12px; inset-inline-end: 14px; z-index: 3; background: rgba(28,28,28,.6); color: #fff;
  font-size: 12px; font-weight: 500; padding: 5px 10px; border-radius: 999px;
}
.detail__main.has-img::after { display: none; }
.detail__head { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.detail__head .save-btn { position: static; flex: none; border: 1px solid var(--line); box-shadow: none; }

/* Floor plan: rooms draw in, hover shows size */
.floorplan .room rect { stroke-dasharray: 1; stroke-dashoffset: 1; transition: fill .2s ease; }
.floorplan.is-in .room rect { animation: draw 1.1s var(--ease) forwards; animation-delay: calc(var(--i) * 120ms); }
.floorplan.is-done .room rect { animation: none; stroke-dashoffset: 0; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.floorplan .room { cursor: pointer; outline: none; }
.floorplan .room:hover rect, .floorplan .room:focus rect, .floorplan .room.is-active rect { fill: var(--accent-soft); }
.floorplan .room:focus-visible rect { stroke: var(--accent-ink); stroke-width: 3; }
.floorplan::after { display: none; }
.plan-readout { display: flex; justify-content: space-between; gap: 12px; margin-top: 10px; font-size: 13px; color: var(--ink-3); min-height: 1.4em; }
.plan-readout b { color: var(--ink); font-weight: 600; }

/* Mortgage / cost calculator */
.calc { margin-top: 8px; border: 1px solid var(--line); border-radius: 16px; background: var(--white); padding: 20px; display: grid; gap: 16px; }
.calc__out { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.calc__big { font-family: var(--serif); font-size: 34px; line-height: 1; }
.calc__big small { font-family: var(--sans); font-size: 14px; color: var(--ink-3); }
.calc__row { display: grid; gap: 8px; }
.calc__row label { display: flex; justify-content: space-between; font-size: 14px; color: var(--ink-2); }
.calc__row label b { color: var(--ink); font-weight: 600; }
.calc input[type="range"] { width: 100%; accent-color: var(--accent-ink); height: 28px; }
.calc__split { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; font-size: 13px; color: var(--ink-3); border-top: 1px solid var(--line); padding-top: 14px; }
.calc__split b { display: block; color: var(--ink); font-size: 15px; font-weight: 600; }
.calc__note { font-size: 12px; color: var(--ink-3); }

/* Enquiry: floating labels, viewing slots, success check */
.enquiry { border-radius: 18px; }
.fl { position: relative; }
.fl input, .fl textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 22px 14px 8px; font-size: 16px; min-height: 54px; transition: border-color .2s, box-shadow .2s;
}
.fl textarea { min-height: 96px; resize: vertical; }
.fl label {
  position: absolute; inset-inline-start: 15px; top: 17px; color: var(--ink-3); font-size: 15px; pointer-events: none;
  transform-origin: left top; transition: transform .2s var(--ease), color .2s;
}
[dir="rtl"] .fl label { transform-origin: right top; }
.fl input:focus, .fl textarea:focus { outline: none; border-color: var(--accent-ink); box-shadow: 0 0 0 3px var(--accent-soft); }
.fl input:focus + label, .fl input:not(:placeholder-shown) + label,
.fl textarea:focus + label, .fl textarea:not(:placeholder-shown) + label { transform: translateY(-10px) scale(.78); color: var(--accent-ink); }
.fl .is-bad { border-color: #B4472E; }
.slots { display: grid; gap: 8px; border: 0; margin: 0; padding: 0; }
.slots legend { font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 8px; padding: 0; }
.slot-row { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.slot-row::-webkit-scrollbar { display: none; }
.slot { position: relative; flex: none; }
.slot input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.slot span {
  display: grid; place-items: center; min-width: 54px; min-height: 44px; padding: 6px 10px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 13px; line-height: 1.2; text-align: center; background: var(--bg); transition: background .2s, color .2s, border-color .2s;
}
.slot span small { display: block; font-size: 11px; color: var(--ink-3); }
.slot input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.slot input:checked + span small { color: rgba(247,245,241,.7); }
.slot input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.slots.is-bad .slot span { border-color: #E2B4A8; }
.enquiry__done { display: none; text-align: center; padding: 24px 8px; gap: 12px; justify-items: center; }
.enquiry.is-sent > :not(.enquiry__done) { display: none; }
.enquiry.is-sent .enquiry__done { display: grid; }
.check { width: 64px; height: 64px; }
.check circle, .check path { fill: none; stroke: #2F6B45; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.check circle { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw .7s var(--ease) forwards; }
.check path { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw .45s var(--ease) .55s forwards; }
.enquiry__done p { color: var(--ink-2); max-width: 30ch; }

/* ---------- Saved drawer ---------- */
.drawer {
  margin: 0; margin-inline-start: auto; height: 100dvh; max-height: none; width: min(420px, 100vw); padding: 0; border: 0;
  background: var(--bg); color: var(--ink); box-shadow: -20px 0 60px -30px rgba(28,28,28,.5);
}
.drawer::backdrop { background: rgba(28,28,28,.45); }
.drawer[open] { animation: drawer-in .45s var(--ease); }
[dir="rtl"] .drawer[open] { animation-name: drawer-in-rtl; }
@keyframes drawer-in { from { transform: translateX(100%); } }
@keyframes drawer-in-rtl { from { transform: translateX(-100%); } }
.drawer__wrap { display: grid; grid-template-rows: auto 1fr; height: 100%; }
.drawer__head { display: flex; align-items: center; justify-content: space-between; padding: 20px 20px 16px; border-bottom: 1px solid var(--line); }
.drawer__head h2 { font-size: 28px; }
.drawer__list { list-style: none; margin: 0; padding: 12px 20px 24px; overflow-y: auto; display: grid; gap: 12px; align-content: start; }
.saved-item { display: grid; grid-template-columns: 96px 1fr auto; gap: 14px; align-items: center; padding: 10px; border-radius: 14px; background: var(--white); border: 1px solid var(--line); }
.saved-item .media { aspect-ratio: 4/3; border-radius: 10px; }
.saved-item .ph::after { display: none; }
.saved-item__open { all: unset; cursor: pointer; display: grid; gap: 2px; }
.saved-item__open:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.saved-item__price { font-family: var(--serif); font-size: 18px; }
.saved-item__title { font-size: 14px; }
.saved-item__area { font-size: 12px; color: var(--ink-3); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--white); cursor: pointer; display: grid; place-items: center; font-size: 20px; line-height: 1; }
.icon-btn:hover { border-color: var(--ink); }
.drawer__empty { text-align: center; color: var(--ink-2); padding: 48px 12px; display: grid; gap: 8px; }

/* ---------- How it's built ---------- */
.built { display: grid; gap: 40px; }
@media (min-width: 900px) { .built { grid-template-columns: 1fr 1.4fr; gap: 80px; } }
.built__list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr; gap: 0; }
@media (min-width: 640px) { .built__list { grid-template-columns: 1fr 1fr; column-gap: 32px; } }
.built__list li { padding: 18px 0; border-top: 1px solid var(--line); }
.built__list h3 { font-family: var(--sans); font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.built__list p { font-size: 14px; color: var(--ink-2); }
.built__stats { display: flex; flex-wrap: wrap; gap: 28px; margin-top: 24px; }
.built__stats b { display: block; font-family: var(--serif); font-size: 32px; font-weight: 400; }
.built__stats span { font-size: 13px; color: var(--ink-3); }

/* ---------- Arabic / RTL ---------- */
[lang="ar"] body { font-family: var(--ar-sans); }
[lang="ar"] h1, [lang="ar"] h2, [lang="ar"] h3, [lang="ar"] .brand, [lang="ar"] .search__title,
[lang="ar"] .card__price, [lang="ar"] .detail__price, [lang="ar"] .calc__big, [lang="ar"] .drawer__head h2,
[lang="ar"] .saved-item__price, [lang="ar"] .built__stats b, [lang="ar"] .facts b, [lang="ar"] .steps span { font-family: var(--ar-serif); letter-spacing: 0; }
[lang="ar"] .hero h1 { line-height: 1.25; font-size: clamp(40px, 6vw, 84px); }
[lang="ar"] h2 { line-height: 1.3; }
[lang="ar"] .eyebrow, [lang="ar"] .field > span, [lang="ar"] .field legend, [lang="ar"] .tag, [lang="ar"] .facts span,
[lang="ar"] .footer h4, [lang="ar"] .slots legend, [lang="ar"] .map__lbl, [lang="ar"] .ph::after { letter-spacing: 0; text-transform: none; }
[dir="rtl"] .field select { background-position: left 14px center; padding: 0 14px 0 36px; }
[dir="rtl"] .hero__copy { left: auto; right: 20px; }
@media (min-width: 900px) { [dir="rtl"] .hero__copy { right: 56px; left: 20px; } }
@media (min-width: 1100px) {
  [dir="rtl"] .hero__copy { right: 56px; left: 500px; }
  [dir="rtl"] .search { right: auto; left: calc(var(--gutter) + 48px); }
}
[dir="rtl"] .ph::after { left: auto; right: 12px; }
[dir="rtl"] .amenities li::before { margin-right: 0; margin-left: 10px; }
[dir="rtl"] .detail__close { float: left; }
[dir="rtl"] .map__inner { direction: ltr; }
[dir="rtl"] .map__note { direction: rtl; }
[dir="rtl"] .nav__links a + a { margin: 0; }
[dir="rtl"] .card__tags { right: 12px; left: auto; }
[dir="rtl"] .gal-count { direction: ltr; }
.num { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ---------- Reduced motion: everything lands in its final state ---------- */
@media (prefers-reduced-motion: reduce) {
  .hero h1 .line > span, .search { animation: none !important; opacity: 1 !important; translate: none !important; }
  .hero__media img { translate: none !important; }
  .reveal-up { opacity: 1; transform: none; transition: none; }
  .section--rule::before { transform: scaleX(1); transition: none; }
  .map__land, .map__road { stroke-dashoffset: 0 !important; fill-opacity: 1 !important; transition: none !important; }
  .map__lbl, .map__pins .pin { opacity: 1; translate: none; transition: none !important; }
  .floorplan .room rect { stroke-dashoffset: 0 !important; animation: none !important; }
  .check circle, .check path { stroke-dashoffset: 0; animation: none; }
  .odo__strip, .nav__ink, .detail__main img, .detail__main .img-next { transition: none !important; }
  .save-btn.pop, .save-btn.pop::after, .pin.pulse::before, .card.flash .media, .saved-count.bump, .drawer[open] { animation: none !important; }
  .cursor { display: none; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
