:root {
  --bg: #f5f0e8;
  --surface: #fbf7ef;
  --surface-strong: #fffdf8;
  --text: #352f2a;
  --muted: #8a7e72;
  --line: rgba(53, 47, 42, 0.13);
  --accent: #9b7664;
  --accent-dark: #725747;
  --accent-soft: rgba(155, 118, 100, 0.14);
  --sage: #e4eadf;
  --blue-note: #e1e8ec;
  --pink-note: #eadedf;
  --yellow-note: #e8dec6;
  --apricot-note: #ead8c7;
  --paper: #fbf4e6;
  --shadow: 0 16px 36px rgba(65, 49, 37, 0.1);
  --soft-shadow: 0 10px 22px rgba(65, 49, 37, 0.1);
  --font-literary: "Iowan Old Style", "Songti SC", "STSong", "Noto Serif SC", Georgia, serif;
  --font-ui: "Avenir Next", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-family: var(--font-literary);
  color: var(--text);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  overflow: hidden;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.36) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.28) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  font-family: var(--font-ui);
  white-space: nowrap;
}

.site-header {
  height: 64px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 12px 0;
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  color: var(--text);
  text-decoration: none;
  font-family: var(--font-literary);
  font-size: 23px;
  font-weight: 650;
  letter-spacing: 0;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(251, 247, 239, 0.74);
  box-shadow: 0 8px 20px rgba(65, 49, 37, 0.06);
}

.tab {
  min-width: 92px;
  min-height: 38px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-size: 15px;
  font-weight: 600;
}

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

main {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  height: calc(100vh - 64px);
  padding: 16px 0 20px;
}

.view {
  display: none;
}

.view.active {
  display: block;
  height: 100%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.mood-layout,
.week-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
  gap: 20px;
  align-items: start;
  height: 100%;
  min-height: 0;
}

.input-panel,
.preview-panel,
.week-list-panel,
.analysis-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251, 247, 239, 0.78);
  box-shadow: var(--shadow);
}

.input-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  padding: 20px;
}

.input-panel label {
  display: block;
  margin-bottom: 10px;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 650;
}

textarea,
input[type="search"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-strong);
  outline: 0;
}

textarea:focus,
input[type="search"]:focus {
  border-color: rgba(155, 118, 100, 0.46);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

#mood-input {
  flex: 1;
  min-height: 0;
  resize: vertical;
  padding: 16px;
  font-size: 16px;
  line-height: 1.8;
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  flex-wrap: nowrap;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-height: 44px;
  min-width: max-content;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
}

.primary-button {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 10px 18px rgba(114, 87, 71, 0.16);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary-button.small {
  min-height: 38px;
  padding: 0 15px;
  font-size: 14px;
}

.secondary-button {
  width: 100%;
  margin-top: 16px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
}

.status-text,
.toast {
  font-family: var(--font-ui);
  flex: 1 1 auto;
  min-width: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.status-text.error,
.toast.error {
  color: var(--accent-dark);
}

.status-text.block {
  display: block;
  margin: 0 0 16px;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  padding: 20px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel-title-row h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 650;
}

.panel-title-row span {
  color: var(--muted);
  font-size: 14px;
}

.note-card {
  position: relative;
  min-height: 200px;
  padding: 30px 22px 20px;
  border-radius: 6px;
  color: var(--text);
  background: var(--paper);
  box-shadow: var(--soft-shadow);
  overflow: hidden;
}

.note-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.55;
  background-image:
    radial-gradient(rgba(80, 54, 38, 0.08) 0.7px, transparent 0.7px);
  background-size: 13px 13px;
}

.preview-card {
  flex: 1;
  min-height: 0;
}

#preview-content {
  position: relative;
  z-index: 1;
  min-height: 0;
  height: calc(100% - 78px);
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  resize: none;
  font-size: 18px;
  line-height: 1.86;
}

#preview-content:focus {
  box-shadow: none;
}

.tape {
  position: absolute;
  z-index: 2;
  width: 92px;
  height: 28px;
  background: rgba(232, 222, 198, 0.78);
  box-shadow: 0 4px 10px rgba(78, 52, 35, 0.08);
}

.tape-top {
  top: 12px;
  left: 50%;
  transform: translateX(-50%) rotate(-2deg);
}

.tape-left {
  top: 42px;
  left: -23px;
  transform: rotate(-90deg);
}

.hidden-tape {
  display: none;
}

