:root {
  color-scheme: dark;
  --night: #0e211d;
  --cream: #f5eee1;
  --muted: rgba(245, 238, 225, 0.58);
  --gold: #e8bd67;
  --gold-light: #ffe0a0;
  --line: rgba(245, 238, 225, 0.16);
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

/* Keep conditional page sections hidden even when their component styles set display. */
[hidden] { display: none !important; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0e211d;
}

body {
  color: var(--cream);
  -webkit-font-smoothing: antialiased;
}

button { color: inherit; font: inherit; }

.experience {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 560px;
  overflow: hidden;
  isolation: isolate;
  background: #0e211d;
}

.experience::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 64px 64px;
  content: "";
  mask-image: linear-gradient(to bottom, transparent, black 18%, black 70%, transparent);
  opacity: 0.15;
}

.experience::after {
  display: none;
}

#tree-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#tree-canvas:active { cursor: grabbing; }

.camera-preview {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  z-index: 8;
  width: 126px;
  height: 96px;
  overflow: hidden;
  border: 1px solid rgba(240, 209, 135, 0.58);
  border-radius: 6px;
  background: rgba(5, 17, 14, 0.9);
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.28);
  transition: width 160ms ease, height 160ms ease, border-color 160ms ease;
}

.camera-preview[hidden] { display: none; }

.camera-preview video {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.camera-preview.is-hidden video { visibility: hidden; }

.camera-preview.is-hidden {
  width: auto;
  height: 34px;
  border-color: rgba(240, 209, 135, 0.38);
}

.camera-preview-toggle {
  position: absolute;
  z-index: 1;
  top: 5px;
  right: 5px;
  min-height: 25px;
  padding: 0 7px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  background: rgba(7, 23, 19, 0.82);
  color: #f5eee1;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.camera-preview.is-hidden .camera-preview-toggle {
  position: static;
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--gold-light);
}

.topbar {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 5;
  display: flex;
  justify-content: flex-end;
  padding: max(22px, env(safe-area-inset-top)) clamp(20px, 5vw, 64px) 0;
  pointer-events: none;
}

.menu-button,
.close-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.menu-button {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 14px 0;
  gap: 3px;
  border: 0;
  border-radius: 0;
  background: transparent;
  pointer-events: auto;
  transition: 180ms ease;
}

.menu-button span {
  display: block;
  width: 14px;
  height: 1.25px;
  justify-self: center;
  background: var(--cream);
  opacity: 0.82;
}

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

.menu-panel {
  position: absolute;
  top: max(56px, calc(env(safe-area-inset-top) + 46px));
  right: max(12px, clamp(20px, 5vw, 64px));
  z-index: 8;
  width: min(168px, calc(100vw - 32px));
  max-height: min(560px, calc(100vh - 90px));
  overflow-y: auto;
  padding: 8px 10px;
  border: 1px solid rgba(245, 238, 225, 0.18);
  border-radius: 8px;
  background: #0e211d;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.34);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transform: translateX(102%);
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 220ms ease;
}

.message-panel,
.gesture-sheet {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 9;
  width: min(410px, 100%);
  min-height: min(470px, 74vh);
  padding: max(66px, calc(env(safe-area-inset-top) + 46px)) clamp(25px, 6vw, 48px) 34px;
  border-left: 1px solid rgba(245, 238, 225, 0.13);
  background: #0e211d;
  box-shadow: -22px 0 70px rgba(0, 0, 0, 0.26);
  transform: translateX(102%);
  transition: transform 400ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.menu-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transform: translateX(0);
}

.message-panel.is-open,
.gesture-sheet.is-open { transform: translateX(0); }

