:root {
  color-scheme: dark;
  --bg: #0b100f;
  --surface: #101715;
  --surface-soft: #16201c;
  --text: #edf0e7;
  --muted: #a4ada4;
  --dim: #65706a;
  --line: rgba(237, 240, 231, 0.13);
  --line-strong: rgba(237, 240, 231, 0.28);
  --accent: #bdd2bf;
  --accent-strong: #e6f0dc;
  --serif: "Noto Serif SC", "Songti SC", serif;
  --sans: "Noto Sans SC", "PingFang SC", sans-serif;
  --mono: "DM Mono", "SFMono-Regular", monospace;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  letter-spacing: 0;
  overflow-x: hidden;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  opacity: 0.13;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.24'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

button, a { font: inherit; }
button { color: inherit; }

.app-shell {
  position: relative;
  display: flex;
  min-height: 100svh;
  flex-direction: column;
  isolation: isolate;
}

.topbar,
.footer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 42px;
}

.topbar { position: relative; z-index: 5; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  color: var(--text);
  text-decoration: none;
}

.brand-glyph {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line-strong);
  color: var(--accent-strong);
  font-family: var(--serif);
  font-size: 22px;
}

.brand-copy { display: grid; gap: 3px; }
.brand-copy strong { font-size: 14px; font-weight: 600; }
.brand-copy small, .eyebrow, .dock-label, .readout-label, .page-index, .footer-bar, .intro-note {
  font-family: var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.brand-copy small { color: var(--dim); font-size: 9px; }

.top-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(189, 210, 191, 0.09);
}

.stage {
  position: relative;
  display: grid;
  width: min(1400px, 100%);
  min-height: 0;
  flex: 1;
  margin: 0 auto;
  padding: 22px 42px 30px;
  grid-template-columns: minmax(170px, 0.72fr) minmax(440px, 1.65fr) minmax(250px, 0.86fr);
  grid-template-rows: 1fr;
  gap: 20px;
}

.intro {
  align-self: center;
  max-width: 220px;
  padding-bottom: 18vh;
}

.eyebrow {
  margin: 0 0 22px;
  color: var(--dim);
  font-size: 10px;
}

h1 {
  margin: 0;
  color: var(--accent-strong);
  font-family: var(--serif);
  font-size: 64px;
  font-weight: 600;
  line-height: 1;
}

.intro-copy {
  max-width: 150px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

.intro-rule {
  width: 54px;
  height: 1px;
  margin: 34px 0 16px;
  background: var(--line-strong);
}

.intro-note { margin: 0; color: var(--dim); font-size: 10px; }

.scene-frame {
  position: relative;
  min-height: 510px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #171c18;
  box-shadow: inset 0 0 90px rgba(3, 6, 4, 0.36), 0 18px 50px rgba(0, 0, 0, 0.18);
}

.scene {
  position: absolute;
  inset: 0;
  cursor: default;
  touch-action: none;
}
.scene:has(canvas) { user-select: none; }
.scene.is-ink-ready { cursor: grab; }
.scene.is-ink-ready:active { cursor: grabbing; }
.scene canvas { display: block; width: 100%; height: 100%; }
.scene.is-fallback { display: grid; place-items: center; padding: 28px; }
.scene .fallback-canvas { width: min(100%, 440px); height: auto; aspect-ratio: auto; box-shadow: 0 22px 34px rgba(0, 0, 0, 0.28); }
.scene .fallback-canvas.is-video-frame { width: 100%; height: 100%; aspect-ratio: auto; box-shadow: none; }
.writing-video-source { display: none; }
.scene.is-fallback .writing-video-source.is-fallback-visible {
  display: block;
  width: min(100%, 640px);
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  box-shadow: 0 22px 34px rgba(0, 0, 0, 0.28);
}

.scene-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 110px rgba(2, 5, 4, 0.46);
}

.scene-corner {
  position: absolute;
  width: 24px;
  height: 24px;
  pointer-events: none;
  border-color: rgba(237, 240, 231, 0.4);
  border-style: solid;
}
.scene-corner--tl { top: 16px; left: 16px; border-width: 1px 0 0 1px; }
.scene-corner--br { right: 16px; bottom: 16px; border-width: 0 1px 1px 0; }

.stroke-readout {
  position: absolute;
  right: 22px;
  bottom: 20px;
  display: grid;
  gap: 6px;
  pointer-events: none;
  text-align: right;
}
.readout-label { color: var(--dim); font-size: 9px; }
.stroke-readout strong { color: var(--accent-strong); font-family: var(--mono); font-size: 12px; font-weight: 400; }
.scene-hint {
  position: absolute;
  bottom: 20px;
  left: 22px;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.04em;
}

.control-dock {
  display: flex;
  align-self: end;
  justify-content: flex-end;
  gap: 26px;
  padding-bottom: 18vh;
  flex-direction: column;
}

