:root {
  --paper: #f5f0e8;
  --paper-deep: #ece3d7;
  --card: #fffff8;
  --input-background-color: #ffffff;
  --ink: #292622;
  --muted: #766f67;
  --line: #d6d6d6;
  --accent: #7f3f35;
  --accent-dark: #653129;
  --accent-soft: #f0ddd7;
  --success: #426246;
  --success-soft: #e3eee3;
  --danger: #9b352f;
  --danger-soft: #f7e3e0;
  --shadow: 0 10px 28px rgba(70, 52, 38, 0.07);
  --tab-active-color: #7a4a00;
  --save-button-color: #42a846;
  --tab-text-color: #606060;
  --tab-active-text-color: #ffffff;
  --year-color: #42a846;
  --edit-button-color: #7a4a00;
  --brand-color: #606060;
  --memory-text-color: #503e32;
  --writing-placeholder-color: #c0c0c0;
  --input-focus-color: #42a846;
  --memory-line-height: 1.6;
  --memory-text-indent: 1em;
  --content-radius: 10px;
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 80% -10%, rgba(154, 107, 81, 0.11), transparent 38rem),
    var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.65;
  min-height: 100vh;
}

a { color: inherit; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.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;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(16px);
}

.header-inner {
  max-width: 880px;
  margin: 0 auto;
  min-height: 58px;
  padding: 8px 14px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.brand { color: var(--brand-color); text-decoration: none; min-width: 0; font-family: inherit; font-size: .98rem; font-weight: 700; white-space: nowrap; }
.quiet-link, .quiet-button { min-height: 40px; display: inline-flex; align-items: center; border: 0; background: transparent; color: var(--accent); text-decoration: none; padding: 5px 0; cursor: pointer; font-size: .84rem; white-space: nowrap; }
.quiet-link:hover, .quiet-button:hover { color: var(--accent); }

.header-actions { min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: 9px; }
.top-search { width: min(42vw, 180px); min-width: 0; }
.top-search input { width: 100%; min-height: 38px; height: 38px; border-radius: 99px; padding: 7px 12px; font-size: .83rem; background: var(--input-background-color); }
.top-search-placeholder { width: min(42vw, 180px); height: 38px; }
.more-menu { position: relative; flex: 0 0 auto; }
.more-menu > .quiet-button { color: var(--brand-color); }
.more-menu > .quiet-button:hover { color: var(--brand-color); opacity: .8; }
.more-menu-popover { position: absolute; top: calc(100% + 5px); right: -8px; z-index: 30; width: 108px; padding: 5px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); box-shadow: 0 12px 30px rgba(70, 52, 38, .16); }
.more-menu-item { width: 100%; min-height: 38px; display: flex; align-items: center; border: 0; border-radius: 7px; background: transparent; color: var(--ink); padding: 7px 11px; text-decoration: none; font-size: .84rem; cursor: pointer; }
.more-menu-item:hover { background: var(--paper-deep); }

.import-dialog-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; background: rgba(41, 38, 34, .38); backdrop-filter: blur(3px); }
.import-dialog { width: min(100%, 480px); max-height: min(82vh, 640px); overflow-y: auto; border: 1px solid var(--line); border-radius: var(--content-radius); background: var(--card); padding: 18px; box-shadow: 0 24px 70px rgba(41, 38, 34, .24); }
.import-dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.import-dialog-heading h2 { margin: 0; font-size: 1.16rem; }
.import-dialog-close { width: 36px; height: 36px; border: 0; border-radius: 99px; background: transparent; color: var(--muted); font-size: 1.45rem; line-height: 1; cursor: pointer; }
.import-dialog-close:hover { background: var(--paper-deep); color: var(--ink); }
.import-dialog-help, .import-warning, .import-dialog-status, .import-result { margin: 10px 0 0; font-size: .8rem; }
.import-dialog-help, .import-warning, .import-dialog-status { color: var(--muted); }
.import-file-list { list-style: none; display: grid; gap: 7px; margin: 14px 0 0; padding: 0; }
.import-file-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--input-background-color); padding: 9px 11px; }
.import-file-list span { min-width: 0; overflow-wrap: anywhere; font-size: .86rem; }
.import-file-list small { flex: 0 0 auto; color: var(--year-color); font-size: .72rem; }
.import-file-list li.error small, .import-result.error { color: var(--danger); }
.import-result.success { color: var(--success); }
.import-dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }
.import-dialog-actions .primary-button, .import-dialog-actions .secondary-button { min-height: 40px; padding: 7px 14px; font-size: .84rem; }

