:root {
  color-scheme: light;
  --ink: #2c2218;
  --ink-soft: #6e563d;
  --beige: #f2dba6;
  --beige-deep: #d9a260;
  --tile-bg: #fff8e9;
  --tile-line: #bd8b57;
  --warm-orange: #d97757;
  --teal: #3f8f86;
  --teal-deep: #28675f;
  --cream: #fff5e6;
  --wood-dark: #9b6336;
  --wood-mid: #c9894c;
  --wood-light: #e3b26f;
  --ui-menu-bg: url("./assets/ui/app-shell-v1/menu-background.png");
  font-family: "Nunito", "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--beige);
  color: var(--ink);
  overflow-x: hidden;
  transition: background 260ms ease;
}

body.view--picker,
body.app--loading {
  background-color: #f4d18b;
  background-image: var(--ui-menu-bg);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: fixed;
}

body.view--picker::before,
body.app--loading::before {
  content: none;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

button {
  font: inherit;
}

.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;
}

/* ----------------------------------------------------------------- */
/* Splash                                                            */
/* ----------------------------------------------------------------- */

.splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background-color: #f4d18b;
  background-image: var(--ui-menu-bg);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  opacity: 0;
  pointer-events: none;
  /* Smooth fade tuned per spec (R1). */
  transition: opacity 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

.app--loading .splash {
  opacity: 1;
  pointer-events: auto;
}

.splash__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 0;
}

