:root {
  color-scheme: light;
  --bg: #F6F1EA;
  --ink: #1F1A17;
  --gold: #A0764A;
  --mute: #6B6058;
  --line: rgba(31, 26, 23, 0.28);
  --font-zh: "Noto Serif SC", "Songti SC", "STSong", Georgia, serif;
  --font-en: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --font-mix: "Cormorant Garamond", "Noto Serif SC", Georgia, serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html[lang^="zh"] body {
  font-family: var(--font-zh);
}

html[lang^="en"] body {
  font-family: var(--font-en);
}

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

/* Top bar & language switch */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(14px, 2.6vw, 26px) clamp(16px, 3.6vw, 38px);
  pointer-events: none;
}

.topbar--right-only {
  justify-content: flex-end;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 4px 2px;
  pointer-events: auto;
  text-decoration: none;
  border-radius: 6px;
  transition: opacity 220ms ease;
}

.brand-link:hover {
  opacity: 0.78;
}

.brand-link:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
}

.brand-mark {
  display: block;
  width: clamp(120px, 28vw, 152px);
  height: auto;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-family: var(--font-mix);
  font-size: 15px;
  letter-spacing: 0.06em;
  line-height: 1;
  pointer-events: auto;
  user-select: none;
}

.lang-btn {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: transparent;
  padding: 0 7px;
  min-height: 44px;
  min-width: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  color: var(--mute);
  opacity: 0.62;
  cursor: pointer;
  border-radius: 999px;
  transition: color 200ms ease, opacity 200ms ease;
}

.lang-btn[data-lang-choice="zh"] {
  font-family: var(--font-zh);
  font-size: 14px;
}

.lang-btn[data-lang-choice="en"] {
  font-family: var(--font-en);
  font-size: 16px;
  font-weight: 500;
}

.lang-btn.is-active {
  color: var(--ink);
  opacity: 1;
  font-weight: 600;
}

.lang-btn:hover {
  color: var(--gold);
  opacity: 1;
}

.lang-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  color: var(--gold);
  opacity: 1;
}

.lang-sep {
  color: var(--mute);
  opacity: 0.4;
  font-size: 13px;
  pointer-events: none;
}

/* Homepage full-viewport stage */
.page-home .lang-switch {
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

html.is-settled .page-home .lang-switch {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 400ms ease;
}

.home-main {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  overflow-x: clip;
}

.bunny-svg {
  --bunny-h: min(54.4vh, calc(82vw * 640 / 353));
  --bunny-h: min(54.4dvh, calc(82vw * 640 / 353));
  position: absolute;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  height: var(--bunny-h);
  width: calc(var(--bunny-h) * 353 / 640);
  display: block;
  pointer-events: none;
  z-index: 1;
}

.stage-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  z-index: 2;
}

.stage-shell {
  --stage-w: min(92vw, calc(260px + 45.5vw), 1120px, calc(62vh * 16 / 9));
  --stage-w: min(92vw, calc(260px + 45.5vw), 1120px, calc(62dvh * 16 / 9));
  position: absolute;
  left: 50%;
  top: 45.5%;
  transform: translate(-50%, -50%);
  width: var(--stage-w);
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 3;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  flex-shrink: 0;
}

.stage svg,
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.stage canvas {
  pointer-events: none;
}

.stage svg {
  pointer-events: none;
}

/* Clickable wordmark hit area for replay */
.wordmark-replay {
  position: absolute;
  left: 11%;
  top: 33%;
  width: 78%;
  height: 32%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 16px;
  cursor: pointer;
  pointer-events: none;
  opacity: 0;
}

html.is-settled .wordmark-replay {
  pointer-events: auto;
}

.wordmark-replay:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 6px;
  opacity: 1;
}

/* Instant settled state (repeat visit in same session or skip) */
html.is-instant #svgS {
  opacity: 0;
}

html.is-instant #end {
  opacity: 1;
}

html.is-instant .actions,
html.is-instant .page-home .lang-switch {
  transition: none;
}

/* Entrance buttons */
.actions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(11vh + env(safe-area-inset-bottom, 0px));
  bottom: calc(11dvh + env(safe-area-inset-bottom, 0px));
  z-index: 5;
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 20px;
  padding: 0 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

html.is-settled .actions {
  opacity: 1;
  transition: opacity 400ms ease;
}

.pill-btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 48px;
  padding: 12px 30px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 240ms ease, color 240ms ease, background-color 240ms ease;
}

.actions .pill-btn {
  width: clamp(196px, 14.2vw, 208px);
  min-height: 52px;
  padding: 8px 14px;
  gap: 2px;
  border-color: var(--line);
  pointer-events: none;
}

html.is-settled .actions .pill-btn {
  pointer-events: auto;
}

.pill-btn__title {
  display: block;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.14em;
  line-height: 1.3;
}

html[lang^="en"] .pill-btn__title {
  font-size: 19px;
  font-weight: 500;
  letter-spacing: 0.08em;
}

.pill-btn__sub {
  display: block;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.08em;
  line-height: 1.35;
  color: var(--mute);
  transition: color 240ms ease;
}

html[lang^="en"] .pill-btn__sub {
  font-size: 14px;
  letter-spacing: 0.04em;
}

.actions .pill-btn__title {
  font-size: 14.5px;
  letter-spacing: 0.12em;
  line-height: 1.25;
}

html[lang^="en"] .actions .pill-btn__title {
  font-size: 16.5px;
  letter-spacing: 0.06em;
  line-height: 1.2;
}

.actions .pill-btn__sub {
  font-size: 11.5px;
  letter-spacing: 0.06em;
  line-height: 1.25;
}

