:root {
  --paper: #f4f0e6;
  --paper-deep: #e7dfcf;
  --ink: #20201d;
  --muted: #6d6a62;
  --line: #c8bfad;
  --wine: #7b2f32;
  --wine-soft: #ead9d6;
  --green: #173f3b;
  --green-soft: #dce5df;
  --blue: #31506f;
  --blue-soft: #dce4ec;
  --gold: #9a7436;
  --white: #fbfaf6;
  --shadow: 0 14px 38px rgba(46, 39, 29, 0.09);
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", Georgia, serif;
  --sans: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  letter-spacing: 0;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(rgba(116, 94, 57, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 100% 28px;
}

button, textarea, input { font: inherit; letter-spacing: 0; }
button { color: inherit; }

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon, .entrance-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.app-shell { min-height: 100vh; }

.masthead {
  position: relative;
  min-height: 118px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: #d8ded8;
}

.masthead::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(244, 240, 230, 0.98) 0%, rgba(244, 240, 230, 0.89) 47%, rgba(244, 240, 230, 0.58) 100%),
    repeating-linear-gradient(90deg, transparent 0 74px, rgba(23, 63, 59, 0.07) 74px 76px);
}

.masthead-art { position: absolute; inset: 0; opacity: 0.8; }

.column {
  position: absolute;
  bottom: -10px;
  width: 62px;
  height: 132px;
  border: 9px solid rgba(49, 80, 111, 0.22);
  border-top-width: 18px;
  border-bottom-width: 15px;
  background: repeating-linear-gradient(90deg, transparent 0 9px, rgba(49,80,111,.12) 9px 13px);
}

.column-left { right: 340px; }
.column-right { right: 36px; }

.shelf {
  position: absolute;
  right: 115px;
  height: 34px;
  border-bottom: 8px solid rgba(123, 47, 50, 0.25);
  background: repeating-linear-gradient(90deg, rgba(23,63,59,.26) 0 9px, transparent 9px 12px, rgba(123,47,50,.22) 12px 20px, transparent 20px 23px);
}

.shelf-one { top: 18px; width: 280px; }
.shelf-two { top: 69px; width: 220px; right: 132px; }

.masthead-inner {
  position: relative;
  z-index: 1;
  width: min(1120px, calc(100% - 40px));
  min-height: 118px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 0;
  padding: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid var(--green);
  color: var(--wine);
  font-family: Georgia, serif;
  font-size: 27px;
}

.brand strong {
  display: block;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.brand small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.date-label { margin: 0; color: var(--green); font-family: var(--serif); font-size: 14px; }

.main-content {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 34px 0 120px;
}

.view { display: none; }
.view.is-active { display: block; animation: reveal 220ms ease-out; }

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

.eyebrow {
  margin: 0 0 9px;
  color: var(--wine);
  font-size: 12px;
  font-weight: 700;
}

.question-band {
  position: relative;
  min-height: 330px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 54px 8% 50px;
  border-top: 4px solid var(--wine);
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(circle at 86% 25%, rgba(154,116,54,.14) 0 2px, transparent 3px),
    linear-gradient(112deg, var(--white) 0 72%, var(--green-soft) 72% 100%);
}

.question-band::after {
  content: "Ω";
  position: absolute;
  right: 7%;
  bottom: 16px;
  color: rgba(23, 63, 59, 0.12);
  font-family: Georgia, serif;
  font-size: 142px;
  line-height: 1;
}

.question-band h1 {
  position: relative;
  z-index: 1;
  max-width: 790px;
  margin: 0;
  font-family: var(--serif);
  font-size: 52px;
  font-weight: 600;
  line-height: 1.42;
}

.question-source {
  margin: 20px 0 28px;
  color: var(--muted);
  font-size: 13px;
}

.primary-command, .quiet-command {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--green);
  padding: 11px 17px;
  cursor: pointer;
}

.primary-command { background: var(--green); color: #fff; }
.primary-command:hover { background: #22564f; }
.quiet-command { background: transparent; color: var(--green); }

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.section-heading h2, .page-heading h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
}

.section-heading h2 { font-size: 26px; }
.page-heading { margin: 8px 0 28px; }
.page-heading h1 { font-size: 38px; }

.unfinished-section, .entrance-section, .resurface-section { padding: 48px 0 0; }

.unfinished-record {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  padding: 18px 22px;
  background: rgba(251,250,246,.68);
  text-align: left;
  cursor: pointer;
}

.entrance-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.entrance {
  position: relative;
  min-height: 225px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  border: 0;
  border-right: 1px solid var(--line);
  padding: 24px;
  background: rgba(251, 250, 246, 0.76);
  text-align: left;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease;
}

.entrance:last-child { border-right: 0; }
.entrance:hover { background: var(--white); transform: translateY(-3px); }
.entrance-index { color: var(--muted); font-family: Georgia, serif; font-size: 13px; }
.entrance-icon { width: 28px; height: 28px; }
.entrance-thought .entrance-icon { color: var(--wine); }
.entrance-product .entrance-icon { color: var(--blue); }
.entrance-problem .entrance-icon { color: var(--green); }
.entrance-copy { grid-column: 1 / -1; align-self: end; }
.entrance-copy strong { display: block; font-family: var(--serif); font-size: 24px; }
.entrance-copy small { display: block; margin-top: 10px; color: var(--muted); line-height: 1.7; }
.entrance-arrow { grid-column: 2; justify-self: end; }

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  margin-bottom: 30px;
  background: var(--white);
}