.page-shell { width: min(100%, 880px); margin: 0 auto; padding: 14px 14px 72px; }
.page-shell.narrow { width: min(100%, 720px); }

.search-form { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; margin-bottom: 20px; }
.search-form input { width: 100%; }
.clear-search { color: var(--accent); font-size: .9rem; padding: 9px 4px; }

input, textarea, select {
  border: 1px solid var(--line);
  border-radius: var(--content-radius);
  background: var(--input-background-color);
  color: var(--ink);
  padding: 12px 13px;
  min-height: 48px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, textarea:focus, select:focus { border-color: var(--input-focus-color); box-shadow: 0 0 0 3px color-mix(in srgb, var(--input-focus-color) 18%, transparent); }
input:disabled, textarea:disabled, select:disabled, button:disabled { opacity: .65; cursor: not-allowed; }

.category-tabs {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 3px;
  margin: 0 0 12px;
}
.category-tab { min-width: 0; min-height: 66px; padding: 5px 1px; border: 1px solid var(--line); border-radius: var(--content-radius); background: var(--card); color: var(--tab-text-color); text-decoration: none; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; line-height: 1.05; overflow: hidden; }
.category-tab-label { width: 100%; font-weight: 750; font-size: clamp(.74rem, 3vw, .92rem); white-space: pre-line; overflow-wrap: anywhere; letter-spacing: -.04em; line-height: 1.08; }
.category-tab small { width: 100%; margin-top: 4px; color: var(--tab-text-color); opacity: .65; font-size: clamp(.49rem, 1.9vw, .65rem); white-space: nowrap; letter-spacing: -.04em; }
.category-tab.active { background: var(--tab-active-color); border-color: var(--tab-active-color); color: var(--tab-active-text-color); }
.category-tab.active small { color: var(--tab-active-text-color); opacity: .82; }

.quick-capture { margin-bottom: 14px; border: 1px solid var(--line); border-radius: var(--content-radius); background: var(--card); overflow: hidden; box-shadow: var(--shadow); }
.quick-capture-heading { min-height: 48px; padding: 6px 9px 5px 13px; display: grid; grid-template-columns: minmax(52px, 1fr) minmax(76px, 116px) auto; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.quick-category-label { color: var(--ink); font-size: 1.08rem; font-weight: 750; }
.quick-time-anchor { width: 100%; min-width: 0; min-height: 34px; height: 34px; border-radius: 99px; padding: 4px 8px; text-align: center; font-size: .78rem; }
.save-button { min-width: 64px; min-height: 34px; border: 0; border-radius: 8px; background: var(--save-button-color); color: white; padding: 5px 12px; font-weight: 650; cursor: pointer; }
.quick-capture-heading .save-button { justify-self: end; }
.quick-capture textarea { display: block; width: 100%; height: 132px; min-height: 132px; border: 0; border-radius: 0; padding: 13px; resize: none; overflow: hidden; box-shadow: none; background: var(--input-background-color); line-height: 1.75; }
.quick-capture textarea::placeholder { color: var(--writing-placeholder-color); opacity: 1; }
.quick-capture textarea:focus { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--input-focus-color) 35%, transparent); }
.quick-message { margin: 0; padding: 7px 12px; border-top: 1px solid var(--line); font-size: .76rem; }
.quick-message.success { color: var(--success); background: var(--success-soft); }
.quick-message.error { color: var(--danger); background: var(--danger-soft); }
.search-summary { display: flex; align-items: center; gap: 8px; margin: 3px 1px 13px; font-size: .86rem; }
.search-summary small { color: var(--muted); }
.search-summary a { margin-left: auto; color: var(--accent); font-size: .78rem; }

.list-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin: 8px 2px 18px; }
.list-heading h1, .page-title h1, .memory-detail h1 { font-family: Georgia, "Songti SC", serif; }
.list-heading h1 { margin: 0; font-size: 1.45rem; }
.list-heading p { margin: 2px 0 0; color: var(--muted); font-size: .85rem; }

