/* 《海液》 —— anemoia.ink
   夜海（默认）/ 纸白 双主题；通道呈现：内心＝默认（凡非他人发言/外界信息/回忆皆是，「旁白」不存在）/
   海声 / 他人发言 / 主角发言 / 回忆话语 / 手机信息 / 信息流；
   「显影」为无楷体系统的可读性回退（三下划线，不波及气泡）。 */

:root {
  --bg: #0a0f14;
  --bg-hi: #0c1219;   /* 海水纵深：顶部微亮、底部更沉，渐变铺在固定层 body::before */
  --bg-lo: #080d12;
  --text: #d8dee6;
  --sea: #9fc4d8;
  --sea-strong: #c6e2f2;
  --inner: #dcbf9d;   /* 内心荧光笔：仅 .lit 高亮联动底色；内心戏正文本身不上色 */
  --msg: #8fa0ad;
  --dim: #5f7181;        /* 暗石板色：供设置行 */
  --rule: #22303b;
  /* 气泡 */
  --bubble-say-bg: #141d26;
  --bubble-say-border: #26333f;
  --bubble-own-bg: #262019;
  --bubble-recall-bg: rgba(20, 29, 38, .55);
  --im-thread-bg: #0d141b;
  --im-in-bg: #182330;
  --im-out-bg: #251f18;
  --bubble-shadow: 0 1px 8px rgba(0, 0, 0, .25);  /* 极轻统一光源 */
  --note-shadow: 0 6px 18px rgba(0, 0, 0, .35);   /* 浮现卡片：浮出层用更重的投影 */
  /* 说话人配色（他人发言气泡按人着色） */
  --sp-man-bg: #2a2118;     --sp-man-border: #4a3a26;
  --sp-girl-bg: #201f2c;    --sp-girl-border: #3f3a58;
  --sp-sis-bg: #122627;     --sp-sis-border: #24504f;
  --sp-machine-bg: #1a2026; --sp-machine-border: #333d46;
  --sp-mom-bg: #2b1d1c;     --sp-mom-border: #4e332f;
  /* 可点词条：暗示强度旋钮（作者可拨；0 = 纯阈下模式） */
  --term-hint-opacity: .25;
}

html[data-theme="paper"] {
  --bg: #f5f2ea;
  --bg-hi: #f8f5ee;
  --bg-lo: #f0ebdd;
  --text: #1c1c1c;
  --sea: #1d4e79;
  --sea-strong: #0e3a63;
  --inner: #7a5230;
  --msg: #70747c;
  --dim: #8f8877;
  --rule: #d9d2c0;
  --bubble-say-bg: #ece7da;
  --bubble-say-border: #d8d2c2;
  --bubble-own-bg: #efe6d4;
  --bubble-recall-bg: rgba(236, 231, 218, .5);
  --im-thread-bg: #f0ece1;
  --im-in-bg: #e4ddcc;
  --im-out-bg: #f8f0dd;
  --bubble-shadow: 0 1px 8px rgba(96, 80, 50, .12);
  --note-shadow: 0 6px 18px rgba(96, 80, 50, .18);
  /* 说话人配色（纸白） */
  --sp-man-bg: #ede3cf;     --sp-man-border: #d9c7a4;
  --sp-girl-bg: #e7e3f0;    --sp-girl-border: #cfc8e2;
  --sp-sis-bg: #dbebe8;     --sp-sis-border: #b5d3cc;
  --sp-machine-bg: #e8e6df; --sp-machine-border: #cfccbe;
  --sp-mom-bg: #f1ddd6;     --sp-mom-border: #dfc0b6;
}

/* 字号三档：小 / 中 / 大 */
html.fs-0 { --fs: 16px; }
html.fs-1 { --fs: 19px; }
html.fs-2 { --fs: 22px; }

@media (max-width: 640px) {
  html.fs-0 { --fs: 15px; }
  html.fs-1 { --fs: 18px; }
  html.fs-2 { --fs: 21px; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", serif;
  font-size: var(--fs);
  transition: background-color .35s ease, color .35s ease;
  /* 整页禁选：快速连点推进时防止误划选正文（作者指令，防误触、非版权保护）；错误卡仍可复制 */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#error, #error * {
  -webkit-user-select: text;
  user-select: text;
}

/* 海水纵深：极淡的垂直渐变铺在固定层，正文浮于其上 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, var(--bg-hi), var(--bg-lo));
}

/* 细滚动条与选区（整页禁选下实际只有错误卡可选中） */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

::selection { background: color-mix(in srgb, var(--sea) 28%, transparent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- 固定件：设置行（左上）与时钟（右上） ---------- */

#settings {
  position: fixed;
  top: 1em;
  left: 1.2em;
  z-index: 20;
  display: flex;
  gap: 1.2em;
  font-size: 12px;
  letter-spacing: .1em;
}

#clock {
  position: fixed;
  top: 1em;
  right: 1.2em;
  z-index: 20;
  font-size: 12px;
  letter-spacing: .14em;
  color: var(--dim);
  white-space: nowrap;
}

#settings button {
  appearance: none;
  background: none;
  border: 0;
  padding: .2em 0;
  font: inherit;
  letter-spacing: inherit;
  color: var(--dim);
  cursor: pointer;
  transition: color .2s ease;
}