.dock-group { display: grid; gap: 13px; }
.dock-label { color: var(--dim); font-size: 9px; }
.dock-actions { display: flex; align-items: center; gap: 9px; }
.control-button {
  display: inline-flex;
  min-width: 104px;
  height: 42px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  background: rgba(16, 23, 21, 0.7);
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  white-space: nowrap;
  transition: border-color 180ms ease, background 180ms ease, color 180ms ease, opacity 180ms ease;
}
.control-button span:first-child { color: var(--accent); font-family: var(--mono); font-size: 15px; }
.control-button:hover:not(:disabled) { border-color: var(--accent); background: var(--surface-soft); color: var(--accent-strong); }
.control-button:disabled { cursor: not-allowed; opacity: 0.34; }
.icon-button,
.share-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  border: 1px solid var(--line-strong);
  background: rgba(16, 23, 21, 0.7);
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease, color 180ms ease;
}
.icon-button { width: 42px; color: var(--muted); font-size: 20px; }
.share-button { gap: 22px; padding: 0 15px; color: var(--accent-strong); font-size: 12px; white-space: nowrap; }
.icon-button:hover, .share-button:hover { border-color: var(--accent); background: var(--surface-soft); color: var(--accent-strong); }
.icon-button:focus-visible, .share-button:focus-visible, .control-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.page-index {
  position: absolute;
  right: 3px;
  top: 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--dim);
  font-size: 9px;
  transform: rotate(90deg) translateX(50%);
  transform-origin: right center;
}
.page-index-line { display: inline-block; width: 30px; height: 1px; background: var(--line); }

.footer-bar {
  position: relative;
  z-index: 5;
  padding-top: 12px;
  color: var(--dim);
  font-size: 9px;
}
.footer-bar a { color: var(--muted); text-decoration: none; }
.footer-bar a:hover { color: var(--accent-strong); }
.footer-links { display: flex; gap: 18px; }

.toast {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 20;
  max-width: 280px;
  padding: 12px 15px;
  border: 1px solid var(--line-strong);
  background: #151f1b;
  color: var(--accent-strong);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-content: center;
  gap: 18px;
  background: var(--bg);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
  transition: opacity 420ms ease, visibility 420ms ease;
}
.loading-screen.is-hidden { opacity: 0; visibility: hidden; }
.loading-mark { color: var(--accent-strong); font-family: var(--serif); font-size: 58px; }
.loading-track { width: 150px; height: 1px; overflow: hidden; background: var(--line); }
.loading-track span { display: block; width: 55%; height: 100%; background: var(--accent); animation: loading 1.2s ease-in-out infinite; }
@keyframes loading { 0% { transform: translateX(-100%); } 100% { transform: translateX(280%); } }

.noscript-message { padding: 40px; color: #fff; font-family: var(--sans); }

@media (max-width: 980px) {
  .topbar, .footer-bar { padding-right: 24px; padding-left: 24px; }
  .stage { padding-right: 24px; padding-left: 24px; grid-template-columns: 160px minmax(360px, 1fr); }
  .control-dock { grid-column: 1 / -1; grid-row: 2; align-items: center; justify-content: center; padding: 0; flex-direction: row; }
  .page-index { display: none; }
  .intro { padding-bottom: 8vh; }
}

@media (max-width: 680px) {
  .topbar { padding: 18px 18px; }
  .top-meta { font-size: 9px; }
  .brand-copy small { display: none; }
  .stage { display: flex; min-height: 0; padding: 15px 18px 20px; gap: 18px; flex-direction: column; }
  .intro { display: flex; align-items: baseline; max-width: none; padding: 0; gap: 14px; }
  .eyebrow { margin: 0; font-size: 9px; }
  h1 { font-size: 38px; }
  .intro-copy, .intro-rule, .intro-note { display: none; }
  .scene-frame { min-height: min(72svh, 610px); flex: 1; }
  .control-dock { justify-content: flex-end; width: 100%; gap: 12px; }
  .dock-actions { gap: 6px; }
  .control-button { min-width: 0; padding: 0 9px; }
  .share-button { gap: 11px; padding: 0 12px; }
  .footer-bar { align-items: flex-start; padding: 12px 18px 18px; gap: 7px; flex-direction: column; }
  .footer-links { gap: 10px; flex-wrap: wrap; }
  .scene-hint { bottom: 16px; left: 16px; font-size: 8px; }
  .stroke-readout { right: 16px; bottom: 16px; }
  .control-button { width: 42px; min-width: 42px; padding: 0; }
  .control-button span:last-child { display: none; }
  .control-button span:first-child { font-size: 16px; }
  .share-button { width: 42px; padding: 0; gap: 0; flex: 0 0 42px; }
  .share-button span:first-child { display: none; }
}

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