.gesture-sheet {
  position: absolute;
  inset: 0;
  z-index: 15;
  width: 100%;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding: 0;
  border: 0;
  background: #0e211d;
  box-shadow: none;
  transform: translateX(100%);
  transition: transform 320ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.message-panel {
  inset: 0;
  display: grid;
  width: 100%;
  min-height: 0;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  border: 0;
  background: transparent;
  box-shadow: none;
  opacity: 0;
  pointer-events: none;
  transform: none;
  transition: opacity 220ms ease;
}

.message-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.message-card {
  width: min(390px, 100%);
  padding: 28px 25px 25px;
  border: 1px solid rgba(245, 238, 225, 0.16);
  border-radius: 8px;
  background: rgba(7, 22, 18, 0.97);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  opacity: 0;
  transform: translate(var(--message-from-x, 0px), var(--message-from-y, 0px)) scale(0.12);
  transition:
    transform 420ms cubic-bezier(0.18, 0.86, 0.25, 1),
    opacity 260ms ease;
}

.message-panel.is-open .message-card {
  opacity: 1;
  transform: translate(0, 0) scale(1);
}

.message-panel.is-photo-message .message-card {
  width: min(330px, calc(100vw - 72px));
  padding: 12px 12px 18px;
  border-color: rgba(19, 39, 29, 0.12);
  background: #eee4d9;
  color: #193226;
  transform: translate(var(--message-from-x, 0px), calc(var(--message-from-y, 0px) - 10px)) rotate(-3deg) scale(0.12);
}

.message-panel.is-open.is-photo-message .message-card {
  transform: translate(0, -10px) rotate(-3deg) scale(0.92);
}

.message-panel.is-photo-message .close-button,
.message-panel.is-photo-message .message-kicker,
.message-panel.is-photo-message .message-swatch,
.message-panel.is-photo-message h2,
.message-panel.is-photo-message .message-meta {
  display: none;
}

.message-photo-frame {
  overflow: hidden;
  aspect-ratio: 1 / 0.78;
  border-radius: 4px;
  background: #f1ebdf;
}

.message-photo-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-panel.is-photo-message .message-swatch {
  display: none;
}

.message-panel.is-photo-message h2 {
  margin: 18px 10px 0;
  color: #193226;
  font-size: clamp(25px, 6vw, 34px);
}

.message-panel.is-photo-message p {
  margin: 14px 10px 0;
  color: rgba(25, 50, 38, 0.76);
  font-size: 16px;
  line-height: 1.75;
  text-align: center;
}

.preview-back {
  position: absolute;
  top: max(22px, env(safe-area-inset-top));
  left: max(20px, 5vw);
  z-index: 2;
  padding: 8px 0;
  border-bottom: 1px solid rgba(232, 189, 103, 0.5);
  color: var(--gold-light);
  font-size: 12px;
  text-decoration: none;
  pointer-events: auto;
}

.preview-back:hover,
.preview-back:focus-visible {
  color: var(--cream);
  outline: none;
}

.menu-kicker,
.message-kicker {
  color: var(--gold);
  font-size: 9px;
  letter-spacing: 0.28em;
}

.close-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid rgba(245, 238, 225, 0.2);
  border-radius: 50%;
  color: rgba(245, 238, 225, 0.72);
  font-size: 23px;
  font-weight: 200;
  line-height: 1;
}

.close-button:hover,
.close-button:focus-visible {
  border-color: var(--gold);
  color: var(--gold-light);
  outline: none;
}

.menu-actions {
  display: grid;
  gap: 2px;
}

.menu-action {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 10px 5px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: 180ms ease;
}

.menu-action:last-child {
  border-bottom: 0;
}

.menu-action.is-active {
  border-radius: 4px;
  background: rgba(232, 189, 103, 0.13);
}

.menu-action:hover,
.menu-action:focus-visible {
  color: var(--gold-light);
  outline: none;
  transform: translateX(4px);
}

.action-icon {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  color: var(--gold-light);
}

.action-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.65;
}

#gesture-button .action-icon svg {
  fill: currentColor;
  stroke-width: 0;
}

#tree-info-button .action-icon svg {
  fill: currentColor;
  stroke-width: 0;
}

#sound-icon.is-muted svg .sound-waves {
  opacity: 0.22;
}

.menu-action strong { display: block; }

.menu-action strong {
  font-size: 12px;
  font-weight: 500;
}

.message-panel { padding-top: 60px; }

.message-panel h2,
.gesture-sheet h2 {
  margin: 18px 0 0;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(35px, 6vw, 52px);
  font-weight: 400;
  letter-spacing: -0.04em;
  line-height: 1.12;
}

em { color: var(--gold-light); font-style: normal; }

.message-swatch {
  width: 50px;
  height: 4px;
  margin-top: 35px;
  background: #bd4b43;
  box-shadow: 24px 0 #e8bd67, 48px 0 #afd7d3;
}

