:root {
  color-scheme: light;
  --night: #344137;
  --paper: #fff8eb;
  --surface: #f5efe3;
  --muted: #64685c;
  --sage: #53654f;
  --sage-pressed: #465842;
  --gold: #d4bd8b;
  --line: #6a75633b;
  --serif: Georgia,"Times New Roman",serif;
  --sans: system-ui,-apple-system,"PingFang SC","Microsoft YaHei",sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--surface); color: var(--night); font-family: var(--sans); }
body { min-height: 100svh; }
button, input { font: inherit; }
button, a { touch-action: manipulation; }
button { cursor: pointer; color: inherit; }
a { color: inherit; text-decoration: none; }
#scene { position: fixed; inset: 0; z-index: 0; }
#scene canvas { display: block; width: 100%; height: 100%; touch-action: none; }
header, main, .tools, .hint, .toast, .loading { position: relative; z-index: 1; }
header { display: flex; align-items: center; justify-content: space-between; padding: 26px 5vw; }
.brand { display: flex; gap: 12px; align-items: center; font: 22px var(--serif); color: var(--sage); }
.home { padding: 8vh 0 120px 9vw; max-width: 660px; }
h1 { font: normal 2.25rem/1.12 var(--serif); margin: 26px 0; }
h1 em { font-weight: normal; color: #895f5c; }
.actions { display: flex; align-items: center; gap: 18px; margin-top: 34px; }
.primary, .secondary { border-radius: 4px; min-height: 48px; padding: 0 20px; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; gap: 14px; }
.primary { border: 0; background: var(--sage); color: var(--paper); font-weight: 600; }
.primary:hover { background: var(--sage-pressed); }
.primary:disabled { opacity: .45; }
.secondary { border: 1px solid #a8ac98; background: #fffaf0ed; color: var(--night); }
.secondary:hover { border-color: var(--sage); }
.muted { font-size: 11px; color: var(--muted); line-height: 1.9; }
.panel { position: relative; z-index: 1; width: min(430px,calc(100% - 32px)); margin: 5vh auto 30px; padding: 25px 28px; background: #f8f3e9f2; border: 1px solid var(--line); border-radius: 7px; backdrop-filter: blur(18px); }
h2 { font-size: 24px; font-weight: 500; }
.pairline { display: flex; gap: 22px; align-items: center; margin: 25px 0; }
#qr { width: 118px; height: 118px; background: var(--paper); padding: 8px; border-radius: 4px; flex: none; }
#qr svg { width: 100%; height: 100%; }
.pairline > div:last-child { display: flex; flex-direction: column; gap: 10px; }
.pairline small { color: var(--muted); font-size: 10px; }
.pairline strong { font-size: 23px; color: var(--sage); }
.status { color: var(--muted); font-size: 11px; }
.status.connected { color: #496542; }
.full { width: 100%; }
.tools { position: fixed; top: 12px; left: 12px; display: flex; gap: 7px; opacity: .3; }
.tools:hover { opacity: 1; }
.tools .secondary { min-height: 34px; padding: 0 12px; font-size: 10px; }
.hint { position: fixed; inset: 0; z-index: 3; background: #344137ed; color: var(--paper); display: grid; place-content: center; text-align: center; font-size: 20px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--paper); color: var(--night); padding: 12px 18px; border-radius: 4px; font-size: 12px; white-space: nowrap; }
.hidden { display: none !important; }
.loading { position: fixed; inset: 0; background: var(--surface); display: grid; place-content: center; text-align: center; color: var(--sage); font-size: 12px; }
.loading span { font-size: 36px; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .45; transform: scale(.95); } }
body.playing { overflow: hidden; background: #000; }
body.playing header { display: none; }
@media (max-width: 600px) {
  header { padding: 18px 20px; }
  .home { padding: 13vh 24px 80px; }
  .actions { align-items: flex-start; flex-direction: column; gap: 12px; }
  .panel { margin: 3vh auto; padding: 21px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .home { padding: 2vh 0 40px 8vw; }
  .home h1 { margin: 12px 0; }
  .home .actions { margin-top: 15px; flex-direction: row; }
  .panel { margin: 4px auto; padding: 12px 22px; }
  .pairline { margin: 10px 0; gap: 14px; }
  #qr { width: 86px; height: 86px; }
  .tools { opacity: .5; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.home .actions { flex-flow: row wrap; }
.home .actions button { min-width: 7rem; }
.pair-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.panel > button + button { margin-top: .5rem; }
#home-status:empty, #game-status:empty { display: none; }
.vr-choices { display: grid; gap: .5rem; margin-bottom: 1rem; }
.bluetooth-help { font-size: .875rem; line-height: 1.65; color: var(--muted); }
#bluetooth-status { margin-block: .75rem; font-size: .8125rem; }
#scene:focus { outline: none; }

.touch-play {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.touch-play [hidden] { display: none !important; }
.touch-menu, .touch-deck {
  position: absolute;
  inset-inline: max(.5rem, env(safe-area-inset-left)) max(.5rem, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: .5rem;
}
.touch-menu { top: max(.5rem, env(safe-area-inset-top)); }
.touch-deck {
  --direction-size: clamp(44px, 10vw, 56px);
  bottom: max(.5rem, env(safe-area-inset-bottom));
}
.touch-play button {
  pointer-events: auto;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.touch-play button:focus-visible { outline: 2px solid var(--paper); outline-offset: 2px; }
.touch-pad { text-align: center; }
.touch-directions {
  display: grid;
  grid-template-columns: repeat(3, var(--direction-size));
  gap: .25rem;
  user-select: none;
}
.touch-directions button {
  min-height: var(--direction-size);
  padding: 0;
  background: #344137e8;
  color: var(--paper);
  font-size: 1.375rem;
  touch-action: none;
}
.touch-directions button:first-child { grid-column: 2; }
.touch-directions button:nth-child(2) { grid-column: 1; }
.touch-directions .pressed { background: var(--gold); color: var(--night); }
.touch-label {
  display: inline-block;
  width: max-content;
  max-width: 100%;
  margin: 0 0 .25rem;
  padding: .25rem .5rem;
  border-radius: 4px;
  background: #344137e8;
  color: var(--paper);
  font-size: .8125rem;
  line-height: 1.4;
}
.touch-action { display: grid; justify-items: center; }
.touch-action button { min-width: 4.5rem; }

@media (max-width: 525px) {
  .touch-deck { display: grid; grid-template-columns: repeat(2, auto); }
  .touch-action { grid-area: 1 / 1 / 2 / -1; justify-self: center; }
}
@media (orientation: landscape) and (max-height: 430px) {
  .touch-deck { --direction-size: 44px; }
}

body[data-page="viewer"]:not(.playing)::after {
  content: '';
  position: fixed;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, #f6f0e5f5 0%, #f6f0e5e8 25%, #f6f0e548 71%, #f6f0e500 100%);
}
.home h1 { font-family: Georgia, "Songti SC", "Noto Serif CJK SC", SimSun, serif; font-size: 4.5rem; }
.home h1 em { font-style: normal; }
@media (max-width: 600px) { .home h1 { font-size: 2.6rem; } }
@media (orientation: landscape) and (max-height: 500px) { .home h1 { font-size: 3rem; } }

.room-content {
  width: min(29rem, calc(100% - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: clamp(1rem, 3.8vw, 2rem);
  border: 1px solid #d2c7b1;
  border-radius: .75rem;
  background: var(--paper);
  color: var(--night);
  color-scheme: light;
  box-shadow: 0 1.5rem 4rem #26332b66;
  overflow: auto;
}
.room-content::backdrop { background: #34413799; }
.room-content [hidden], .remote-target[hidden], .remote-target [hidden] { display: none !important; }
.room-content h2 { margin: 1rem 0 .5rem; font-size: 1.3rem; font-weight: 650; }
.room-content p { margin: .5rem 0; line-height: 1.85; white-space: pre-line; }
.room-content img { display: block; width: 100%; height: min(39vh, 15rem); object-fit: cover; border-radius: .35rem; }
.room-content .secondary {
  background: var(--surface);
  min-height: 44px;
  padding-inline: .8rem;
}
.room-content button:disabled { opacity: .46; cursor: default; }
.room-content button:focus-visible { outline: 2px solid var(--sage); outline-offset: 2px; }
.content-pages { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-top: .75rem; }
.content-pages span { font-size: .8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.eye-preview:disabled { opacity: .45; }
.tools { top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); }
.tools:focus-within { opacity: 1; }
.hint { gap: 1rem; }
.hint button { justify-self: center; }

.eye-guides { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
.eye-guide {
  position: absolute;
  top: 50%;
  left: calc(50% - var(--half-spacing));
  width: 1.75rem;
  height: 1.75rem;
  transform: translate(-50%, -50%);
  color: var(--gold);
  border: 2px solid currentColor;
  border-radius: 50%;
  filter: drop-shadow(0 0 2px #000);
}
.eye-guide + .eye-guide { left: calc(50% + var(--half-spacing)); }
.eye-guide::before, .eye-guide::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: currentColor;
}
.eye-guide::before { width: .75rem; height: 2px; }
.eye-guide::after { width: 2px; height: .75rem; }

.eye-calibration {
  position: fixed;
  z-index: 3;
  inset-inline: max(.5rem, env(safe-area-inset-left)) max(.5rem, env(safe-area-inset-right));
  bottom: max(.5rem, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .25rem .75rem;
  max-width: 33rem;
  margin-inline: auto;
  padding: .5rem .75rem;
  background: #344137f2;
  color: var(--paper);
  border: 1px solid #fff8eb52;
  border-radius: 7px;
}
.eye-reading {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .25rem .5rem;
  font-size: .875rem;
}
.eye-value { color: var(--gold); font-variant-numeric: tabular-nums; }
.eye-reading p { margin: 0 0 0 auto; color: #e2d8c5; font-size: .75rem; }
.eye-calibration input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  accent-color: var(--gold);
}
.eye-calibration-actions { display: flex; gap: .5rem; }
.eye-calibration button { min-height: 44px; padding-inline: .75rem; }
.eye-calibration :focus-visible { outline: 2px solid var(--paper); outline-offset: 2px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.remote { max-width: 34rem; margin: 1.5rem auto; padding: 0 1.25rem 2rem; }
.remote h1 { margin: 1.5rem 0; }
.remote form { margin: 1.5rem 0; }
.remote form label { font-size: .875rem; color: var(--muted); }
.joinline { display: flex; gap: .5rem; margin-top: .5rem; }
.joinline input {
  min-width: 0;
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fffcf5;
  color: var(--night);
  padding: .75rem;
  font-size: 1.125rem;
  text-transform: uppercase;
}

.remote-panel { border-top: 1px solid var(--line); padding-top: 1rem; }
.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(8rem, 1fr));
  gap: .5rem;
  padding: 1rem 0 .75rem;
}
.remote-zone {
  display: grid;
  place-content: center;
  gap: .2rem;
  min-height: 8rem;
  border: 1px solid #b4b8a4;
  border-radius: .75rem;
  background: #e8e7d9;
  color: var(--night);
  font: inherit;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  cursor: pointer;
}
.remote-zone > span { color: var(--sage); font-size: 2rem; line-height: 1; }
.remote-zone > strong { font-size: .875rem; font-weight: 650; }
.remote-zone:active:not(:disabled), .remote-zone.active:not(:disabled) {
  background: var(--sage);
  border-color: var(--sage);
  color: var(--paper);
  transform: translateY(1px);
}
.remote-zone:active:not(:disabled) > span, .remote-zone.active:not(:disabled) > span { color: var(--paper); }
.remote-instructions { margin: 0; color: var(--muted); font-size: .8125rem; line-height: 1.5; text-align: center; }
.remote-target {
  display: grid;
  gap: .25rem;
  border-top: 1px solid var(--line);
  padding: 1rem 0;
  color: var(--sage);
  text-align: center;
}
.remote-target strong { font-size: 1rem; }
.remote-target span { color: var(--muted); font-size: .8125rem; }
.remote button:disabled { cursor: default; }
.remote-zone:disabled, .remote-actions button:disabled { opacity: .5; }
.remote :focus-visible { outline: 2px solid var(--sage); outline-offset: 3px; }

@media (orientation: landscape) and (max-height: 500px) and (min-width: 620px) {
  .remote { max-width: 46rem; margin: .5rem auto; padding-bottom: 1rem; }
  .remote-panel { display: grid; grid-template-columns: minmax(0, 3fr) minmax(13rem, 2fr); gap: .75rem 1.5rem; }
  .controls { grid-column: 1; grid-row: 1 / 3; padding: 0; }
  .remote-target { grid-column: 2; grid-row: 1; border: 0; padding: 0; }
  .remote-actions { grid-column: 2; grid-row: 2; }
}
