/* ==========================================================================
   EVERYDAY 3D — Reality ↔ Model teaching stage

   Palette contract: render .e3d-shell with the repository's .dark-well class
   when it sits inside .light-band. All color and type values below inherit
   from studio-tokens.css; the course wrapper supplies --accent.
   ========================================================================== */

html.has-everyday-3d,
html.has-everyday-3d body {
  max-width: 100%;
  overflow-x: clip;
}

.e3d-section,
.e3d-shell,
.e3d-head,
.e3d-grid,
.e3d-viewport,
.e3d-panel,
.e3d-copy,
.e3d-control,
.e3d-parts,
.e3d-actions {
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
}

.e3d-section {
  width: 100%;
  margin-block: clamp(2rem, 5vw, 4.5rem);
  overflow: clip;
}

.e3d-precision-lab {
  inline-size: 100%;
  max-inline-size: 100%;
  margin-top: clamp(2rem, 5vw, 4rem);
  padding-top: clamp(1.25rem, 3vw, 2rem);
  border-top: 1px solid var(--line);
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.e3d-precision-note {
  margin-top: .55rem !important;
  color: var(--accent) !important;
  font-family: var(--font-heading);
  font-size: .82rem !important;
  font-weight: 700;
  letter-spacing: .01em;
}

.e3d-shell {
  position: relative;
  isolation: isolate;
  width: 100%;
  padding: clamp(1rem, 2.6vw, 2.25rem);
  color: var(--ink-2);
  background:
    linear-gradient(color-mix(in srgb, var(--accent) 8%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--accent) 8%, transparent) 1px, transparent 1px),
    radial-gradient(circle at 12% 0%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 42%),
    var(--paper);
  background-size: 32px 32px, 32px 32px, auto, auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--ah-r-xl, 28px);
  box-shadow: var(--arch-shadow-lg);
  overflow: hidden;
}

.e3d-shell::before,
.e3d-shell::after {
  position: absolute;
  z-index: -1;
  content: "";
  pointer-events: none;
}

.e3d-shell::before {
  inset: 0;
  border: 1px solid color-mix(in srgb, var(--gold) 14%, transparent);
  border-radius: inherit;
}

.e3d-shell::after {
  top: 0;
  left: clamp(1rem, 2.6vw, 2.25rem);
  width: clamp(4rem, 11vw, 9rem);
  height: 3px;
  background: linear-gradient(90deg, var(--gold), var(--accent));
  box-shadow: var(--glow-gold);
}

.e3d-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, .52fr);
  gap: clamp(1rem, 3vw, 2.5rem);
  align-items: end;
  padding-block: clamp(.25rem, 1vw, .75rem) clamp(1.25rem, 3vw, 2.25rem);
  border-bottom: 1px solid var(--line);
}

.e3d-head-main {
  min-width: 0;
}

.e3d-eyebrow {
  display: flex;
  gap: .65rem;
  align-items: center;
  width: fit-content;
  margin: 0 0 .75rem;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: clamp(.72rem, .68rem + .15vw, .82rem);
  font-weight: 700;
  letter-spacing: .13em;
  line-height: 1.35;
  text-transform: uppercase;
}

.e3d-eyebrow::before {
  width: 1.65rem;
  height: 1px;
  content: "";
  background: currentcolor;
  box-shadow: var(--glow-gold);
}

.e3d-title {
  max-width: 24ch;
  margin: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(2rem, 1.65rem + 1.4vw, 3.25rem);
  font-weight: 700;
  letter-spacing: -.035em;
  line-height: .98;
  text-wrap: balance;
}

.e3d-question {
  max-width: 62ch;
  margin: clamp(.8rem, 1.8vw, 1.25rem) 0 0;
  color: var(--ink-2);
  font-family: var(--font-body);
  font-size: clamp(1rem, .93rem + .35vw, 1.2rem);
  line-height: 1.65;
  text-wrap: pretty;
}

