/* 布局:深夜的家。一列居中的故事页 + 顶部细工具栏;纸条与规则是纸张卡片,抹杀是红色印章。
   单一夜色世界(刻意不跟随系统浅色),真结局时整页过渡到早晨(:root.morning)。 */

@property --night { syntax: '<color>'; inherits: true; initial-value: #151a2c; }
@property --wall  { syntax: '<color>'; inherits: true; initial-value: #1e2439; }
@property --ink   { syntax: '<color>'; inherits: true; initial-value: #e9e3d3; }
@property --dim   { syntax: '<color>'; inherits: true; initial-value: #9095ab; }
@property --arrow { syntax: '<color>'; inherits: true; initial-value: #9ccaf2; }
@property --line  { syntax: '<color>'; inherits: true; initial-value: rgba(156, 202, 242, 0.22); }
@property --glow  { syntax: '<color>'; inherits: true; initial-value: rgba(255, 214, 150, 0.07); }

:root {
  --night: #151a2c;   /* 关了灯的房间 */
  --wall: #1e2439;    /* 按钮、锁的底 */
  --ink: #e9e3d3;     /* 台灯下的字 */
  --dim: #9095ab;     /* 次要文字 */
  --arrow: #9ccaf2;   /* 浅浅的蓝色箭头 */
  --line: rgba(156, 202, 242, 0.22);
  --glow: rgba(255, 214, 150, 0.07);
  --paper: #efe5cb;   /* 纸条、规则单(两种光线下都是纸) */
  --pencil: #2e2b33;  /* 纸上的铅笔字 */
  --seal: #c63b30;    /* 抹杀印章 */

  --font-display: "Ma Shan Zheng", "STKaiti", "KaiTi", serif;
  --font-body: "Noto Serif SC", "Songti SC", "SimSun", serif;
  --font-hand: "Long Cang", "STKaiti", "KaiTi", cursive;
  --font-ui: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;

  color-scheme: dark;
  transition: --night 2.6s ease, --wall 2.6s ease, --ink 2.6s ease, --dim 2.6s ease,
              --arrow 2.6s ease, --line 2.6s ease, --glow 2.6s ease;
}

/* 真结局:天亮了 */
:root.morning {
  --night: #e2ecf7;
  --wall: #f7fbff;
  --ink: #1f2f47;
  --dim: #5b6b84;
  --arrow: #2f6fb3;
  --line: rgba(47, 111, 179, 0.24);
  --glow: rgba(255, 196, 130, 0.55);
  color-scheme: light;
}

html { background: var(--night); }

body {
  margin: 0;
  min-height: 100vh;
  padding-inline: 16px;
  background:
    radial-gradient(ellipse 90% 55% at 50% -5%, var(--glow), transparent 70%),
    var(--night);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.9;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--arrow); outline-offset: 3px; }

/* ---------- 顶栏 ---------- */
.bar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-inline: -16px;
  padding: 0.55rem 16px;
  background: color-mix(in srgb, var(--night) 86%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  line-height: 1.4;
}
.bar-name { color: var(--dim); letter-spacing: 0.2em; }
.bar-gap { flex: 1; }
.bar-btn {
  padding: 0.35em 0.8em;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.bar-btn:hover { border-color: var(--arrow); }
.hint-btn { color: var(--arrow); }
.hint-btn b { font-variant-numeric: tabular-nums; margin-left: 0.15em; }
.bar-btn[aria-pressed="false"] { color: var(--dim); }
@media (max-width: 26rem) { .bar-name { display: none; } }

#screen {
  max-width: 34rem;
  margin-inline: auto;
  padding-block: 1.75rem 5rem;
}

/* ---------- 标题页 ---------- */
.title-screen { display: grid; gap: 1.5rem; padding-top: 6vh; }
.title-screen:has(.cover) { padding-top: 0; }
.cover { margin: 0; }
.cover img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: 4px;
  -webkit-mask-image: linear-gradient(#000 55%, transparent);
  mask-image: linear-gradient(#000 55%, transparent);
}
.cover + .game-title { position: relative; margin-top: -3.4rem; }
.game-title {
  display: grid;
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.05;
}
.t-main { font-size: clamp(3.4rem, 17vw, 5.4rem); letter-spacing: 0.04em; }
.t-sub { font-size: clamp(1.6rem, 7vw, 2.2rem); color: var(--arrow); padding-left: 0.15em; }
.byline, .tagline { margin: 0; }
.byline { font-family: var(--font-ui); font-size: 0.85rem; letter-spacing: 0.15em; color: var(--dim); }
.tagline { color: var(--ink); }
.menu { display: grid; gap: 0.6rem; max-width: 20rem; }

.collection h2, .check h2 {
  margin: 0 0 0.6rem;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--dim);
}
.endings {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.55rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.end-tile {
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0.3rem;
  border: 1px dashed var(--line);
  border-radius: 4px;
  color: var(--dim);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
}
.end-tile.death {
  border: 3px double var(--seal);
  color: var(--seal);
  font-family: var(--font-display);
  font-size: 1.05rem;
  transform: rotate(-4deg);
}
.end-tile.good {
  border: 2px solid var(--arrow);
  color: var(--arrow);
  font-family: var(--font-display);
  font-size: 1rem;
}

.check {
  padding: 0.8rem 1rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  line-height: 1.6;
}
.check.has-error { border-color: var(--seal); }
.check.has-error h2 { color: var(--seal); }
.check ul { margin: 0; padding-left: 1.2em; display: grid; gap: 0.35rem; }
.check .err { color: var(--ink); }
.check .warn { color: var(--dim); }
.fatal { padding: 1rem; border: 1px solid var(--seal); color: var(--ink); font-family: var(--font-ui); }

/* ---------- 按钮 ---------- */
.btn {
  padding: 0.75em 1.2em;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--wall);
  font-size: 1rem;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s;
}
.btn:hover { border-color: var(--arrow); }
.btn.primary { background: var(--arrow); border-color: var(--arrow); color: var(--night); font-weight: 600; }
.btn.ghost { background: transparent; }

/* ---------- 场景 ---------- */
.echo {
  margin: 0 0 1.4rem;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--dim);
}
.echo::before { content: "➜ "; color: var(--arrow); }

.line {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.line.in { opacity: 1; transform: none; }
.lines > * + * { margin-top: 0.85em; }
.narr, .say { margin: 0; }
.say { padding-left: 0.9em; border-left: 2px solid var(--line); }

.sys {
  display: flex;
  gap: 0.6em;
  margin: 0;
  color: var(--arrow);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  line-height: 1.75;
}
.sys-tag {
  flex: none;
  height: fit-content;
  margin-top: 0.3em;
  padding: 0 0.45em;
  border: 1px solid currentColor;
  border-radius: 2px;
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  line-height: 1.7;
}
.sys-text { min-width: 0; }
.sys.hint { padding: 0.5em 0.75em; border: 1px dashed var(--line); border-radius: 4px; }
.sys.error { color: var(--seal); }

.note {
  width: fit-content;
  max-width: 100%;
  padding: 0.55em 1.1em 0.65em;
  background:
    repeating-linear-gradient(transparent 0 1.45em, rgba(46, 43, 51, 0.08) 1.45em calc(1.45em + 1px)),
    var(--paper);
  color: var(--pencil);
  font-family: var(--font-hand);
  font-size: 1.7rem;
  line-height: 1.45;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.32);
  transform: translateY(6px) rotate(-1.5deg);
}
.note.in { transform: rotate(-1.5deg); }
.note p { margin: 0; }
.lines > .note { margin-block: 1.1em; }

/* 漫画格:印在纸上的一格画,和纸条同一种纸 */
.panel {
  margin: 0;
  padding: 6px;
  background: var(--paper);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
  transform: translateY(6px) rotate(-0.4deg);
}
.panel.in { transform: rotate(-0.4deg); }
.panel img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border: 2px solid var(--pencil);
  background: var(--wall);
}
.lines > .panel { margin-block: 0.2em 1.4em; }
.panel.missing, .cover.missing {
  padding: 1em;
  background: transparent;
  border: 1px dashed var(--seal);
  color: var(--seal);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  box-shadow: none;
}

.rules {
  position: relative;
  padding: 1.3em 1.2em 1em;
  background: var(--paper);
  color: var(--pencil);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
  line-height: 1.7;
}
.rules::before { /* 图钉 */
  content: "";
  position: absolute;
  top: 0.55em;
  left: 50%;
  width: 0.7em;
  height: 0.7em;
  margin-left: -0.35em;
  border-radius: 50%;
  background: var(--seal);
}
.rules-head {
  margin: 0.2em 0 0.6em;
  font-family: var(--font-display);
  font-size: 1.7rem;
  text-align: center;
  letter-spacing: 0.3em;
}
.rules-list { display: grid; gap: 0.55em; margin: 0; padding: 0; list-style: none; }
.rules-list li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.6em; }
.rule-label { color: var(--seal); font-weight: 600; white-space: nowrap; }
.rules-foot { margin: 0.9em 0 0; font-size: 0.9rem; text-align: center; color: var(--seal); }

/* ---------- 选项 ---------- */
.actions { display: grid; gap: 0.6rem; margin-top: 1.8rem; }
.actions > * { animation: rise 0.45s ease both; animation-delay: calc(var(--i, 0) * 90ms); }
.choice {
  display: flex;
  align-items: baseline;
  gap: 0.7em;
  width: 100%;
  padding: 0.85em 1em;
  background: var(--wall);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 1rem;
  line-height: 1.6;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s;
}
.choice:hover { border-color: var(--arrow); }
.choice-arrow { flex: none; color: var(--arrow); transition: transform 0.2s; }
.choice:hover .choice-arrow { transform: translateX(3px); }
.choice-text { min-width: 0; }

/* ---------- 密码锁 ---------- */
.lock {
  display: grid;
  justify-items: center;
  gap: 0.9rem;
  padding: 1.2rem 1rem 1rem;
  background: var(--wall);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.35rem; }
.slot {
  display: grid;
  place-items: center;
  width: 2.3rem;
  height: 2.9rem;
  border-radius: 4px;
  font-family: var(--font-hand);
  font-size: 1.9rem;
  line-height: 1;
}
.slot.fixed { background: var(--paper); color: var(--pencil); }
.slot.blank { border: 2px dashed var(--arrow); color: var(--ink); }
.slot.blank.cur { border-style: solid; }
.lock.ok .slot.blank { background: var(--arrow); border-style: solid; color: var(--night); }
.lock.bad .slots { animation: shake 0.38s; }
.keypad { display: grid; grid-template-columns: repeat(3, 4.2rem); gap: 0.45rem; }
.key {
  height: 3rem;
  background: var(--night);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--font-ui);
  font-size: 1.25rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.key:hover { border-color: var(--arrow); }
.key:active { transform: translateY(1px); }
.key.small { font-size: 0.9rem; }
.key.go { background: var(--arrow); border-color: var(--arrow); color: var(--night); }
.lock-msg { min-height: 1.6em; margin: 0; color: var(--dim); font-family: var(--font-ui); font-size: 0.9rem; text-align: center; }

/* ---------- 抹杀 / 结局 ---------- */
.death { display: grid; justify-items: center; gap: 0.4rem; padding-top: 1.2rem; text-align: center; }
.stamp {
  display: grid;
  place-items: center;
  width: 7.6rem;
  height: 7.6rem;
  border: 6px double var(--seal);
  border-radius: 8px;
  color: var(--seal);
  font-family: var(--font-display);
  font-size: 2.9rem;
  line-height: 1;
  transform: rotate(-8deg);
  opacity: 0.94;
  animation: stamp 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.25) 0.15s both;
}
.death-reason { margin: 1rem 0 0; font-size: 1.05rem; text-wrap: balance; }
.collect { margin: 0; color: var(--dim); font-family: var(--font-ui); font-size: 0.85rem; }
.end-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; }

