:root {
  --navy: #102c3a;
  --navy-2: #173f51;
  --ink: #16303c;
  --muted: #58717d;
  --paper: #fffaf1;
  --white: #ffffff;
  --sky: #65c9e8;
  --sky-soft: #dff6fc;
  --coral: #ff6b5f;
  --yellow: #ffd75a;
  --mint: #59d6ad;
  --line: rgba(16, 44, 58, 0.13);
  --glass: rgba(255, 255, 255, 0.91);
  --glass-dark: rgba(16, 44, 58, 0.88);
  --shadow: 0 14px 38px rgba(11, 39, 52, 0.18);
  --round: 22px;
  --ui: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Fredoka", var(--ui);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--ui);
  overscroll-behavior: none;
  touch-action: manipulation;
}

button,
a {
  font: inherit;
}

button {
  min-height: 48px;
  color: inherit;
  border: 0;
  cursor: pointer;
}

button:focus-visible,
a:focus-visible {
  outline: 4px solid var(--yellow);
  outline-offset: 3px;
}

canvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

.pill {
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 18px;
  background: var(--glass);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.eyebrow {
  margin: 0 0 8px;
  color: #15708d;
  font-family: var(--display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

/* Live guidance */
#hud {
  position: fixed;
  z-index: 40;
  top: 0;
  right: 0;
  left: 0;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 0;
  pointer-events: none;
}

#hint {
  display: flex;
  width: min(94vw, 540px);
  min-height: 50px;
  margin: 0 auto;
  padding: 11px 15px;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  pointer-events: auto;
}

#hint b {
  color: #c93f36;
}

#hint.locked {
  border-color: rgba(45, 166, 124, 0.58);
}

#hint.lost {
  border-color: rgba(255, 107, 95, 0.72);
}

.dot {
  width: 11px;
  height: 11px;
  flex: none;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 0 0 rgba(89, 214, 173, 0.6);
  animation: pulse 1.8s infinite;
}

#hint.locked .dot {
  animation: none;
}

#hint.lost .dot {
  background: var(--coral);
}

@keyframes pulse {
  70% { box-shadow: 0 0 0 11px rgba(89, 214, 173, 0); }
  100% { box-shadow: 0 0 0 0 rgba(89, 214, 173, 0); }
}

/* Scan coach */
#scan {
  position: fixed;
  z-index: 45;
  top: 40%;
  left: 50%;
  display: grid;
  width: min(86vw, 370px);
  padding: 20px;
  transform: translate(-50%, -50%);
  grid-template-columns: 54px 1fr auto;
  gap: 7px 12px;
  align-items: center;
  text-align: left;
  pointer-events: none;
}

.scanIcon {
  display: grid;
  width: 54px;
  height: 54px;
  grid-row: 1 / 4;
  place-items: center;
  color: var(--navy);
  border-radius: 18px;
  background: var(--yellow);
  font-family: var(--display);
  font-size: 34px;
}

#scanTitle {
  font-family: var(--display);
  font-size: 20px;
  font-weight: 700;
}

#scanPct {
  color: #167b69;
  font-family: var(--display);
  font-size: 20px;
  font-weight: 700;
}

#scanBar {
  position: relative;
  height: 11px;
  overflow: hidden;
  border-radius: 999px;
  background: #d9e7eb;
}

#scanFill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--sky), var(--mint));
  transition: width 120ms linear;
}

#scanSub {
  grid-column: 2 / 4;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.25;
}

.primaryAction {
  position: fixed;
  z-index: 44;
  bottom: calc(env(safe-area-inset-bottom) + 214px);
  left: 50%;
  display: inline-flex;
  min-width: 190px;
  padding: 14px 22px;
  transform: translateX(-50%);
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: var(--white);
  border-radius: 999px;
  background: var(--coral);
  box-shadow: 0 10px 30px rgba(143, 41, 35, 0.35);
  font-family: var(--display);
  font-size: 18px;
  font-weight: 700;
}

.primaryAction:active {
  transform: translateX(-50%) scale(0.97);
}

/* A giant subject is intentionally too large to fit. This coach guides a physical
   phone tilt while the WebXR camera remains registered to the real camera. */