.primary-button, .secondary-button, .danger-button {
  min-height: 46px;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 650;
  cursor: pointer;
  text-decoration: none;
}
.primary-button { color: white; background: var(--accent); }
.primary-button:hover { background: var(--accent-dark); }
.edit-button { background: var(--edit-button-color); }
.edit-button:hover { background: var(--edit-button-color); filter: brightness(.9); }
.secondary-button { color: var(--ink); border-color: var(--line); background: var(--card); }
.danger-button { color: var(--danger); border-color: #ddb9b4; background: transparent; }
.write-button { white-space: nowrap; box-shadow: 0 6px 16px rgba(127, 63, 53, .16); }
.full-width { width: 100%; }
.centered { text-align: center; }

.memory-list { display: grid; gap: 8px; }
.memory-card { border: 1px solid var(--line); border-radius: var(--content-radius); background: var(--card); box-shadow: var(--shadow); overflow: hidden; }
.memory-card-link { display: block; padding: 18px; text-decoration: none; }
.memory-card-link.has-time-anchor { padding-bottom: 9px; }
.memory-card-link:hover { background: var(--card); }
.memory-card-meta { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 0; line-height: 1; }
.memory-card-meta.with-category { margin-bottom: 7px; line-height: normal; }
.memory-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.memory-card h2 { margin: 0; font-family: inherit; font-size: 1.08rem; line-height: 1.45; }
.memory-card p { color: var(--memory-text-color); }
.memory-card p.untitled-content { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: inherit; line-height: var(--memory-line-height); text-indent: var(--memory-text-indent); }
.memory-card-meta + .untitled-content { margin-top: 0; }
.memory-card-footer { display: flex; justify-content: flex-end; margin-top: 4px; line-height: 1; }
.memory-card mark { background: #f2d78a; color: inherit; border-radius: 2px; padding-inline: 1px; }
.category-badge { display: inline-flex; flex: 0 0 auto; width: fit-content; border-radius: 99px; background: var(--accent-soft); color: var(--accent-dark); padding: 3px 9px; font-size: .73rem; font-weight: 650; }
.time-anchor-badge { flex: 0 1 auto; color: var(--year-color); font-size: .61rem; font-weight: 700; line-height: 1; text-align: right; overflow-wrap: anywhere; }

.empty-state { padding: 24px 20px; text-align: center; color: var(--muted); }
.empty-state p { margin: 0 0 8px; }
.empty-state a { color: var(--accent); font-weight: 650; }
.notice, .form-message { border-radius: 10px; padding: 10px 12px; font-size: .9rem; }
.notice { margin: 0 0 16px; }
.notice.success, .form-message.success { color: var(--success); background: var(--success-soft); }
.notice.error, .form-message.error { color: var(--danger); background: var(--danger-soft); }
.form-message.setup { color: #66511e; background: #f4e8be; }

.back-link { display: inline-flex; align-items: center; min-height: 44px; color: var(--muted); text-decoration: none; margin-bottom: 10px; }
.back-link:hover { color: var(--accent); }
.page-title { margin-bottom: 24px; }
.page-title h1 { margin: 0; font-size: 1.65rem; }
.page-title p { color: var(--muted); margin: 4px 0 0; }
.editor { display: grid; gap: 20px; }
.field { display: grid; gap: 7px; }
.field label { font-weight: 650; font-size: .92rem; }
.field label span { font-weight: 400; color: var(--muted); font-size: .78rem; }
.field textarea { width: 100%; min-height: 240px; resize: none; overflow: hidden; line-height: 1.8; }
.field-error { color: var(--danger); font-size: .8rem; margin: 0; }
.form-message { margin: 0; }
.editor-actions, .detail-actions { display: flex; gap: 10px; }

.memory-detail { border: 1px solid var(--line); border-radius: var(--content-radius); padding: clamp(20px, 5vw, 36px); background: var(--card); box-shadow: var(--shadow); }
.memory-detail h1 { margin: 14px 0 8px; font-size: clamp(1.55rem, 4vw, 2rem); line-height: 1.4; }
.memory-meta { display: flex; flex-wrap: wrap; gap: 4px 18px; color: var(--muted); font-size: .78rem; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.memory-content { white-space: pre-wrap; overflow-wrap: anywhere; padding-top: 24px; color: var(--memory-text-color); font-family: inherit; font-size: 1.06rem; line-height: var(--memory-line-height); text-indent: var(--memory-text-indent); }
.detail-actions { justify-content: space-between; margin-top: 18px; }
.detail-action-group { display: flex; gap: 10px; }
.inline-memory-form textarea { display: block; width: 100%; min-height: 260px; resize: none; overflow: hidden; color: var(--memory-text-color); line-height: var(--memory-line-height); text-indent: var(--memory-text-indent); font-family: inherit; font-size: 1.06rem; }
.memory-detail-simple { min-height: 180px; border: 1px solid var(--line); border-radius: var(--content-radius); padding: 8px clamp(20px, 5vw, 36px) clamp(20px, 5vw, 36px); background: var(--card); color: var(--memory-text-color); box-shadow: var(--shadow); font-family: inherit; font-size: 1.06rem; line-height: var(--memory-line-height); }
.memory-detail-text { white-space: pre-wrap; overflow-wrap: anywhere; text-indent: var(--memory-text-indent); }
.detail-anchor-control { display: grid; justify-items: end; margin: 0 0 1px; line-height: 1; }
.detail-anchor-control input { width: 104px; min-height: 26px; height: 26px; border-radius: 99px; padding: 2px 8px; color: var(--year-color); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif; font-size: .69rem; line-height: 1; text-align: right; }
.field #time-anchor { border-radius: 99px; }
.detail-anchor-control input::placeholder { color: #829684; opacity: .8; }
.detail-anchor-control .field-error { margin-top: 4px; }
.detail-category-label { display: block; margin: 14px 0 6px; font-size: .82rem; font-weight: 650; }
.inline-memory-form select { width: 100%; }
.inline-memory-form .form-message { margin-top: 12px; }
.save-changes-button { min-height: 46px; border: 0; border-radius: 10px; padding: 10px 17px; background: #aaa59f; color: white; font-weight: 650; cursor: not-allowed; }
.save-changes-button.ready { background: var(--save-button-color); cursor: pointer; }
.save-changes-button.ready:hover { filter: brightness(.9); }

.settings-card { border: 1px solid var(--line); border-radius: var(--content-radius); background: var(--card); padding: clamp(18px, 4vw, 28px); box-shadow: var(--shadow); }
.settings-heading { margin-bottom: 20px; }
.settings-heading h1 { margin: 0; font-size: 1.4rem; }
.settings-heading p { margin: 4px 0 0; color: var(--muted); font-size: .82rem; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 18px; }
.color-setting, .number-setting { min-height: 45px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); font-size: .88rem; }
.color-setting input[type="color"] { width: 42px; height: 30px; min-height: 30px; padding: 2px; border-radius: 6px; cursor: pointer; }
.number-settings { margin-top: 18px; display: grid; gap: 9px; }
.number-setting input { width: 88px; min-height: 38px; height: 38px; padding: 6px 9px; text-align: right; }
.settings-message { margin: 14px 0 0; color: var(--success); font-size: .82rem; }
.settings-actions { margin-top: 20px; display: flex; gap: 10px; }
.save-settings-button { min-height: 46px; border: 0; border-radius: 10px; padding: 10px 17px; background: #aaa59f; color: white; font-weight: 650; cursor: not-allowed; }
.save-settings-button.ready { background: var(--save-button-color); cursor: pointer; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 18px; }
.auth-card { width: min(100%, 420px); border: 1px solid var(--line); border-radius: 20px; background: rgba(255, 253, 249, .92); padding: clamp(24px, 7vw, 40px); box-shadow: 0 20px 50px rgba(70,52,38,.1); }
.auth-heading { text-align: center; margin-bottom: 28px; }
.auth-heading .eyebrow { color: var(--accent); font-weight: 700; font-size: .75rem; letter-spacing: .16em; }
.auth-heading h1 { margin: 4px 0 8px; font-family: Georgia, "Songti SC", serif; font-size: 2rem; }
.auth-heading p { margin: 0; color: var(--muted); }
.auth-form { display: grid; gap: 17px; }
.text-button { min-height: 44px; border: 0; background: none; color: var(--accent); cursor: pointer; }
.privacy-note { text-align: center; color: var(--muted); font-size: .75rem; margin: 24px 0 0; }
.account-settings { margin-top: 18px; }
.empty-page { min-height: 100vh; display: grid; place-content: center; justify-items: center; padding: 24px; text-align: center; }
.empty-page h1 { font-family: Georgia, "Songti SC", serif; margin-bottom: 4px; }
.empty-page p { color: var(--muted); margin: 0 0 22px; }

@media (min-width: 720px) {
  .page-shell { padding-top: 20px; }
  .memory-card-link { padding: 21px 22px; }
}

@media (max-width: 430px) {
  .quiet-link, .quiet-button { font-size: .78rem; }
  .brand { font-size: .88rem; }
  .header-inner { gap: 7px; padding-inline: 10px; }
  .page-shell { padding-inline: 10px; }
  .settings-grid { grid-template-columns: 1fr; }
}

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