:root {
  --bg: #faf8f4;
  --surface: #fffefb;
  --surface-2: #f4f1eb;
  --border: #e5dfd6;
  --border-focus: #a8c4b4;
  --text: #2d2926;
  --text-2: #7a6f65;
  --green: #4a7c65;
  --green-mid: #6b9e86;
  --green-light: #e4ede7;
  --amber: #c8882e;
  --amber-light: #fdf3e0;
  --amber-mid: #e8a84a;
  --blue: #4e7299;
  --blue-light: #e6eef6;
  --clay: #b86a4a;
  --clay-light: #faece6;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 20px;
  --shadow: 0 2px 12px rgba(45, 41, 38, 0.07);
  --shadow-lg: 0 8px 32px rgba(45, 41, 38, 0.1);
  --header-h: 64px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.4; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(74, 124, 101, 0.3);
  outline-offset: 2px;
}

/* ─── Header ──────────────────────────────────────────────── */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 28px;
  background: rgba(250, 248, 244, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--green);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-sub {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-2);
  letter-spacing: 0.03em;
}

.brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.nav-pills {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: 4px;
}

.nav-tab {
  padding: 7px 16px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  transition: background 140ms ease, color 140ms ease;
}

.nav-tab:hover { background: var(--green-light); color: var(--green); }

.nav-tab.active {
  background: var(--green);
  color: #fff;
}

.privacy-pill {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
}

/* ─── Body ───────────────────────────────────────────────── */

.app-body {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 28px 64px;
}

.view { display: none; }
.view.active { display: block; }

.view-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.view-top h2 {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  line-height: 1.2;
}

.view-date {
  margin: 0;
  font-size: 13px;
  color: var(--text-2);
  font-weight: 600;
  flex-shrink: 0;
}

/* ─── Cards ──────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.card-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.card-label {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 800;
  color: var(--text-2);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--green-light);
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
}

.text-muted { color: var(--text-2); line-height: 1.7; }

/* ─── Buttons ────────────────────────────────────────────── */

.btn-primary,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-weight: 700;
  font-size: 14px;
  border: 1px solid transparent;
  transition: background 130ms ease, box-shadow 130ms ease, transform 80ms ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

.btn-primary:hover { background: var(--green-mid); border-color: var(--green-mid); }
.btn-primary:active { transform: scale(0.97); }

.btn-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--green);
}

.btn-ghost:hover { background: var(--green-light); border-color: #b8d0c2; }

.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ─── Inputs ─────────────────────────────────────────────── */

label {
  display: grid;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
}

input, select, textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
  transition: border-color 130ms ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  background: #fff;
}

textarea { resize: vertical; line-height: 1.65; }

.full-width { grid-column: 1 / -1; }

/* ─── Today ──────────────────────────────────────────────── */

.pace-card { padding-bottom: 0; overflow: hidden; }

.pace-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 0;
}

.pace-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  padding: 14px 12px;
  text-align: left;
  transition: border-color 150ms, background 150ms, box-shadow 150ms;
}

.pace-icon { font-size: 20px; margin-bottom: 2px; }
.pace-option strong { font-size: 14px; line-height: 1.3; }
.pace-option span { font-size: 12px; color: var(--text-2); line-height: 1.5; }

.pace-option:hover { border-color: #b8d0c2; background: var(--green-light); }

.pace-option[data-pace="rest"].active {
  border-color: #b0c6de;
  background: var(--blue-light);
  box-shadow: 0 -3px 0 var(--blue) inset;
}
.pace-option[data-pace="gentle"].active {
  border-color: #a4c8b4;
  background: var(--green-light);
  box-shadow: 0 -3px 0 var(--green) inset;
}
.pace-option[data-pace="open"].active {
  border-color: #d4b878;
  background: var(--amber-light);
  box-shadow: 0 -3px 0 var(--amber-mid) inset;
}

.pace-suggestion {
  margin-top: 14px;
  padding: 14px 18px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.75;
  color: var(--text-2);
}

.task-list { display: grid; gap: 10px; }

.task-empty { margin: 0; color: var(--text-2); line-height: 1.7; font-size: 14px; }

.task-item {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  transition: background 120ms;
}

.task-item:hover { background: var(--green-light); }

.task-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  accent-color: var(--green);
  cursor: pointer;
}

