/**
 * @file components.css
 * @description Reusable Nova Soul UI components (v0.1). Copy the markup from
 * index.html (the style guide) and these classes work on any page.
 *
 * Depends on: css/tokens.css, css/base.css.
 * Loaded by: every HTML page.
 * Behaviour: js/app.js (language switch, price sync), js/i18n.js (texts).
 *
 * Naming: .ns-block, .ns-block__element, .ns-block--variant.
 * Each component sets only its own internals; spacing BETWEEN components
 * belongs to the page layout, which prevents specificity fights.
 */

/* =====================================================================
 * Mark + wordmark
 * ===================================================================== */
.ns-mark {
  width: var(--mark-size, 2.5rem);
  aspect-ratio: 1;
  color: var(--color-ornament);
  flex: none;
}

/* The single orchestrated motion moment: the compass settles to north. */
.ns-mark--settle {
  animation: ns-settle var(--duration-settle) var(--ease-settle) both;
}

@keyframes ns-settle {
  from {
    opacity: 0;
    transform: rotate(-28deg) scale(0.96);
  }
  to {
    opacity: 1;
    transform: rotate(0) scale(1);
  }
}

.ns-wordmark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text);
  font-family: var(--font-display);
  font-weight: var(--weight-medium);
  font-size: var(--text-s);
  letter-spacing: var(--tracking-wordmark);
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
}

/* =====================================================================
 * Language switch (native select: accessible, works on every device)
 * ===================================================================== */
.ns-lang__select {
  appearance: none;
  min-height: 2.5rem;
  padding: var(--space-1) var(--space-6) var(--space-1) var(--space-4);
  border: var(--border-hairline);
  border-radius: var(--radius-round);
  background: transparent
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2384561A' stroke-width='1.3'/%3E%3C/svg%3E")
    no-repeat right var(--space-4) center;
  font-size: var(--text-s);
  cursor: pointer;
}

.ns-lang__select:hover {
  border-color: var(--color-line-strong);
}

/* =====================================================================
 * Buttons
 * ===================================================================== */
.ns-button {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  min-height: 3.5rem;
  padding: var(--space-3) var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font-weight: var(--weight-medium);
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration-quick) ease, border-color var(--duration-quick) ease;
}

.ns-button--primary {
  background: var(--color-inverse-bg);
  color: var(--color-inverse-text);
}

.ns-button--primary:hover {
  background: color-mix(in srgb, var(--color-inverse-bg) 86%, black);
}

.ns-button--secondary {
  border-color: var(--color-line-strong);
  background: transparent;
  color: var(--color-text);
}

.ns-button--secondary:hover {
  border-color: var(--color-text);
  background: var(--color-surface);
}

.ns-button--block {
  width: 100%;
}

.ns-button__price {
  font-family: var(--font-display);
  font-size: var(--text-l);
  font-weight: var(--weight-medium);
  font-variant-numeric: lining-nums;
  color: var(--color-inverse-accent);
}

/* =====================================================================
 * Meridian: step indicator derived from the logo's dotted cardinal line.
 * Dots grow toward the current step; the current step wears the pendant ring.
 * Markup: <ol class="ns-meridian"> <li data-state="done|current|todo">
 * ===================================================================== */
.ns-meridian {
  --dot: 0.4rem;
  display: grid;
  grid-template-columns: repeat(var(--steps, 4), 1fr);
  padding: 0;
  list-style: none;
  counter-reset: none;
}

.ns-meridian__step {
  position: relative;
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  font-size: var(--text-s);
  color: var(--color-text-muted);
  text-align: center;
}

/* Dotted connector from the previous step's centre to this one. */
.ns-meridian__step + .ns-meridian__step::before {
  content: "";
  position: absolute;
  top: calc(0.8125rem - 1px);
  right: 50%;
  width: 100%;
  height: 2px;
  background: radial-gradient(circle, var(--color-ornament) 0.9px, transparent 1.1px) left center / 7px 2px repeat-x;
  z-index: 0;
}

.ns-meridian__dot {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 1.625rem;
  aspect-ratio: 1;
  border-radius: var(--radius-round);
  background: var(--color-bg);
}

