/* ---------- tokens ---------- */
:root {
  --bg: #faf8f4;
  --bg-raised: #ffffff;
  --bg-sunk: #f2ede4;
  --ink: #23201c;
  --ink-soft: #5d564c;
  --ink-faint: #928a7d;
  --rule: #e3dbcd;
  --rule-soft: #efe8dc;
  --accent: #a4501f;
  --accent-soft: #f6ebe1;
  --leif: #2f6f6a;
  --candy: #a8446e;
  --shadow: 0 1px 2px rgba(60, 45, 25, .05), 0 8px 24px -12px rgba(60, 45, 25, .18);
  --radius: 14px;
  --measure: 34em;

  --fs: 1.0625rem;
  --lh: 1.95;

  --sans: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei UI", "Microsoft YaHei",
          "Hiragino Sans GB", "Source Han Sans SC", "Noto Sans CJK SC", system-ui, sans-serif;
  --serif: "Songti SC", "Source Han Serif SC", "Noto Serif CJK SC", "Noto Serif SC",
           "SimSun", Georgia, serif;
  --body-font: var(--sans);
}

body[data-font="serif"] { --body-font: var(--serif); }

body[data-size="s"]  { --fs: 1rem;      --lh: 1.9; }
body[data-size="m"]  { --fs: 1.0625rem; --lh: 1.95; }
body[data-size="l"]  { --fs: 1.1875rem; --lh: 2.0; }
body[data-size="xl"] { --fs: 1.3125rem; --lh: 2.05; }

body[data-theme="sepia"] {
  --bg: #f3e9d6; --bg-raised: #fbf4e6; --bg-sunk: #ebdec5;
  --ink: #3a2f1e; --ink-soft: #6b5a41; --ink-faint: #9a876a;
  --rule: #ddcdae; --rule-soft: #e7dac0; --accent-soft: #f0e0c9;
}

body[data-theme="dark"] {
  --bg: #16181a; --bg-raised: #1e2124; --bg-sunk: #131517;
  --ink: #e6e2da; --ink-soft: #a8a49b; --ink-faint: #7a766e;
  --rule: #2f3438; --rule-soft: #262b2f;
  --accent: #e0a06a; --accent-soft: #2a2320;
  --leif: #5fb3ab; --candy: #e08bb0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px -14px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }

/* our display rules would otherwise beat the UA stylesheet's [hidden] */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- passcode gate ---------- */
.gate {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: var(--bg); padding: 24px;
}
.gate-card {
  width: min(360px, 100%); text-align: center;
  display: flex; flex-direction: column; gap: 12px;
}
.gate-mark {
  font-size: .75rem; letter-spacing: .4em; text-indent: .4em;
  color: var(--accent); text-transform: uppercase; margin-bottom: 4px;
}
.gate-card h1 { margin: 0; font-size: 1.75rem; letter-spacing: .08em; font-weight: 600; }
.gate-sub { margin: 0 0 12px; color: var(--ink-faint); font-size: .875rem; }
.gate-card input {
  width: 100%; padding: 13px 16px; font: inherit; text-align: center;
  letter-spacing: .12em;
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--bg-raised); color: var(--ink);
}
.gate-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.gate-card button {
  padding: 13px 16px; border: 0; border-radius: 10px;
  background: var(--ink); color: var(--bg); font-weight: 600; letter-spacing: .1em;
}
.gate-err { min-height: 1.2em; margin: 0; color: #c0392b; font-size: .8125rem; }

/* ---------- chrome ---------- */
.progressbar {
  position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 40;
  background: transparent; pointer-events: none;
}
.progressbar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--rule-soft);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: .02em; }
.brand-mark {
  display: grid; place-items: center; width: 26px; height: 26px; flex: none;
  border-radius: 7px; background: var(--accent); color: #fff;
  font-size: .8125rem; font-weight: 700;
}
.brand-text { font-size: .9375rem; white-space: nowrap; }
.topnav { display: flex; gap: 4px; margin-left: auto; }
.topnav a {
  padding: 6px 12px; border-radius: 999px; white-space: nowrap;
  font-size: .875rem; color: var(--ink-soft);
}
.topnav a[aria-current] { background: var(--bg-sunk); color: var(--ink); font-weight: 600; }

