:root {
  --paper: #f4f0e7;
  --paper-deep: #e9e3d7;
  --surface: #fffdf8;
  --ink: #21332b;
  --muted: #68756c;
  --line: #d8d1c2;
  --forest: #315a49;
  --forest-soft: #dce8dc;
  --amber: #b87531;
  --amber-soft: #f3e2cb;
  --chart-low: #ece9dc;
  --chart-mid: #b5cdb5;
  --chart-high: #315a49;
  --danger: #a4473d;
  --nav-h: 70px;
  color: var(--ink);
  background: var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root { --paper: #15211c; --paper-deep: #1d2c25; --surface: #213129; --ink: #f4f0e7; --muted: #afbaaf; --line: #405248; --forest: #b5d1b8; --forest-soft: #294335; --amber: #e3a966; --amber-soft: #453726; --chart-low: #314238; --chart-mid: #709c78; --chart-high: #b5d1b8; --danger: #f19b8f; }
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body { min-width: 320px; margin: 0; background: var(--paper); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }
a { color: inherit; }

.login-view { display: grid; min-height: 100svh; place-items: center; padding: 28px; color: #f8f3e8; background: #20352b; }
.login-view[hidden] { display: none; }
.login-form { width: min(100%, 390px); }
.login-form h1, h1, h2, .brand { font-family: "Noto Serif SC", "Songti SC", STSong, serif; font-weight: 600; }
.login-form h1 { margin: 0; font-size: clamp(2.65rem, 12vw, 4.2rem); line-height: 1.06; letter-spacing: -.08em; }
.login-form p:not(.status) { max-width: 24em; margin: 16px 0 34px; color: #c9d1c9; }
.login-form label { display: grid; gap: 8px; font-size: .9rem; }
.login-form input { min-height: 50px; padding: 10px 2px; color: inherit; background: transparent; border: 0; border-bottom: 1px solid #91a092; border-radius: 0; font-size: 16px; }
.login-form button { width: 100%; min-height: 52px; margin-top: 28px; color: #183025; background: #dce987; border: 0; border-radius: 5px; font-weight: 750; }
.app-shell { min-height: 100svh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.app-header { display: flex; align-items: baseline; justify-content: space-between; max-width: 860px; margin: 0 auto; padding: 20px 20px 12px; color: var(--muted); font-size: .78rem; letter-spacing: .06em; }
.brand { color: var(--ink); text-decoration: none; font-size: 1.2rem; letter-spacing: -.05em; }
.workspace { width: min(100%, 860px); margin: 0 auto; padding: 0 20px 132px; }
.page-shell .workspace { padding-bottom: 108px; }
.page-heading, .datebar { display: flex; align-items: end; justify-content: space-between; gap: 18px; padding: 20px 0 28px; }
.page-heading h1 { margin: 0; font-size: clamp(2.4rem, 9vw, 4.25rem); line-height: 1; letter-spacing: -.08em; }
.eyebrow { margin: 0 0 7px; color: var(--amber); font-size: .7rem; font-weight: 800; letter-spacing: .15em; text-transform: uppercase; }
.status { min-height: 1.45em; margin: 0; color: var(--muted); font-size: .86rem; }
.status.error { color: var(--danger); }

.app-nav { position: fixed; z-index: 10; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(4, 1fr); height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding: 7px 12px env(safe-area-inset-bottom); background: color-mix(in srgb, var(--surface) 94%, transparent); border-top: 1px solid var(--line); backdrop-filter: blur(16px); }
.app-nav a, .app-nav button { display: grid; place-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: .73rem; text-align: center; }
.app-nav button { padding: 0; background: transparent; border: 0; }
.app-nav a > span, .app-nav button > span { font-size: 1rem; line-height: 1; }
.app-nav a.is-active { color: var(--forest); font-weight: 800; }
.app-nav .nav-brand { display: none; }

.datebar { display: grid; grid-template-columns: 56px 1fr 56px; align-items: center; padding-top: 8px; }
.date-step { width: 56px; height: 56px; color: var(--forest); background: transparent; border: 1px solid var(--line); border-radius: 50%; font-size: 2.15rem; line-height: 1; }
.date-field { display: grid; gap: 5px; color: var(--muted); font-size: .72rem; font-weight: 750; letter-spacing: .1em; text-align: center; }
.date-field input { width: 100%; min-height: 48px; padding: 0; color: var(--ink); background: transparent; border: 0; font-size: 1.1rem; text-align: center; }

label { color: var(--muted); font-size: .87rem; }
input, textarea, select { width: 100%; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 4px; font-size: 16px; }
input, select { min-height: 50px; padding: 9px 11px; }
textarea { min-height: 112px; padding: 12px; resize: vertical; }
.record-section, .content-section { padding: 30px 0; border-top: 1px solid var(--line); }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.section-heading > p { margin: 0; color: var(--muted); font-size: .78rem; text-align: right; }
h2 { margin: 0; font-size: clamp(1.6rem, 6vw, 2.2rem); line-height: 1.13; letter-spacing: -.055em; }
.time-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.time-grid > * { min-width: 0; }
.time-grid input { width: 100%; min-width: 0; min-height: 50px; padding: 9px 11px; -webkit-appearance: none; appearance: none; text-align: center; }
.time-grid label, .details-grid label, .note-field, .search-field, .year-select { display: grid; gap: 7px; }
.sleep-summary { display: block; margin-top: 18px; color: var(--forest); font-family: "Noto Serif SC", "Songti SC", serif; font-size: 1.16rem; font-weight: 700; }
.toggle-row { display: flex; flex-wrap: wrap; gap: 18px; }
.toggle { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); }
.toggle input, .quality-options input { position: absolute; width: 1px; height: 1px; min-height: 1px; margin: -1px; clip: rect(0 0 0 0); }
.toggle span { position: relative; width: 45px; height: 26px; border-radius: 99px; background: var(--line); transition: background .18s ease; }
.toggle span::after { position: absolute; top: 4px; left: 4px; width: 18px; height: 18px; content: ""; background: var(--surface); border-radius: 50%; transition: transform .18s ease; }
.toggle input:checked + span { background: var(--forest); }
.toggle input:checked + span::after { transform: translateX(19px); }
.quality-options { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 25px; }
.quality-options span { display: inline-block; padding: 8px 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; transition: background .18s ease, color .18s ease, border-color .18s ease; }
.quality-options input:checked + span { color: var(--surface); background: var(--forest); border-color: var(--forest); }
.details-section { padding: 25px 0 2px; border-top: 1px solid var(--line); }
.details-section summary { color: var(--forest); cursor: pointer; font-weight: 800; }
.details-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; padding-top: 22px; }
.input-suffix { position: relative; display: block; }
.input-suffix input { padding-right: 34px; }
.input-suffix b { position: absolute; top: 50%; right: 12px; color: var(--muted); font-size: .85rem; transform: translateY(-50%); }
.save-static { display: grid; gap: 10px; margin-top: 24px; }
.record-actions { display: flex; justify-content: flex-end; gap: 10px; }
.save-status { opacity: 1; transition: opacity .2s ease; }
.save-status.is-fading { opacity: 0; }
.savebar { position: fixed; z-index: 5; right: 0; bottom: calc(var(--nav-h) + 9px + env(safe-area-inset-bottom)); left: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; width: min(calc(100% - 24px), 820px); margin: 0 auto; padding: 10px 12px 10px 16px; background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--line); border-radius: 7px; box-shadow: 0 8px 26px color-mix(in srgb, var(--ink) 13%, transparent); backdrop-filter: blur(14px); }
.savebar[hidden], .save-static[hidden] { display: none; }
.save-button, .export-link, .copy-button { min-height: 48px; padding: 10px 18px; border-radius: 4px; font-weight: 800; text-decoration: none; }
.save-button, .export-link { color: #fffaf0; background: var(--forest); border: 0; }
.copy-button { color: var(--forest); background: transparent; border: 1px solid var(--forest); }

.stats-heading { align-items: end; }
.year-select { min-width: 96px; font-size: .73rem; font-weight: 750; letter-spacing: .1em; }
.year-select select { min-height: 44px; }
.table-wrap { overflow-x: auto; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
table { width: 100%; min-width: 580px; border-collapse: collapse; font-size: .84rem; }
#monthly-table { min-width: 0; table-layout: fixed; font-size: .85rem; }
#monthly-table th, #monthly-table td { padding: 9px 2px; text-align: center; }
#monthly-table th:first-child, #monthly-table td:first-child { text-align: center; }
#monthly-table th { font-size: .67rem; letter-spacing: 0; }
#monthly-table td:not(:first-child) { font-size: .8rem; }
#monthly-table th:nth-child(1) { width: 10%; }
#monthly-table th:nth-child(2) { width: 27%; }
#monthly-table th:nth-child(3) { width: 11%; }
#monthly-table th:nth-child(4) { width: 19%; }
#monthly-table th:nth-child(5), #monthly-table th:nth-child(6) { width: 16.5%; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead { color: var(--muted); background: var(--paper-deep); font-size: .72rem; letter-spacing: .06em; }
tbody tr:last-child > * { border-bottom: 0; }
.annual-row { background: var(--forest-soft); font-weight: 800; }
.chart { width: 100%; height: 330px; }

.log-heading { align-items: end; }
.log-heading h1 { position: relative; left: -.035em; }
.export-link { display: inline-grid; place-items: center; min-height: 44px; padding: 8px 13px; font-size: .84rem; white-space: nowrap; }
.log-filters { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 12px; align-items: end; margin-bottom: 16px; }
.search-field { margin: 0; }
.log-filters input, .log-filters select { box-sizing: border-box; height: 44px; min-height: 44px; }
.month-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: -2px 0 18px; }
.month-chip { min-height: 36px; padding: 6px 11px; color: var(--forest); background: var(--forest-soft); border: 1px solid transparent; border-radius: 99px; font-size: .82rem; font-weight: 750; }
.month-chip:hover { border-color: var(--forest); }
.log-list { display: grid; gap: 30px; }
.log-month > h2 { margin: 0 0 12px; color: var(--forest); font-size: 1.2rem; letter-spacing: -.03em; }
.log-card { padding: 17px 0; border-top: 1px solid var(--line); }
.log-card header { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.log-card time { color: var(--ink); font-weight: 800; }
.weekday { margin-left: 7px; color: var(--muted); font-size: .82rem; }
.record-markers, .metric-line, .device-line { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { padding: 3px 7px; border-radius: 99px; font-size: .72rem; font-weight: 750; }
.quality-tag { color: var(--forest); background: var(--forest-soft); }
.training-tag { color: #73451c; background: var(--amber-soft); }
.sleep-line { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; margin-top: 13px; }
.sleep-line strong { font-family: "Noto Serif SC", "Songti SC", serif; font-size: 1.15rem; }
.sleep-line i { color: var(--amber); font-style: normal; }
.sleep-line > span, .metric-line, .device-line, .extra-data { color: var(--muted); font-size: .83rem; }
.metric-line { margin-top: 10px; }
.metric-line span + span::before { margin-right: 6px; content: "·"; }
.device-line { margin-top: 9px; }
.device-line span { padding: 4px 7px; background: var(--paper-deep); border-radius: 3px; }
.note-copy { margin: 12px 0 0; line-height: 1.72; white-space: pre-wrap; }
.extra-data { margin: 10px 0 0; }
.empty-state { margin: 26px 0; color: var(--muted); }
.log-sentinel { height: 1px; }

@media (max-width: 767px) {
  .log-month > h2, .sleep-line strong {
    font-family: inherit;
    font-size: 1.06rem;
    font-weight: 750;
    letter-spacing: -.02em;
  }
}

@media (min-width: 640px) {
  .app-header { padding-right: 32px; padding-left: 32px; }
  .workspace { padding-right: 32px; padding-left: 32px; }
  .details-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 768px) {
  body { padding-top: 64px; }
  .app-shell { padding-bottom: 0; }
  .app-header { display: none; }
  .workspace { padding-top: 22px; padding-bottom: 48px; }
  .page-shell .workspace { padding-bottom: 48px; }
  .app-nav { top: 0; bottom: auto; display: flex; align-items: center; justify-content: flex-end; gap: 6px; height: 64px; padding: 0 max(32px, calc((100vw - 860px) / 2)); background: color-mix(in srgb, var(--paper) 93%, transparent); border-top: 0; border-bottom: 1px solid var(--line); }
  .app-nav .nav-brand { display: block; margin-right: auto; color: var(--ink); font-family: "Noto Serif SC", "Songti SC", serif; font-size: 1.18rem; font-weight: 700; letter-spacing: -.05em; }
  .app-nav a, .app-nav button { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px; border-radius: 3px; font-size: .84rem; }
  .app-nav a > span, .app-nav button > span { font-size: .94rem; }
  .app-nav a.is-active { background: var(--forest-soft); }
  .savebar { position: sticky; bottom: 14px; width: 100%; margin-top: 24px; }
  .chart { height: 370px; }
}