.ns-meridian__dot::after {
  content: "";
  width: var(--dot);
  aspect-ratio: 1;
  border-radius: inherit;
  background: var(--color-ornament);
}

.ns-meridian__step[data-state="done"] .ns-meridian__dot::after {
  --dot: 0.55rem;
}

.ns-meridian__step[data-state="todo"] .ns-meridian__dot::after {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--color-ornament);
}

.ns-meridian__step[data-state="current"] {
  color: var(--color-text);
}

.ns-meridian__step[data-state="current"] .ns-meridian__dot {
  box-shadow: inset 0 0 0 1px var(--color-ornament);
}

.ns-meridian__step[data-state="current"] .ns-meridian__dot::after {
  --dot: 0.7rem;
  background: var(--color-text);
}

/* Narrow screens: only the current label stays visible. */
@media (max-width: 36rem) {
  .ns-meridian__step:not([data-state="current"]) .ns-meridian__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
}

/* =====================================================================
 * Product choice: one panel, rows divided by a hairline (not twin cards).
 * The radio is drawn as the logo's pendant: ring + centre dot.
 * ===================================================================== */
.ns-choice-group {
  min-width: 0;
  padding: 0;
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-panel);
  overflow: hidden;
}

.ns-choice {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: var(--space-4);
  padding: var(--space-5);
  cursor: pointer;
  transition: background-color var(--duration-quick) ease;
}

.ns-choice + .ns-choice {
  border-top: var(--border-hairline);
}

.ns-choice:has(.ns-choice__input:checked) {
  background: var(--color-surface);
}

.ns-choice__input {
  appearance: none;
  width: 1.5rem;
  aspect-ratio: 1;
  margin-top: 0.2rem;
  border: 1px solid var(--color-ornament);
  border-radius: var(--radius-round);
  background: transparent;
  cursor: pointer;
}

.ns-choice__input:checked {
  background: radial-gradient(circle, var(--color-text) 0 31%, transparent 34%);
}

.ns-choice__name {
  display: block;
  font-family: var(--font-display);
  font-size: var(--text-l);
  font-weight: var(--weight-medium);
  line-height: var(--leading-snug);
}

.ns-choice__meta {
  display: block;
  font-size: var(--text-s);
  color: var(--color-text-muted);
}

.ns-choice__price {
  display: grid;
  justify-items: end;
  text-align: right;
}

.ns-choice__price-label {
  font-size: var(--text-xs);
  color: var(--color-link);
}

.ns-price {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: var(--weight-light);
  font-variant-numeric: lining-nums;
  line-height: 1;
}

@media (max-width: 30rem) {
  .ns-choice {
    grid-template-columns: auto 1fr;
  }

  .ns-choice__price {
    grid-column: 2;
    justify-items: start;
    text-align: left;
  }
}

/* =====================================================================
 * Form field. Errors appear only after the person has interacted
 * (:user-invalid), never on page load.
 * ===================================================================== */
.ns-field {
  display: grid;
  gap: var(--space-2);
  max-width: 24rem;
}

.ns-field__label {
  font-weight: var(--weight-medium);
}

.ns-field__help {
  font-size: var(--text-s);
  color: var(--color-text-muted);
  line-height: 1.45;
}

.ns-field__input {
  min-height: 3.25rem;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-control);
  background: color-mix(in srgb, white 45%, var(--color-bg));
  font-variant-numeric: lining-nums tabular-nums;
}

.ns-field__input:hover {
  border-color: var(--color-text);
}

.ns-field__input:focus-visible {
  border-color: var(--color-text);
  outline-offset: 1px;
}

.ns-field__error {
  display: none;
  font-size: var(--text-s);
  color: var(--color-error);
}

.ns-field:has(.ns-field__input:user-invalid) .ns-field__input {
  border-color: var(--color-error);
}

.ns-field:has(.ns-field__input:user-invalid) .ns-field__error {
  display: block;
}

.ns-field__aside {
  font-size: var(--text-s);
  justify-self: start;
}

/* =====================================================================
 * Arch: illustration framed as an arched window, echoing the oval
 * vignettes in the Nova Soul illustrations.
 * ===================================================================== */