.who { display: flex; gap: 4px; padding: 3px; border-radius: 999px; background: var(--bg-sunk); }
.who button {
  border: 0; background: transparent; border-radius: 999px;
  padding: 5px 11px; font-size: .8125rem; color: var(--ink-faint);
}
.who button[aria-pressed="true"] { background: var(--bg-raised); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.who button { white-space: nowrap; }

@media (max-width: 560px) {
  .topbar { gap: 8px; }
  .brand-text { display: none; }
  .topnav a { padding: 6px 9px; }
}

main { padding: 0 max(16px, env(safe-area-inset-left)) 64px max(16px, env(safe-area-inset-right)); }

.foot {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: 62em; margin: 0 auto; padding: 24px 16px 40px;
  border-top: 1px solid var(--rule-soft);
  color: var(--ink-faint); font-size: .8125rem;
}
.linkbtn { border: 0; background: none; color: var(--ink-faint); text-decoration: underline; padding: 0; }

/* ---------- floating toolbar ---------- */
.toolbar {
  position: fixed; z-index: 35;
  right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 1px;
  padding: 4px; border-radius: 999px;
  background: var(--bg-raised); border: 1px solid var(--rule-soft);
  box-shadow: var(--shadow);
}
.toolbar button {
  width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: transparent; color: var(--ink-soft);
  font-size: .75rem; line-height: 1; display: grid; place-items: center;
}
.toolbar button:hover { background: var(--bg-sunk); color: var(--ink); }
@media (max-width: 720px) {
  .toolbar { flex-direction: row; left: 50%; right: auto; transform: translateX(-50%); }
}

/* ---------- home ---------- */
.home { max-width: 62em; margin: 0 auto; }

.hero { padding: 44px 0 28px; border-bottom: 1px solid var(--rule-soft); }
.hero h1 { margin: 0 0 8px; font-size: clamp(1.75rem, 5vw, 2.5rem); letter-spacing: .04em; font-weight: 650; }
.hero p { margin: 0; color: var(--ink-soft); font-size: .9375rem; }

.stats { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.stat {
  flex: 1 1 150px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--bg-raised); border: 1px solid var(--rule-soft);
}
.stat b { display: block; font-size: 1.5rem; font-weight: 650; letter-spacing: .02em; }
.stat span { font-size: .75rem; color: var(--ink-faint); }
.stat.leif b { color: var(--leif); }
.stat.candy b { color: var(--candy); }

.track { margin-top: 14px; height: 6px; border-radius: 999px; background: var(--bg-sunk); overflow: hidden; display: flex; }
.track i { display: block; height: 100%; }
.track .t-both { background: var(--accent); }
.track .t-leif { background: var(--leif); }
.track .t-candy { background: var(--candy); }

.chapter { margin-top: 40px; }
.chapter-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.chapter-no {
  font-size: .6875rem; letter-spacing: .22em; color: var(--accent);
  font-weight: 700; white-space: nowrap;
}
.chapter-head h2 { margin: 0; font-size: 1.0625rem; font-weight: 650; letter-spacing: .04em; }
.chapter-head em { margin-left: auto; font-style: normal; font-size: .75rem; color: var(--ink-faint); white-space: nowrap; }

.days { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: 10px; }
.daycard {
  display: block; position: relative; padding: 14px 16px 13px;
  border-radius: var(--radius); background: var(--bg-raised);
  border: 1px solid var(--rule-soft); transition: border-color .15s, transform .15s, box-shadow .15s;
}
.daycard:hover { border-color: var(--rule); transform: translateY(-1px); box-shadow: var(--shadow); }
.daycard .n { font-size: .6875rem; letter-spacing: .14em; color: var(--ink-faint); font-weight: 600; }
.daycard .t {
  margin: 5px 0 9px; font-size: .9375rem; font-weight: 550; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.daycard .m { display: flex; align-items: center; gap: 8px; font-size: .6875rem; color: var(--ink-faint); }
.daycard .dots { margin-left: auto; display: flex; gap: 4px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--rule); }
.dot.on-leif { background: var(--leif); }
.dot.on-candy { background: var(--candy); }
.daycard.done { background: var(--accent-soft); border-color: transparent; }

/* ---------- reader ---------- */
.reader { max-width: var(--measure); margin: 0 auto; }
.reader-wide { max-width: 62em; margin: 0 auto; }

.crumbs {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 30px 0 0; font-size: .75rem; color: var(--ink-faint); letter-spacing: .05em;
}
.crumbs .sep { opacity: .45; }
.crumbs a { color: var(--accent); }

.reader h1 {
  margin: 14px 0 10px; font-size: clamp(1.5rem, 4.5vw, 2rem);
  line-height: 1.35; letter-spacing: .02em; font-weight: 650;
}
.reader-meta {
  display: flex; flex-wrap: wrap; gap: 6px 14px; padding-bottom: 22px;
  border-bottom: 1px solid var(--rule); font-size: .75rem; color: var(--ink-faint);
}

article {
  font-family: var(--body-font);
  font-size: var(--fs);
  line-height: var(--lh);
  color: var(--ink);
  padding: 26px 0 8px;
}
article p { margin: 0 0 1.1em; text-align: justify; word-break: normal; overflow-wrap: anywhere; }
article h2 {
  margin: 2.2em 0 .9em; font-size: 1.0625em; font-weight: 650;
  letter-spacing: .04em; line-height: 1.5;
  padding-left: .7em; border-left: 3px solid var(--accent);
}
article h2:first-child { margin-top: .4em; }

figure { margin: 2em 0; text-align: center; }
figure img {
  max-width: 100%; height: auto; border-radius: 10px;
  border: 1px solid var(--rule-soft); background: #fff;
}
body[data-theme="dark"] figure img { filter: invert(.92) hue-rotate(180deg); }
figcaption { margin-top: .7em; font-size: .75rem; color: var(--ink-faint); font-family: var(--sans); }

.tip {
  margin: 2em 0; padding: 18px 20px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 18%, transparent);
}
.tip-label {
  display: block; margin-bottom: .5em; font-family: var(--sans);
  font-size: .6875rem; font-weight: 700; letter-spacing: .2em; color: var(--accent);
}
.tip p { margin: 0 0 .7em; }
.tip p:last-child { margin: 0; }