#revealGuide {
  position: fixed;
  z-index: 43;
  top: calc(env(safe-area-inset-top) + 76px);
  left: 50%;
  display: grid;
  width: min(88vw, 390px);
  padding: 12px 16px 13px;
  transform: translateX(-50%);
  grid-template-columns: 42px 1fr;
  gap: 11px;
  align-items: center;
  pointer-events: none;
}

#revealArrow {
  color: var(--coral);
  font-family: var(--display);
  font-size: 38px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  animation: revealNudge 1.25s ease-in-out infinite;
}

#revealMessage {
  font-family: var(--display);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
}

#revealProgress {
  height: 7px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #d9e7eb;
}

#revealFill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--sky), var(--mint), var(--yellow));
  transition: width 180ms ease-out;
}

@keyframes revealNudge {
  0%, 100% { transform: translateY(4px); }
  50% { transform: translateY(-4px); }
}

/* Scale and movement */
#scalebar {
  position: fixed;
  z-index: 32;
  bottom: calc(env(safe-area-inset-bottom) + 180px);
  left: 50%;
  display: flex;
  transform: translateX(-50%);
  align-items: center;
  flex-direction: column;
  gap: 5px;
  opacity: 0;
  transition: opacity 180ms ease;
  pointer-events: none;
}

#scalebar.show {
  opacity: 1;
}

#scaleNum {
  padding: 6px 12px;
  color: var(--navy);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 11px;
  background: var(--glass);
  box-shadow: 0 6px 22px rgba(11, 39, 52, 0.13);
  font-family: var(--display);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

#scaleNum span {
  color: var(--muted);
  font-family: var(--ui);
  font-weight: 400;
}

#ruler {
  position: relative;
  width: min(66vw, 300px);
  height: 15px;
}

#ruler .bar,
#ruler .cap {
  position: absolute;
  background: var(--yellow);
  filter: drop-shadow(0 1px 2px rgba(16, 44, 58, 0.5));
}

#ruler .bar {
  top: 7px;
  right: 0;
  left: 0;
  height: 3px;
}

#ruler .cap {
  top: 1px;
  width: 3px;
  height: 15px;
}

#ruler .cap.l { left: 0; }
#ruler .cap.r { right: 0; }

#credit {
  position: fixed;
  z-index: 31;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 158px);
  left: 12px;
  overflow: hidden;
  color: rgba(255, 255, 255, 0.88);
  font-size: 10px;
  line-height: 1.25;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;
}

#credit.show {
  opacity: 1;
}

#mover {
  position: fixed;
  z-index: 36;
  right: 14px;
  bottom: calc(env(safe-area-inset-bottom) + 205px);
  display: none;
  width: 108px;
  height: 108px;
  align-items: center;
  justify-content: center;
  border: 3px solid rgba(255, 255, 255, 0.82);
  border-radius: 50%;
  background: var(--glass-dark);
  box-shadow: var(--shadow);
  touch-action: none;
}

#mover.show {
  display: flex;
}

#mover::before {
  position: absolute;
  inset: 12px;
  content: "";
  border: 1px dashed rgba(255, 255, 255, 0.34);
  border-radius: 50%;
}

#moverKnob {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255, 255, 255, 0.75);
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
  will-change: transform;
}

#mover .ax {
  position: absolute;
  color: rgba(255, 255, 255, 0.78);
  font-size: 11px;
  font-weight: 700;
  pointer-events: none;
}

#mover .ax.up {
  top: 5px;
}

#mover .ax.dn {
  bottom: 5px;
}

/* Model dock */
#dock {
  position: fixed;
  z-index: 35;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 6px 0 calc(env(safe-area-inset-bottom) + 10px);
  border-top: 1px solid rgba(255, 255, 255, 0.56);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.76), rgba(255, 255, 255, 0.94));
  box-shadow: 0 -10px 30px rgba(12, 38, 50, 0.14);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

/* Blur is pretty on menus but costs GPU bandwidth beside the live camera feed. */
.arMode .pill,
.arMode #dock {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

