:root {
  --bg-deep: #04060e;
  --ink: #eaf7ff;
  --ink-dim: rgba(228, 244, 255, 0.56);
  --ink-faint: rgba(228, 244, 255, 0.34);
  --accent: #4ef0c8;
  --accent-soft: rgba(78, 240, 200, 0.22);
  --panel: rgba(10, 18, 30, 0.44);
  --border: rgba(196, 236, 255, 0.15);
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  min-height: 100dvh;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  font-family: ui-sans-serif, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* ---------- backdrop ---------- */
.sky {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 80% at 50% 6%, rgba(30, 62, 112, 0.55) 0%, transparent 55%),
    radial-gradient(95% 70% at 12% 88%, var(--sky-a, rgba(9, 78, 78, 0.34)), transparent 62%),
    radial-gradient(100% 92% at 88% 72%, var(--sky-b, rgba(66, 36, 118, 0.34)), transparent 64%),
    linear-gradient(180deg, #05080f 0%, #04060e 55%, #02040a 100%);
  transition: background 1.8s ease;
}

#stage {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#stage.grabbing { cursor: grabbing; }

.grain {
  position: fixed;
  inset: -10%;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='3'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(62% 58% at 50% 44%, transparent 40%, rgba(0, 0, 0, 0.5) 100%);
}

/* ---------- top bar ---------- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(16px + env(safe-area-inset-top)) 18px 0;
  pointer-events: none;
  z-index: 3;
}

.brand { min-width: 0; }

.brand h1 {
  margin: 0;
  font-family: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "STSong", ui-serif, serif;
  font-size: 25px;
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: 0.22em;
  color: #f2fbff;
  text-shadow: 0 0 26px rgba(120, 240, 255, 0.35);
}

.latin {
  margin: 7px 0 0;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 9.5px;
  letter-spacing: 0.42em;
  color: var(--accent);
  opacity: 0.85;
}

.tag {
  margin: 9px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}

.tools {
  display: flex;
  gap: 8px;
  flex: none;
  pointer-events: auto;
}

.tool {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 15px;
  border: 1px solid var(--border);
  background: rgba(12, 20, 32, 0.42);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  color: rgba(232, 248, 255, 0.8);
  cursor: pointer;
  transition: color 0.25s, border-color 0.25s, background 0.25s, transform 0.2s;
}
.tool:hover { color: #fff; border-color: rgba(160, 240, 255, 0.4); }
.tool:active { transform: scale(0.94); }
.tool:focus-visible,
.bloom-close:focus-visible,
.sheet-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.tool svg { width: 20px; height: 20px; }
.tool .ic-off { display: none; }
.tool[aria-pressed="false"] .ic-on { display: none; }
.tool[aria-pressed="false"] .ic-off { display: block; }
.tool[aria-pressed="true"] { color: var(--accent); border-color: rgba(78, 240, 200, 0.36); background: rgba(14, 38, 38, 0.5); }
.tool-text {
  font-family: ui-serif, "Songti SC", serif;
  font-size: 17px;
  color: rgba(232, 248, 255, 0.72);
}

/* ---------- bottom hud ---------- */
.hud {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(430px, calc(100% - 36px));
  z-index: 3;
  pointer-events: none;
  text-align: center;
}

.chapter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--ink-dim);
}
.chapter .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
#chapter-name { color: rgba(236, 250, 255, 0.86); letter-spacing: 0.28em; }

.meter {
  margin: 11px auto 0;
  height: 3px;
  width: 100%;
  border-radius: 99px;
  background: rgba(190, 230, 255, 0.13);
  overflow: hidden;
}
.meter i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent-soft), var(--accent) 45%, #ffffff 100%);
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform 0.45s cubic-bezier(0.22, 0.9, 0.3, 1);
  box-shadow: 0 0 10px var(--accent);
}