#settings button:hover,
#settings button:focus-visible { color: var(--text); }

#settings button[aria-pressed="true"] {
  color: var(--text);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: .35em;
}

button.choice:focus-visible,
.title-actions button:focus-visible,
#settings button:focus-visible {
  outline: 1px dashed var(--dim);
  outline-offset: 3px;
}

/* ---------- 标题屏 ---------- */

#title {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3em 1.5em;
}

#title h1 {
  margin: 0 0 1.1em;
  font-size: clamp(3em, 12vw, 5em);
  font-weight: 600;
  letter-spacing: .38em;
  text-indent: .38em; /* 抵消末字字距，保持视觉居中 */
}

#title .rule {
  width: 5.5em;
  height: 1px;
  border: 0;
  margin: 0 0 1.6em;
  background: var(--rule);
}

#title .tagline {
  margin: 0 0 3.5em;
  color: var(--dim);
  font-size: .95em;
  letter-spacing: .18em;
}

.title-actions { display: flex; flex-direction: column; gap: 1em; }

/* 入场渐次显影：题名收字距、分隔线展开、标语与动作延迟淡入（一次性；reduced-motion 直接落定终态） */
#title h1 { animation: title-in 1.1s ease-out both; }

#title .rule {
  transform-origin: center;
  animation: rule-in .8s ease .35s both;
}

#title .tagline { animation: fade-in .9s ease .6s both; }
#title .title-actions { animation: fade-in .9s ease .8s both; }

@keyframes title-in {
  from { opacity: 0; letter-spacing: .5em; text-indent: .5em; }
}

@keyframes rule-in {
  from { transform: scaleX(0); }
}

@keyframes fade-in {
  from { opacity: 0; }
}

/* ---------- 选项与标题动作（当前全文零选项，机制为未来预留） ---------- */

.title-actions button,
button.choice {
  appearance: none;
  background: none;
  border: 0;
  padding: .1em 0;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  opacity: .42;
  transition: opacity .25s ease;
}

.title-actions button { letter-spacing: .22em; }

.title-actions button:hover,
.title-actions button:focus-visible,
button.choice:hover,
button.choice:focus-visible { opacity: 1; }

/* 选项只活在内心声部：与内心戏同款呈现（默认色，不加 tint） */

/* ---------- 阅读流：只涨不退的潮 ---------- */

#reading { min-height: 100vh; }

#flow {
  max-width: 36em;
  margin: 0 auto;
  padding: 4em 1.5em 45vh; /* 底部留白，让新段落永远有落潮的空气 */
}

#flow p {
  margin: 0 0 1.5em;
  line-height: 2;
  text-align: justify;
  line-break: strict;
  hanging-punctuation: first;
  overflow-wrap: break-word;
}

/* 内心戏＝默认通道：不加色、不改字体字号，整行居中（通道类由渲染层挂段落）。海声同归居中 */
#flow p.inner,
#flow p.sea { text-align: center; }

/* 落潮：段落/章头/线程浮现即入潮。只写 from，落定值交还元素本身（recall 的 .8 半透明不会被顶回 1） */
#flow > *,
#flow p {
  animation: tide-in .7s cubic-bezier(.25, .6, .3, 1) both;
}

/* 存档批量恢复时禁用入场动画，避免整卷重播 */
#flow.no-anim * { animation: none; }

@keyframes tide-in {
  from { opacity: 0; transform: translateY(.7em); }
}

/* 海声：楷体 + 色温偏移 */
.sea {
  font-family: "Kaiti SC", "STKaiti", "KaiTi", "DFKai-SB", serif;
  color: var(--sea);
}

/* 外部信息／屏幕文本：屏灰，宋体不变 */
.msg { color: var(--msg); }

/* 显影：三通道不同下划线（楷体／色彩降级可辨；不波及气泡通道） */
html.reveal .sea {
  color: var(--sea-strong);
  text-decoration: underline;
  text-decoration-style: solid;
  text-decoration-thickness: 1px;
  text-underline-offset: .32em;
}

html.reveal .inner {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-thickness: 1px;
  text-underline-offset: .32em;
}

html.reveal .msg {
  color: var(--msg);
  text-decoration: underline;
  text-decoration-style: dashed;
  text-decoration-thickness: 1px;
  text-underline-offset: .32em;
}

/* …… 六点省略号永不跨行折断（气泡内同样生效） */
.ell { white-space: nowrap; }

/* ---------- 可点词条：顶标（ruby 注本）与浮现（卡片） ---------- */

.term {
  cursor: help;
  border-bottom: 1px dotted currentColor;
  border-bottom-color: color-mix(in srgb, currentColor calc(var(--term-hint-opacity) * 100%), transparent);
  transition: border-bottom-color .3s ease;
}

.term:hover,
.term:focus {
  border-bottom-color: currentColor; /* hover/focus 满显示 */
  outline: none;
}