.e3d-why {
  position: relative;
  margin: 0;
  padding: 1rem 1rem 1rem 1.2rem;
  color: var(--ink-2);
  font-family: var(--font-body);
  font-size: .95rem;
  line-height: 1.6;
  background: color-mix(in srgb, var(--gold) 7%, var(--recessed));
  border: 1px solid color-mix(in srgb, var(--gold) 34%, var(--line));
  border-left: 3px solid var(--gold);
  border-radius: var(--ah-r-md, 12px);
}

.e3d-why strong {
  color: var(--gold);
}

.e3d-course-tabs,
.e3d-modebar,
.e3d-actions,
.e3d-model-key {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
}

.e3d-orbit-hint {
  position: absolute;
  z-index: 4;
  bottom: 1rem;
  left: 1rem;
  max-width: calc(100% - 18rem);
  margin: 0;
  padding: .48rem .65rem;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: .66rem;
  font-weight: 700;
  letter-spacing: .08em;
  line-height: 1.35;
  background: color-mix(in srgb, var(--recessed) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--gold) 42%, var(--line));
  border-radius: 999px;
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.e3d-course-tabs {
  margin-block: clamp(1rem, 2vw, 1.5rem);
  padding: .35rem;
  background: color-mix(in srgb, var(--recessed) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--ah-r-lg, 18px);
}

.e3d-course-tab,
.e3d-mode,
.e3d-action {
  min-height: 44px;
  padding: .65rem .95rem;
  color: var(--ink-2);
  font-family: var(--font-heading);
  font-size: .9rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--ah-r-sm, 8px);
  cursor: pointer;
  transition:
    color var(--ah-dur-fast, 160ms) var(--ah-ease-out, ease-out),
    background-color var(--ah-dur-fast, 160ms) var(--ah-ease-out, ease-out),
    border-color var(--ah-dur-fast, 160ms) var(--ah-ease-out, ease-out),
    transform var(--ah-dur-fast, 160ms) var(--ah-ease-out, ease-out);
}

.e3d-course-tab {
  flex: 1 1 10rem;
}

.e3d-course-tab:hover,
.e3d-mode:hover,
.e3d-action:hover {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 11%, transparent);
  border-color: var(--line-strong);
}

.e3d-course-tab[aria-selected="true"],
.e3d-course-tab[aria-pressed="true"],
.e3d-course-tab.is-active,
.e3d-mode[aria-selected="true"],
.e3d-mode[aria-pressed="true"],
.e3d-mode.is-active {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  border-color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent), var(--glow-accent);
}

.e3d-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(19rem, .85fr);
  gap: clamp(.8rem, 2vw, 1.35rem);
  align-items: start;
}

.e3d-viewport {
  position: relative;
  min-height: 430px;
  height: clamp(540px, 52vw, 720px);
  background:
    linear-gradient(color-mix(in srgb, var(--ink) 5%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--ink) 5%, transparent) 1px, transparent 1px),
    linear-gradient(color-mix(in srgb, var(--accent) 7%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--accent) 7%, transparent) 1px, transparent 1px),
    radial-gradient(circle at 50% 42%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 52%),
    var(--recessed);
  background-size: 24px 24px, 24px 24px, 96px 96px, 96px 96px, auto, auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--ah-r-lg, 18px);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--gold) 5%, transparent);
  overflow: hidden;
}

.e3d-viewport::before,
.e3d-viewport::after {
  position: absolute;
  z-index: 2;
  content: "";
  pointer-events: none;
}

.e3d-viewport::before {
  inset: .65rem;
  border: 1px solid color-mix(in srgb, var(--gold) 19%, transparent);
  border-radius: calc(var(--ah-r-lg, 18px) - .35rem);
}

