:root {
  color-scheme: light;
  --page: #f7f8f6;
  --surface: #fff;
  --ink: #26312d;
  --muted: #84908a;
  --line: #e8ece8;
  --accent: #527766;
  --shadow: 0 8px 26px rgb(46 64 54 / 5%);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px 28px calc(38px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark, .login-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: #e4eee8;
  color: #527766;
  font-weight: 750;
}

.date-controls, .top-actions, .mood-row, .tag-row {
  display: flex;
  align-items: center;
}

.date-controls { gap: 7px; }
.top-actions { gap: 8px; }

.icon-button, .quiet-button {
  border: 0;
  background: transparent;
  border-radius: 9px;
  cursor: pointer;
  transition: background-color .15s ease;
}

.icon-button {
  width: 34px;
  height: 34px;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.quiet-button {
  padding: 8px 10px;
  color: #59665f;
  font-size: 13px;
  white-space: nowrap;
}

.icon-button:hover, .quiet-button:hover { background: #edf1ed; }
.danger-text { color: #a26868; }

#date-picker {
  width: 142px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
}

.sync-status {
  max-width: 170px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.sync-status.is-error { color: #b35454; cursor: pointer; }
.sync-status.is-saving { color: #77877e; }

.day-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  padding: 38px 2px 22px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #96a39c;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .16em;
}

.day-heading h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 32px);
  font-weight: 650;
  letter-spacing: -.035em;
}

.day-hint {
  margin: 0 0 5px;
  color: #9aa39e;
  font-size: 13px;
}

.empty-day {
  display: flex;
  min-height: 310px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  padding: 34px 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.empty-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  margin-bottom: 20px;
  border-radius: 16px;
  background: #e8f0ea;
  color: #527766;
  font-size: 24px;
}

.empty-day .eyebrow { margin-bottom: 7px; }
.empty-day h2 { margin: 0; font-size: 21px; font-weight: 650; }
.empty-day > p:not(.eyebrow) { margin: 9px 0 20px; color: var(--muted); font-size: 13px; }
.empty-day .primary-button { width: auto; min-width: 150px; }

.wizard-header {
  padding: 8px 2px 20px;
}

.wizard-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.wizard-meta .quiet-button { margin-right: -10px; }
.wizard-progress {
  height: 4px;
  margin: 5px 0 23px;
  overflow: hidden;
  border-radius: 10px;
  background: #e8ece8;
}

.wizard-progress span {
  display: block;
  width: 20%;
  height: 100%;
  border-radius: inherit;
  background: #779783;
  transition: width .18s ease;
}

.wizard-header h2 { margin: 0; font-size: 23px; font-weight: 650; }
.wizard-header > p { margin: 7px 0 0; color: var(--muted); font-size: 13px; line-height: 1.7; }

.entry-layout.is-guided .quadrants { display: block; }
.entry-layout.is-guided .quadrant {
  display: none;
  min-height: 250px;
  margin-bottom: 12px;
}
.entry-layout.is-guided .quadrant.is-current { display: block; }
.entry-layout.is-guided .quadrant textarea { min-height: 155px; }
.entry-layout.is-guided .quadrant-food .meal-list textarea { min-height: 28px; }
.entry-layout.is-guided .extras { display: none; margin-top: 0; }
.entry-layout.is-guided .extras.is-current { display: block; }

.wizard-navigation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 1px 5px;
}

.wizard-forward { display: flex; align-items: center; gap: 8px; }
.wizard-navigation .primary-button { width: auto; min-width: 116px; }

.quadrants {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px;
}

.quadrant {
  min-height: 184px;
  padding: 20px 21px;
  border: 1px solid rgb(91 107 97 / 6%);
  border-radius: 17px;
  box-shadow: var(--shadow);
}

.quadrant-food { background: #f5f2e9; }
.quadrant-done { background: #edf4ee; }
.quadrant-thoughts { background: #edf2f6; }
.quadrant-gratitude { background: #f6eef0; }

.quadrant label, .quadrant-title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 13px;
  color: #53625a;
  font-size: 14px;
  font-weight: 650;
}

.quadrant-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 13px;
}

.quadrant-heading label, .quadrant-heading .quadrant-title { margin: 0; }
.quadrant-title { margin-top: 0; }
.markdown-toggle {
  padding: 4px 8px;
  border: 1px solid rgb(91 107 97 / 16%);
  border-radius: 7px;
  background: rgb(255 255 255 / 45%);
  color: #64746a;
  font-size: 11px;
}
.markdown-toggle:hover { background: rgb(255 255 255 / 75%); }

.field-icon { font-size: 16px; }

.quadrant textarea {
  display: block;
  width: 100%;
  min-height: 88px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #303b35;
  font-size: 15px;
  line-height: 1.8;
  resize: none;
  overflow: hidden;
  field-sizing: content;
}

.quadrant textarea::placeholder { color: #a5ada8; opacity: 1; }

.markdown-preview-active .markdown-field textarea { display: none; }
.markdown-preview:not([hidden]) {
  color: #303b35;
  font-size: 15px;
  line-height: 1.8;
  overflow-wrap: anywhere;
}
.markdown-preview[hidden] { display: none; }
.markdown-preview p:first-child, .markdown-content p:first-child { margin-top: 0; }
.markdown-preview p:last-child, .markdown-content p:last-child { margin-bottom: 0; }
.markdown-preview ul, .markdown-preview ol,
.markdown-content ul, .markdown-content ol { padding-left: 1.5em; }
.markdown-preview blockquote, .markdown-content blockquote {
  margin: 10px 0;
  padding-left: 12px;
  border-left: 3px solid #aebdb2;
  color: #68766d;
}
.markdown-preview pre, .markdown-content pre {
  padding: 12px;
  border-radius: 8px;
  background: rgb(35 45 39 / 7%);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.markdown-preview code, .markdown-content code {
  padding: 1px 4px;
  border-radius: 4px;
  background: rgb(35 45 39 / 7%);
}
.markdown-image-placeholder { color: #86938a; font-style: italic; }

.meal-list {
  margin: 0;
  padding-left: 22px;
}

.meal-list li { padding-left: 2px; color: #78877e; }
.meal-list li + li { margin-top: 5px; }
.meal-list label { display: inline; margin: 0 8px 0 0; color: #53625a; font-size: 13px; }
.meal-list textarea {
  width: calc(100% - 58px);
  min-height: 28px;
  padding: 2px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #303b35;
  font: inherit;
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  overflow: hidden;
  vertical-align: top;
}
.meal-list textarea::placeholder { color: #a5ada8; opacity: 1; }

.extras {
  margin-top: 17px;
  padding: 19px 21px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.mood-row { min-height: 28px; gap: 10px; }
.extras-label { color: #758179; font-size: 13px; white-space: nowrap; }
.mood-stars { display: flex; gap: 4px; }
.mood-star {
  padding: 1px 2px;
  border: 0;
  background: transparent;
  color: #d3d9d4;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}
.mood-star.active { color: #e3b65f; }
.mood-caption { color: #a0aaa3; font-size: 12px; }

.tag-row { min-height: 32px; gap: 10px; margin-top: 13px; }
.tags-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 20px;
  background: #f0f3f0;
  color: #69766e;
  font-size: 12px;
}
.tag-remove {
  padding: 0;
  border: 0;
  background: none;
  color: #9aa49d;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
#tag-input {
  min-width: 135px;
  flex: 1;
  padding: 5px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
}
#tag-input::placeholder { color: #b2bab5; }

.modal-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: flex;
  align-items: end;
  justify-content: center;
  padding: 16px;
  background: rgb(25 34 29 / 30%);
}
.modal-backdrop[hidden] { display: none; }
.modal-panel {
  width: min(600px, 100%);
  max-height: min(82vh, 760px);
  overflow: auto;
  border: 1px solid rgb(255 255 255 / 70%);
  border-radius: 20px 20px 14px 14px;
  background: var(--surface);
  box-shadow: 0 18px 65px rgb(29 40 33 / 18%);
  padding-bottom: env(safe-area-inset-bottom);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 21px 12px;
  border-bottom: 1px solid var(--line);
}
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-content { padding: 17px 21px 23px; }
.modal-section-title { margin: 14px 0 8px; color: #87928b; font-size: 12px; }
.export-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.action-card {
  min-height: 58px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}
.action-card:hover { border-color: #b8c9bd; background: #fafcf9; }
.action-card strong { display: block; font-size: 13px; }
.action-card small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.range-controls { display: flex; align-items: center; gap: 8px; margin: 9px 0; }
.range-controls input { min-width: 0; flex: 1; padding: 9px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); }
.primary-button {
  width: 100%;
  padding: 11px 15px;
  border: 0;
  border-radius: 10px;
  background: #557865;
  color: white;
  font-weight: 600;
  cursor: pointer;
}
.primary-button:disabled { opacity: .6; cursor: wait; }
.history-list { display: grid; gap: 5px; }
.history-item {
  display: flex;
  justify-content: space-between;
  padding: 11px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.history-item:hover { background: var(--page); }
.history-item small { color: var(--muted); }
.empty-note { padding: 20px 4px; color: var(--muted); font-size: 13px; text-align: center; }
.login-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.login-card {
  width: min(390px, 100%);
  padding: 38px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.login-mark { width: 42px; height: 42px; margin-bottom: 24px; border-radius: 14px; font-size: 20px; }
.login-card h1 { margin: 0; font-size: 25px; }
.login-subtitle { margin: 9px 0 25px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.login-card label { display: block; margin-bottom: 8px; color: #66736b; font-size: 12px; }
.login-card input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: var(--surface);
  color: var(--ink);
}
.login-card input:focus { border-color: #91aa9a; }
.login-card .primary-button { margin-top: 7px; }
.login-error { min-height: 18px; margin: 7px 0; color: #b35454; font-size: 12px; }

.export-card {
  position: fixed;
  z-index: -1;
  left: -20000px;
  top: 0;
  width: 1080px;
  padding: 56px;
  box-sizing: border-box;
  color: #28332d;
  background: white;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.75;
  overflow-wrap: anywhere;
}
.export-title { margin: 0 0 8px; font-size: 68px; font-weight: 650; line-height: 1.2; }
.export-weekday { margin: 0 0 28px; color: #8d9992; font-size: 28px; }
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.export-section { min-width: 0; padding: 26px 28px; border-radius: 17px; }
.export-section h3 { margin: 0 0 12px; font-size: 30px; }
.export-section p { margin: 0; white-space: pre-wrap; font-size: 28px; line-height: 1.7; }
.export-section .markdown-content { font-size: 28px; line-height: 1.7; overflow-wrap: anywhere; }
.export-section .markdown-content > :first-child { margin-top: 0; }
.export-section .markdown-content > :last-child { margin-bottom: 0; }
.export-meals { display: grid; gap: 12px; margin: 0; padding-left: 30px; font-size: 28px; }
.export-meals li > strong { display: block; margin-bottom: 4px; font-size: 25px; }
.export-meals .markdown-content { font-size: 26px; }
.export-meals .markdown-content p { margin: 0; }
.export-empty { color: #aab2ad; font-size: 24px !important; }
.export-footer { display: flex; justify-content: space-between; margin-top: 24px; color: #a7afaa; font-size: 20px; }
.export-card.template-a { border: 1px solid #e8e8e8; }
.template-a .export-section { border: 1px solid #e4e6e4; background: #fff; }
.export-card.template-b {
  background-color: #faf5e8;
  background-image: radial-gradient(#dfd5bd 1px, transparent 1px);
  background-size: 18px 18px;
}
.template-b .export-title { font-family: "PingFang SC", "Microsoft YaHei", cursive; }
.template-b .export-section { box-shadow: 0 6px 12px rgb(96 76 41 / 12%); transform: rotate(-.25deg); }
.template-b .export-section:nth-child(4n+1) { background: #fff0bd; }
.template-b .export-section:nth-child(4n+2) { background: #e3f0df; transform: rotate(.3deg); }
.template-b .export-section:nth-child(4n+3) { background: #e1edf6; }
.template-b .export-section:nth-child(4n+4) { background: #f5e3e5; transform: rotate(.2deg); }
.export-card.template-c { background: #202322; color: #ede8dc; }
.template-c .export-weekday, .template-c .export-footer { color: #9ca39d; }
.template-c .export-section { border: 1px solid #414844; background: #252a28; }
.template-c .mood-stars-text { color: #f2c56f; text-shadow: 0 0 8px rgb(242 197 111 / 40%); }
.export-card.template-d { padding-top: 60px; padding-bottom: 60px; }
.template-d .export-title { margin-bottom: 6px; }
.template-d .export-weekday { margin-bottom: 26px; }
.template-d .export-grid { display: block; }
.template-d .export-section { padding: 24px 0; border-radius: 0; background: transparent; transform: none; box-shadow: none; }
.template-d .export-section + .export-section { border-top: 1px solid #e4e7e4; }
.template-d .export-section h3 { margin-bottom: 8px; }
.template-d .export-footer { border-top: 1px solid #e4e7e4; padding-top: 18px; }

@media (max-width: 760px) {
  .app-shell { padding: 12px 15px calc(25px + env(safe-area-inset-bottom)); }
  .topbar { flex-wrap: wrap; gap: 9px; }
  .brand { margin-right: auto; }
  .date-controls { order: 2; }
  .top-actions { order: 3; width: 100%; justify-content: space-between; gap: 2px; }
  .top-actions .quiet-button { padding: 7px 6px; }
  .sync-status { margin-right: auto; font-size: 11px; }
  .day-heading { padding: 28px 2px 18px; }
  .day-hint { display: none; }
  .empty-day { min-height: 270px; }
  .wizard-header { padding-top: 3px; }
  .wizard-header h2 { font-size: 21px; }
  .entry-layout.is-guided .quadrant { min-height: 220px; }
  .entry-layout.is-guided .quadrant textarea { min-height: 135px; }
  .quadrants { grid-template-columns: 1fr; gap: 11px; }
  .quadrant { min-height: 150px; padding: 17px 18px; border-radius: 15px; }
  .quadrant textarea { min-height: 76px; }
  .extras { padding: 15px 16px; }
  .mood-row, .tag-row { flex-wrap: wrap; }
  .tag-row { align-items: flex-start; }
  #tag-input { flex-basis: 100%; margin-left: 0; }
  .modal-backdrop { padding: 0; }
  .modal-panel { max-height: 88vh; border-radius: 20px 20px 0 0; }
}

@media (max-width: 400px) {
  .top-actions .quiet-button { font-size: 12px; }
  .sync-status { max-width: 108px; overflow: hidden; text-overflow: ellipsis; }
  .date-controls { gap: 3px; }
  #date-picker { width: 128px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #1d2220;
    --surface: #262c29;
    --ink: #e8ece9;
    --muted: #9ba69f;
    --line: #39413c;
    --accent: #9bb9a5;
    --shadow: 0 8px 26px rgb(0 0 0 / 13%);
  }
  .brand, .quadrant textarea, .tag-pill, .history-item { color: var(--ink); }
  .brand-mark, .login-mark { background: #34443a; color: #b1c9b8; }
  .empty-mark { background: #34443a; color: #b1c9b8; }
  .quiet-button { color: #c1cbc4; }
  .icon-button:hover, .quiet-button:hover, .history-item:hover { background: #333b36; }
  #date-picker, .login-card input { background: #202623; color: var(--ink); }
  .quadrant-food { background: #35332a; }
  .quadrant-done { background: #29352e; }
  .quadrant-thoughts { background: #2a3238; }
  .quadrant-gratitude { background: #382e32; }
  .quadrant label, .extras-label { color: #c1cbc4; }
  .quadrant-title { color: #c1cbc4; }
  .markdown-preview:not([hidden]) { color: var(--ink); }
  .markdown-toggle { background: #303934; color: #c1cbc4; border-color: #465149; }
  .markdown-preview blockquote, .markdown-content blockquote { color: #b7c1ba; }
  .markdown-preview pre, .markdown-content pre, .markdown-preview code, .markdown-content code { background: rgb(0 0 0 / 18%); }
  .quadrant-title, .meal-list label { color: #c1cbc4; }
  .meal-list li { color: #a0b2a5; }
  .quadrant textarea::placeholder { color: #818d85; }
  .wizard-progress { background: #39413c; }
  .tag-pill { background: #353d38; }
  .action-card { background: var(--surface); color: var(--ink); }
  .action-card:hover { background: #303934; }
  .template-b { color: #28332d; }
}