.chapter-band {
  margin: 0 0 1.6em; padding: 16px 18px; border-radius: var(--radius);
  background: var(--bg-sunk); font-family: var(--sans);
}
.chapter-band b { display: block; font-size: .6875rem; letter-spacing: .22em; color: var(--accent); }
.chapter-band span { font-size: 1rem; font-weight: 600; letter-spacing: .04em; }

/* ---------- reflections ---------- */
.reflect { margin-top: 46px; padding-top: 30px; border-top: 2px solid var(--rule); }
.reflect > h2 {
  margin: 0 0 4px; font-size: 1.125rem; font-weight: 650; letter-spacing: .06em;
}
.reflect > p.hint { margin: 0 0 20px; font-size: .8125rem; color: var(--ink-faint); }

.pads { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .pads { grid-template-columns: 1fr 1fr; } }

.pad {
  display: flex; flex-direction: column;
  border-radius: var(--radius); background: var(--bg-raised);
  border: 1px solid var(--rule-soft); overflow: hidden;
}
.pad.mine { border-color: color-mix(in srgb, var(--who-color) 45%, var(--rule-soft)); }
.pad[data-person="leif"] { --who-color: var(--leif); }
.pad[data-person="candy"] { --who-color: var(--candy); }

.pad-head {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 14px; border-bottom: 1px solid var(--rule-soft);
}
.pad-avatar {
  width: 24px; height: 24px; flex: none; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-size: .6875rem; font-weight: 700;
  background: var(--who-color);
}
.pad-name { font-size: .875rem; font-weight: 600; }
.pad-status { margin-left: auto; font-size: .6875rem; color: var(--ink-faint); }
.pad-status[data-state="saving"] { color: var(--accent); }
.pad-status[data-state="saved"] { color: var(--leif); }
.pad-status[data-state="error"] { color: #c0392b; }

.pad textarea {
  border: 0; resize: vertical; min-height: 190px;
  padding: 15px 16px; background: transparent; color: var(--ink);
  font-family: var(--body-font); font-size: 1rem; line-height: 1.85;
}
.pad textarea:focus { outline: none; }
.pad textarea::placeholder { color: var(--ink-faint); }
.pad .readonly {
  padding: 15px 16px; min-height: 190px; white-space: pre-wrap;
  font-family: var(--body-font); font-size: 1rem; line-height: 1.85;
}
.pad .readonly:empty::before { content: "还没有写"; color: var(--ink-faint); }
.pad-foot {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 9px 14px; border-top: 1px solid var(--rule-soft);
  font-size: .6875rem; color: var(--ink-faint); background: var(--bg-sunk);
}

/* ---------- pager ---------- */
.pager { display: flex; gap: 10px; margin: 40px 0 0; }
.pager > a, .pager > span {
  flex: 1; min-width: 0; padding: 14px 16px; border-radius: var(--radius);
  background: var(--bg-raised); border: 1px solid var(--rule-soft);
}
.pager > span { opacity: .4; }
.pager > a:hover { border-color: var(--rule); }
.pager .dir { display: block; font-size: .6875rem; letter-spacing: .14em; color: var(--ink-faint); margin-bottom: 4px; }
.pager .ttl { font-size: .875rem; font-weight: 550; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager .next { text-align: right; }

/* ---------- log view ---------- */
.logentry {
  padding: 18px 20px; margin-bottom: 12px;
  border-radius: var(--radius); background: var(--bg-raised); border: 1px solid var(--rule-soft);
}
.logentry .lh { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.logentry .lh b { font-size: .8125rem; }
.logentry .lh b.leif { color: var(--leif); }
.logentry .lh b.candy { color: var(--candy); }
.logentry .lh a { font-size: .8125rem; font-weight: 550; }
.logentry .lh time { margin-left: auto; font-size: .6875rem; color: var(--ink-faint); }
.logentry .body {
  white-space: pre-wrap; font-family: var(--body-font);
  font-size: .9375rem; line-height: 1.85; color: var(--ink-soft);
}

.empty { padding: 60px 20px; text-align: center; color: var(--ink-faint); font-size: .9375rem; }
.loading { padding: 80px 20px; text-align: center; color: var(--ink-faint); font-size: .875rem; }
