:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  color: #f1eae1;
  background: #12100e;
  --gold: #d8b982;
  --muted: #c1b4a4;
  --edge: #4a3b2a;
  --inset: clamp(0.875rem, 3.4vw, 2.75rem);
}

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

body {
  margin: 0;
}

button {
  font: inherit;
  cursor: pointer;
}

button:focus-visible {
  outline: 2px solid #f5d8a0;
  outline-offset: 3px;
}

.demo {
  display: grid;
  grid-template-rows: minmax(min(22rem, 57vh), 1fr) auto;
  min-block-size: 100vh;
  min-block-size: 100dvh;
}

.stage {
  position: relative;
  min-inline-size: 0;
  overflow: clip;
  isolation: isolate;
  background-color: #11100e;
  background-image:
    linear-gradient(180deg, #100c095e, transparent 62%, #0b090621),
    url('./stage-background.webp');
  background-size: cover;
  background-position: center bottom;
}

.stage::before {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 52% 53%, #bb8b4d2e, transparent 61%);
  transform: translate3d(var(--light-shift-x, 0%), var(--light-shift-y, 0%), 0);
  pointer-events: none;
  content: '';
}

#scene, .stage-poster {
  position: absolute;
  inset: 0;
  display: block;
  inline-size: 100%;
  block-size: 100%;
}

.stage-poster { object-fit: contain; }
.stage.is-ready .stage-poster { visibility: hidden; }
.stage:not(.is-ready) #scene { visibility: hidden; }

