:root {
  color-scheme: light;
  --bg: #f6efdf;
  --surface: #fffaf0;
  --ink: #30261f;
  --muted: #64554b;
  --main: #903522;
  --on-main: #fff;
  --bright: #e1a844;
  --second: #183e50;
  --tag-a: #f4d9c5;
  --tag-b: #d9e5df;
  --tag-c: #f4e3b6;
  --danger: #a23d31;
  --ok: #1f674d;
  --radius: 5px;
  --title-font: "Songti SC", STSong, SimSun, Georgia, serif;
  --sans: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  --rule: color-mix(in srgb, var(--ink) 22%, var(--surface));
  --field-border: color-mix(in srgb, var(--ink) 52%, var(--surface));
  --gutter: clamp(12px, 4vw, 22px);
  --frame: 480px;
  --nav-height: 70px;
}
:root[data-theme="coast"] {
  --bg: #e8f1f4;
  --surface: #f8fcfc;
  --ink: #102e43;
  --muted: #435d69;
  --main: #174c91;
  --on-main: #fff;
  --bright: #ffba72;
  --second: #16665c;
  --tag-a: #d9e8fa;
  --tag-b: #cdece5;
  --tag-c: #ffe1c2;
  --danger: #973641;
  --ok: #12614d;
  --radius: 9px;
  --title-font: var(--sans);
}
:root[data-theme="grove"] {
  --bg: #eef1e3;
  --surface: #fcf9ec;
  --ink: #273522;
  --muted: #505e47;
  --main: #365637;
  --on-main: #fff;
  --bright: #e9b3a0;
  --second: #704062;
  --tag-a: #dce8c9;
  --tag-b: #ecdbea;
  --tag-c: #f5ddbe;
  --danger: #953f39;
  --ok: #296442;
  --radius: 18px;
}
:root[data-theme="night"] {
  color-scheme: dark;
  --bg: #141624;
  --surface: #202436;
  --ink: #eef1fc;
  --muted: #b7bfd3;
  --main: #bdb0f4;
  --on-main: #221b38;
  --bright: #79d7bf;
  --second: #ffb693;
  --tag-a: #3c365f;
  --tag-b: #204841;
  --tag-c: #493749;
  --danger: #ffa9a8;
  --ok: #8edbb3;
  --radius: 14px;
  --title-font: var(--sans);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; scroll-padding-bottom: calc(var(--nav-height) + 1.5rem); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  color: var(--ink);
  background: var(--bg);
  font: 1rem/1.6 var(--sans);
  overflow-wrap: anywhere;
  -webkit-text-size-adjust: 100%;
}
body:has(dialog[open]), body:has(.viewer:not([hidden]):not(dialog)) { overflow: hidden; }
main#app, #app:not(main) {
  width: 100%;
  max-width: var(--frame);
  min-height: 80svh;
  margin-inline: auto;
  padding: max(16px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right))
    calc(var(--nav-height) + env(safe-area-inset-bottom) + 28px) max(var(--gutter), env(safe-area-inset-left));
}
h1, h2, h3, p, figure, fieldset { margin: 0; }
h1, h2, h3 { color: inherit; font-family: var(--title-font); line-height: 1.34; }
h1 { font-size: clamp(1.9rem, 8vw, 2.6rem); letter-spacing: .035em; }
h2 { font-size: 1.36rem; }
h3 { font-size: 1.12rem; }
p + p { margin-top: .55em; }
small, .meta, .muted { color: var(--muted); }
.meta, small { font-size: .83rem; }
time, .count { font-variant-numeric: tabular-nums; }
a { color: var(--main); text-underline-offset: .17em; }
hr { border: none; border-top: 1px solid var(--rule); margin: 16px 0; }
mark { background: var(--tag-c); color: var(--ink); border-bottom: 2px solid var(--main); }
.success, .saved { color: var(--ok); }
.error, .error-text { color: var(--danger); }
.stack { display: grid; gap: 12px; min-width: 0; }
.stack > *, .row > *, .toolbar > * { min-width: 0; }
.row, .toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.row.between, .toolbar { justify-content: space-between; }
.row > input:not([type="checkbox"]):not([type="radio"]), .toolbar > input { flex: 1 1 8rem; }
.toolbar { margin-block: 12px; }
.hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: grid;
  align-content: center;
  gap: 3px;
  min-height: 120px;
  margin-block-end: 14px;
  padding: 22px 30% 22px 20px;
  background: var(--main);
  border-radius: var(--radius);
  color: var(--on-main);
}
.hero time, .hero small, .hero .eyebrow {
  color: inherit; font: 650 .8rem/1.5 ui-monospace, monospace; letter-spacing: .09em;
}
.hero .art {
  position: absolute; z-index: -1; inset: 0 0 0 auto; width: 30%; overflow: hidden; pointer-events: none;
}
.art::before, .art::after { content: ""; position: absolute; }
[data-theme="paper"] .hero { border-bottom: 6px double var(--bright); }
[data-theme="paper"] .art::before { width: 64px; height: 64px; border-radius: 50%; background: var(--bright); top: 14px; right: 15px; }
[data-theme="paper"] .art::after {
  width: 150px; height: 75px; right: -20px; bottom: -17px; transform: rotate(-24deg);
  background: repeating-linear-gradient(0deg,var(--second) 0 4px,transparent 4px 8px);
}
[data-theme="coast"] .art {
  background-image: linear-gradient(#ffffff38 1px,transparent 1px),linear-gradient(90deg,#ffffff38 1px,transparent 1px);
  background-size: 15px 15px;
}
[data-theme="coast"] .art::before { bottom: 0; right: 0; width: 85px; height: 56px; background: var(--bright); clip-path: polygon(0 100%,100% 0,100% 100%); }
[data-theme="coast"] .art::after { right: 30px; top: 20px; width: 38px; height: 38px; border: 5px double white; border-radius: 50%; }
[data-theme="grove"] .art::before, [data-theme="grove"] .art::after {
  width: 52px; height: 84px; border-radius: 95% 5% 95% 8%; transform: rotate(22deg); background: var(--bright); right: 21px; top: -12px;
}
[data-theme="grove"] .art::after { right: 45px; top: 54px; background: #d5dba6; transform: rotate(67deg); }
[data-theme="night"] .hero { background: #302b50; color: #f4eeff; border: 1px solid #676091; }
[data-theme="night"] .art::before {
  width: 120px; height: 43px; border: 3px double var(--bright); border-radius: 50%; top: 45px; right: -7px; transform: rotate(-35deg);
}
[data-theme="night"] .art::after {
  width: 38px; height: 38px; border-radius: 50%; background: var(--second); right: 33px; top: 30px;
  box-shadow: -39px 41px 0 -16px var(--bright),26px -13px 0 -16px var(--main);
}
.panel, .card {
  min-width: 0; padding: clamp(14px,4vw,20px); border: 1px solid var(--rule);
  background: var(--surface); color: var(--ink); border-radius: var(--radius);
}
.panel + .panel, .card + .card, .panel + .card, .card + .panel { margin-top: 12px; }
.stack > .panel, .stack > .card { margin: 0; }
.panel > h2, .panel > h3, .card > h2, .card > h3 { margin-bottom: 8px; }
[data-theme="paper"] .card { border-top: 3px double var(--second); }
[data-theme="coast"] .card { border-inline-start: 4px solid var(--main); }
[data-theme="grove"] .card { border-radius: 3px 20px 20px 20px; }
[data-theme="night"] .card { border-top: 2px solid var(--bright); }
.record-text, .body-text, .record-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.72; }
.empty { padding: 22px 8px; text-align: center; color: var(--muted); }
button, .button, input, textarea, select { font-family: inherit; font-size: 1rem; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: .35em;
  min-height: 44px; padding: 7px 12px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--rule); border-radius: var(--radius);
  font-weight: 630; line-height: 1.35; text-align: center; text-decoration: none;
  cursor: pointer; touch-action: manipulation;
}
button:active, .button:active { filter: brightness(.92); }
button:disabled, input:disabled { cursor: default; opacity: .64; }
:is(button,a,input,textarea,select,summary,[tabindex]):focus-visible { outline: 3px solid var(--main); outline-offset: 2px; }
.primary, button[type="submit"]:not([class]):not(.secondary) { color: var(--on-main); background: var(--main); border-color: var(--main); }
.secondary { color: var(--second); background: var(--surface); border-color: var(--field-border); }
.danger { color: var(--danger); border-color: var(--danger); }
button.ghost, button.link { color: var(--main); background: transparent; border-color: transparent; }
label { display: block; color: var(--ink); font-weight: 600; }
label > :is(input,textarea,select) { margin-top: 4px; }
input:not([type="checkbox"]):not([type="radio"]), textarea, select {
  display: block; min-height: 44px; max-width: 100%; width: 100%; border: 1px solid var(--field-border);
  border-radius: var(--radius); padding: 9px 11px; color: var(--ink); background: var(--surface); line-height: 1.4;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--main); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input[type="file"] { overflow: hidden; }
input::file-selector-button {
  margin-right: 8px; padding: 5px 9px; color: var(--ink); background: var(--tag-b); border: 0; border-radius: 3px; font: inherit;
}
textarea { min-height: 8em; resize: vertical; }
fieldset { border: 0; min-width: 0; padding: 0; }
legend { padding: 0; margin-bottom: 6px; font-weight: 650; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-block: 7px; }
.tag { display: inline-flex; align-items: center; width: fit-content; border: 0; padding: 3px 9px; border-radius: var(--radius); color: var(--ink); background: var(--tag-a); font-size: .85rem; font-weight: 650; }
.tag:nth-child(3n + 2) { background: var(--tag-b); }
.tag:nth-child(3n) { background: var(--tag-c); }
button.tag, a.tag { min-height: 36px; }
.gallery { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 5px; margin-block: 12px; }
.gallery:empty { display: none; }
.gallery > :only-child { grid-column: 1 / -1; max-width: 100%; }
.gallery > *, .gallery button { padding: 0; min-width: 0; overflow: hidden; border: 0; background: transparent; border-radius: min(var(--radius),8px); }
.gallery img { display: block; width: 100%; height: auto; aspect-ratio: 1; object-fit: cover; background: var(--tag-b); }
.gallery > :only-child img, .gallery > img:only-child { aspect-ratio: 16 / 10; object-fit: contain; }
.file {
  display: flex; align-items: center; gap: 8px; min-width: 0; min-height: 44px; padding: 8px 0;
  text-align: start; font-size: .9rem; font-weight: 550; border: 0; border-top: 1px solid var(--rule);
  color: var(--second); background: transparent; border-radius: 0; overflow-wrap: anywhere;
}
.file > small { margin-inline-start: auto; }
.calendar-grid { display: grid; grid-template-columns: repeat(7,minmax(0,1fr)); gap: 2px; margin-block: 10px; text-align: center; }
.calendar-grid > * { min-width: 0; }
.calendar-grid .weekday, .calendar-grid > small { color: var(--muted); font-size: .8rem; padding-block: 5px; }
.day {
  display: flex; flex-direction: column; justify-content: flex-start; align-items: center; gap: 3px;
  min-height: 54px; width: 100%; padding: 5px 1px; background: transparent;
  border: 1px solid transparent; border-radius: min(var(--radius),10px); font-variant-numeric: tabular-nums;
}
.day.today { border-color: var(--second); }
.day.selected, .day[aria-pressed="true"], .day[aria-selected="true"] {
  background: var(--main); color: var(--on-main); font-weight: 800;
  box-shadow: inset 0 0 0 2px var(--main),inset 0 0 0 3px var(--on-main);
}
.day small, .day .tag {
  display: block; min-height: 0; max-width: 100%; overflow: hidden;
  padding: 0 2px; border-radius: 3px; background: var(--tag-c); color: var(--ink);
  white-space: nowrap; text-overflow: ellipsis; font-size: .68rem; line-height: 1.5;
}
.theme-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.theme-grid > button { justify-content: flex-start; min-width: 0; text-align: start; }
.theme-grid .selected, .theme-grid [aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--main); border-color: var(--main); }
.theme-grid [data-palette]::before {
  content: ""; flex: none; width: 26px; height: 19px; border-radius: 3px; border: 1px solid #0003;
  background: linear-gradient(to right,var(--sample-1) 0 33%,var(--sample-2) 33% 66%,var(--sample-3) 66% 100%);
}
[data-palette="paper"] { --sample-1:#903522; --sample-2:#e1a844; --sample-3:#183e50; }
[data-palette="coast"] { --sample-1:#174c91; --sample-2:#ffba72; --sample-3:#16665c; }
[data-palette="grove"] { --sample-1:#365637; --sample-2:#e9b3a0; --sample-3:#704062; }
[data-palette="night"] { --sample-1:#bdb0f4; --sample-2:#79d7bf; --sample-3:#ffb693; }
.theme-grid [data-palette="auto"]::before { background: linear-gradient(135deg,#fffaf0 50%,#302b50 50%); }
.notice { padding: 10px 12px; background: var(--tag-c); color: var(--ink); border-inline-start: 3px solid var(--second); border-radius: var(--radius); }
.notice:empty { display: none; }
.toast:not(:empty) { position:fixed; z-index:8; left:50%; bottom:calc(var(--nav-height) + env(safe-area-inset-bottom) + 12px); transform:translateX(-50%); width:max-content; max-width:calc(100% - 24px); padding:10px 16px; border:1px solid var(--main); border-radius:var(--radius); background:var(--surface); color:var(--ink); box-shadow:0 4px 20px #0002; }
.notice.error, .notice[role="alert"] { border-inline-start-color: var(--danger); }
.nav {
  position: fixed; z-index: 8; inset: auto 0 0; margin-inline: auto; width: 100%; max-width: var(--frame);
  display: flex; justify-content: space-around; gap: 5px;
  padding: 6px max(8px,env(safe-area-inset-right)) max(6px,env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left));
  background: var(--surface); border-top: 1px solid var(--rule);
}
.nav :is(button,a) {
  flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center;
  min-width: 0; min-height: 44px; padding: 4px; gap: 2px; border: 0; border-radius: var(--radius);
  color: var(--muted); background: transparent; font-size: .92rem; font-weight: 650; text-decoration: none;
}
.nav :is(button,a).active, .nav [aria-current="page"] { color: var(--main); background: var(--tag-a); box-shadow: inset 0 -2px 0 var(--main); }
.nav svg { width: 20px; height: 20px; }
dialog {
  width: min(calc(100% - 28px),440px); max-height: min(86vh,86dvh); max-width: none;
  overflow: auto; overscroll-behavior: contain; margin: auto; padding: 18px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--field-border); border-radius: var(--radius);
}
dialog::backdrop { background: rgb(10 14 20 / .69); }
dialog .row:last-child { margin-top: 12px; }
.viewer {
  position: fixed; z-index: 20; inset: 0; margin: 0; padding: 0;
  width: 100%; max-width: none; height: 100%; max-height: none;
  background: #0e0f12; color: #fbfbfd; border: 0; border-radius: 0; overflow: hidden; overscroll-behavior: none;
}
.viewer:not(dialog), dialog.viewer[open] { display: flex; flex-direction: column; }
.viewer-stage {
  position: relative; display: grid; flex: 1 1 auto; min-width: 0; min-height: 0;
  overflow: hidden; place-items: center; touch-action: none; user-select: none; -webkit-user-select: none;
}
.viewer-stage img {
  display: block; max-width: 100%; max-height: 100%; width: 100%; height: 100%; object-fit: contain;
  transform-origin: center; pointer-events: none; -webkit-user-drag: none;
}
.viewer-bar {
  flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px;
  padding: 8px max(12px,env(safe-area-inset-right)) max(10px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left));
  background: #1c2027; color: #fff;
}
.viewer-bar button { border: 1px solid #7f8790; background: #282e36; color: #fff; min-width: 44px; }
.viewer-bar button:focus-visible { outline-color: #fff; }
@media (max-width: 359px) {
  :root { --gutter: 10px; }
  .panel, .card { padding: 11px; }
  .calendar-grid { gap: 1px; }
  .theme-grid > button { padding-inline: 7px; }
}
@media (min-width: 600px) {
  main#app, #app:not(main) { padding-top: max(26px,env(safe-area-inset-top)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