html[lang^="en"] .actions .pill-btn__sub {
  font-size: 12px;
  letter-spacing: 0.02em;
  line-height: 1.25;
}

.pill-btn:hover,
.pill-btn:focus-visible {
  border-color: var(--gold);
  color: var(--gold);
  background-color: rgba(160, 118, 74, 0.045);
}

.pill-btn:hover .pill-btn__sub,
.pill-btn:focus-visible .pill-btn__sub {
  color: var(--gold);
}

.actions .pill-btn:hover,
.actions .pill-btn:focus-visible {
  border-color: var(--ink);
  color: var(--ink);
  background-color: transparent;
}

.actions .pill-btn:hover .pill-btn__sub,
.actions .pill-btn:focus-visible .pill-btn__sub {
  color: var(--mute);
}

.pill-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

/* Stacked entrance buttons under 600px width */
@media (max-width: 599px) {
  .bunny-svg {
    --bunny-h: min(41.5vh, calc(82vw * 640 / 353));
    --bunny-h: min(41.5dvh, calc(82vw * 640 / 353));
  }

  .stage-shell {
    --stage-w: min(104vw, calc(58vh * 16 / 9));
    --stage-w: min(104vw, calc(58dvh * 16 / 9));
    top: 43.2%;
    max-width: none;
  }

  .actions {
    bottom: calc(8vh + env(safe-area-inset-bottom, 0px));
    bottom: calc(8dvh + env(safe-area-inset-bottom, 0px));
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
  }

  .actions .pill-btn {
    width: min(75vw, 312px);
    min-height: 58px;
    padding: 10px 20px;
    gap: 3px;
  }

  .actions .pill-btn__title {
    font-size: 15px;
  }

  html[lang^="en"] .actions .pill-btn__title {
    font-size: 17px;
  }

  .actions .pill-btn__sub {
    font-size: 12px;
  }

  html[lang^="en"] .actions .pill-btn__sub {
    font-size: 12.5px;
  }
}

/* Graceful fallback on short screens (height < 640px) */
@media (max-height: 639px) {
  .home-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: clamp(16px, 4vh, 32px) 0 calc(clamp(16px, 5vh, 36px) + env(safe-area-inset-bottom, 0px));
    gap: 8px;
  }

  .stage-shell {
    --stage-w: min(92vw, calc(260px + 45.5vw), 1120px, calc(66vh * 16 / 9));
    --stage-w: min(92vw, calc(260px + 45.5vw), 1120px, calc(66dvh * 16 / 9));
    position: relative;
    top: auto;
    left: auto;
    transform: none;
    margin: auto 0;
  }

  .actions {
    position: relative;
    bottom: auto;
    width: 100%;
    flex-shrink: 0;
  }
}

@media (max-width: 599px) and (max-height: 639px) {
  .stage-shell {
    --stage-w: min(104vw, calc(54vh * 16 / 9));
    --stage-w: min(104vw, calc(54dvh * 16 / 9));
    max-width: none;
  }
}

/* Placeholder pages (/visit.html, /client.html) */
.sub-main {
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 96px 24px 64px;
  text-align: center;
}

.sub-message {
  margin: 0;
  font-size: clamp(18px, 3vw, 24px);
  font-weight: 400;
  letter-spacing: 0.14em;
  line-height: 1.6;
  color: var(--ink);
  max-width: 30ch;
}

html[lang^="en"] .sub-message {
  font-size: clamp(22px, 3.6vw, 30px);
  letter-spacing: 0.05em;
}

/* Client entry form */
.client-form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.field-label {
  font-size: 15px;
  letter-spacing: 0.18em;
  color: var(--mute);
}

html[lang^="en"] .field-label {
  font-size: 18px;
  letter-spacing: 0.08em;
}

.client-controls {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
}

.code-input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 16px;
  letter-spacing: 0.1em;
  text-align: center;
  transition: border-color 220ms ease;
}

.code-input:hover {
  border-color: var(--ink);
}

.code-input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-color: var(--gold);
}

.pill-btn--compact {
  flex: 0 0 auto;
  padding: 0 26px;
  min-height: 48px;
  font-size: 15px;
  letter-spacing: 0.14em;
}

html[lang^="en"] .pill-btn--compact {
  font-size: 18px;
  letter-spacing: 0.06em;
}

.client-notice {
  margin: 4px 0 0;
  min-height: 1.6em;
  font-size: 15px;
  letter-spacing: 0.12em;
  color: var(--mute);
  opacity: 0;
  transition: opacity 320ms ease;
}

html[lang^="en"] .client-notice {
  font-size: 18px;
  letter-spacing: 0.04em;
}

.client-notice.is-visible {
  opacity: 1;
}

@media (max-width: 440px) {
  .client-controls {
    flex-direction: column;
    gap: 14px;
  }

  .pill-btn--compact {
    width: 100%;
  }
}

/* Reduced motion: show final state immediately, no animation */
@media (prefers-reduced-motion: reduce) {
  #svgS,
  #cv {
    opacity: 0 !important;
  }

  #end {
    opacity: 1 !important;
  }

  .actions,
  .page-home .lang-switch {
    opacity: 1 !important;
    transition: none !important;
  }

  .actions .pill-btn,
  .page-home .lang-switch {
    pointer-events: auto !important;
  }

  .wordmark-replay {
    display: none !important;
  }

  .pill-btn,
  .pill-btn__sub,
  .lang-btn,
  .brand-link,
  .code-input,
  .client-notice {
    transition: none !important;
  }
}
