/* Kraftfactory — a fixed stage. Ivory by default; choosing a brand adopts that brand's
   documented palette, motif and type. Values from tokens.css only. */

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

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--color-canvas);
  color: var(--color-text);
  font-family: var(--font-text);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--motion-slow) var(--ease-out),
    color var(--motion-slow) var(--ease-out);
}

.sr-only {
  position: absolute;
  width: var(--rule);
  height: var(--rule);
  margin: calc(var(--rule) * -1);
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- footage layer: absent until a brand is chosen ---- */
.stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  opacity: 0;
  background: var(--play-composite);
  transition: opacity var(--motion-slow) var(--ease-out);
}

body[data-playing="true"] .stage {
  opacity: 1;
}

.stage__video,
.stage__still {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* the accessibility control swaps the moving clip for one still frame of it */
body[data-still="true"] .stage__video {
  display: none;
}

body[data-still="false"] .stage__still {
  display: none;
}

.stage__scrim {
  position: absolute;
  inset: 0;
  background: var(--play-scrim);
}

/* ---- the stage frame: one viewport, no overflow ---- */
.page {
  position: relative;
  z-index: 1;
  height: 100dvh;
  overflow: hidden;
}

/* ---- the house mark: big while resting, a small corner lockup while playing ---- */
.house {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  width: var(--logo-w);
  height: auto;
  text-decoration: none;
  transform-origin: center;
  transform: translate(var(--hx), var(--hy)) scale(var(--hs));
  transition: transform var(--motion-slow) var(--ease-out);
  z-index: 2;
}

.house img {
  display: block;
  width: 100%;
  height: auto;
}

body[data-playing="false"] .house {
  --hx: calc(50vw - var(--logo-w) / 2);
  --hy: calc(38dvh - var(--logo-h) / 2);
  --hs: 1;
}

/* scaling happens about the centre, so the translate goes negative to bring the
   shrunk mark's top-left corner back to the corner gutter */
body[data-playing="true"] .house {
  --hx: calc(var(--space-6) - var(--logo-w) * 0.33);
  --hy: calc(var(--space-5) - var(--logo-h) * 0.33);
  --hs: 0.34;
}

/* ---- the brand's ornament, at the opacity the brand docs prescribe over imagery ---- */
.watermark {
  position: absolute;
  right: var(--space-6);
  top: calc(50dvh - var(--watermark) / 2);
  width: var(--watermark);
  height: auto;
  opacity: 0.5;
  display: none;
  pointer-events: none;
  z-index: 1;
}

@media (min-width: 1100px) {
  body[data-playing="true"][data-brand="lovemadisar"] .watermark--lovemadisar,
  body[data-playing="true"][data-brand="tamboolamsarees"] .watermark--tamboolamsarees,
  body[data-playing="true"][data-brand="pattukuttypavadai"] .watermark--pattukuttypavadai,
  body[data-playing="true"][data-brand="tamarai"] .watermark--tamarai,
  body[data-playing="true"][data-brand="hakinaki"] .watermark--hakinaki {
    display: block;
  }
}

/* ---- the dot field: a paper texture that breathes, not a hero graphic ---- */
.veil {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  transform-origin: 50% 42%;
  z-index: 0;
  animation: veil-expand var(--motion-slow) var(--ease-out) both;
}

.veil__grid,
.veil__pulse {
  position: absolute;
  inset: -10%;
  transform-origin: 50% 42%;
  /* dots fade away from the centre, so the field reads as light falling on paper */
  mask-image: radial-gradient(circle at 50% 42%, var(--color-mask) 0%, transparent 64%);
  -webkit-mask-image: radial-gradient(circle at 50% 42%, var(--color-mask) 0%, transparent 64%);
}

.veil__grid {
  background-image: radial-gradient(circle, var(--color-dots) 0 var(--dot-r), transparent var(--dot-r));
  background-size: var(--dot-pitch) var(--dot-pitch);
}

/* the slower gold layer underneath is the pulse — the house's breathing, not a loop for its own sake */
.veil__pulse {
  background-image: radial-gradient(circle, var(--color-dot-pulse) 0 var(--dot-r), transparent var(--dot-r));
  background-size: calc(var(--dot-pitch) * 4) calc(var(--dot-pitch) * 4);
  animation: veil-breathe var(--pulse) var(--ease-in-out) infinite;
}

/* The lens: the same grid, larger and denser, revealed only under the pointer.
   JS moves two custom properties on pointermove — there is no animation loop. */
.veil__lens {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(
    circle,
    var(--color-dot-lens) 0 var(--dot-r-lens),
    transparent var(--dot-r-lens)
  );
  background-size: var(--dot-pitch) var(--dot-pitch);
  mask-image: radial-gradient(
    circle var(--lens-r) at var(--mx, 50%) var(--my, 42%),
    var(--color-mask) 0%,
    transparent 100%
  );
  -webkit-mask-image: radial-gradient(
    circle var(--lens-r) at var(--mx, 50%) var(--my, 42%),
    var(--color-mask) 0%,
    transparent 100%
  );
}

@keyframes veil-expand {
  from {
    transform: scale(0.74);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes veil-breathe {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 0.95;
  }
}

/* the house line, under the mark, resting state only */
.mission {
  position: absolute;
  left: var(--space-6);
  right: var(--space-6);
  top: calc(38dvh + var(--logo-h) / 2 + var(--space-6));
  margin: 0;
  text-align: center;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  line-height: var(--leading-snug);
  color: var(--color-text-dim);
  z-index: 2;
}

body[data-playing="true"] .mission {
  display: none;
}

/* the motion setting stops the dot field too, not just the film */
body[data-still="true"] .veil,
body[data-still="true"] .veil__pulse {
  animation: none;
}

body[data-still="true"] .veil__lens {
  display: none;
}

/* ---- stickers ---- */
.rail {
  margin: 0;
  padding: 0;
  list-style: none;
}

.sticker {
  --slot: 0;
  position: absolute;
  left: 0;
  top: 0;
  width: var(--sticker);
  height: var(--sticker);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  transform: translate(
      calc(var(--cx) - var(--sticker) / 2),
      calc(var(--cy) - var(--sticker) / 2)
    )
    scale(var(--ss));
  transition: transform var(--motion-base) var(--ease-out);
  z-index: 2;
}

.rail .sticker:nth-child(1) { --slot: 0; }
.rail .sticker:nth-child(2) { --slot: 1; }
.rail .sticker:nth-child(3) { --slot: 2; }
.rail .sticker:nth-child(4) { --slot: 3; }
.rail .sticker:nth-child(5) { --slot: 4; }

/* resting: an evenly spaced row along the bottom band */
body[data-playing="false"] .sticker {
  --cx: calc(50vw + (var(--slot) - 2) * var(--step));
  --cy: var(--band-cy);
  --ss: 1;
}

/* playing, not chosen: gathered into an overlapping deck in the same band */
body[data-playing="true"] .sticker[aria-pressed="false"] {
  --cx: calc(50vw + (var(--slot) - 2) * var(--deck-step));
  --cy: var(--band-cy);
  --ss: var(--deck-scale);
}

/* playing, chosen: the hero, centred, with the record to its right */
body[data-playing="true"] .sticker[aria-pressed="true"] {
  --cx: var(--hero-cx);
  --cy: var(--hero-cy);
  --ss: var(--hero-scale);
  z-index: 3;
}

.sticker img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: var(--rule) solid var(--color-control);
  transition: border-color var(--motion-fast) var(--ease-in);
}

.sticker:hover img {
  border-color: var(--color-accent);
  transition-timing-function: var(--ease-out);
}

.sticker[aria-pressed="true"] img {
  outline: calc(var(--rule) * 2) solid var(--color-accent);
  outline-offset: var(--space-1);
}

/* ---- the record, to the right of the hero ---- */
.detail {
  position: absolute;
  left: calc(var(--hero-cx) + var(--sticker) * var(--hero-scale) / 2 + var(--space-8));
  top: var(--hero-cy);
  transform: translateY(-50%);
  width: min(var(--measure), 38vw);
  visibility: hidden;
  opacity: 0;
  transition: opacity var(--motion-base) var(--ease-out),
    visibility 0s linear var(--motion-base);
  z-index: 2;
}

body[data-playing="true"] .detail.is-active {
  visibility: visible;
  opacity: 1;
  transition: opacity var(--motion-base) var(--ease-out), visibility 0s;
}

.detail__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding-top: var(--space-3);
  border-top: var(--rule) solid var(--play-accent);
}