.task-item.done span { text-decoration: line-through; color: var(--text-2); }

.quick-form { display: grid; gap: 14px; }

/* ─── Stories ────────────────────────────────────────────── */

.stories-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 20px;
  align-items: start;
}

.story-browser {
  padding: 0;
  overflow: hidden;
  position: sticky;
  top: calc(var(--header-h) + 16px);
  max-height: calc(100vh - var(--header-h) - 48px);
  display: flex;
  flex-direction: column;
}

.story-browser .card-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

.story-browser .card-header h3 { font-size: 16px; }

.story-list {
  display: grid;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.story-list-item {
  width: 100%;
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 10px;
  align-items: start;
  padding: 11px 16px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-align: left;
  transition: background 120ms;
  cursor: pointer;
  min-height: 44px;
}

.story-list-item:last-child { border-bottom: 0; }
.story-list-item:hover { background: var(--green-light); }
.story-list-item.active {
  background: var(--green-light);
  box-shadow: inset 3px 0 0 var(--green);
}

.story-list-number {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  font-weight: 800;
  color: var(--green);
  padding-top: 3px;
}

.story-list-details { display: grid; gap: 5px; min-width: 0; }

.story-list-details strong {
  font-family: "Songti SC", STSong, "Noto Serif CJK SC", serif;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
}

.story-list-meta { font-size: 11px; color: var(--text-2); font-weight: 600; }
.story-list-feedback {
  width: fit-content;
  font-size: 11px;
  font-weight: 800;
  color: var(--green);
  background: var(--green-light);
  padding: 2px 7px;
  border-radius: 6px;
}

.story-reader {
  background: #fffefb;
  border: 1px solid var(--border);
  border-top: 3px solid var(--amber-mid);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.story-reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.story-back { display: none; }

.reading-progress { height: 3px; background: var(--border); }
.reading-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--green);
  transition: width 100ms linear;
}

.story-copy { padding: 32px 36px 36px; }

.story-kicker {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 800;
  color: var(--green);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.story-copy > h3 {
  margin: 0 0 26px;
  font-family: "Songti SC", STSong, "Noto Serif CJK SC", serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
}

.story-body {
  font-family: "Songti SC", STSong, "Noto Serif CJK SC", serif;
  font-size: 17px;
  line-height: 2.1;
  color: #383130;
}

.story-body p { margin: 0 0 1.2em; }

.story-response { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--border); }
.story-response .card-label { margin-bottom: 12px; }

.story-response-options { display: flex; flex-wrap: wrap; gap: 8px; }

.story-response-options button {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  padding: 8px 14px;
  font-weight: 700;
  font-size: 13px;
  transition: all 130ms;
}

.story-response-options button:hover,
.story-response-options button.active {
  border-color: var(--border-focus);
  background: var(--green-light);
  color: var(--green);
}

.story-pager {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 26px;
}

.story-position { font-size: 12px; }

/* ─── Record form ────────────────────────────────────────── */

.record-form { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }

.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ─── Library ────────────────────────────────────────────── */

.library-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.library-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.library-card h3 { margin: 0 0 8px; font-size: 17px; }
.library-card > p { margin: 0 0 14px; font-size: 14px; line-height: 1.7; color: var(--text-2); }

.mini-task {
  background: var(--blue-light);
  border-left: 3px solid var(--blue);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.65;
}

.mini-task p { margin: 0 0 6px; }
.mini-task p:last-child { margin-bottom: 0; }
.mini-task strong { color: var(--text); }

/* ─── Toast ──────────────────────────────────────────────── */

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(320px, calc(100vw - 40px));
  background: var(--text);
  color: #fff;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
  box-shadow: var(--shadow-lg);
}

.toast.show { opacity: 1; transform: translateY(0); }

/* ─── Animations ────────────────────────────────────────── */

