:root {
  color-scheme: light;
  --forest: #284d42;
  --forest-dark: #1d3b32;
  --forest-soft: #e6eee5;
  --paper: #f5f3ec;
  --surface: #fffefa;
  --ink: #252e27;
  --muted: #526158;
  --rule: #dedfd4;
  --accent: #a36a40;
  --danger: #8b4535;
  --radius: 1.12rem;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 18rem; line-height: 1.55; }
[hidden] { display: none !important; }
button, input, select, textarea { color: inherit; font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button, a, input, select, textarea { -webkit-tap-highlight-color: #284d4220; }
a { color: var(--forest); text-underline-offset: 0.2em; }
:focus-visible { outline: 3px solid #a36a40; outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
img { max-width: 100%; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.skip-link {
  position: fixed;
  z-index: 12;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: 0.6rem;
  background: var(--surface);
  transform: translateY(calc(-100% - 1.5rem));
}
.skip-link:focus { transform: none; }

.app-shell {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  padding: 2rem 1.15rem 1.5rem;
  display: flex;
  flex-direction: column;
  background: var(--forest-dark);
  color: #f4f4e8;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 0.78rem;
  min-height: 3rem;
  padding: 0 0.32rem;
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.brand-mark {
  flex: 0 0 2.5rem;
  display: grid;
  width: 2.5rem;
  height: 2.5rem;
  place-items: center;
  border: 1px solid #a4bba7;
  border-radius: 0.68rem;
  color: #fffefa;
  font: 700 1.5rem/1 "Songti SC", "SimSun", serif;
  background: #31574b;
}

.nav {
  display: grid;
  gap: 0.43rem;
  margin-top: 2.7rem;
}

.nav-button {
  display: flex;
  align-items: center;
  gap: 0.78rem;
  width: 100%;
  min-height: 3.15rem;
  padding: 0.48rem 0.72rem;
  border: 1px solid transparent;
  border-radius: 0.75rem;
  color: inherit;
  background: transparent;
  text-align: left;
  font-weight: 650;
}

.sidebar .nav-button:hover { background: #f3f4ea12; }
.sidebar .nav-button:focus-visible { outline-color: #ebc08d; }
.sidebar .nav-button.is-active,
.sidebar .nav-button[aria-current="page"] {
  border-color: #f2f3e725;
  color: #fffefa;
  background: #3a5d51;
}

.nav-icon {
  display: grid;
  width: 1.85rem;
  height: 1.85rem;
  flex-shrink: 0;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 0.5rem;
  font-size: 0.82rem;
  line-height: 1;
}

.sidebar-footer {
  margin-top: auto;
  padding: 1.05rem 0.32rem 0;
  border-top: 1px solid #f2f3e735;
  color: #d5dfd5;
  font-size: 0.875rem;
}

.main-content { min-width: 0; }

#app-root {
  width: min(100%, 76rem);
  min-width: 0;
  margin-inline: auto;
  padding: 2.6rem clamp(1.5rem, 4.2vw, 4rem) 4.25rem;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.85rem 1.4rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 1.45rem;
}

.page-heading {
  min-width: 0;
  overflow-wrap: anywhere;
}

.page-heading h1, h1.page-heading {
  font-family: "Songti SC", "Noto Serif CJK SC", "SimSun", Georgia, serif;
  font-size: clamp(2rem, 3.5vw, 3rem);
  line-height: 1.15;
  letter-spacing: 0.027em;
  font-weight: 750;
}

.page-heading p, .eyebrow {
  color: var(--muted);
  font-size: 0.875rem;
}

.eyebrow { margin-top: 0.43rem; }
.page-heading h1 + p { margin-top: 0.6rem; }
.page-content { min-width: 0; }

.primary-button, .secondary-button, .text-button, .icon-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 0.38rem;
  min-height: 2.75rem;
  padding: 0.55rem 0.9rem;
  border: 1px solid transparent;
  border-radius: 0.66rem;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}

.primary-button { background: var(--forest); color: #fffefa; }
.primary-button:hover:not(:disabled) { background: var(--forest-dark); }
.secondary-button, .icon-button {
  color: var(--forest-dark);
  background: var(--forest-soft);
  border-color: #d4e0d1;
}
.secondary-button:hover:not(:disabled), .icon-button:hover:not(:disabled) { background: #dce8db; }
.text-button { color: var(--forest); background: transparent; }
.text-button:hover:not(:disabled) { background: #e9eee4; }
:is(.primary-button, .secondary-button, .text-button, .icon-button):disabled {
  color: #56625b;
  border-color: var(--rule);
  background: #e8e9e2;
}

.search-panel, .toolbar, .period-controls, .dialog-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.search-panel { margin-bottom: 1.35rem; }
.search-field {
  display: flex;
  align-items: center;
  flex: 1 1 15rem;
  gap: 0.6rem;
  min-width: 0;
  min-height: 3.12rem;
  padding: 0.1rem 0.85rem;
  border: 1px solid var(--rule);
  border-radius: 0.75rem;
  color: var(--forest);
  background: var(--surface);
}
input.search-field { padding: 0.55rem 0.85rem; }
.search-field:focus-within { border-color: var(--forest); }
.search-field input {
  min-width: 0;
  padding: 0.55rem 0;
  width: 100%;
  border: 0;
  color: var(--ink);
  background: transparent;
}
.search-field input:focus { outline: 0; }
.search-field:focus-within:not(input) { outline: 2px solid var(--forest); outline-offset: 2px; }
.page-content > .toolbar { margin-bottom: 1.1rem; }
.split { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }
.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(14rem, 1fr);
  align-items: start;
  gap: 1.3rem;
}
.summary-stack { display: grid; gap: 1.05rem; min-width: 0; }
.section { min-width: 0; }
.section + .section, .page-content > .section { margin-top: 1.55rem; }
.summary-stack > .section + .section { margin-top: 0; }
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.45rem 0.8rem;
  min-height: 2.35rem;
  margin-bottom: 0.45rem;
}
.section-heading h2, h2.section-heading { font-size: 1.16rem; font-weight: 750; line-height: 1.35; }
.section-heading h3 { font-size: 1.04rem; line-height: 1.35; }
.section-heading p, .section-heading small { font-size: 0.875rem; color: var(--muted); }

.card, .week-board, .entry-list, .period-list {
  min-width: 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
}
.card, .week-board { padding: clamp(0.85rem, 1.8vw, 1.25rem); }
.card + .card { margin-top: 0.8rem; }
.week-board > .entry-meta + .week-grid, .week-board > .week-grid + * { margin-top: 0.8rem; }
.workbench-primary :is(.entry-list, .empty-state) + .week-board { margin-top: 0.75rem; }
.week-board > .section { padding-top: 0.55rem; border-top: 1px solid var(--rule); }
.entry-list, .period-list { padding: 0; overflow: hidden; }
.entry-list:empty, .period-list:empty { display: none; }
.entry-row, .period-row {
  position: relative;
  display: flex;
  width: 100%;
  min-width: 0;
  min-height: 3.4rem;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem 0.75rem;
  padding: 0.75rem 0.9rem;
  border: 0;
  color: var(--ink);
  background: transparent;
  text-align: left;
  overflow-wrap: anywhere;
}
.entry-row + .entry-row, .period-row + .period-row { border-top: 1px solid var(--rule); }
.history-row { display: grid; justify-items: start; gap: 0.2rem; padding: 0.8rem 0.9rem; overflow-wrap: anywhere; }
.history-row + .history-row { border-top: 1px solid var(--rule); }
.entry-row:where(button, a):hover, .period-row:where(button, a):hover { background: #f0f3eb; }
.entry-row:focus-visible, .period-row:focus-visible { outline-offset: -3px; }
.entry-text {
  display: grid;
  flex: 1 1 12rem;
  gap: 0.18rem;
  min-width: 0;
}
.entry-text :is(h2, h3, strong), .entry-title { font-size: 1rem; font-weight: 740; line-height: 1.35; }
.entry-meta, .entry-preview, .entry-progress {
  color: var(--muted);
  font-size: 0.875rem;
}
.entry-meta { display: flex; flex-wrap: wrap; gap: 0.15rem 0.55rem; }
.entry-preview, .entry-progress {
  display: -webkit-box;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.entry-progress { color: var(--forest); }
.status-tag {
  flex-shrink: 0;
  max-width: 8rem;
  padding: 0.2rem 0.43rem;
  border-radius: 0.38rem;
  background: var(--forest-soft);
  color: var(--forest-dark);
  font-size: 0.875rem;
  line-height: 1.3;
}
.empty-state, .state-message, .error-message {
  display: block;
  padding: 0.9rem 1rem;
  border: 1px dashed #cdd1c3;
  border-radius: 0.8rem;
  color: var(--muted);
  background: #fcfbf5;
  font-size: 0.9375rem;
}
.state-message { margin-bottom: 0.8rem; }
.error-message { border-color: #d8beb1; background: #fff6ef; color: var(--danger); }
.card > :is(.empty-state, .state-message) { background: #f8f8f1; }

.week-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.3rem;
}
.day-button {
  display: grid;
  place-items: center;
  gap: 0.15rem;
  min-width: 0;
  min-height: clamp(3.25rem, 5.5vw, 4.15rem);
  padding: 0.35rem 0;
  border: 1px solid transparent;
  border-radius: 0.64rem;
  color: var(--forest-dark);
  background: #f0f2e9;
  font-size: 0.875rem;
}
.day-button :is(strong, .day-number) { font-size: 1.18rem; font-weight: 740; line-height: 1; }
.day-button:hover { border-color: #7d9a86; }
.day-button.is-today { border-color: var(--forest); }
.day-button.is-active, .day-button[aria-pressed="true"] { background: var(--forest); color: #fffefa; }
.day-dot { width: 0.3rem; height: 0.3rem; border-radius: 50%; background: var(--accent); visibility: hidden; }
.day-button.is-active .day-dot { background: #fffefa; }
.day-dot.is-visible { visibility: visible; }

.segment {
  display: flex;
  gap: 0.2rem;
  padding: 0.22rem;
  border: 1px solid #d9e1d4;
  border-radius: 0.78rem;
  background: #e9eee3;
}
.segment-button {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.35rem 0.74rem;
  border: 0;
  border-radius: 0.56rem;
  background: transparent;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 680;
}
.segment-button:hover { background: #dfe7dc; }
.segment-button.is-active, .segment-button[aria-pressed="true"] { color: #fffefa; background: var(--forest); }
.period-controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.7rem; margin: 0.9rem 0; }
.period-controls > .section-heading { margin-bottom: 0; }
.period-controls :is(.text-button, .secondary-button, .icon-button) { min-width: 2.75rem; }
.period-row .entry-meta { text-align: right; }
.session-card { max-width: 36rem; }
.session-card h2 { margin-bottom: 0.45rem; font-size: 1.22rem; }
.session-card p { margin-bottom: 0.65rem; color: var(--muted); }
.session-card form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0.45rem 0.65rem; margin-top: 1.2rem; }
.session-card :is(label, .form-error) { grid-column: 1 / -1; margin: 0; }
.session-card .form-error { color: var(--danger); }
.session-card .account-switch { margin-bottom: 1.1rem; }
.session-card .account-form { grid-template-columns: minmax(0, 1fr); }
.account-form .field:not(:first-child) { margin-top: 0.45rem; }
.account-form .primary-button { margin-top: 0.65rem; justify-self: start; }
.account-form .field-help { margin: 0; font-size: 0.875rem; color: var(--muted); }
.notebook-list p { display: flex; justify-content: space-between; align-items: baseline; gap: 0.7rem; }
.notebook-list p + p { margin-top: 0.7rem; padding-top: 0.7rem; border-top: 1px solid var(--rule); }
.notebook-list span { color: var(--muted); font-size: 0.875rem; }
.account-card .entry-meta { margin: 0.3rem 0 0.85rem; }
.account-preferences { display: flex; flex-wrap: wrap; align-items: end; gap: 0.65rem; margin: 0.8rem 0 1rem; }
.account-preferences .field { flex: 1 0 12rem; max-width: 18rem; }
.account-preferences .form-error { flex-basis: 100%; }
.draft-notice, .capture-status { margin: 0.55rem 0; }
.draft-notice[hidden] { display: none; }
.danger-button { color: var(--danger); }

.dialog {
  width: min(calc(100% - 2rem), 42rem);
  max-height: min(90vh, 48rem);
  max-height: min(90dvh, 48rem);
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 1.25rem;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1.4rem 3.5rem #0b261a40;
}
.dialog::backdrop { background: #142c24a3; }
.dialog-content { min-width: 0; padding: clamp(1rem, 3.2vw, 1.75rem); }
.dialog-heading {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.9rem;
  padding: 0.6rem clamp(1rem, 3.2vw, 1.75rem);
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
  font-size: 1.35rem;
  font-weight: 750;
}
.dialog-heading :is(h1, h2) { font-size: 1.35rem; }
.dialog-actions { justify-content: flex-end; margin-top: 1.1rem; padding-top: 0.85rem; border-top: 1px solid var(--rule); }
.editor-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem; }
.field { display: grid; gap: 0.34rem; min-width: 0; margin-bottom: 0.75rem; font-weight: 630; }
.editor-fields .field { margin: 0; }
.field:has(textarea), .field.is-wide, .editor-fields > details { grid-column: 1 / -1; }
.field :is(input, textarea, select), .date-field input, .session-card input, .search-panel select {
  width: 100%;
  min-width: 0;
  min-height: 2.72rem;
  padding: 0.5rem 0.63rem;
  border: 1px solid #cfd8cb;
  border-radius: 0.62rem;
  background: #fafaf5;
  color: var(--ink);
  font-weight: 400;
}
.field textarea { min-height: 7.8rem; resize: vertical; }
.field select, .search-panel select {
  appearance: none;
  padding-right: 2rem;
  background:
    linear-gradient(45deg, transparent 49%, var(--forest) 51%) calc(100% - 17px) 50% / 6px 6px no-repeat,
    linear-gradient(135deg, var(--forest) 49%, transparent 51%) calc(100% - 11px) 50% / 6px 6px no-repeat,
    #fafaf5;
}
.field input[type="checkbox"] { width: 1.2rem; min-height: 1.2rem; accent-color: var(--forest); }
.field:has(input[type="checkbox"]) { display: flex; align-items: center; gap: 0.65rem; }
.field :is(small, .field-hint) { color: var(--muted); font-weight: 400; font-size: 0.875rem; }
.form-error, .form-feedback { margin-top: 0.72rem; color: var(--muted); font-size: 0.9rem; }
.form-error, .form-feedback.is-error, .danger-button { color: var(--danger); }
.editor-options { margin-top: 0.9rem; border-top: 1px solid var(--rule); }
.editor-options summary { min-height: 2.75rem; padding: 0.63rem 0; color: var(--forest); font-weight: 650; cursor: pointer; }
.editor-options[open] > .editor-fields { padding-top: 0.38rem; }
.checkbox-field { display: inline-flex; align-items: center; gap: 0.45rem; min-height: 2.75rem; font-weight: 620; cursor: pointer; }
.checkbox-field input { width: 1.12rem; height: 1.12rem; margin: 0; accent-color: var(--forest); }
.search-panel select { width: auto; min-height: 3.12rem; background-color: var(--surface); }
.live-notice {
  position: fixed;
  z-index: 8;
  inset: auto max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) auto;
  max-width: min(24rem, calc(100% - 2rem));
  padding: 0.68rem 0.88rem;
  border-radius: 0.7rem;
  background: var(--forest-dark);
  color: #fffefa;
}
.live-notice:empty { display: none; }
.mobile-nav { display: none; }

@media (max-width: 62rem) {
  .app-shell { grid-template-columns: 12rem minmax(0, 1fr); }
  .sidebar { padding-inline: 0.85rem; }
  .workspace-grid { gap: 1rem; grid-template-columns: minmax(0, 1.5fr) minmax(12rem, 1fr); }
}

@media (max-width: 49rem) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  #app-root { padding: 1.35rem 1.15rem calc(6.1rem + env(safe-area-inset-bottom)); }
  .page-header { align-items: center; padding-bottom: 0.9rem; margin-bottom: 1rem; }
  .workspace-grid { grid-template-columns: minmax(0, 1fr); gap: 1.05rem; }
  .mobile-nav, .mobile-nav .nav {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.2rem;
    margin: 0;
  }
  .mobile-nav {
    position: fixed;
    z-index: 5;
    inset: auto 0 0;
    padding: 0.38rem max(0.55rem, env(safe-area-inset-right)) calc(0.4rem + env(safe-area-inset-bottom)) max(0.55rem, env(safe-area-inset-left));
    border-top: 1px solid var(--rule);
    background: #fffefa;
    box-shadow: 0 -0.3rem 1rem #263d2b0b;
  }
  .mobile-nav .nav { grid-column: 1 / -1; }
  .mobile-nav .nav-button {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 0.26rem;
    min-height: 3.65rem;
    padding: 0.24rem 0.1rem;
    color: var(--muted);
    text-align: center;
    font-size: 0.875rem;
    line-height: 1.15;
  }
  .mobile-nav .nav-icon { width: 1.4rem; height: 1.4rem; border-radius: 0.4rem; }
  .mobile-nav .nav-button.is-active, .mobile-nav .nav-button[aria-current="page"] { color: var(--forest-dark); background: var(--forest-soft); }
  .live-notice { bottom: calc(5.45rem + env(safe-area-inset-bottom)); }
}

@media (max-width: 32rem) {
  #app-root { padding-inline: max(0.87rem, env(safe-area-inset-left)) max(0.87rem, env(safe-area-inset-right)); }
  .day-button { min-height: 3.5rem; }
  .search-panel { display: grid; grid-template-columns: minmax(0, 1fr) auto; margin-bottom: 1.05rem; }
  .entry-row, .period-row { padding-inline: 0.7rem; }
  .dialog {
    inset: auto 0 0;
    width: 100%;
    max-width: none;
    margin: 0;
    border-radius: 1rem 1rem 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (max-width: 23rem) {
  .page-header { align-items: start; flex-wrap: wrap; }
  .editor-fields { grid-template-columns: minmax(0, 1fr); }
  .dialog-actions > .primary-button { flex-grow: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