.ns-arch {
  position: relative;
  display: grid;
  justify-items: center;
}

.ns-arch__image {
  width: 100%;
  aspect-ratio: 924 / 1180;
  object-fit: cover;
  object-position: center 20%;
  border-radius: 50% 50% var(--radius-panel) var(--radius-panel) / 36% 36% var(--radius-panel) var(--radius-panel);
  background: var(--color-surface);
}

/* The compass mark hangs on the arch like the pendant under the logo. */
.ns-arch__pendant {
  --mark-size: 5.5rem;
  margin-block-start: calc(var(--mark-size) / -2);
  padding: var(--space-2);
  border-radius: var(--radius-round);
  background: var(--color-bg);
  box-sizing: content-box;
}

/* =====================================================================
 * Shelf: horizontal scroll-snap row (report pages, soul animals).
 * Works with touch, trackpad and keyboard; js/shelf.js adds buttons.
 * ===================================================================== */
.ns-shelf {
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--shelf-item, 16rem);
  gap: var(--space-5);
  padding: var(--space-2) var(--space-1) var(--space-5);
  list-style: none;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: var(--space-1);
  scrollbar-width: thin;
  scrollbar-color: var(--color-ornament) transparent;
}

.ns-shelf > * {
  scroll-snap-align: start;
}

.ns-shelf-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

.ns-icon-button {
  display: grid;
  place-items: center;
  width: 2.75rem;
  aspect-ratio: 1;
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-round);
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
}

.ns-icon-button:hover:not(:disabled) {
  border-color: currentColor;
}

.ns-icon-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.ns-icon-button svg {
  width: 1rem;
  height: 1rem;
}

/* =====================================================================
 * Report preview: contents list (styled like the report's own contents
 * page, with dotted leaders) + a shelf of sample pages + reader dialog.
 * ===================================================================== */
.ns-report {
  display: grid;
  grid-template-columns: minmax(15rem, 1fr) minmax(0, 2.3fr);
  gap: var(--space-7);
  align-items: start;
}

@media (max-width: 52rem) {
  .ns-report {
    grid-template-columns: minmax(0, 1fr);
  }
}

.ns-report__intro > * + * {
  margin-block-start: var(--space-4);
}

.ns-report__note {
  font-size: var(--text-s);
  color: var(--color-text-muted);
}

.ns-report__chapters {
  margin-block-start: var(--space-6);
  padding: 0;
  list-style: none;
}

.ns-report__chapter {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding-block: var(--space-2);
  color: var(--color-text);
  text-decoration: none;
}

.ns-report__chapter::after {
  content: "";
  order: 1;
  flex: 1;
  border-bottom: 1px dotted var(--color-ornament);
}

.ns-report__chapter-number {
  order: 2;
  font-size: var(--text-s);
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--color-text-muted);
}

.ns-report__chapter:hover .ns-report__chapter-name,
.ns-report__chapter[aria-current="true"] .ns-report__chapter-name {
  color: var(--color-link);
}

.ns-report__chapter[aria-current="true"] .ns-report__chapter-number {
  color: var(--color-link);
}

/* Cover stack: the sample report as a small pile of paper, opening the reader. */
.ns-report__cover {
  position: relative;
  display: block;
  width: min(100%, 22rem);
  margin-inline: auto;
  isolation: isolate;
}

.ns-report__cover::before,
.ns-report__cover::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: var(--radius-control);
  background: var(--ns-cream-warm);
  box-shadow: 0 0 0 1px var(--color-line);
  transition: transform var(--duration-quick) ease;
}

.ns-report__cover::before {
  transform: rotate(-5deg) translate(-4%, 1%);
}

.ns-report__cover::after {
  transform: rotate(3deg) translate(3%, 2%);
}

.ns-report__cover:hover::before {
  transform: rotate(-8deg) translate(-8%, 1%);
}

.ns-report__cover:hover::after {
  transform: rotate(6deg) translate(7%, 2%);
}

.ns-report__cover img {
  width: 100%;
  aspect-ratio: 924 / 1316;
  object-fit: cover;
  border-radius: var(--radius-control);
  box-shadow: 0 0 0 1px var(--color-line), 0 28px 40px -30px color-mix(in srgb, var(--ns-forest) 70%, transparent);
}