.ending { display: grid; justify-items: center; gap: 0.3rem; padding-top: 1.4rem; text-align: center; }
.ending-kicker { margin: 0; color: var(--arrow); font-family: var(--font-ui); font-size: 0.85rem; letter-spacing: 0.4em; }
.ending-name {
  margin: 0.1em 0 0.2em;
  font-family: var(--font-display);
  font-size: clamp(2rem, 9vw, 2.6rem);
  font-weight: 400;
  line-height: 1.2;
  text-wrap: balance;
}
.next { margin: 0.6rem 0 0; color: var(--ink); font-size: 0.95rem; }

/* ---------- 浮层 ---------- */
.tap-hint {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  z-index: 4;
  transform: translateX(-50%);
  padding: 0.35em 1em;
  background: var(--wall);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--dim);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  white-space: nowrap;
  cursor: pointer;
}
.sheet {
  width: min(30rem, calc(100% - 32px));
  max-width: none;
  max-height: 86vh;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  overflow: visible;
}
.sheet::backdrop { background: rgba(6, 8, 16, 0.66); } /* ::backdrop 在部分浏览器拿不到 :root 变量,直接写色值 */
.sheet-card { display: grid; gap: 1rem; max-height: 86vh; overflow-y: auto; }

/* ---------- 动效 ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes stamp {
  from { opacity: 0; transform: rotate(-8deg) scale(2.4); }
  70% { opacity: 1; }
  to { opacity: 0.94; transform: rotate(-8deg) scale(1); }
}
@keyframes shake {
  0%, 100% { transform: none; }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}
.shake #screen { animation: shake 0.35s; }

@media (prefers-reduced-motion: reduce) {
  :root { transition: none; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .line { opacity: 1; transform: none; }
  .note { transform: rotate(-1.5deg); }
  .panel { transform: rotate(-0.4deg); }
}
