:root {
  --paper: #f3ecdc;
  --paper-deep: #e9dfc9;
  --ink: #1d1e1f;
  --ink-2: #4b4b47;
  --ink-3: #7c786e;
  --line: #1d1e1f22;
  --cinnabar: #b23a2a;
  --indigo: #2e4a5c;
  --ochre: #9a6233;
  --kai: 'Kaiti SC', 'STKaiti', 'KaiTi', 'BiauKai', 'Songti SC', serif;
  --song: 'Songti SC', 'STSong', 'Noto Serif CJK SC', 'SimSun', Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --leaf: clamp(400px, 40vw, 580px);
  --ease: cubic-bezier(.2, .7, .2, 1);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { color: var(--ink); background: var(--paper); font: 14.5px/1.72 var(--sans); }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
a { color: var(--indigo); text-decoration: none; }
h1, h2, h3, p { margin: 0; }
svg { flex-shrink: 0; vertical-align: middle; }
:focus-visible { outline: 2px solid var(--cinnabar); outline-offset: 3px; }

/* ---------- the world ---------- */
#world { position: fixed; inset: 0; background: var(--paper) center / cover no-repeat; }
#world canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#world.still { background-image: url('./assets/still.jpg'); }
body.roaming #world canvas { cursor: grab; }
body.roaming #world canvas:active { cursor: grabbing; }

#ink-load { position: fixed; inset: 0; z-index: 90; background: var(--paper); display: grid; place-content: center; justify-items: center; gap: 12px; font: 20px/1 var(--kai); letter-spacing: .4em; color: var(--ink-2); transition: opacity 1.6s var(--ease), visibility 1.6s; }
#ink-load i { width: 34px; height: 34px; border-radius: 50%; background: radial-gradient(circle at 45% 42%, #1d1e1f 0 30%, #1d1e1f55 58%, transparent 72%); filter: url(#deckle); animation: bleed 1.8s var(--ease) infinite alternate; }
@keyframes bleed { from { transform: scale(.7); opacity: .6; } to { transform: scale(1.15); opacity: 1; } }
body.ready #ink-load { opacity: 0; visibility: hidden; }

/* ---------- pieces pasted on the painting ---------- */
.brand { position: fixed; z-index: 30; top: calc(20px + env(safe-area-inset-top, 0px)); left: 20px; }
.brand span { display: flex; align-items: center; justify-content: center; width: 40px; height: 56px; background: var(--cinnabar); color: #f7ecdc; font: 600 17px/1.15 var(--kai); text-align: center; border-radius: 3px 2px 4px 2px; box-shadow: 0 1px 0 #0003; }

#route { position: fixed; z-index: 30; left: 20px; top: 96px; display: flex; flex-direction: column; gap: 6px; }
.strip { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 40px; padding: 8px 0 9px; background: var(--paper); color: var(--ink); border-radius: 1.5px; box-shadow: 0 1px 2px #0002, 0 0 0 1px #1d1e1f12; transition: transform .35s var(--ease), background .25s; }
.strip i { font: 12px/1 var(--kai); color: var(--ink-3); }
.strip b { font: 500 15px/1.15 var(--kai); writing-mode: vertical-rl; letter-spacing: .08em; }
.strip:hover { transform: translateX(4px); }
.strip.on { background: var(--cinnabar); color: #f7ecdc; }
.strip.on i { color: #f7ecdccc; }
.strip.quiet { background: #f3ecdcd8; }
.strip.quiet.on { background: var(--ink); }
.strip.quiet:first-of-type { margin-top: 6px; }

#place { position: fixed; z-index: 20; left: 84px; top: 40px; writing-mode: vertical-rl; display: flex; gap: 8px; align-items: flex-start; opacity: 0; transition: opacity 1.2s var(--ease); pointer-events: none; color: var(--ink); text-shadow: 0 0 18px var(--paper), 0 0 6px var(--paper); }
/* Swapping the animation when roaming toggles lets a name that changes corner fade in there instead of jumping. */
@keyframes place-in { from { opacity: 0; } }
@keyframes place-in-roaming { from { opacity: 0; } }
#place.show { opacity: 1; animation: place-in 1.2s var(--ease); }
body.roaming #place.show { animation-name: place-in-roaming; }
#place strong { font: 500 44px/1.1 var(--kai); letter-spacing: .14em; }
#place span { font: 14px/1.2 var(--kai); letter-spacing: .28em; color: var(--ink-2); padding-top: 6px; }

/* ---------- the album leaf ---------- */
#leaf { position: fixed; z-index: 25; top: 0; bottom: 0; right: 0; width: var(--leaf); transition: transform .9s var(--ease), opacity .6s; }
.leaf-paper { position: absolute; inset: -10px -30px -10px 0; background: var(--paper); filter: url(#deckle); box-shadow: -14px 0 40px -18px #1d1e1f55; }
.leaf-paper::after { content: ''; position: absolute; inset: 0; background:
  repeating-linear-gradient(90deg, transparent 0 calc(100%/12 - 1px), #9a62330f calc(100%/12 - 1px) calc(100%/12)),
  radial-gradient(120% 90% at 100% 0, #fff6 0, transparent 60%); }
#leaf-scroll { position: absolute; inset: 0; overflow-y: auto; padding: 26px 40px 40px 46px; scrollbar-width: thin; scrollbar-color: #1d1e1f30 transparent; }
body.sheet-closed #leaf, body.roaming #leaf { transform: translateX(calc(100% + 40px)); }
#unfold { position: fixed; z-index: 26; right: 20px; top: 50%; transform: translateY(-50%); }

.leaf-head { padding-bottom: 14px; }
.leaf-bar { display: flex; align-items: center; justify-content: space-between; min-height: 30px; }
.eyebrow { font: 13px/1.3 var(--kai); letter-spacing: .2em; color: var(--ochre); }
h1 { font: 500 clamp(30px, 3vw, 38px)/1.2 var(--kai); letter-spacing: .05em; margin: 8px 0 8px; }
.leaf-head p { color: var(--ink-2); font-family: var(--song); }
h2 { font: 500 21px/1.3 var(--kai); letter-spacing: .05em; }
h3 { font: 600 16px/1.4 var(--song); }
p { color: var(--ink-2); }
.fine { font-size: 12px; color: var(--ink-3); }
.note { font-family: var(--song); padding: 2px 0 2px 12px; border-left: 2px solid var(--cinnabar); margin: 2px 0 16px; }

.tally { display: grid; grid-template-columns: repeat(4, 1fr); border-block: 1px solid var(--ink); margin: 6px 0 18px; }
.tally div { padding: 12px 8px 10px; border-left: 1px solid var(--line); }
.tally div:first-child { border-left: 0; padding-left: 0; }
.tally b { display: block; font: 500 27px/1.1 var(--song); font-variant-numeric: lining-nums; }
.tally span { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.tally small { font-size: 13px; color: var(--ink-3); margin-left: 2px; }
#leaf-scroll footer { display: flex; justify-content: space-between; gap: 12px; margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--line); font: 13px/1.4 var(--kai); color: var(--ink-3); }

.block { padding: 16px 0 18px; border-top: 1px solid var(--line); }
.block-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.next-card { display: block; width: 100%; text-align: left; padding: 11px 14px; margin-bottom: 18px; background: var(--paper-deep); border-left: 3px solid var(--cinnabar); }
.next-card span { display: block; font-size: 12px; color: var(--ink-3); }
.next-card strong { font: 600 15.5px/1.5 var(--song); }

.focus-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
#focus-clock { font: 400 46px/1 var(--song); font-variant-numeric: tabular-nums lining-nums; letter-spacing: .02em; }
.focus-actions, .row-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

.button { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; background: var(--ink); color: var(--paper); border-radius: 2px; font-size: 13.5px; transition: background .2s, transform .2s; }
.button:hover { background: var(--cinnabar); }
.button.ghost { background: none; color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.button.ghost:hover { color: var(--cinnabar); box-shadow: inset 0 0 0 1px var(--cinnabar); background: none; }
.button.small { padding: 6px 12px; font-size: 13px; }
.text-button { display: inline-flex; align-items: center; gap: 4px; color: var(--indigo); font-size: 13px; }
.text-button:hover { color: var(--cinnabar); }
.text-button.danger { color: var(--cinnabar); }
.text-button.more { margin-top: 8px; }
.icon-button { display: inline-flex; padding: 6px; color: var(--ink-2); border-radius: 2px; }
.icon-button:hover { color: var(--cinnabar); }

.task { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.task-check { width: 19px; height: 19px; display: grid; place-items: center; box-shadow: inset 0 0 0 1px var(--ink-2); border-radius: 50%; }
.task.done .task-check { background: var(--ink); color: var(--paper); }
.task-copy { flex: 1; min-width: 0; text-align: left; }
.task-copy strong { display: block; font: 600 15px/1.45 var(--song); }
.task.done strong { color: var(--ink-3); text-decoration: line-through; }
.task-copy span { font-size: 12px; color: var(--ink-3); }

.chain { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 18px; }
.chain button { display: flex; gap: 10px; align-items: center; width: 100%; padding: 8px 0; text-align: left; }
.chain i { width: 30px; height: 30px; display: grid; place-items: center; font: 17px/1 var(--kai); color: var(--cinnabar); box-shadow: inset 0 0 0 1px var(--cinnabar); border-radius: 2px; flex-shrink: 0; }
.chain button:hover i { background: var(--cinnabar); color: var(--paper); }
.chain strong { display: block; font: 600 14px/1.3 var(--song); }
.chain small { font-size: 11.5px; color: var(--ink-3); }

details { border-top: 1px solid var(--line); padding: 12px 0; }
summary { cursor: pointer; font: 15px/1.5 var(--kai); }
.starters article { padding: 10px 0; border-bottom: 1px solid var(--line); }
.history div { display: grid; grid-template-columns: 1.2fr 1.2fr auto; gap: 8px; font-size: 12.5px; padding: 6px 0; border-bottom: 1px solid var(--line); }

.toolbar { display: flex; gap: 8px; align-items: center; }
.search { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--ink); padding: 3px 2px; color: var(--ink-2); }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; color: var(--ink); }
select { background: none; border: 0; border-bottom: 1px solid var(--ink); padding: 4px 2px; border-radius: 0; }
.count { margin: 10px 0 4px; }

.entry { padding: 13px 0 12px; border-bottom: 1px solid var(--line); }
.entry-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3px; }
.entry-date { font-size: 11.5px; color: var(--ink-3); }
.entry-title { display: block; text-align: left; font: 600 16.5px/1.45 var(--song); }
.entry-title:hover { color: var(--cinnabar); }
.entry-text { font-size: 13.5px; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.next-line { font-size: 13px; margin-top: 6px; color: var(--ink); }
.next-line span { color: var(--cinnabar); margin-right: 8px; font: 13px var(--kai); }
.thread { display: inline-flex; gap: 4px; align-items: center; font-size: 12px; color: var(--indigo); margin: 6px 10px 0 0; text-align: left; }
.entry-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.text-link { font-size: 13px; }
.tag { display: inline-block; padding: 0 6px; font-size: 11.5px; line-height: 19px; color: var(--ochre); box-shadow: inset 0 0 0 1px #9a623366; border-radius: 1.5px; }
.tag.done { color: var(--paper); background: var(--ink-2); box-shadow: none; }
.reading { padding: 11px 0; border-bottom: 1px solid var(--line); }
.reading h3 { margin-top: 5px; font-size: 14.5px; }
.reading p { font-size: 13.5px; }

.blank { padding: 22px 0; text-align: center; }
.blank h3 { font: 500 19px/1.4 var(--kai); }
.blank p { font-size: 13.5px; margin: 4px 0 12px; }

.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; height: 148px; align-items: end; margin-bottom: 8px; }
.bars div { display: grid; grid-template-rows: auto 1fr auto; height: 100%; align-items: end; justify-items: center; gap: 3px; font-size: 11px; color: var(--ink-3); }
.bars i { display: block; width: 62%; height: max(var(--bar), 1px); background: var(--ink); border-radius: 1px; }
.prompt p { margin: 3px 0 10px; }
.pref { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.toggle { width: 38px; height: 21px; border-radius: 12px; box-shadow: inset 0 0 0 1px var(--ink); position: relative; flex-shrink: 0; }
.toggle span { position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: var(--ink); transition: transform .25s var(--ease); }
.toggle.on { background: var(--ink); }
.toggle.on span { background: var(--paper); transform: translateX(17px); }

form label, .file-label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 11px; }
input:not([type=file]):not([type=search]), textarea, form select { display: block; width: 100%; margin-top: 3px; padding: 6px 8px; background: #fffaf0a8; border: 0; border-bottom: 1px solid var(--ink-2); border-radius: 0; color: var(--ink); font-family: var(--song); font-size: 15px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--cinnabar); }
textarea { resize: vertical; line-height: 1.6; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.alert { padding: 10px 12px; margin: 10px 0; background: #b23a2a14; border-left: 3px solid var(--cinnabar); font-size: 13.5px; }
.form-error { color: var(--cinnabar); font-size: 13px; }
.relations { font-size: 13px; }

dialog { width: min(600px, calc(100vw - 28px)); max-height: calc(100dvh - 40px); padding: 0; border: 0; color: var(--ink); background: var(--paper); box-shadow: 0 30px 80px -24px #1d1e1f99; overflow: hidden; }
dialog[open] { display: flex; flex-direction: column; }
dialog form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
dialog::backdrop { background: #1d1e1f4d; }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 18px 22px 8px; }
.dialog-body { padding: 8px 22px 12px; overflow-y: auto; flex: 1; }
.dialog-body .button { margin: 4px 0 12px; }
.dialog-foot { display: flex; justify-content: space-between; align-items: center; padding: 12px 22px; border-top: 1px solid var(--line); }

#toast { position: fixed; z-index: 80; left: 50%; bottom: 26px; transform: translate(-50%, 16px); padding: 8px 16px; background: var(--ink); color: var(--paper); font-size: 13.5px; border-radius: 2px; opacity: 0; pointer-events: none; transition: .35s var(--ease); max-width: calc(100vw - 28px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { color: #f2b9a8; margin-left: 10px; }

#pill { position: fixed; z-index: 27; left: 72px; bottom: 24px; padding: 6px 12px; background: var(--ink); color: var(--paper); font-size: 13px; font-variant-numeric: tabular-nums; border-radius: 2px; }

/* ---------- roaming ---------- */
body.roaming .brand, body.roaming #route { opacity: 0; pointer-events: none; }
.brand, #route { transition: opacity .6s; }
/* Top left belongs to the hint, so in the full picture the place name hangs at the right, like an inscription. */
body.roaming #place { left: auto; right: 30px; top: 84px; }
#roam { position: fixed; inset: 0; z-index: 28; pointer-events: none; }
#roam[hidden] { display: none; }
#roam > * { pointer-events: auto; }
.roam-hint { position: absolute; left: 28px; top: 26px; pointer-events: none !important; color: var(--ink); text-shadow: 0 0 14px var(--paper), 0 0 5px var(--paper); }
.roam-hint strong { display: block; font: 500 24px/1.3 var(--kai); letter-spacing: .1em; }
.roam-hint span { font-size: 12.5px; color: var(--ink-2); }
.roam-stops { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); display: flex; gap: 4px; background: var(--paper); padding: 5px; box-shadow: 0 2px 8px #0003; border-radius: 2px; }
.roam-stops button { display: flex; flex-direction: column; align-items: center; padding: 3px 12px; font: 14px/1.3 var(--kai); white-space: nowrap; }
.roam-stops i { font-size: 12px; color: var(--ink-3); }
.roam-stops button.on, .roam-stops button:hover { color: var(--cinnabar); }
.roam-back { position: absolute; right: 24px; top: 24px; }
kbd { font: 11px var(--sans); opacity: .7; margin-left: 4px; }

/* ---------- small screens: picture above, leaf below ---------- */
@media (max-width: 859px) {
  :root { --leaf: 100vw; }
  #leaf { top: 34dvh; left: 0; right: 0; width: auto; bottom: 0; }
  .leaf-paper { inset: 0 -20px -20px -20px; box-shadow: 0 -14px 40px -18px #1d1e1f55; }
  #leaf-scroll { padding: 16px max(18px, env(safe-area-inset-right, 0px)) 92px max(18px, env(safe-area-inset-left, 0px)); }
  body.sheet-closed #leaf, body.roaming #leaf { transform: translateY(calc(100% + 40px)); }
  #route { left: 0; right: 0; top: auto; bottom: 0; flex-direction: row; gap: 3px; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: var(--paper-deep); overflow-x: auto; box-shadow: 0 -1px 0 var(--line); }
  .strip { flex: 1 0 44px; width: auto; padding: 4px 2px; flex-direction: row; justify-content: center; gap: 3px; box-shadow: none; }
  .strip b { writing-mode: horizontal-tb; font-size: 14px; letter-spacing: 0; white-space: nowrap; }
  .strip i { display: none; }
  .strip:hover { transform: none; }
  .strip.quiet:first-of-type { margin-top: 0; }
  .brand { top: calc(12px + env(safe-area-inset-top, 0px)); left: 12px; }
  .brand span { width: 32px; height: 46px; font-size: 14px; }
  #place { left: 54px; top: 14px; }
  #place strong { font-size: 30px; }
  #unfold { top: auto; bottom: 62px; right: 12px; transform: none; flex-direction: row; padding: 6px 10px; width: auto; }
  #unfold b { writing-mode: horizontal-tb; }
  #pill { left: auto; right: 12px; top: 12px; bottom: auto; }
  .tally { grid-template-columns: repeat(4, 1fr); }
  .tally b { font-size: 22px; }
  .tally span { font-size: 10.5px; }
  .roam-stops { left: 8px; right: 8px; bottom: 12px; transform: none; overflow-x: auto; }
  .roam-hint { left: 14px; top: 14px; max-width: calc(100vw - 134px); }
  .roam-hint strong { font-size: 18px; }
  .roam-back { right: 12px; top: 12px; }
  .roam-back kbd { display: none; }
  body.roaming #place { right: 14px; top: 62px; }
  body.roaming #pill { left: 14px; right: auto; top: auto; bottom: 76px; }
  #toast { bottom: 76px; }
}
@media (max-height: 400px) {
  #place span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation: none !important; }
}