.term rt {
  font-size: .6em;
  letter-spacing: .05em;
  color: var(--dim);
}

.note-card {
  position: absolute;
  z-index: 50;
  max-width: 22em;
  padding: .6em .8em;
  font-size: .85em;
  line-height: 1.8;
  text-align: left;
  background: var(--bubble-say-bg);
  border: 1px solid var(--bubble-say-border);
  border-radius: 8px;
  box-shadow: var(--note-shadow);
  cursor: default;
  transition: background-color .35s ease, border-color .35s ease, box-shadow .35s ease;
}

/* 高亮联动：inner 暖色荧光笔底；入场 1.2s 呼吸脉冲后落定为静态（reduced-motion 直接静态） */
.lit {
  background: color-mix(in srgb, var(--inner) 32%, transparent);
  border-radius: 2px;
  padding: 0 .05em;
  animation: lit-pulse 1.2s ease-out 1;
}

@keyframes lit-pulse {
  0% { background: color-mix(in srgb, var(--inner) 55%, transparent); }
  100% { background: color-mix(in srgb, var(--inner) 32%, transparent); }
}

/* ---------- 会话气泡：say / own / recall ---------- */

#flow p.say,
#flow p.own,
#flow p.recall {
  width: fit-content;
  max-width: 78%;
  padding: .55em .9em;
  line-height: 1.9;
  text-align: left;
  box-shadow: var(--bubble-shadow);
  transition: background-color .35s ease, border-color .35s ease, box-shadow .35s ease;
}

#flow p.say {
  margin-right: auto;
  background: var(--bubble-say-bg);
  border: 1px solid var(--bubble-say-border);
  border-radius: 10px 10px 10px 2px;
}

#flow p.own {
  margin-left: auto;
  background: var(--bubble-own-bg);
  border-radius: 10px 10px 2px 10px;
}

/* 回忆：虚线、半透明、文字整体调暗一档（记忆降级） */
#flow p.recall {
  margin-right: auto;
  background: var(--bubble-recall-bg);
  border: 1.5px dashed var(--bubble-say-border);
  border-radius: 10px 10px 10px 2px;
  opacity: .8;
}

/* ---------- 手机聊天线程：im-in / im-out ---------- */

/* 说话人配色：他人发言气泡按人着色（底色/边框，文字色不变）；无说话人标识时用通道底色 */
#flow p.say.sp-man     { background: var(--sp-man-bg);     border-color: var(--sp-man-border); }
#flow p.say.sp-girl    { background: var(--sp-girl-bg);    border-color: var(--sp-girl-border); }
#flow p.say.sp-sis     { background: var(--sp-sis-bg);     border-color: var(--sp-sis-border); }
#flow p.say.sp-machine { background: var(--sp-machine-bg); border-color: var(--sp-machine-border); }
#flow p.say.sp-mom     { background: var(--sp-mom-bg);     border-color: var(--sp-mom-border); }

.im-thread {
  width: min(78%, 30em);
  margin: 0 auto 1.5em;
  padding: .7em .8em;
  border-radius: 12px;
  background: var(--im-thread-bg);
  box-shadow: var(--bubble-shadow);
  transition: background-color .35s ease, box-shadow .35s ease;
}

.im-thread p {
  width: fit-content;
  max-width: 100%;
  margin: 0 0 .35em;
  padding: .35em .7em;
  font-size: .95em;
  line-height: 1.9;
  text-align: left;
  border-radius: 10px;
  transition: background-color .35s ease;
}

.im-thread p:last-child { margin-bottom: 0; }

#flow p.im-in { margin-right: auto; background: var(--im-in-bg); }
#flow p.im-out { margin-left: auto; background: var(--im-out-bg); }

/* ---------- 信息流分组：连续 msg 成组（feed 块感） ---------- */

.msg-group { margin: 0 0 1.5em; }

.msg-group p { margin: 0 0 .25em; }
.msg-group p:last-child { margin-bottom: 0; }

/* ---------- 章头：新的潮带 ---------- */

header.chapter {
  margin: 5.5em 0 3.5em;
  text-align: center;
}

header.chapter span {
  font-size: 1.55em;
  letter-spacing: .2em;
  opacity: .88;
}

/* ---------- 结局屏 ---------- */

p.endline {
  text-align: center;
  letter-spacing: .14em;
  margin: 2.4em 0;
}

.restart-wrap {
  text-align: center;
  margin: 3.5em 0 10vh;
}

.restart-wrap .choice {
  display: inline-block;
  width: auto;
}

/* 移动端：气泡放宽到 85% */
@media (max-width: 640px) {
  #flow p.say, #flow p.own, #flow p.recall { max-width: 85%; }
  .im-thread { width: 85%; }
}

/* ---------- 错误卡（.ink 编译错误直接可读） ---------- */

#error {
  max-width: 42em;
  margin: 18vh auto;
  padding: 1.6em 2em;
  border: 1px solid var(--rule);
}

#error .error-title { margin: 0 0 .8em; font-size: 1.1em; letter-spacing: .08em; }

#error pre {
  margin: 0;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.9;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--dim);
}