@keyframes iconGrow {
  from { transform: scale(0) rotate(-15deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes iconFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  40%       { transform: translateY(-4px) rotate(-2deg); }
  70%       { transform: translateY(-2px) rotate(1.5deg); }
}

@keyframes iconWiggle {
  0%   { transform: rotate(0deg) scale(1); }
  20%  { transform: rotate(-10deg) scale(1.1); }
  50%  { transform: rotate(8deg) scale(1.08); }
  75%  { transform: rotate(-4deg) scale(1.04); }
  100% { transform: rotate(0deg) scale(1); }
}

.brand-mark {
  animation:
    iconGrow   500ms cubic-bezier(0.22, 1, 0.36, 1) both,
    iconFloat  4s ease-in-out 500ms infinite;
}

.brand-mark:hover {
  animation: iconWiggle 500ms cubic-bezier(0.22, 1, 0.36, 1);
}


@keyframes slideUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes scalePop {
  0%   { transform: scale(1); }
  35%  { transform: scale(0.93); }
  65%  { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.view.active .view-top {
  animation: slideUp 300ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.view.active .card,
.view.active .stories-layout,
.view.active .library-grid {
  animation: slideUp 360ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.view.active .card:nth-child(2),
.view.active .stories-layout { animation-delay: 55ms; }
.view.active .card:nth-child(3) { animation-delay: 110ms; }
.view.active .card:nth-child(4) { animation-delay: 165ms; }

.library-card:nth-child(1) { animation: slideUp 340ms cubic-bezier(0.22, 1, 0.36, 1) 80ms both; }
.library-card:nth-child(2) { animation: slideUp 340ms cubic-bezier(0.22, 1, 0.36, 1) 140ms both; }
.library-card:nth-child(3) { animation: slideUp 340ms cubic-bezier(0.22, 1, 0.36, 1) 200ms both; }
.library-card:nth-child(4) { animation: slideUp 340ms cubic-bezier(0.22, 1, 0.36, 1) 260ms both; }

.story-list-item { animation: slideUp 220ms cubic-bezier(0.22, 1, 0.36, 1) both; }

.pace-option { transform-origin: center; transition: border-color 150ms, background 150ms, transform 100ms; }
.pace-option:active { transform: scale(0.94); }
.pace-option.popping { animation: scalePop 320ms cubic-bezier(0.22, 1, 0.36, 1); }

.nav-tab { transition: background 180ms ease, color 180ms ease, transform 80ms ease; }
.nav-tab:active { transform: scale(0.93); }

.btn-primary { transition: background 130ms ease, border-color 130ms ease, transform 80ms ease, box-shadow 130ms ease; }
.btn-ghost   { transition: background 130ms ease, border-color 130ms ease, transform 80ms ease; }
.btn-primary:active, .btn-ghost:active { transform: scale(0.95); transition-duration: 50ms; }

.task-item { transition: background 120ms ease, transform 80ms ease; }
.task-item:active { transform: scale(0.99); }

.task-item span { transition: color 200ms ease; }

/* ─── Responsive ─────────────────────────────────────────── */

@media (max-width: 720px) {
  .app-header {
    padding: 0 16px;
    gap: 10px;
  }

  .nav-pills {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    display: flex;
    justify-content: space-around;
    gap: 4px;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    background: rgba(250, 248, 244, 0.96);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(45, 41, 38, 0.06);
  }

  .nav-tab {
    flex: 1;
    padding: 8px 6px;
    font-size: 13px;
    border-radius: 10px;
  }

  .privacy-pill { display: none; }

  .app-body {
    padding: 20px 16px calc(80px + env(safe-area-inset-bottom));
  }

  .view-top h2 { font-size: 24px; }

  .pace-options { grid-template-columns: repeat(3, 1fr); }

  /* Stories on mobile */
  .stories-layout {
    display: block;
    position: static;
  }

  .story-browser {
    position: static;
    max-height: none;
    margin-bottom: 16px;
  }

  .story-reader { display: none; }

  .stories-layout.is-reading .story-browser { display: none; }
  .stories-layout.is-reading .story-reader { display: block; }

  .story-reader-toolbar {
    position: sticky;
    top: var(--header-h);
    z-index: 5;
    justify-content: space-between;
    background: rgba(255, 254, 251, 0.96);
    backdrop-filter: blur(10px);
  }

  .story-back { display: inline-flex; }
  .story-copy { padding: 24px 20px 32px; }
  .story-copy > h3 { font-size: 24px; }
  .story-body { font-size: 17px; }

  .library-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .pace-options { grid-template-columns: 1fr; gap: 8px; }
  .pace-option { flex-direction: row; align-items: center; gap: 12px; }
  .pace-icon { font-size: 22px; margin: 0; }
  .pace-option strong, .pace-option span { display: inline; }
  .pace-option > span:not(.pace-icon)::before { content: " · "; }
}

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