.segmented button {
  min-width: 78px;
  border: 0;
  border-right: 1px solid var(--line);
  padding: 9px 15px;
  background: transparent;
  cursor: pointer;
}

.segmented button:last-child { border-right: 0; }
.segmented button.is-selected { background: var(--green); color: #fff; }

.timeline-list { border-top: 1px solid var(--line); }

.timeline-entry {
  width: 100%;
  display: grid;
  grid-template-columns: 110px 1fr auto;
  align-items: start;
  gap: 28px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 26px 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.timeline-entry:hover { background: rgba(251,250,246,.72); }
.timeline-date { color: var(--muted); font-family: var(--serif); font-size: 13px; line-height: 1.7; }
.timeline-copy strong { display: block; margin-bottom: 7px; font-family: var(--serif); font-size: 21px; }
.timeline-copy p { margin: 0; color: var(--muted); line-height: 1.65; }
.kind-badge { padding: 4px 7px; border: 1px solid currentColor; font-size: 11px; }
.kind-thought { color: var(--wine); }
.kind-product { color: var(--blue); }
.kind-problem { color: var(--green); }

.empty-state {
  padding: 68px 20px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
  font-family: var(--serif);
}

.weekly-ledger {
  display: grid;
  grid-template-columns: 1.35fr repeat(3, 1fr);
  border-top: 4px solid var(--green);
  border-bottom: 1px solid var(--line);
  background: var(--white);
}

.ledger-cell { min-height: 150px; padding: 26px; border-right: 1px solid var(--line); }
.ledger-cell:last-child { border-right: 0; }
.ledger-cell strong { display: block; margin-top: 15px; font-family: var(--serif); font-size: 34px; }
.ledger-lead strong { font-size: 26px; line-height: 1.45; }
.ledger-cell small { color: var(--muted); }

.resurface-card {
  border-left: 4px solid var(--wine);
  padding: 24px 26px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.resurface-card h3 { margin: 0 0 10px; font-family: var(--serif); font-size: 24px; }
.resurface-card p { margin: 0 0 20px; color: var(--muted); line-height: 1.75; }

.settings-list { border-top: 1px solid var(--line); }
.settings-row {
  width: 100%;
  min-height: 78px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 15px 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.settings-row:hover { background: rgba(251,250,246,.72); }
.settings-row > span strong, .settings-row > span small { display: block; }
.settings-row > span small { margin-top: 5px; color: var(--muted); }
.settings-upload input { position: absolute; opacity: 0; pointer-events: none; }
.storage-summary { margin: 24px 0 0; color: var(--muted); font-size: 13px; }

.guide-view, .detail-view, .ai-view { max-width: 780px; margin: 0 auto; }
.guide-topbar {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 18px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.guide-topbar h1 { margin: 0; font-family: var(--serif); font-size: 29px; font-weight: 600; }
.guide-progress { color: var(--muted); font-family: Georgia, serif; }
.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--white);
  cursor: pointer;
}
.icon-button.danger { color: var(--wine); }
.guide-thread { padding-top: 30px; }
.guide-history { display: grid; gap: 16px; margin-bottom: 32px; }
.history-pair { border-left: 2px solid var(--line); padding: 2px 0 4px 18px; }
.history-pair dt { margin-bottom: 7px; color: var(--muted); font-size: 12px; }
.history-pair dd { margin: 0; line-height: 1.75; white-space: pre-wrap; }
.guide-form label { display: block; margin-bottom: 16px; font-family: var(--serif); font-size: 26px; line-height: 1.5; }
.guide-form textarea {
  width: 100%;
  min-height: 170px;
  resize: vertical;
  border: 1px solid var(--line);
  border-top: 3px solid var(--green);
  border-radius: 0;
  padding: 18px;
  outline: 0;
  background: var(--white);
  color: var(--ink);
  line-height: 1.75;
}
.guide-form textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23,63,59,.1); }
.guide-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; margin-top: 18px; }
#guide-save-exit { margin-right: auto; }

.detail-content { padding: 28px 0; }
.detail-section { padding: 22px 0; border-bottom: 1px solid var(--line); }
.detail-section h2 { margin: 0 0 10px; color: var(--muted); font-family: var(--sans); font-size: 12px; }
.detail-section p { margin: 0; font-family: var(--serif); font-size: 19px; line-height: 1.75; white-space: pre-wrap; }
.detail-continue { margin-top: 10px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

.ai-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--blue);
  color: var(--blue);
  font-family: Georgia, serif;
  font-size: 12px;
}
.ai-intro {
  margin: 22px 0 0;
  border-left: 3px solid var(--blue);
  padding: 11px 16px;
  background: rgba(220, 228, 236, .55);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}