.message-panel p {
  max-width: 330px;
  margin: 24px 0 52px;
  color: rgba(245, 238, 225, 0.74);
  font-family: Georgia, "Songti SC", serif;
  font-size: 18px;
  line-height: 1.85;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(245, 238, 225, 0.45);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.message-line {
  flex: 1;
  height: 1px;
  background: var(--line);
}

.info-panel {
  position: absolute;
  inset: 0;
  z-index: 15;
  overflow-y: auto;
  background: #0e211d;
  pointer-events: none;
  transform: translateX(100%);
  transition: transform 320ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.info-panel.is-open {
  pointer-events: auto;
  transform: translateX(0);
}

.subpage-inner {
  min-height: 100%;
  padding-bottom: max(30px, env(safe-area-inset-bottom));
}

.subpage-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  min-height: 64px;
  padding: max(8px, env(safe-area-inset-top)) 20px 8px;
  border-bottom: 0;
  background: #0e211d;
  backdrop-filter: blur(14px);
}

.subpage-header h1 {
  margin: 0;
  text-align: center;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(22px, 6vw, 32px);
  font-weight: 400;
  line-height: 1.15;
}

.subpage-back {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--cream);
  cursor: pointer;
  font-size: 27px;
  font-weight: 200;
  line-height: 1;
}

.subpage-back:hover,
.subpage-back:focus-visible {
  color: var(--gold-light);
  outline: none;
}

.subpage-content {
  width: min(620px, calc(100% - 40px));
  margin: 0 auto;
  padding: 48px 0 64px;
}

.gesture-sheet .subpage-header {
  position: sticky;
  top: 0;
}

.gesture-sheet .subpage-content {
  padding-top: 34px;
}

.info-copy {
  margin: 0;
  color: rgba(245, 238, 225, 0.74);
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(17px, 4.5vw, 21px);
  line-height: 2;
  white-space: pre-line;
}

.tree-info-block {
  display: grid;
  justify-items: center;
  gap: 24px;
  margin-top: 4px;
}

.tree-info-qr {
  display: grid;
  justify-items: center;
  gap: 14px;
}

.qr-frame {
  display: grid;
  width: 188px;
  height: 188px;
  place-items: center;
  padding: 7px;
  border-radius: 5px;
  background: #f4eddf;
}

#space-qr {
  display: block;
  width: 174px;
  height: 174px;
}

.space-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid rgba(232, 189, 103, 0.32);
  border-radius: 5px;
  background: rgba(232, 189, 103, 0.05);
}

.space-id-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
  text-align: left;
}

.space-id-copy span {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.space-id-copy strong {
  overflow-wrap: anywhere;
  color: var(--gold-light);
  font-size: 13px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.copy-id-button,
.download-qr-button,
.feedback-submit {
  width: fit-content;
  padding: 8px 11px;
  border: 1px solid rgba(232, 189, 103, 0.48);
  border-radius: 4px;
  background: rgba(232, 189, 103, 0.08);
  color: var(--gold-light);
  cursor: pointer;
  font-size: 11px;
}

.download-qr-button {
  width: 188px;
}

.copy-id-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  border-color: transparent;
  background: transparent;
}

.copy-id-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.copy-id-button:hover,
.copy-id-button:focus-visible {
  border-color: transparent;
  background: transparent;
  color: var(--gold-light);
  outline: none;
}

.download-qr-button:hover,
.download-qr-button:focus-visible,
.feedback-submit:hover,
.feedback-submit:focus-visible {
  border-color: var(--gold-light);
  outline: none;
}

.feedback-form {
  display: grid;
  gap: 9px;
  margin-top: 36px;
}

.feedback-form label {
  color: var(--gold-light);
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(17px, 4.5vw, 21px);
  line-height: 2;
}

.feedback-form textarea {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  padding: 10px;
  border: 1px solid rgba(245, 238, 225, 0.18);
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.14);
  color: var(--cream);
  font: inherit;
  font-size: 12px;
  line-height: 1.6;
}

.feedback-form textarea:focus {
  border-color: rgba(232, 189, 103, 0.72);
  outline: none;
}

.feedback-state {
  min-height: 17px;
  margin: 0;
  color: var(--muted);
  font-size: 10px;
}

.info-panel[data-kind="about"] .info-copy {
  text-indent: 0;
}