.stage-callout, .stage-callout__graphic {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.stage-callout__leader {
  fill: none;
  stroke: #e6b979;
  stroke-width: 1;
  stroke-dasharray: 1;
  filter: drop-shadow(0 0 4px #dca65955);
}

.stage-callout__dot {
  fill: #ffdfab;
  stroke: #754924;
  stroke-width: 1;
  filter: drop-shadow(0 0 5px #ffbc6caa);
}

.stage-callout__anchor {
  position: absolute;
  left: var(--callout-x);
  top: var(--callout-y);
  width: max-content;
  max-width: min(17rem, 45%);
  translate: -50% -100%;
}

.stage-callout__plate {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: .5rem .82rem;
  border: 1px solid #a6804e59;
  border-block-end-color: #c49b61bd;
  border-radius: .3rem .3rem .15rem .15rem;
  background: linear-gradient(140deg, #2e261cfa, #171310f5 76%);
  box-shadow: 0 .35rem 1.3rem #08060388, 0 0 1rem #b8893422;
}

.stage-callout__label {
  position: relative;
  display: block;
  color: #f8e8cf;
  font-weight: 530;
  font-size: .86rem;
  line-height: 1.3;
  text-align: center;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.stage-callout__plate::before, .stage-callout__plate::after {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  content: '';
}

.stage-callout__plate::before {
  inset: 0 auto 0 0;
  width: 56%;
  background: linear-gradient(102deg, transparent, #ebc78522 60%, transparent);
  transform: translateX(-116%) skewX(-24deg);
}

.stage-callout__plate::after {
  inset: auto auto 0 0;
  width: 48%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #f7d391 54%, transparent);
  transform: translateX(-115%);
  filter: drop-shadow(0 -1px 3px #ffbe67bd);
}

@media (prefers-reduced-motion: no-preference) {
  .stage-callout__plate { animation: callout-breathe 5.8s ease-in-out infinite; }
  .stage-callout__plate::before { animation: callout-face-glint 7.8s ease-in-out infinite; }
  .stage-callout__plate::after { animation: callout-edge-glint 7.8s ease-in-out infinite; }
  .stage[data-offscreen] .stage-callout__plate,
  .stage[data-offscreen] .stage-callout__plate::before,
  .stage[data-offscreen] .stage-callout__plate::after { animation-play-state: paused; }
}

@keyframes callout-breathe { 50% { transform: translateY(-1.5px); } }
@keyframes callout-face-glint {
  0%, 31% { transform: translateX(-116%) skewX(-24deg); opacity: 0; }
  40% { opacity: 1; }
  53%, 100% { transform: translateX(218%) skewX(-24deg); opacity: 0; }
}
@keyframes callout-edge-glint {
  0%, 8% { transform: translateX(-115%); opacity: 0; }
  17% { opacity: .87; }
  27%, 100% { transform: translateX(218%); opacity: 0; }
}

.is-embedded .demo {
  display: block;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

.is-embedded .stage { height: 100%; }
.is-embedded .stage-bar, .is-embedded .layers, .is-embedded .render-status { display: none; }

.stage-bar {
  position: relative;
  padding: clamp(1rem, 2.8vw, 2rem) var(--inset);
  pointer-events: none;
}

h1 {
  max-inline-size: 28ch;
  margin: 0;
  color: #f2dfc4;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(1.42rem, 4vw, 2.75rem);
  font-weight: 400;
  line-height: 1.03;
  letter-spacing: -0.035em;
  text-wrap: balance;
  text-shadow: 0 2px 16px #100b08;
}

.render-status {
  position: absolute;
  inset: auto auto 1rem 50%;
  width: min(25rem, calc(100% - 2 * var(--inset)));
  margin: 0;
  padding: 1rem;
  transform: translateX(-50%);
  border: 1px solid var(--edge);
  border-radius: 0.5rem;
  background: #151210;
  color: var(--muted);
  text-align: center;
}

.layers {
  min-inline-size: 0;
  border-block-start: 1px solid #5a4732;
  padding: clamp(0.65rem, 2vw, 1.15rem) var(--inset);
  background: linear-gradient(110deg, #1c1814, #151210 76%);
}

.layer-controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(0.35rem, 1.1vw, 0.75rem);
}

.layer-controls button {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-inline-size: 0;
  min-block-size: 2.75rem;
  padding: 0.45rem clamp(0.5rem, 1.1vw, 0.8rem);
  border: 1px solid var(--edge);
  border-radius: 0.38rem;
  background: #24201b;
  color: #ded3c7;
  font-size: clamp(0.74rem, 1.35vw, 0.88rem);
  font-weight: 500;
  line-height: 1.2;
  text-align: start;
  overflow-wrap: anywhere;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.layer-controls button::before {
  flex: 0 0 0.55rem;
  inline-size: 0.55rem;
  block-size: 0.55rem;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 1px #f4dfbc45;
  content: '';
}

[data-layer='core'] {
  --swatch: linear-gradient(140deg, #60616b, #f2f0e8 48%, #a4a2a3 68%);
}

[data-layer='thread'] {
  --swatch: repeating-linear-gradient(135deg, #e5d9bb 0 2px, #ac977a 2px 3px);
}

[data-layer='individual'] {
  --swatch: radial-gradient(circle at 50% 50%, transparent 37%, #a7aab0 43%, #625c56 65%);
}

[data-layer='shared'] {
  --swatch: radial-gradient(circle at 50% 50%, transparent 34%, #d6ad74 45%, #695746 66%);
}

[data-layer='braid'] {
  --swatch: repeating-linear-gradient(50deg, #49382b 0 1px, #d0b08b 1px 3px, #79624d 3px 4px);
}

@media (hover: hover) {
  .layer-controls button:hover {
    border-color: #aa8b5f;
    background: #31281e;
  }
}

.layer-controls button[aria-pressed='true'] {
  border-color: #b8945f;
  background: #3b2c1c;
  color: #f7e5cb;
}

.layer-info {
  display: flex;
  align-items: baseline;
  gap: 0.15rem 0.9rem;
  flex-wrap: wrap;
  min-block-size: 2.5rem;
  padding-block-start: 0.65rem;
}

.layer-info h2,
.layer-info p {
  margin: 0;
  line-height: 1.4;
}

.layer-info h2 {
  color: var(--gold);
  font-size: 0.88rem;
  font-weight: 600;
}

.layer-info p {
  color: var(--muted);
  font-size: 0.82rem;
}

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 650px) {
  .layer-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr)) minmax(0, 1.2fr);
  }

  .layer-info {
    min-block-size: 3.9rem;
    align-content: flex-start;
  }
}

@media (max-width: 420px) {
  .layer-controls button {
    gap: 0.35rem;
    padding-inline: 0.4rem;
  }

  .layer-controls button::before {
    flex-basis: 0.42rem;
    inline-size: 0.42rem;
    block-size: 0.42rem;
  }
}

@media (max-width: 340px) {
  .layer-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
  }
}
