/*
 * incense · 样式
 *
 * 两套主题只是换一组变量：暗室微光（默认）/ 极简留白。
 * 纸白 #eeece3、橄榄 #52634e、旧金 #988762、深墨 #24251f —— 沿用 sansa-local 的那组颜色，
 * 但这里的分工是反的：纸不是背景板，而是"暗室之外"的另一种可能。
 * 文字对比度全部 >= 4.5:1（正文与说明文字分别 7.6:1 / 5.6:1 上下）。
 */

:root {
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --serif: "Songti SC", "STSong", "SimSun", "Noto Serif SC", Georgia, serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

body[data-theme="dark"] {
  --bg: #141612;
  --ink: #efeee6;
  --ink-2: #cdd0c4;
  --muted: #a9ac9e;
  --line: rgba(239, 238, 230, .17);
  --line-soft: rgba(239, 238, 230, .09);
  --focus: #d8c08a;
  --chip-bg: rgba(239, 238, 230, .05);
  --chip-on: rgba(239, 238, 230, .15);
}

body[data-theme="paper"] {
  --bg: #e2dfd3;
  --ink: #24251f;
  --ink-2: #333630;
  --muted: #565c4f;
  --line: rgba(36, 37, 31, .22);
  --line-soft: rgba(36, 37, 31, .11);
  --focus: #6d5c3d;
  --chip-bg: rgba(36, 37, 31, .04);
  --chip-on: rgba(36, 37, 31, .11);
}

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

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .9s ease, color .9s ease;
}

button { font: inherit; color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- 画布 ---------- */

#altar {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
}

/* 一点纸/布的颗粒，让纯色不那么"数字化"。只是 1px 的点阵，很便宜 */
.grain {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: .13;
  mix-blend-mode: overlay;
  background-image: radial-gradient(rgba(255, 255, 255, .9) .5px, transparent .6px);
  background-size: 3px 3px;
}

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

.masthead {
  position: fixed;
  left: 0; right: 0;
  top: calc(var(--safe-t) + clamp(18px, 6.5vh, 68px));
  text-align: center;
  pointer-events: none;
  z-index: 2;
}

.title {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(17px, 2.1vw, 22px);
  font-weight: 400;
  letter-spacing: .42em;
  text-indent: .42em;
  color: var(--ink);
}

.dek {
  margin: .95em 0 0;
  font-size: 11.5px;
  font-weight: 400;
  letter-spacing: .22em;
  text-indent: .22em;
  color: var(--muted);
}

/* ---------- 香与炉 ---------- */

.stage {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 3;
}

/*
 * 点香的热区。盖住香头到炉身，本身透明；
 * 尺寸全部由 canvas 算出来的 CSS 变量驱动，所以它永远跟画面严丝合缝。
 */
.ignite {
  position: absolute;
  left: var(--censer-x, 50%);
  top: calc(var(--stick-top, 40%) - 26px);
  width: calc(var(--censer-w, 240px) + 116px);
  height: calc(var(--censer-y, 70%) + var(--censer-h, 120px) - var(--stick-top, 40%) + 78px);
  transform: translateX(-50%);
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 46% 46% 40% 40% / 38% 38% 52% 52%;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.ignite:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.readout {
  position: absolute;
  left: 0; right: 0;
  top: calc(var(--censer-y, 70%) + var(--censer-h, 120px) + 18px);
  margin: 0;
  text-align: center;
  font-size: 11px;
  letter-spacing: .28em;
  text-indent: .28em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.wish-echo,
.hint {
  position: absolute;
  left: 50%;
  top: calc(var(--censer-y, 70%) + var(--censer-h, 120px) + 44px);
  transform: translateX(-50%);
  margin: 0;
  width: min(440px, 74vw);
  text-align: center;
  z-index: 3;
}

.hint {
  position: fixed;
  font-size: 11px;
  letter-spacing: .2em;
  text-indent: .2em;
  color: var(--muted);
  pointer-events: none;
  transition: opacity 1.4s ease;
}

.hint.is-gone { opacity: 0; }

.wish-echo {
  font-family: var(--serif);
  font-size: 12.5px;
  line-height: 1.75;
  letter-spacing: .16em;
  color: var(--ink-2);
  opacity: .78;
  pointer-events: none;
  /* 香烧完时，这句话跟着烟慢慢散掉 */
  transition: opacity 11s ease, letter-spacing 11s ease;
}

.wish-echo.is-gone {
  opacity: 0;
  letter-spacing: .46em;
}

/* ---------- 底部控制条 ---------- */

.console {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 14px);
  transform: translateX(-50%);
  width: min(600px, calc(100% - 24px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 4;
}

.row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.row-quiet { gap: 8px; }

.group {
  display: flex;
  gap: 4px;
}

.sep {
  width: 1px;
  height: 13px;
  background: var(--line-soft);
  margin: 0 2px;
}

.chip {
  appearance: none;
  height: 26px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--ink-2);
  font-size: 11.5px;
  letter-spacing: .14em;
  text-indent: .14em;
  cursor: pointer;
  transition: background-color .3s ease, color .3s ease, border-color .3s ease;
  -webkit-tap-highlight-color: transparent;
}

.chip:hover { border-color: var(--line); background: var(--chip-on); }

.chip[aria-pressed="true"] {
  background: var(--chip-on);
  color: var(--ink);
  border-color: var(--line-soft);
}

.chip:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.chip-icon { min-width: 46px; }
.chip-again { border-color: var(--focus); color: var(--ink); }

.scent-line {
  margin: 0;
  font-size: 10.5px;
  letter-spacing: .1em;
  color: var(--muted);
  white-space: nowrap;
  transition: opacity .5s ease;
}

.wish-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.wish-input {
  width: min(210px, 46vw);
  height: 26px;
  padding: 0 11px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 11.5px;
  letter-spacing: .1em;
}

.wish-input::placeholder { color: var(--muted); opacity: .85; }
.wish-input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.wish-input:disabled { opacity: .38; }

.nojs {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  margin: 0; padding: 24px;
  background: var(--bg); color: var(--muted);
  font-size: 13px; letter-spacing: .1em;
  z-index: 20;
}

/* ---------- 窄屏 ---------- */

@media (max-width: 600px) {
  .title { letter-spacing: .3em; text-indent: .3em; }
  .dek { font-size: 10.5px; letter-spacing: .16em; text-indent: .16em; }
  .chip { padding: 0 9px; font-size: 11px; }
  .scent-line { flex-basis: 100%; text-align: center; font-size: 10px; }
  .wish-input { width: min(190px, 52vw); }
  .console { gap: 7px; }
}

/* 太矮的窗口：把说明藏起来，别让控制条压住香炉 */
@media (max-height: 640px) {
  .dek { display: none; }
  .scent-line { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
  .wish-echo { transition: opacity 1.2s linear; }
}