/* the brand's own motif, from the shared Storivo motif library, in its own colour */
.detail__motif {
  display: block;
  width: var(--space-10);
  height: var(--space-10);
  object-fit: contain;
  flex: none;
}

.detail__name {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 400;
  line-height: var(--leading-tight);
  margin: 0;
}

.detail__line {
  margin: 0 0 var(--space-3);
  font-size: var(--text-base);
  line-height: var(--leading-snug);
}

.detail__meta {
  margin: 0 0 var(--space-4);
  font-family: var(--font-text);
  font-weight: 700;
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.detail__action {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* ---- icon actions ---- */
/* No box: the glyph is the affordance. The tap target stays 44px regardless. */
.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: inherit;
  text-decoration: none;
  transition: opacity var(--motion-fast) var(--ease-out);
}

.icon svg {
  width: var(--space-8);
  height: var(--space-8);
  display: block;
}

.icon:hover {
  opacity: 0.72;
}

/* the word "opening" beside it carries the unavailable state, not colour alone */
.icon--pending {
  cursor: default;
}

.icon--pending:hover {
  opacity: 1;
}

.icon-note {
  font-family: var(--font-text);
  font-weight: 700;
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

/* ---- chrome ---- */
.chrome-top {
  position: absolute;
  top: var(--space-4);
  right: var(--space-6);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3) var(--space-4);
  align-items: center;
  justify-content: flex-end;
  z-index: 4;
}

.stamp {
  margin: 0;
  font-family: var(--font-text);
  font-weight: 700;
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--color-text-dim);
}