.splash__logo {
  width: clamp(86px, 12vw, 128px);
  height: clamp(86px, 12vw, 128px);
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.splash__wordmark {
  width: clamp(210px, 28vw, 360px);
  height: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

/* ----------------------------------------------------------------- */
/* Route curtain                                                     */
/* ----------------------------------------------------------------- */

.route-curtain {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  place-items: center;
  background-color: #f4d18b;
  background-image: var(--ui-menu-bg);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.route-curtain.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.route-curtain__card {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.route-curtain__logo {
  width: clamp(76px, 10vw, 110px);
  height: clamp(76px, 10vw, 110px);
  object-fit: contain;
}

.route-curtain__wordmark {
  width: clamp(190px, 26vw, 320px);
  height: auto;
  object-fit: contain;
}

/* ----------------------------------------------------------------- */
/* Picker                                                            */
/* ----------------------------------------------------------------- */

.picker-shell {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 2048px;
  height: 1152px;
  padding: 14px 18px 18px;
  display: grid;
  grid-template-rows: auto 1fr;
  align-content: start;
  gap: 14px;
  transform: translate(-50%, -50%) scale(var(--menu-scale, 1));
  transform-origin: center;
}

.picker-header {
  position: absolute;
  inset: 0;
  width: 100%;
  margin: 0;
  padding: 0;
  pointer-events: none;
}

.app-brand {
  display: contents;
  min-width: 0;
}

.picker-header__logo {
  position: absolute;
  left: var(--top-brandMedallion-x, 21.2%);
  top: var(--top-brandMedallion-y, 1.2%);
  width: var(--top-brandMedallion-w, 4%);
  height: var(--top-brandMedallion-h, 7.1%);
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.picker-header__wordmark {
  position: absolute;
  left: var(--top-wordmark-x, 25.7%);
  top: var(--top-wordmark-y, 1.2%);
  width: var(--top-wordmark-w, 14.6%);
  height: var(--top-wordmark-h, 7.6%);
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.app-actions {
  display: contents;
}

.icon-button {
  position: absolute;
  width: var(--top-button-w, 3.6%);
  height: var(--top-button-h, 6.4%);
  border: 0;
  border-radius: 0;
  display: grid;
  place-items: center;
  background: transparent;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, opacity 120ms ease;
  pointer-events: auto;
}

.icon-button[data-action="sound"] {
  left: var(--top-sound-x, 67.2%);
  top: var(--top-sound-y, 1.2%);
  width: var(--top-sound-w, 3.6%);
  height: var(--top-sound-h, 6.4%);
}

.icon-button[data-action="settings"] {
  left: var(--top-settings-x, 71.2%);
  top: var(--top-settings-y, 1.2%);
  width: var(--top-settings-w, 3.6%);
  height: var(--top-settings-h, 6.4%);
}

.icon-button[data-action="feedback"] {
  left: var(--top-feedback-x, 75.2%);
  top: var(--top-feedback-y, 1.2%);
  width: var(--top-feedback-w, 3.6%);
  height: var(--top-feedback-h, 6.4%);
}

.icon-button:hover,
.icon-button:focus-visible {
  outline: none;
  transform: translateY(-1px);
}

.icon-button:active {
  transform: translateY(1px) scale(0.96);
}

.icon-button[aria-pressed="false"] {
  opacity: 0.62;
}

.icon-button--small {
  width: 48px;
  height: 48px;
}

.icon-button__art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.scene-shelf {
  position: absolute;
  left: 50%;
  top: 110px;
  transform: translateX(-50%);
  width: 1180px;
  align-self: start;
  margin: 0 auto;
  padding: 14px 34px 34px;
}

.scene-picker {
  display: grid;
  grid-template-columns: repeat(3, 190px);
  gap: 22px;
  padding: 0;
  width: 1020px;
  max-width: none;
  margin: 0 auto;
  justify-content: center;
}

.scene-tile {
  display: block;
  position: relative;
  background: transparent;
  border: 0;
  border-radius: 0;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  max-width: 190px;
  width: 190px;
  aspect-ratio: 0.79;
  transition: transform 140ms ease, filter 140ms ease;
  -webkit-tap-highlight-color: transparent;
}

.scene-tile:hover,
.scene-tile:focus-visible {
  transform: translateY(-2px);
  filter: brightness(1.03);
  outline: none;
}

.scene-tile:active {
  transform: translateY(1px) scale(0.98);
}

.scene-tile__art,
.scene-tile__frame {
  position: absolute;
}

.scene-tile__art {
  left: var(--card-x, 0%);
  top: var(--card-y, 0%);
  width: var(--card-w, 100%);
  height: var(--card-h, 100%);
}

.scene-tile__frame {
  inset: 0;
  width: 100%;
  height: 100%;
}

.scene-tile__frame {
  display: block;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.scene-tile__thumb-art {
  position: absolute;
  left: var(--thumb-x, 12%);
  top: var(--thumb-y, 8%);
  width: var(--thumb-w, 76%);
  height: var(--thumb-h, 61%);
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.scene-tile__label-art {
  position: absolute;
  left: var(--label-x, 9%);
  top: var(--label-y, 73%);
  width: var(--label-w, 82%);
  height: var(--label-h, 20%);
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.scene-tile__lock {
  position: absolute;
  left: var(--lock-x, 50%);
  top: var(--lock-y, 42%);
  width: var(--lock-size, 26%);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.scene-tile__lock img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

@media (max-height: 500px) and (orientation: landscape) {
  .picker-shell {
    gap: 14px;
    padding: 14px 18px 18px;
  }

  .picker-header {
    padding: 0;
  }

  .picker-header__logo {
    width: 82px;
    height: 82px;
  }

  .picker-header__wordmark {
    width: 300px;
    max-height: 88px;
  }

  .icon-button {
    width: 74px;
    height: 74px;
  }

  .scene-shelf {
    padding: 14px 34px 34px;
  }

  .scene-picker {
    grid-template-columns: repeat(3, 190px);
    gap: 22px;
    max-width: none;
  }

  .scene-tile {
    max-width: 190px;
  }
}

@media (min-width: 1400px) and (min-height: 650px) {
  .scene-picker {
    grid-template-columns: repeat(3, 190px);
  }
}

/* ----------------------------------------------------------------- */
/* Viewer                                                            */
/* ----------------------------------------------------------------- */

.stage-wrap {
  position: fixed;
  inset: 0;
  background: var(--beige);
}

/* The stage is the viewport. .scene-content is sized to the cover-rendered
   plate rect by JS, then panned/zoomed as one unit so the plate and objects
   remain locked to the same image-space coordinates. */
.scene-stage {
  position: absolute;
  inset: 0;
  background: var(--beige);
  overflow: hidden;
  isolation: isolate;
  user-select: none;
  touch-action: none;
  opacity: 1;
  transition: opacity 320ms cubic-bezier(0.4, 0, 0.2, 1);
}

.scene-stage.is-panning {
  cursor: grabbing;
}

.scene-stage--loading {
  opacity: 0;
}

.scene-plate {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.scene-content {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 50% 50%;
  will-change: transform;
}

.scene-objects {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.scene-object {
  position: absolute;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  /* R6: subtle pulse so kids know what's tappable. transform-origin centered
     so the scale doesn't shift the apparent position of the object. */
  transform-origin: 50% 50%;
  animation: scene-object-pulse 3.6s ease-in-out infinite;
}

.scene-object.is-playing {
  animation-play-state: paused;
  transform: scale(1);
}

.scene-object:focus-visible {
  outline: 0;
}

.scene-object img,
.scene-object canvas {
  display: block;
  width: 100%;
  height: 100%;
  /* fill (not contain) so the canvas stretches to fill the bbox the user
     tuned in the editor — editor renders without object-fit (i.e. fill), so
     viewer must match or wood frames get letterboxed within their bbox. */
  object-fit: fill;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.scene-object .video-source {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

@keyframes scene-object-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.012); }
}

/* ----------------------------------------------------------------- */
/* Back button                                                       */
/* ----------------------------------------------------------------- */

.back-button {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  width: clamp(54px, 7vw, 78px);
  height: clamp(54px, 7vw, 78px);
  border-radius: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 500;
  display: grid;
  place-items: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, filter 120ms ease;
  padding: 0;
}

.back-button__icon {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.back-button:hover,
.back-button:focus-visible {
  outline: none;
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.back-button:active {
  transform: translateY(1px) scale(0.96);
}

/* Hide back button on the picker. */
body.view--picker .back-button {
  display: none;
}

/* When still loading and no view rendered yet, hide the back button too. */
body.app--loading .back-button {
  display: none;
}

/* ----------------------------------------------------------------- */
/* Sheets                                                            */
/* ----------------------------------------------------------------- */

.app-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 850;
  display: grid;
  place-items: end center;
  padding: 18px;
  background: rgba(44, 34, 24, 0.20);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.app-sheet-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.app-sheet {
  width: min(520px, 100%);
  max-height: min(78vh, 520px);
  overflow: auto;
  border-radius: 18px;
  background: #fff8e8;
  box-shadow: 0 22px 54px rgba(43, 30, 18, 0.28), inset 0 0 0 1px rgba(255, 255, 255, 0.52);
  transform: translateY(18px);
  transition: transform 180ms ease;
}

.app-sheet-backdrop.is-visible .app-sheet {
  transform: translateY(0);
}

.app-sheet__header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: rgba(255, 248, 232, 0.96);
  border-bottom: 1px solid rgba(154, 95, 45, 0.16);
}

.app-sheet__header h2 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.1;
}

.app-sheet__body {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.app-sheet__body p {
  margin: 0;
  color: var(--ink-soft);
  font-weight: 700;
  line-height: 1.45;
}

.setting-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  min-height: 58px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(63, 143, 134, 0.08);
  cursor: pointer;
}

.setting-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.setting-row__text {
  display: grid;
  gap: 3px;
}

.setting-row__text strong,
.setting-row__text small {
  display: block;
}

.setting-row__text strong {
  color: var(--ink);
  font-size: 0.96rem;
}

.setting-row__text small {
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.25;
}

.setting-row__switch {
  position: relative;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: rgba(108, 86, 61, 0.24);
  box-shadow: inset 0 0 0 1px rgba(77, 52, 27, 0.16);
}

.setting-row__switch::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff9ec;
  box-shadow: 0 2px 6px rgba(43, 30, 18, 0.24);
  transition: transform 120ms ease;
}

.setting-row input:checked + .setting-row__switch {
  background: var(--teal);
}

.setting-row input:checked + .setting-row__switch::after {
  transform: translateX(22px);
}

.setting-row input:disabled + .setting-row__switch {
  opacity: 0.48;
}

.unlock-sheet {
  gap: 14px;
}

.unlock-sheet__note,
.unlock-sheet__status {
  font-size: 0.86rem;
}

.unlock-sheet__status:empty {
  display: none;
}

.unlock-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.app-command {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: rgba(63, 143, 134, 0.14);
  color: var(--teal-deep);
  font-weight: 900;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

.app-command--primary {
  background: var(--teal);
  color: #fffdf4;
}

.app-command--dev {
  background: rgba(217, 119, 87, 0.16);
  color: #9b4e35;
}

.app-command:hover,
.app-command:focus-visible {
  outline: none;
  transform: translateY(-1px);
}

.app-command:active {
  transform: translateY(1px) scale(0.98);
}

.app-command:disabled {
  cursor: wait;
  opacity: 0.58;
  transform: none;
}

.feedback-sheet {
  gap: 14px;
}

.feedback-choices {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.feedback-choice {
  position: relative;
  min-height: 40px;
  cursor: pointer;
}

.feedback-choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.feedback-choice span {
  display: grid;
  place-items: center;
  min-height: 40px;
  border-radius: 8px;
  background: rgba(63, 143, 134, 0.10);
  color: var(--teal-deep);
  font-size: 0.84rem;
  font-weight: 900;
}

.feedback-choice input:checked + span {
  background: var(--teal);
  color: #fffdf4;
}

.feedback-field {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  color: var(--ink);
  font-weight: 900;
}

.feedback-field--stack {
  grid-template-columns: 1fr;
  gap: 6px;
}

.feedback-field input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

.feedback-field input[type="email"],
.feedback-field textarea {
  width: 100%;
  border: 1px solid rgba(154, 95, 45, 0.22);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fffdf4;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

.feedback-field textarea {
  resize: vertical;
  min-height: 96px;
}

.feedback-field input[type="email"]:focus,
.feedback-field textarea:focus {
  outline: 2px solid rgba(63, 143, 134, 0.34);
  border-color: var(--teal);
}

.feedback-sheet__privacy,
.feedback-sheet__status {
  font-size: 0.82rem;
}

.feedback-sheet__status:empty {
  display: none;
}

.feedback-actions {
  display: flex;
  justify-content: flex-start;
}

@media (orientation: landscape) and (max-height: 520px) {
  .app-sheet-backdrop {
    place-items: center;
  }

  .app-sheet {
    max-height: calc(100vh - 28px);
  }
}

/* ----------------------------------------------------------------- */
/* App banner (transient errors)                                     */
/* ----------------------------------------------------------------- */

.app-banner {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  background: rgba(217, 119, 87, 0.95);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
  max-width: min(90vw, 480px);
  text-align: center;
}

.app-banner.is-visible {
  opacity: 1;
}