.ns-report__actions {
  margin-block-start: var(--space-6);
}

/* =====================================================================
 * Soul animal figure (inside a shelf)
 * ===================================================================== */
.ns-animal {
  display: grid;
  gap: var(--space-3);
}

.ns-animal img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: var(--radius-panel);
  background: var(--color-surface);
}

.ns-animal figcaption {
  font-family: var(--font-display);
  font-size: var(--text-l);
  font-weight: var(--weight-medium);
  line-height: 1.1;
}

/* =====================================================================
 * Checkbox row
 * ===================================================================== */
.ns-check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  cursor: pointer;
}

.ns-check input {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.2rem;
  accent-color: var(--ns-forest);
}

.ns-check > span:not(.ns-check__label) {
  display: grid;
  gap: var(--space-1);
}

/* Consent text flows as one paragraph, links included. */
.ns-check__label {
  display: block;
  line-height: 1.5;
}

/* Errors marked by js/order-form.js after "Continue". */
.ns-field.is-invalid .ns-field__input {
  border-color: var(--color-error);
}

.ns-field.is-invalid .ns-field__error {
  display: block;
}

/* =====================================================================
 * Order form
 * ===================================================================== */
.ns-order {
  max-width: 46rem;
}

.ns-order__progress {
  margin-block-end: var(--space-7);
}

.ns-order__step {
  display: grid;
  gap: var(--space-5);
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.ns-order__step[hidden] {
  display: none;
}

.ns-order__title {
  margin-block-end: var(--space-2);
  padding: 0;
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: var(--weight-light);
}

.ns-order__grid,
.ns-order__birth-fields,
.ns-order__gift-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
  gap: var(--space-5) var(--space-6);
}

.ns-order__birth-fields,
.ns-order__gift-fields {
  grid-column: 1 / -1;
}

.ns-order__birth-fields[hidden],
.ns-order__gift-fields[hidden] {
  display: none;
}

.ns-order .ns-field {
  max-width: none;
}

.ns-order__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-3);
  margin-block-start: var(--space-3);
}

.ns-order__actions > :only-child {
  margin-inline-start: auto;
}

.ns-order__pay {
  flex: 1 1 18rem;
}

.ns-order__note {
  font-size: var(--text-s);
  color: var(--color-text-muted);
}

.ns-order__failure {
  font-size: var(--text-s);
  color: var(--color-error);
}

.ns-order__review {
  display: grid;
  grid-template-columns: minmax(8rem, auto) minmax(0, 1fr);
  gap: 0 var(--space-5);
  border-top: var(--border-hairline);
}

.ns-order__review dt,
.ns-order__review dd {
  margin: 0;
  padding-block: var(--space-3);
  border-bottom: var(--border-hairline);
}

.ns-order__review dt {
  font-size: var(--text-s);
  color: var(--color-text-muted);
}

@media (max-width: 30rem) {
  .ns-order__review {
    grid-template-columns: minmax(0, 1fr);
  }

  .ns-order__review dt {
    padding-block-end: 0;
    border-bottom: 0;
  }
}

.ns-order-summary {
  max-width: 40rem;
  margin-block: var(--space-6);
  padding: var(--space-5) var(--space-6);
  border: 1px solid var(--color-ornament);
  border-radius: var(--radius-panel);
  background: color-mix(in srgb, var(--ns-cream-warm) 70%, var(--color-bg));
}

.ns-order-summary__title {
  margin-block-end: var(--space-3);
  font-size: var(--text-l);
}

/* =====================================================================
 * Reviews
 * ===================================================================== */
.ns-reviews {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
  gap: var(--space-5);
  margin-block-start: var(--space-6);
}

.ns-review {
  display: grid;
  gap: var(--space-4);
  margin: 0;
  padding: var(--space-6) var(--space-5);
  border-top: 1px solid var(--color-ornament);
  background: color-mix(in srgb, white 30%, var(--color-bg));
}

.ns-review__quote p {
  font-family: var(--font-display);
  font-size: var(--text-l);
  font-style: italic;
  line-height: 1.35;
}