#strip {
  display: flex;
  overflow-x: auto;
  padding: 3px 14px 8px;
  gap: 10px;
  scroll-padding-inline: 14px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

#strip::-webkit-scrollbar,
#stageGrid::-webkit-scrollbar {
  display: none;
}

.card,
.scard {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink);
  border: 2px solid transparent;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 5px 15px rgba(13, 47, 61, 0.09);
  text-align: center;
}

.card {
  width: 102px;
  min-height: 82px;
  padding: 7px 8px;
  flex: 0 0 auto;
  scroll-snap-align: center;
}

.card.active,
.scard.active {
  color: var(--navy);
  border-color: var(--coral);
  background: #fff3e8;
  box-shadow: 0 6px 18px rgba(176, 58, 48, 0.17);
}

.card:active,
.scard:active {
  transform: scale(0.97);
}

.emoji {
  font-size: 29px;
  line-height: 1;
}

.nm {
  font-family: var(--display);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.05;
}

.sz {
  color: var(--muted);
  font-size: 11px;
}

#actions {
  display: flex;
  padding: 0 14px;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#actions button {
  display: inline-flex;
  min-height: 46px;
  padding: 8px 12px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--navy);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.9);
  font-size: 13px;
  font-weight: 700;
}

#actions button:active {
  transform: scale(0.97);
}

#actions svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Landing */
#intro,
#stage {
  position: fixed;
  inset: 0;
  z-index: 60;
  overflow-y: auto;
  background:
    radial-gradient(circle at 88% 14%, rgba(255, 215, 90, 0.9) 0 8%, transparent 8.3%),
    radial-gradient(circle at 7% 72%, rgba(101, 201, 232, 0.6) 0 13%, transparent 13.3%),
    linear-gradient(155deg, #effbff 0%, #fff9ec 54%, #ffe9e2 100%);
}

#intro {
  display: flex;
  padding: calc(env(safe-area-inset-top) + 22px) 22px calc(env(safe-area-inset-bottom) + 22px);
}

#intro .wrap {
  width: min(100%, 460px);
  margin: auto;
}

.brandMark {
  display: grid;
  width: 62px;
  height: 62px;
  margin-bottom: 15px;
  place-items: center;
  color: var(--white);
  border: 5px solid var(--white);
  border-radius: 21px;
  background: var(--coral);
  box-shadow: 0 9px 20px rgba(166, 53, 44, 0.24);
  font-family: var(--display);
  font-size: 35px;
  font-weight: 700;
  transform: rotate(-4deg);
}

#intro h1 {
  margin: 0;
  color: var(--navy);
  font-family: var(--display);
  font-size: clamp(48px, 14vw, 72px);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 0.87;
}

#intro h1 em {
  color: var(--coral);
  font-style: normal;
}

#intro .sub {
  margin: 15px 0 20px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.35;
}

#intro ol {
  display: grid;
  margin: 0 0 21px;
  padding: 0;
  gap: 8px;
  list-style: none;
  counter-reset: step;
}

#intro li {
  display: flex;
  min-height: 58px;
  padding: 9px 12px;
  align-items: center;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.66);
  counter-increment: step;
}

#intro li::before {
  display: grid;
  width: 36px;
  height: 36px;
  flex: none;
  place-items: center;
  content: counter(step);
  color: var(--navy);
  border-radius: 12px;
  background: var(--yellow);
  font-family: var(--display);
  font-weight: 700;
}

#intro li b {
  display: block;
  font-family: var(--display);
  font-size: 16px;
}

#intro li span {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: 13px;
}

#go,
#stageGo {
  width: 100%;
  min-height: 58px;
  padding: 14px 18px;
  color: var(--white);
  border-radius: 18px;
  background: var(--coral);
  box-shadow: 0 10px 25px rgba(176, 58, 48, 0.24);
  font-family: var(--display);
  font-size: 20px;
  font-weight: 700;
}

#go.studio {
  background: var(--navy);
  box-shadow: 0 10px 25px rgba(16, 44, 58, 0.2);
}

#go:active,
#stageGo:active {
  transform: scale(0.99);
}

#go:disabled,
#stageGo:disabled {
  opacity: 0.55;
  box-shadow: none;
}