.e3d-viewport::after {
  inset: 0;
  background:
    linear-gradient(90deg, var(--gold) 0 3rem, transparent 3rem) top .65rem left .65rem / 7rem 1px no-repeat,
    linear-gradient(var(--gold) 0 3rem, transparent 3rem) top .65rem left .65rem / 1px 7rem no-repeat,
    linear-gradient(270deg, var(--accent) 0 3rem, transparent 3rem) right .65rem bottom .65rem / 7rem 1px no-repeat,
    linear-gradient(0deg, var(--accent) 0 3rem, transparent 3rem) right .65rem bottom .65rem / 1px 7rem no-repeat;
  opacity: .66;
}

.e3d-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 430px;
  border: 0;
  outline: 0;
  touch-action: pan-y;
}

.e3d-canvas[hidden] {
  display: none;
}

.e3d-pins {
  position: absolute;
  z-index: 4;
  inset: 0;
  pointer-events: none;
}

.e3d-pin {
  position: absolute;
  z-index: 4;
  top: 50%;
  left: 50%;
  display: inline-grid;
  grid-template-columns: 1.9rem minmax(0, 1fr);
  gap: .5rem;
  align-items: center;
  min-width: 44px;
  min-height: 44px;
  max-width: min(15rem, calc(100% - 2rem));
  padding: .35rem .65rem .35rem .35rem;
  color: var(--ink);
  font-family: var(--font-heading);
  font-size: .78rem;
  font-weight: 700;
  line-height: 1.25;
  text-align: left;
  background: color-mix(in srgb, var(--gold) 16%, var(--surface));
  border: 1px solid var(--gold);
  border-radius: 999px;
  box-shadow: var(--glow-gold), var(--arch-shadow-sm);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.e3d-pin[hidden] {
  display: none;
}

.e3d-pin:hover,
.e3d-pin[aria-expanded="true"],
.e3d-pin.is-active {
  background: color-mix(in srgb, var(--gold) 27%, var(--surface));
  transform: translate(-50%, -50%) scale(1.035);
}

.e3d-pin-number {
  display: inline-grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  color: var(--paper);
  font-family: var(--font-mono);
  font-size: .78rem;
  font-weight: 800;
  background: var(--gold);
  border-radius: 50%;
}

.e3d-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 430px;
  padding: clamp(.85rem, 1.6vw, 1.2rem);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--ah-r-lg, 18px);
  box-shadow: var(--arch-shadow-sm);
}

.e3d-modebar {
  padding-bottom: .8rem;
  border-bottom: 1px solid var(--line);
}

.e3d-mode {
  flex: 1 1 7rem;
  padding-inline: .7rem;
}

.e3d-copy {
  color: var(--ink-2);
  font-family: var(--font-body);
  font-size: .95rem;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.e3d-copy > :first-child {
  margin-top: 0;
}

.e3d-copy > :last-child {
  margin-bottom: 0;
}

.e3d-copy :is(h2, h3, h4, strong) {
  color: var(--ink);
  font-family: var(--font-heading);
}

.e3d-control {
  display: grid;
  gap: .65rem;
  padding: .85rem;
  background: color-mix(in srgb, var(--recessed) 82%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--ah-r-md, 12px);
}

.e3d-control-head {
  display: flex;
  gap: .75rem;
  align-items: baseline;
  justify-content: space-between;
  color: var(--ink);
  font-family: var(--font-heading);
  font-size: .88rem;
  font-weight: 700;
}

.e3d-range {
  width: 100%;
  min-height: 44px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.e3d-readout {
  display: inline-flex;
  gap: .45rem;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: .55rem .7rem;
  color: var(--accent-bright);
  font-family: var(--font-mono);
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--accent) 9%, var(--recessed));
  border-left: 2px solid var(--accent);
}

.e3d-parts {
  display: grid;
  gap: .55rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.e3d-part {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: .7rem;
  align-items: start;
  width: 100%;
  min-height: 44px;
  padding: .7rem;
  color: var(--ink-2);
  text-align: left;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--ah-r-sm, 8px);
}

button.e3d-part {
  cursor: pointer;
}

.e3d-part::before {
  display: grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: .72rem;
  content: counter(e3d-part, decimal-leading-zero);
  border: 1px solid color-mix(in srgb, var(--gold) 55%, var(--line));
  border-radius: 50%;
  counter-increment: e3d-part;
}