.ns-review__by {
  display: grid;
  font-size: var(--text-s);
}

.ns-review__name {
  font-weight: var(--weight-medium);
}

.ns-review__detail {
  color: var(--color-text-muted);
}

.ns-order__conditional,
.ns-field--wide {
  grid-column: 1 / -1;
}

.ns-order__conditional[hidden] {
  display: none;
}

textarea.ns-field__input {
  min-height: 7rem;
  resize: vertical;
}

.ns-check__label a {
  color: var(--color-link);
}

/* =====================================================================
 * Card deck: front card with the previous and next card behind it.
 * Positions are set by js/card-deck.js through data-pos.
 * ===================================================================== */
.ns-deck {
  --deck-card: clamp(13rem, 58vw, 21rem);
  position: relative;
  margin-block: var(--space-6) 0;
  outline-offset: var(--space-3);
  touch-action: pan-y;
  user-select: none;
  overflow-x: clip;
  overflow-clip-margin: var(--space-4);
}

.ns-deck__track {
  position: relative;
  display: grid;
  place-items: center;
  height: calc(var(--deck-card) * 1.5 + var(--space-7));
  margin: 0;
  padding: 0;
  list-style: none;
}

.ns-deck__card {
  position: absolute;
  width: var(--deck-card);
  aspect-ratio: 2 / 3;
  cursor: pointer;
  transition:
    transform 900ms var(--ease-settle),
    opacity 900ms var(--ease-settle),
    filter 900ms var(--ease-settle);
  will-change: transform;
}

.ns-deck__card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4.5% / 3%;
  box-shadow: 0 1px 0 color-mix(in srgb, var(--ns-forest) 12%, transparent), 0 30px 50px -30px color-mix(in srgb, var(--ns-forest) 65%, transparent);
  pointer-events: none;
}

.ns-deck__card[data-pos="0"] {
  z-index: 3;
  cursor: grab;
  transform: none;
}

.ns-deck__card[data-pos="-1"],
.ns-deck__card[data-pos="1"] {
  z-index: 2;
  opacity: 0.92;
  filter: saturate(0.85) brightness(0.97);
}

.ns-deck__card[data-pos="-1"] {
  transform: translateX(-58%) scale(0.84) rotate(-5deg);
}

.ns-deck__card[data-pos="1"] {
  transform: translateX(58%) scale(0.84) rotate(5deg);
}

.ns-deck__card[data-pos="-2"],
.ns-deck__card[data-pos="2"] {
  z-index: 1;
  opacity: 0;
  pointer-events: none;
}

.ns-deck__card[data-pos="-2"] {
  transform: translateX(-90%) scale(0.7) rotate(-8deg);
}

.ns-deck__card[data-pos="2"] {
  transform: translateX(90%) scale(0.7) rotate(8deg);
}

.ns-deck__controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
}

.ns-deck__status {
  min-width: 7rem;
  font-size: var(--text-s);
  font-variant-numeric: lining-nums tabular-nums;
  text-align: center;
  color: var(--color-text-muted);
}

@media (prefers-reduced-motion: reduce) {
  .ns-deck__card {
    transition: none;
  }
}

/* =====================================================================
 * Page dialog: terms or privacy on top of a form (js/page-dialog.js)
 * ===================================================================== */
.ns-page-dialog {
  width: min(48rem, 100% - 2rem);
  max-height: min(88dvh, 60rem);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-panel);
  background: var(--color-bg);
  color: var(--color-text);
  box-shadow: 0 40px 80px -40px color-mix(in srgb, var(--ns-forest) 70%, transparent);
}

.ns-page-dialog[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.ns-page-dialog::backdrop {
  background: color-mix(in srgb, var(--ns-forest) 45%, transparent);
}

.ns-page-dialog__bar {
  display: flex;
  justify-content: flex-end;
  padding: var(--space-3) var(--space-3) 0;
}

.ns-page-dialog__body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-block-end: var(--space-6);
}

.ns-page-dialog__body .pg-section {
  padding-block: var(--space-4);
}

.ns-page-dialog__body .pg-section__inner {
  width: auto;
  margin-inline: var(--space-6);
}
