:root {
  --paper: #fbf3e2;
  --ink: #221c24;
  --red: #d8432a;
  --muted: #6b5f5a;
  --kai: "KaiTi", "STKaiti", "Kaiti SC", "楷体", "Noto Serif SC", serif;
  --sans: "Microsoft YaHei UI", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  --edge: max(14px, env(safe-area-inset-left));
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #f4d9b8;
  color: var(--ink);
  font-family: var(--sans);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
}

.title, .stats, .scroll, .controls { position: fixed; z-index: 2; pointer-events: none; }

/* 竖排标题，像挂在山水画角上的题款 */
.title {
  top: max(16px, env(safe-area-inset-top));
  left: var(--edge);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.title h1 {
  writing-mode: vertical-rl;
  font-family: var(--kai);
  font-size: clamp(30px, 5.4vmin, 46px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: .08em;
  padding: 12px 7px;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
}

.seal {
  width: 42px;
  padding: 4px 0;
  font-family: var(--kai);
  font-size: 16px;
  line-height: 1.1;
  text-align: center;
  color: var(--paper);
  background: var(--red);
  border-radius: 4px;
}

.stats {
  top: max(16px, env(safe-area-inset-top));
  right: var(--edge);
  display: grid;
  grid-template-columns: repeat(4, auto);
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
}

.stats > div {
  min-width: 76px;
  padding: 7px 12px 8px;
  border-left: 1px solid rgba(34, 28, 36, .28);
}

.stats > div:first-child { border-left: 0; }

.stats dt { font-size: 12px; color: var(--muted); }

.stats dd {
  font-family: var(--kai);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.stats small {
  margin-left: 3px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
}

.stats .rank dd { color: var(--red); }

/* 每次开悟垂下来的一张字条 */
.scroll {
  top: 104px;
  right: calc(var(--edge) + 8px);
  max-height: calc(100dvh - 190px);
  padding: 18px 12px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  transform: translateY(-16px);
  opacity: 0;
  visibility: hidden;
  transition: transform .28s cubic-bezier(.2, .9, .3, 1.2), opacity .2s, visibility 0s .28s;
}

.scroll.show {
  transform: none;
  opacity: 1;
  visibility: visible;
  transition: transform .28s cubic-bezier(.2, .9, .3, 1.2), opacity .2s;
}

.scroll p {
  writing-mode: vertical-rl;
  max-height: min(340px, calc(100dvh - 270px));
  font-family: var(--kai);
  font-size: 25px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: .06em;
}

.scroll.big { background: var(--red); color: var(--paper); }
.scroll.big p { font-size: 34px; }
.scroll.big .scroll-seal { background: var(--paper); color: var(--red); }
.scroll.gold { background: #f7cb4d; }

.scroll-seal {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  font-family: var(--kai);
  font-size: 18px;
  color: var(--paper);
  background: var(--red);
  border-radius: 3px;
}

.controls {
  left: var(--edge);
  right: var(--edge);
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hint {
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.4;
  background: var(--paper);
  border: 2px solid var(--ink);
  transition: opacity .6s;
}

.hint.done { opacity: 0; }

.buttons { display: flex; gap: 8px; margin-left: auto; flex: none; }

button {
  min-width: 72px;
  min-height: 44px;
  padding: 0 14px;
  font: 700 17px var(--kai);
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

#bell { color: var(--paper); background: var(--red); }

button:active { transform: translate(3px, 3px); box-shadow: none; }

button:focus-visible { outline: 3px solid #2b6cb0; outline-offset: 2px; }

.noscript {
  position: fixed;
  inset: 40% 20px auto;
  z-index: 3;
  padding: 16px;
  text-align: center;
  background: var(--paper);
  border: 2px solid var(--ink);
}

@media (max-width: 620px) {
  .stats { grid-template-columns: repeat(2, auto); }
  .stats > div { min-width: 70px; padding: 5px 9px 6px; }
  .stats > div:nth-child(3) { border-left: 0; }
  .stats > div:nth-child(n + 3) { border-top: 1px solid rgba(34, 28, 36, .28); }
  .stats dd { font-size: 20px; }
  .stats .rank dd { font-size: 16px; line-height: 23px; }
  .scroll { top: 132px; }
  .scroll p { font-size: 21px; }
  .scroll.big p { font-size: 28px; }
  .hint { font-size: 12px; padding: 6px 8px; }
  button { min-width: 62px; padding: 0 8px; font-size: 15px; }
}

@media (max-height: 460px) {
  .title h1 { font-size: 24px; padding: 8px 5px; }
  .seal { display: none; }
  .scroll { top: 72px; max-height: calc(100dvh - 140px); padding: 10px 8px; gap: 6px; }
  .scroll p { font-size: 18px; max-height: calc(100dvh - 190px); }
  .scroll.big p { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .scroll, .scroll.show { transform: none; transition: opacity .2s, visibility 0s; }
  .hint { transition: none; }
}