.info-panel[data-kind="about"] .about-paragraph {
  display: block;
  margin: 0;
  text-indent: 2em;
}

.feedback-submit {
  justify-self: end;
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 3px;
  background: var(--gold);
  color: #18241a;
  font-size: 13px;
}

.gesture-page-content {
  padding-top: 34px;
}

.gesture-guide {
  display: grid;
  gap: 0;
  margin-top: 28px;
  border-top: 1px solid var(--line);
}

.gesture-guide p {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  margin: 0;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.gesture-guide strong {
  color: var(--gold-light);
  font-size: 13px;
  font-weight: 500;
}

.gesture-guide span {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.gesture-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 28px;
  padding: 16px;
  border: 1px solid rgba(232, 189, 103, 0.34);
  border-radius: 5px;
  background: rgba(232, 189, 103, 0.06);
  cursor: pointer;
}

.gesture-toggle > span:first-child {
  display: grid;
  gap: 5px;
}

.gesture-toggle strong {
  color: var(--gold-light);
  font-size: 14px;
  font-weight: 500;
}

.gesture-toggle small {
  color: var(--muted);
  font-size: 11px;
}

.gesture-toggle .gesture-description {
  color: rgba(245, 238, 225, 0.76);
  font-size: 12px;
}

.gesture-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.toggle-track {
  position: relative;
  display: block;
  width: 46px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 20px;
  background: rgba(245, 238, 225, 0.22);
  transition: 180ms ease;
}

.toggle-track > span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--cream);
  transition: 180ms ease;
}

.gesture-toggle input:checked + .toggle-track {
  background: var(--gold);
}

.gesture-toggle input:checked + .toggle-track > span {
  transform: translateX(20px);
  background: #0e211d;
}

.gesture-preview {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  height: 164px;
  margin: 0 -8px 36px;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.hand-mark {
  margin: 0 0 22px 15px;
  color: rgba(175, 215, 211, 0.72);
  font-size: 70px;
  transform: rotate(-20deg);
}

.preview-tree {
  position: relative;
  width: 150px;
  height: 150px;
  margin-right: 28px;
}

.preview-tree::before,
.preview-tree::after {
  position: absolute;
  left: 50%;
  border-style: solid;
  border-width: 0 43px 70px;
  border-color: transparent transparent rgba(54, 104, 67, 0.8);
  content: "";
  transform: translateX(-50%);
}

.preview-tree::before { top: 35px; }
.preview-tree::after {
  top: 63px;
  border-width: 0 57px 80px;
  border-color: transparent transparent rgba(38, 77, 52, 0.82);
}

.preview-tree i,
.preview-tree b {
  position: absolute;
  z-index: 1;
  display: block;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 16px rgba(232, 189, 103, 0.8);
}

.preview-tree i:nth-child(1) { top: 61px; left: 45px; }
.preview-tree i:nth-child(2) { top: 83px; left: 87px; background: #bd4b43; }
.preview-tree i:nth-child(3) { top: 113px; left: 56px; background: #afd7d3; }
.preview-tree i:nth-child(4) { top: 123px; left: 100px; }
.preview-tree b {
  top: 14px;
  left: 69px;
  width: auto;
  height: auto;
  background: transparent;
  box-shadow: none;
  color: var(--gold-light);
  font-size: 25px;
}

.toast {
  position: absolute;
  bottom: max(26px, env(safe-area-inset-bottom));
  left: 50%;
  z-index: 20;
  max-width: calc(100% - 40px);
  padding: 11px 15px;
  border: 1px solid rgba(232, 189, 103, 0.35);
  border-radius: 3px;
  background: rgba(7, 23, 19, 0.92);
  color: var(--gold-light);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 13px);
  transition: 220ms ease;
}

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

@media (max-width: 760px) {
  .experience { min-height: 620px; }
  .topbar { padding-right: 18px; padding-left: 18px; }
  .menu-button { width: 44px; height: 44px; }
  .menu-panel { right: 12px; }
  .message-panel { width: min(390px, 100%); }
  .subpage-header { padding-right: 14px; padding-left: 14px; }
  .subpage-content { width: min(100% - 36px, 620px); padding-top: 34px; }
  .tree-info-block { gap: 24px; }
  .qr-frame { width: 188px; height: 188px; }
  #space-qr { width: 174px; height: 174px; }
}