/* Accessibility control — the same 44px circular affordance the other products use.
   It stops the footage and leaves one still frame of the same clip. */
.a11y {
  position: absolute;
  right: var(--space-6);
  bottom: calc(var(--base-h) + var(--space-4));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  border: var(--rule) solid var(--color-control);
  border-radius: 50%;
  background: var(--color-canvas);
  color: var(--color-text);
  font-family: var(--font-text);
  font-size: var(--text-base);
  line-height: 1;
  cursor: pointer;
  z-index: 5;
  transition: background-color var(--motion-fast) var(--ease-out),
    border-color var(--motion-fast) var(--ease-out),
    color var(--motion-fast) var(--ease-out);
}

.a11y:hover {
  border-color: var(--color-accent);
}

.a11y[aria-expanded="true"] {
  background: var(--color-text);
  border-color: var(--color-text);
  color: var(--color-canvas);
}

body[data-playing="true"] .a11y {
  background: var(--play-ground);
  border-color: var(--play-text);
  color: var(--play-text);
}

body[data-playing="true"] .a11y[aria-expanded="true"] {
  background: var(--play-text);
  border-color: var(--play-text);
  color: var(--play-ground);
}

.chrome-base {
  position: absolute;
  left: var(--space-6);
  right: var(--space-6);
  bottom: var(--space-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-6);
  align-items: baseline;
  justify-content: space-between;
  padding-top: var(--space-3);
  border-top: var(--rule) solid var(--color-ornament);
  font-family: var(--font-text);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  transition: border-color var(--motion-slow) var(--ease-out);
  z-index: 4;
}

.chrome-base p {
  margin: 0;
}

.chrome-base a {
  color: inherit;
  text-decoration: none;
  border-bottom: var(--rule) solid var(--color-border);
  transition: border-color var(--motion-fast) var(--ease-out);
}

.chrome-base a:hover {
  border-bottom-color: currentColor;
}

.credit {
  margin-left: auto;
  text-align: right;
  color: var(--color-text-dim);
}

/* ---- focus ---- */
:focus-visible {
  outline: calc(var(--rule) * 2) solid var(--color-accent);
  outline-offset: var(--space-1);
}

/* ---- playing: the page adopts the brand's documented language ---- */
body[data-playing="true"] {
  background: var(--play-ground);
  color: var(--play-text);
}

body[data-playing="true"] .chrome-base,
body[data-playing="true"] .chrome-base a {
  border-color: var(--play-text);
}

body[data-playing="true"] .stamp,
body[data-playing="true"] .credit {
  color: var(--play-text);
}

body[data-playing="true"] .sticker img {
  border-color: var(--play-text);
}

body[data-playing="true"] .sticker[aria-pressed="true"] img {
  outline-color: var(--play-text);
}

body[data-playing="true"] :focus-visible {
  outline-color: var(--play-text);
}

/* ---- accessibility panel ----
   Four further settings, each tied to a criterion rather than offered as a generic switch:
   1.4.1 Use of Colour, 1.4.3 Contrast, 1.4.4 Resize Text, 1.4.6 Contrast (Enhanced),
   2.2.2 Pause Stop Hide. Native <dialog> carries focus trapping and Escape for free. */
.a11y-panel {
  position: fixed;
  inset: auto var(--space-6) calc(var(--base-h) + var(--space-4) + var(--tap) + var(--space-3)) auto;
  margin: 0;
  width: min(380px, calc(100vw - var(--space-8)));
  max-height: calc(100dvh - var(--base-h) - var(--tap) - var(--space-12));
  overflow: auto;
  padding: var(--space-5);
  border: var(--rule) solid var(--color-control-hc);
  border-radius: var(--radius);
  background: var(--color-canvas);
  color: var(--color-text);
  font-family: var(--font-text);
  font-size: var(--text-sm);
  z-index: 20;
}

.a11y-panel::backdrop {
  background: var(--color-scrim-strong);
}

.a11y-panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: var(--rule) solid var(--color-border-hc);
}

.a11y-panel__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 400;
}