.hint {
  margin: 13px 0 0;
  min-height: 15px;
  font-size: 11.5px;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  transition: opacity 0.5s, color 0.5s;
}
.hint.fade { opacity: 0; }

/* ---------- breath ---------- */
.breath-label {
  position: fixed;
  left: 50%;
  top: 24%;
  transform: translate(-50%, -50%);
  z-index: 2;
  font-family: "Songti SC", "Noto Serif CJK SC", ui-serif, serif;
  font-size: 15px;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: rgba(232, 250, 255, 0.55);
  pointer-events: none;
  transition: opacity 0.8s;
}
.breath-label[hidden] { display: none; }

/* ---------- bloom card ---------- */
.bloom {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(324px, calc(100% - 44px));
  padding: 26px 24px 22px;
  z-index: 6;
  border-radius: 26px;
  border: 1px solid rgba(180, 240, 255, 0.2);
  background: linear-gradient(165deg, rgba(16, 28, 44, 0.9), rgba(8, 14, 26, 0.92));
  backdrop-filter: blur(22px) saturate(1.25);
  -webkit-backdrop-filter: blur(22px) saturate(1.25);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 60px var(--accent-soft) inset;
  text-align: center;
  animation: bloomIn 0.62s cubic-bezier(0.16, 1, 0.3, 1);
}
.bloom[hidden] { display: none; }
@keyframes bloomIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.92); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.bloom-kicker {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--accent);
}
.bloom-line {
  margin: 16px 0 22px;
  font-family: "Songti SC", "Noto Serif CJK SC", "STSong", ui-serif, serif;
  font-size: 17px;
  line-height: 1.95;
  letter-spacing: 0.08em;
  color: #f0fbff;
}
.bloom-close {
  width: 100%;
  min-height: 46px;
  border-radius: 15px;
  border: 1px solid rgba(160, 240, 255, 0.28);
  background: rgba(120, 240, 255, 0.1);
  color: #eafcff;
  font-size: 13px;
  letter-spacing: 0.18em;
  cursor: pointer;
  transition: background 0.25s, transform 0.2s;
}
.bloom-close:hover { background: rgba(120, 240, 255, 0.18); }
.bloom-close:active { transform: scale(0.98); }

/* ---------- help sheet ---------- */
.sheet {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(430px, calc(100% - 32px));
  max-height: min(72vh, 560px);
  overflow-y: auto;
  z-index: 7;
  padding: 20px 22px 18px;
  border-radius: 24px;
  border: 1px solid rgba(180, 240, 255, 0.18);
  background: linear-gradient(170deg, rgba(14, 24, 38, 0.94), rgba(6, 12, 22, 0.96));
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.6);
  animation: sheetIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.sheet[hidden] { display: none; }
@keyframes sheetIn {
  from { opacity: 0; transform: translate(-50%, 14px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.sheet-head h2 {
  margin: 0;
  font-family: "Songti SC", "Noto Serif CJK SC", ui-serif, serif;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.24em;
}
.sheet-close {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(232, 248, 255, 0.8);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.sheet-list {
  margin: 14px 0 12px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}
.sheet-list li {
  position: relative;
  padding-left: 15px;
  font-size: 12.5px;
  line-height: 1.7;
  color: rgba(226, 242, 255, 0.66);
}
.sheet-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  opacity: 0.8;
}
.sheet-list b { color: rgba(240, 253, 255, 0.92); font-weight: 500; }
.sheet-foot {
  margin: 0;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: rgba(200, 226, 240, 0.34);
}

@media (min-width: 720px) {
  .topbar { padding: calc(26px + env(safe-area-inset-top)) 30px 0; }
  .brand h1 { font-size: 29px; }
  .tag { font-size: 12.5px; }
  .hud { bottom: calc(26px + env(safe-area-inset-bottom)); }
  .breath-label { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  .bloom, .sheet { animation: none; }
  .meter i, .sky { transition-duration: 0.01s; }
}