.e3d-parts {
  counter-reset: e3d-part;
}

.e3d-part:hover,
.e3d-part[aria-current="true"],
.e3d-part[aria-selected="true"],
.e3d-part.is-active {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  border-color: var(--accent);
}

.e3d-part-copy {
  display: grid;
  gap: .2rem;
  min-width: 0;
  font-family: var(--font-body);
  font-size: .88rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.e3d-part-copy strong {
  color: var(--ink);
  font-family: var(--font-heading);
}

.e3d-boundary {
  padding: .85rem 1rem;
  color: var(--ink-2);
  font-family: var(--font-body);
  font-size: .88rem;
  line-height: 1.55;
  background: color-mix(in srgb, var(--gold) 8%, var(--recessed));
  border: 1px dashed color-mix(in srgb, var(--gold) 58%, var(--line));
  border-radius: var(--ah-r-sm, 8px);
}

.e3d-boundary strong {
  color: var(--gold);
  font-family: var(--font-heading);
}

.e3d-actions {
  margin-top: auto;
  padding-top: .8rem;
  border-top: 1px solid var(--line);
}

.e3d-action {
  flex: 1 1 8rem;
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 13%, var(--surface));
  border-color: var(--line-strong);
}

.e3d-action[data-primary="true"],
.e3d-action.is-primary {
  color: var(--paper);
  background: var(--accent);
  border-color: var(--accent-bright);
}