#mode2,
#stage3d {
  display: block;
  min-height: 44px;
  padding: 13px 8px 4px;
  color: var(--navy);
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  text-underline-offset: 3px;
}

#note {
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}

#note .diag {
  display: block;
  margin-top: 9px;
  padding: 8px 10px;
  color: #657a83;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.65);
  font-size: 11px;
  overflow-wrap: anywhere;
}

/* Choice screen */
#stage {
  z-index: 59;
  display: none;
  padding: calc(env(safe-area-inset-top) + 24px) 18px calc(env(safe-area-inset-bottom) + 18px);
}

#stage.show {
  display: flex;
  flex-direction: column;
}

#stage .shead,
#stageGrid,
#stageFoot {
  width: min(100%, 560px);
  margin-right: auto;
  margin-left: auto;
}

#stage .shead h2 {
  margin: 0 0 4px;
  color: var(--navy);
  font-family: var(--display);
  font-size: 32px;
  line-height: 1;
}

#stage .shead p:last-child {
  margin: 7px 0 0;
  color: var(--muted);
}

#stageGrid {
  display: grid;
  overflow-y: auto;
  padding: 16px 2px;
  flex: 1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 11px;
  align-content: start;
}

.scard {
  min-height: 103px;
  padding: 12px 7px;
}

.stageCardWrap {
  position: relative;
  min-width: 0;
}

.stageCardWrap .scard {
  width: 100%;
  height: 100%;
}

.scard .emoji {
  font-size: 35px;
}

.scard.add {
  color: var(--muted);
  border: 2px dashed #9bb5bf;
  background: rgba(255, 255, 255, 0.52);
}

.stageCardWrap .del {
  position: absolute;
  z-index: 2;
  top: 4px;
  right: 4px;
  display: grid;
  width: 38px;
  min-height: 38px;
  height: 38px;
  place-items: center;
  color: var(--muted);
  border-radius: 50%;
  font-size: 22px;
}

#stageFoot {
  padding-top: 5px;
}

/* Loading and feedback */
#loading {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: none;
  padding: 20px;
  align-items: center;
  justify-content: center;
  background: rgba(16, 44, 58, 0.52);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

#loading.show {
  display: flex;
}

#loadingCard {
  display: flex;
  min-width: 230px;
  padding: 24px;
  align-items: center;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 5px solid #d9e7eb;
  border-top-color: var(--coral);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loadingMsg {
  font-family: var(--display);
  font-size: 18px;
  font-weight: 700;
}

#loadingSub {
  min-height: 1.25em;
  color: var(--muted);
  font-size: 13px;
}

#toast {
  position: fixed;
  z-index: 80;
  top: calc(env(safe-area-inset-top) + 76px);
  left: 50%;
  max-width: min(88vw, 430px);
  padding: 10px 16px;
  transform: translate(-50%, -10px);
  color: var(--white);
  border-radius: 999px;
  background: var(--navy);
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  transition: 180ms ease;
  pointer-events: none;
}

#toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

@media (max-width: 390px) {
  #actions button {
    min-width: 46px;
    padding: 8px 10px;
  }

  #actions button span {
    display: none;
  }

  #mover {
    width: 96px;
    height: 96px;
  }
}

@media (max-width: 540px) {
  .arMode #scalebar {
    left: 40%;
  }

  .arMode #ruler {
    width: 52vw;
  }
}

@media (max-height: 690px) {
  #intro {
    display: block;
  }

  #intro .wrap {
    margin: 0 auto;
  }

  #intro h1 {
    font-size: 48px;
  }

  #intro .sub {
    margin: 10px 0 14px;
  }

  #intro li {
    min-height: 49px;
    padding: 6px 10px;
  }

  .brandMark {
    width: 48px;
    height: 48px;
    margin-bottom: 9px;
    font-size: 28px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  #scan {
    top: 42%;
  }

  #dock {
    right: 0;
    left: 52%;
  }

  #scalebar {
    bottom: 148px;
    left: 26%;
  }

  .primaryAction {
    bottom: 64px;
    left: 25%;
  }
}

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