.a11y-panel__close {
  border: 0;
  background: none;
  padding: var(--space-1) var(--space-2);
  min-height: var(--space-6);
  color: var(--color-text);
  font-family: var(--font-text);
  font-size: var(--text-sm);
  text-decoration: underline;
  cursor: pointer;
}

.a11y-row {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding-block: var(--space-3);
  border-bottom: var(--rule) solid var(--color-border);
}

.a11y-row:last-child {
  border-bottom: 0;
}

.a11y-row__input {
  flex: none;
  width: var(--space-6);
  height: var(--space-6);
  margin: 0;
  accent-color: var(--color-accent);
  cursor: pointer;
}

.a11y-row__label {
  cursor: pointer;
}

.a11y-row__name {
  display: block;
  font-weight: 700;
}

.a11y-row__hint {
  display: block;
  font-size: var(--text-xs);
  line-height: var(--leading-snug);
  color: var(--color-text-dim);
}

.a11y-row__wcag {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-dim);
}

/* ---- setting: solid background, no footage at all ---- */
body[data-solid="true"] .stage__video,
body[data-solid="true"] .stage__still,
body[data-contrast="high"] .stage__video,
body[data-contrast="high"] .stage__still {
  display: none;
}

body[data-solid="true"] .stage__scrim,
body[data-contrast="high"] .stage__scrim {
  background: var(--play-ground);
}

/* ---- setting: underline links ---- */
body[data-links="underline"] .chrome-base a,
body[data-links="underline"] .a11y-panel__close {
  text-decoration: underline;
  text-underline-offset: var(--space-1);
}

body[data-links="underline"] .chrome-base a {
  border-bottom: 0;
}

/* ---- setting: larger text ---- */
body[data-text="112"] .detail__name {
  font-size: calc(var(--text-xl) * 1.12);
}

body[data-text="112"] .detail__line {
  font-size: calc(var(--text-base) * 1.12);
}

body[data-text="112"] .detail__meta,
body[data-text="112"] .stamp,
body[data-text="112"] .icon-note {
  font-size: calc(var(--text-xs) * 1.12);
}

/* ---- setting: high contrast ---- */
body[data-contrast="high"] {
  color: var(--color-text-hc);
}

body[data-contrast="high"] .stamp,
body[data-contrast="high"] .credit,
body[data-contrast="high"] .detail__meta,
body[data-contrast="high"] .icon-note {
  color: var(--color-text-dim-hc);
}

body[data-contrast="high"] .chrome-base,
body[data-contrast="high"] .chrome-base a,
body[data-contrast="high"] .a11y,
body[data-contrast="high"] .sticker img {
  border-color: var(--color-border-hc);
}

body[data-contrast="high"][data-playing="true"] {
  color: var(--color-play-hc);
}

body[data-contrast="high"][data-playing="true"] .stamp,
body[data-contrast="high"][data-playing="true"] .credit {
  color: var(--color-play-hc);
}

body[data-contrast="high"][data-playing="true"] .chrome-base,
body[data-contrast="high"][data-playing="true"] .chrome-base a,
body[data-contrast="high"][data-playing="true"] .a11y,
body[data-contrast="high"][data-playing="true"] .sticker img {
  border-color: var(--color-play-hc);
}

@media (prefers-reduced-motion: reduce) {
  .veil,
  .veil__pulse {
    animation: none;
  }
}

/* ---- narrow: hero up top, record beneath it, deck still in the bottom band ---- */
@media (max-width: 860px) and (min-height: 621px) {
  :root {
    --logo-w: min(70vw, 20dvh, 300px);
    --hero-cx: 50vw;
    --hero-cy: 32dvh;
    --hero-scale: 1.3;
    --text-xl: 26px;
    --measure: 100%;
  }

  .chrome-top {
    right: var(--space-4);
    left: var(--space-4);
    justify-content: space-between;
  }

  .chrome-base {
    left: var(--space-4);
    right: var(--space-4);
  }

  .detail {
    left: var(--space-4);
    right: var(--space-4);
    top: calc(var(--hero-cy) + var(--sticker) * 0.85);
    width: auto;
    transform: none;
    text-align: center;
  }

  .detail__head,
  .detail__action {
    justify-content: center;
  }

  .credit {
    margin-left: 0;
    text-align: left;
  }
}

/* ---- short viewports: drop the least important line rather than overflow ---- */
@media (max-height: 620px) {
  :root {
    --logo-w: min(40vw, 22dvh, 260px);
  }

  .detail__meta {
    display: none;
  }

  /* no vertical room to stack: keep the record beside the hero and push the deck
     to the left edge so the two cannot meet */
  body[data-playing="true"] .sticker[aria-pressed="false"] {
    --cx: calc(var(--sticker) * 1.2 + (var(--slot) - 2) * var(--deck-step));
  }
}