.e3d-fallback {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: block;
  padding: 2rem;
  color: var(--ink-2);
  font-family: var(--font-body);
  line-height: 1.6;
  text-align: center;
  background: color-mix(in srgb, var(--recessed) 94%, transparent);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.e3d-fallback[hidden] {
  display: none;
}

.e3d-viewport.is-fallback .e3d-model-key,
.e3d-viewport.is-fallback .e3d-orbit-hint {
  display: none;
}

.e3d-model-key {
  position: absolute;
  z-index: 4;
  right: 1rem;
  bottom: 1rem;
  max-width: calc(100% - 2rem);
  padding: .5rem .65rem;
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: .7rem;
  letter-spacing: .04em;
  background: color-mix(in srgb, var(--recessed) 88%, transparent);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  backdrop-filter: blur(10px);
}

.e3d-model-key > * {
  display: inline-flex;
  gap: .4rem;
  align-items: center;
}

.e3d-model-key > *::before {
  width: .65rem;
  height: .65rem;
  content: "";
  background: var(--accent);
  border: 1px solid var(--accent-bright);
  border-radius: 50%;
  box-shadow: var(--glow-accent);
}

.e3d-model-key > [data-kind="reality"]::before,
.e3d-model-key > .is-reality::before {
  background: var(--gold);
  border-color: var(--gold);
  box-shadow: var(--glow-gold);
}

.e3d-status {
  position: absolute;
  z-index: 5;
  top: 1rem;
  left: 1rem;
  display: inline-flex;
  gap: .45rem;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  min-height: 32px;
  padding: .35rem .6rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: .72rem;
  line-height: 1.35;
  background: color-mix(in srgb, var(--surface-2) 84%, transparent);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow-wrap: anywhere;
}

.e3d-status[hidden] {
  display: none;
}

.e3d-status::before {
  flex: 0 0 auto;
  width: .48rem;
  height: .48rem;
  content: "";
  background: var(--accent);
  border-radius: 50%;
  box-shadow: var(--glow-accent);
}

.e3d-course-tab:focus-visible,
.e3d-mode:focus-visible,
.e3d-action:focus-visible,
.e3d-pin:focus-visible,
.e3d-part:focus-visible,
.e3d-range:focus-visible,
.e3d-canvas:focus-visible {
  outline: 3px solid var(--accent-bright);
  outline-offset: 3px;
}

.e3d-course-tab:disabled,
.e3d-mode:disabled,
.e3d-action:disabled,
.e3d-pin:disabled,
.e3d-part:disabled,
.e3d-range:disabled,
[aria-disabled="true"]:is(.e3d-course-tab, .e3d-mode, .e3d-action, .e3d-pin, .e3d-part) {
  cursor: not-allowed;
  filter: grayscale(.4);
  opacity: .52;
}

@media (max-width: 900px) {
  .e3d-head {
    grid-template-columns: 1fr;
  }

  .e3d-title {
    max-width: 20ch;
  }

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

  .e3d-viewport {
    height: clamp(430px, 72vw, 620px);
  }

  .e3d-panel {
    min-height: 0;
  }
}

@media (max-width: 600px) {
  .e3d-section {
    margin-block: 1.5rem;
  }

  .e3d-shell {
    padding: .75rem;
    border-radius: var(--ah-r-lg, 18px);
  }

  .e3d-head {
    padding: .5rem .25rem 1rem;
  }

  .e3d-course-tabs {
    display: grid;
    grid-template-columns: 1fr;
  }

  .e3d-course-tab {
    width: 100%;
  }

  .e3d-viewport,
  .e3d-canvas {
    min-height: 340px;
  }

  .e3d-viewport {
    height: min(76vh, 520px);
  }

  .e3d-pin {
    max-width: calc(100% - 1rem);
  }

  .e3d-pin > span:last-child {
    display: none;
  }

  .e3d-model-key {
    right: .65rem;
    bottom: .65rem;
    max-width: calc(100% - 1.3rem);
    border-radius: var(--ah-r-sm, 8px);
  }

  .e3d-orbit-hint {
    top: .65rem;
    right: .65rem;
    bottom: auto;
    left: .65rem;
    max-width: calc(100% - 1.3rem);
    font-size: .58rem;
    text-align: center;
    border-radius: var(--ah-r-sm, 8px);
  }
}

@media (max-width: 360px) {
  html.has-everyday-3d .header-inner {
    width: 100%;
    max-width: 100%;
    gap: .5rem;
    padding-inline: .75rem;
  }

  html.has-everyday-3d .header-logo {
    min-width: 0;
    gap: .4rem;
  }

  html.has-everyday-3d .header-logo img {
    max-width: 142px;
  }

  html.has-everyday-3d .header-logo > div {
    display: none;
  }

  html.has-everyday-3d .mobile-toggle {
    flex: 0 0 auto;
  }
}

@media (prefers-contrast: more) {
  .e3d-shell,
  .e3d-viewport,
  .e3d-panel,
  .e3d-course-tabs,
  .e3d-control,
  .e3d-part,
  .e3d-model-key {
    border-color: var(--ink-2);
  }

  .e3d-question,
  .e3d-copy,
  .e3d-part-copy,
  .e3d-boundary,
  .e3d-status {
    color: var(--ink);
  }
}

@media (forced-colors: active) {
  .e3d-shell,
  .e3d-viewport,
  .e3d-panel,
  .e3d-course-tabs,
  .e3d-course-tab,
  .e3d-mode,
  .e3d-control,
  .e3d-part,
  .e3d-boundary,
  .e3d-action,
  .e3d-model-key {
    color: CanvasText;
    background: Canvas;
    border-color: CanvasText;
    box-shadow: none;
    forced-color-adjust: auto;
  }

  .e3d-orbit-hint {
    color: CanvasText;
    background: Canvas;
    border-color: CanvasText;
    forced-color-adjust: auto;
  }

  .e3d-course-tab[aria-selected="true"],
  .e3d-course-tab[aria-pressed="true"],
  .e3d-mode[aria-selected="true"],
  .e3d-mode[aria-pressed="true"],
  .e3d-part[aria-current="true"],
  .e3d-part[aria-selected="true"],
  .e3d-part[aria-pressed="true"] {
    color: HighlightText;
    background: Highlight;
  }
}

@media (prefers-reduced-motion: reduce) {
  .e3d-shell *,
  .e3d-shell *::before,
  .e3d-shell *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }

}