.ai-intro p { margin: 0; }
.ai-thread { display: grid; gap: 18px; padding: 28px 0 8px; }
.ai-message { max-width: 92%; padding: 18px 20px; border: 1px solid var(--line); line-height: 1.75; white-space: pre-wrap; }
.ai-message p { margin: 0; }
.ai-message-assistant { justify-self: start; border-left: 4px solid var(--blue); background: var(--white); }
.ai-message-user { justify-self: end; border-right: 4px solid var(--green); background: var(--green-soft); }
.ai-message small { display: block; margin-bottom: 8px; color: var(--muted); font-size: 11px; }
.ai-start-panel { margin-top: 28px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 28px 0; }
.ai-start-panel p { margin: 0 0 18px; color: var(--muted); font-family: var(--serif); font-size: 19px; line-height: 1.7; }
.ai-error { border-left: 3px solid var(--wine); padding: 12px 16px; background: var(--wine-soft); color: var(--wine); line-height: 1.6; }
.ai-form { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 24px; }
.ai-form label { display: block; margin-bottom: 10px; color: var(--muted); font-size: 12px; font-weight: 700; }
.ai-form textarea { width: 100%; resize: vertical; border: 1px solid var(--line); border-top: 3px solid var(--blue); border-radius: 0; padding: 16px; background: var(--white); color: var(--ink); line-height: 1.7; outline: 0; }
.ai-form textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(49, 80, 111, .1); }
.ai-form-actions { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 12px; }
.ai-status { color: var(--muted); font-size: 12px; }
.ai-form button:disabled, .ai-start-panel button:disabled { cursor: wait; opacity: .64; }

.bottom-nav {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(4, minmax(78px, 1fr));
  border: 1px solid var(--line);
  background: rgba(251,250,246,.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}
.bottom-nav button {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  border-right: 1px solid var(--line);
  padding: 8px 15px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.bottom-nav button:last-child { border-right: 0; }
.bottom-nav button.is-active { background: var(--green); color: #fff; }
.bottom-nav span { font-size: 12px; }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: 92px;
  transform: translate(-50%, 12px);
  max-width: min(90vw, 420px);
  padding: 11px 16px;
  background: var(--ink);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .masthead { min-height: 96px; }
  .masthead-inner { width: calc(100% - 28px); min-height: 96px; }
  .brand-mark { width: 42px; height: 42px; }
  .brand strong { font-size: 25px; }
  .date-label { display: none; }
  .column-left { right: 180px; }
  .shelf-one { right: 70px; }
  .main-content { width: calc(100% - 28px); padding-top: 20px; }
  .question-band { min-height: 360px; padding: 42px 24px; }
  .question-band h1 { font-size: 31px; line-height: 1.5; }
  .question-band::after { right: 10px; font-size: 104px; }
  .entrance-grid { grid-template-columns: 1fr; }
  .entrance { min-height: 160px; border-right: 0; border-bottom: 1px solid var(--line); }
  .entrance:last-child { border-bottom: 0; }
  .page-heading h1 { font-size: 31px; }
  .segmented { width: 100%; }
  .segmented button { min-width: 0; padding-inline: 8px; }
  .timeline-entry { grid-template-columns: 74px 1fr; gap: 15px; padding-block: 22px; }
  .timeline-entry .kind-badge { grid-column: 2; justify-self: start; }
  .weekly-ledger { grid-template-columns: repeat(3, 1fr); }
  .ledger-cell { min-height: 112px; padding: 18px 14px; }
  .ledger-lead { grid-column: 1 / -1; border-bottom: 1px solid var(--line); }
  .ledger-cell strong { font-size: 26px; }
  .guide-topbar { grid-template-columns: 42px 1fr auto; gap: 10px; }
  .guide-topbar h1 { font-size: 23px; }
  .guide-form label { font-size: 23px; }
  .guide-actions { flex-direction: column-reverse; }
  .guide-actions button { width: 100%; }
  .detail-actions { align-items: stretch; }
  .detail-actions button { width: 100%; }
  .ai-message { max-width: 96%; padding: 15px 16px; }
  .bottom-nav {
    bottom: 0;
    width: 100%;
    grid-template-columns: repeat(4, 1fr);
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
  }
  .bottom-nav button { min-height: 64px; flex-direction: column; gap: 3px; padding: 6px; }
  .bottom-nav .icon { width: 19px; height: 19px; }
  .toast { bottom: 78px; }
}

@media (max-width: 380px) {
  .main-content { width: calc(100% - 20px); }
  .question-band { padding-inline: 18px; }
  .question-band h1 { font-size: 27px; }
  .entrance { padding: 20px; }
  .weekly-ledger { grid-template-columns: 1fr; }
  .ledger-lead, .ledger-cell { grid-column: 1; border-right: 0; border-bottom: 1px solid var(--line); }
}

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