.note-content {
  position: relative;
  z-index: 1;
  margin: 0 0 26px;
  white-space: pre-wrap;
  font-size: 17px;
  line-height: 1.85;
}

.note-meta {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
  color: rgba(58, 51, 44, 0.62);
  font-size: 13px;
}

.tag-row {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  color: rgba(58, 51, 44, 0.78);
  background: rgba(255, 255, 255, 0.52);
  font-size: 12px;
  font-weight: 680;
}

.library-tools {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}

#search-input {
  height: 48px;
  padding: 0 17px;
  font-size: 16px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.filter-chip {
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(251, 247, 239, 0.72);
  font-size: 14px;
  font-weight: 650;
}

.filter-chip.active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.notes-grid {
  column-count: 3;
  column-gap: 20px;
  max-height: calc(100vh - 192px);
  overflow: auto;
  padding-right: 4px;
}

.notes-grid .note-card {
  display: inline-block;
  width: 100%;
  min-height: 210px;
  margin: 0 0 20px;
}

.note-actions {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.note-actions button {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid rgba(58, 51, 44, 0.14);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.48);
  font-size: 13px;
  font-weight: 650;
}

.empty-state {
  display: none;
  padding: 44px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(251, 247, 239, 0.62);
  text-align: center;
}

.empty-state.show {
  display: block;
}

.week-list-panel,
.analysis-panel {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 20px;
}

.analysis-panel {
  display: flex;
  flex-direction: column;
}

.week-list {
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 156px);
  overflow: auto;
  padding-right: 4px;
}

.date-group h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 740;
}

.week-item {
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.week-item p {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.75;
}

.week-item span {
  color: var(--muted);
  font-size: 12px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.summary-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.48);
}

.summary-card strong {
  display: block;
  margin-bottom: 8px;
  color: var(--accent-dark);
  font-size: 14px;
}

.summary-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.analysis-copy {
  max-height: calc(100vh - 260px);
  min-height: 0;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--text);
  font-size: 16px;
  line-height: 1.9;
}

.style-paper {
  background: var(--paper);
}

.style-apricot {
  background: var(--apricot-note);
}

.style-pink {
  background: var(--pink-note);
}

.style-blue {
  background: var(--blue-note);
}

.style-yellow {
  background: var(--yellow-note);
}

.style-sage {
  background: var(--sage);
}

.texture-grid::before {
  background-image:
    linear-gradient(rgba(58, 51, 44, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(58, 51, 44, 0.08) 1px, transparent 1px);
  background-size: 22px 22px;
}

.texture-lined::before {
  background-image: linear-gradient(transparent 26px, rgba(58, 51, 44, 0.12) 27px);
  background-size: 100% 28px;
}

.border-thin {
  border: 1px solid rgba(58, 51, 44, 0.12);
}

.border-pink {
  border-left: 4px solid rgba(155, 118, 100, 0.34);
}

mark {
  border-radius: 4px;
  color: inherit;
  background: rgba(155, 118, 100, 0.16);
}

@media (max-width: 900px) {
  html,
  body {
    overflow: auto;
  }

  .site-header,
  main {
    width: calc(100% - 20px);
    max-width: 720px;
  }

  .site-header {
    align-items: flex-start;
    flex-direction: column;
    height: auto;
    padding-top: 16px;
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    max-width: 100%;
    overflow: hidden;
  }

  .tab {
    min-width: 0;
    padding: 0 6px;
    font-size: 13px;
  }

  main {
    height: auto;
    min-height: calc(100vh - 122px);
    padding-top: 14px;
  }

  .mood-layout,
  .week-layout {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
  }

  .input-panel,
  .preview-panel,
  .week-list-panel,
  .analysis-panel {
    height: auto;
  }

  #mood-input {
    min-height: 250px;
  }

  .preview-card {
    min-height: 300px;
  }

  .notes-grid,
  .week-list,
  .analysis-copy {
    max-height: none;
    overflow: visible;
  }

  .notes-grid {
    column-count: 2;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .sr-only,
  .input-panel,
  .preview-panel,
  .week-list-panel,
  .analysis-panel,
  .note-card {
    max-width: 100%;
    min-width: 0;
  }

  .input-panel,
  .preview-panel,
  .week-list-panel,
  .analysis-panel {
    padding: 18px;
  }

  .notes-grid {
    column-count: 1;
  }

  .input-actions,
  .panel-title-row {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
    min-width: 0;
    padding-inline: 12px;
    font-size: 14px;
  }

  .status-text,
  .toast {
    font-size: 13px;
  }
}
