@font-face {
  font-family: "Source Serif 4";
  src: url("./fonts/source-serif-4/SourceSerif4Variable-Roman.woff2") format("woff2");
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #FAF9F5;
  --ink: #25241f;
  --body: #403c34;
  --muted: #6d6559;
  --rule: #c3bbad;
  --paper-rule: #918778;
  --paper-hover: #eadfd2;
  --title-hint: #7a7060;
  --selection: #efd0bd;
  --accent: #C96340;
  --accent-button: var(--accent);
  --accent-hover: #d1704f;
  --button-ink: #1b120e;
  --archive: #252420;
  --archive-ink: #f3ede1;
  --archive-muted: #c3b8a8;
  --archive-rule: #575146;
  --archive-active: #343028;
  --archive-selected: #3b352c;
  --archive-accent: #e59b80;
  --dialog-surface: var(--paper);
  --dialog-shadow: #25201b24;
  --dialog-backdrop: #22201a66;
  --notice-surface: #f7e9df;
  --notice-ink: #8d3526;
  --notice-rule: #d9b8a6;
  --notice-hover: #f0dbcf;
  --typeface: "Anthropic Serif", "Anthropic Serif Web Text", "Anthropic Serif Text", "Anthropic Serif Web", "Source Serif 4", Georgia, "Songti SC", "Noto Serif CJK SC", serif;
  --gutter: clamp(24px, 3.6vw, 68px);
  --masthead-height: 80px;
  --archive-height: 149px;
  --sheet-width: 1000px;
  --writing-top: clamp(74px, 14.5vh, 136px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --transition: 150ms ease;
  font-family: var(--typeface);
  -webkit-font-smoothing: antialiased;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #292622;
  --ink: #f3e9d9;
  --body: #dfd2c0;
  --muted: #b9aa99;
  --rule: #6c5f52;
  --paper-rule: #695d51;
  --paper-hover: #3b332d;
  --title-hint: #aa9a87;
  --selection: #695044;
  --accent: #e1987f;
  --accent-button: #da836a;
  --accent-hover: #ec9a80;
  --button-ink: #211915;
  --archive: #1d1b18;
  --archive-muted: #ad9f8e;
  --archive-rule: #484035;
  --archive-active: #312923;
  --archive-selected: #393128;
  --archive-accent: #e7a38d;
  --dialog-surface: #332c26;
  --dialog-shadow: #100d0b66;
  --dialog-backdrop: #100e0bb3;
  --notice-surface: #392c25;
  --notice-ink: #f5b4a0;
  --notice-rule: #805744;
  --notice-hover: #54372d;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); }
button, input, textarea { color: inherit; font: inherit; }
button { cursor: pointer; }
button:disabled, button[aria-disabled="true"] { cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
::selection { color: var(--ink); background: var(--selection); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.55; stroke-linecap: round; stroke-linejoin: round; }
.icon-button {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--transition), background-color var(--transition);
}
.icon-button:disabled, .icon-button[aria-disabled="true"] { opacity: .38; }

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) calc(var(--archive-height) + var(--safe-bottom));
  height: 100vh;
  height: 100dvh;
  padding-top: var(--safe-top);
}
@media (min-width: 681px) {
  .workspace[data-index="empty"] {
    grid-template-rows: auto minmax(0, 1fr) calc(96px + var(--safe-bottom));
  }
  .workspace[data-index="empty"] .new-button {
    border-color: var(--rule);
    background: transparent;
    color: var(--ink);
  }
  .workspace[data-index="empty"] .new-button:hover { background: var(--paper-hover); }
}
.masthead { padding-inline: max(var(--gutter), var(--safe-left)) max(var(--gutter), var(--safe-right)); }
.masthead-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: var(--masthead-height);
  gap: 16px;
  border-bottom: 1px solid var(--paper-rule);
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  font: 650 34px/1.08 var(--typeface);
  letter-spacing: -.025em;
  white-space: nowrap;
}
.brand-mark {
  flex: none;
  width: 32px;
  height: 32px;
}
:root[data-theme="dark"] .brand-mark { filter: brightness(1.16) saturate(.9); }
.masthead-controls { display: flex; align-items: center; gap: 22px; min-width: 0; }
.masthead-actions { display: flex; align-items: center; gap: 8px; }
.theme-toggle { color: var(--muted); }
.theme-toggle:hover, .theme-toggle:active { color: var(--ink); background: var(--paper-hover); }
.theme-toggle .icon { width: 19px; height: 19px; }

.search {
  display: flex;
  align-items: center;
  width: min(224px, 35vw);
  min-width: 0;
  height: 40px;
  gap: 8px;
  padding: 0 3px 0 6px;
  border-bottom: 1px solid transparent;
  color: var(--ink);
  transition: border-color var(--transition);
}
.search:hover { border-color: var(--rule); }
.search:focus-within { border-color: var(--accent); }
.search-icon { width: 20px; height: 20px; }
.search input {
  flex: 1;
  align-self: stretch;
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
  outline: none;
  font-size: 14px;
}
.search input::placeholder { color: var(--muted); opacity: 1; }
.search input::-webkit-search-cancel-button { display: none; }
.search kbd {
  padding: 2px 6px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--muted);
  font: 11px/1.25 var(--typeface);
  white-space: nowrap;
}
.clear-search { width: 30px; height: 30px; }
.clear-search .icon { width: 17px; height: 17px; }
.clear-search:hover { color: var(--accent-button); }

.primary-button, .secondary-button, .danger-button, .retry-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 14px;
  font-weight: 560;
  white-space: nowrap;
  transition: color var(--transition), background-color var(--transition), border-color var(--transition);
}
.primary-button, .danger-button { background: var(--accent-button); color: var(--button-ink); }
:where(:root[data-theme="light"]) :is(.primary-button, .danger-button) { color: #fff; }
.primary-button:hover, .primary-button:active, .danger-button:hover, .danger-button:active { background: var(--accent-hover); }
.primary-button .icon { width: 18px; height: 18px; }

.main-pane { position: relative; display: flex; min-width: 0; min-height: 0; background: var(--paper); }
.toolbar { display: none; }
.back-button { display: none; }

.editor-pane {
  display: flex;
  flex: 1;
  min-width: 0;
  overflow: auto;
  padding: var(--writing-top) max(var(--gutter), var(--safe-right)) 34px max(var(--gutter), var(--safe-left));
}
.editor-sheet {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  width: min(100%, var(--sheet-width));
  min-height: 240px;
  margin-inline: auto;
}
.date-stamp { display: block; }
.stamp-parts { position: relative; display: flex; flex-direction: column; align-items: start; gap: 11px; padding-top: 34px; }
.stamp-parts::before {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  content: "";
}
.stamp-meta { display: grid; gap: 5px; font: 16px/1.25 var(--typeface); }
.stamp-meta [data-date="month"] { font: 18px/1.2 var(--typeface); font-variant-numeric: tabular-nums; }
.stamp-day { margin-inline-start: -.06em; font: 500 110px/.86 var(--typeface); letter-spacing: -.055em; font-variant-numeric: lining-nums tabular-nums; }

.writing-area {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 6px 0 0 43px;
}
.writing-area::before {
  position: absolute;
  inset: 0 auto auto 0;
  width: 1px;
  height: min(100%, 365px);
  background: var(--paper-rule);
  content: "";
}
.body-field { flex: 1; display: flex; min-height: 110px; }
.title-field { display: grid; margin-bottom: 30px; }
#note-title, #note-body {
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  caret-color: var(--accent-button);
}
#note-title:focus-visible, #note-body:focus-visible { outline: none; }
#note-title, .title-measure, .empty-writing h1 { font: 540 clamp(38px, 4.35vw, 65px)/1.2 var(--typeface); letter-spacing: -.027em; }
#note-title, .title-measure {
  grid-area: 1 / 1;
  min-width: 0;
  min-height: 1.2em;
  max-height: calc(3.6em + 1px);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#note-title { height: 100%; overflow-y: auto; resize: none; scrollbar-width: thin; }
.title-measure { padding-bottom: 1px; visibility: hidden; overflow: hidden; }
#note-title::placeholder { color: var(--title-hint); opacity: 1; }
#note-body {
  flex: 1;
  max-width: 44rem;
  resize: none;
  color: var(--body);
  font: 21px/1.8 var(--typeface);
  overflow-wrap: anywhere;
  overscroll-behavior: contain;
}
#note-body::placeholder { color: var(--muted); opacity: 1; }

.empty-writing { align-items: start; }
.empty-writing h1 { margin: 0 0 20px; }
.empty-writing p { margin: 0 0 25px; color: var(--muted); font-size: 14px; line-height: 1.65; }

.archive {
  --accent: var(--archive-accent);
  color: var(--archive-ink);
  background: var(--archive);
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  min-height: 0;
}
.archive-inner {
  display: grid;
  grid-template-columns: clamp(154px, 14.4vw, 218px) minmax(0, 1fr);
  height: 100%;
}
.archive-header { display: flex; flex-direction: column; justify-content: center; align-items: start; gap: 6px; padding: 0 12px 0 var(--gutter); }
.archive-heading { display: grid; gap: 5px; }
.archive-heading h2 { margin: 0; font: 700 23px/1.2 var(--typeface); }
#note-count { color: var(--archive-muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.archive-controls { display: flex; gap: 2px; }
.archive-controls .icon-button { width: 30px; height: 28px; color: var(--archive-ink); }
.archive-controls .icon { width: 16px; height: 16px; }
.archive-controls .icon-button[aria-disabled="false"]:hover { color: var(--archive-accent); background: var(--archive-active); }

.note-list {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: max(210px, calc(100% / 3));
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: auto hidden;
  overscroll-behavior-x: contain;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: #766c5d var(--archive);
}
.note-list li { position: relative; min-width: 0; }
.note-list li::before, .list-empty::before {
  position: absolute;
  inset: 18px auto 22px 0;
  width: 1px;
  background: var(--archive-rule);
  content: "";
}
.note-list li:has(> .note-row[aria-current="true"])::before,
.note-list li:has(> .note-row[aria-current="true"]) + li::before { content: none; }
.note-row {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  height: 100%;
  width: 100%;
  min-width: 0;
  padding: 15px clamp(16px, 2.1vw, 34px);
  border: 0;
  color: var(--archive-ink);
  background: transparent;
  text-align: start;
  transition: background-color var(--transition);
}
@media (hover: hover) {
  .note-row:hover { background: #ffffff0a; }
}
.note-row:active { background: #ffffff12; }
.note-row[aria-current="true"] { background: var(--archive-selected); }
.note-row:focus-visible { outline-color: var(--archive-muted); outline-offset: -3px; }
.delete-button {
  position: absolute;
  top: 7px;
  right: 8px;
  width: 33px;
  height: 33px;
  color: var(--archive-muted);
}
.delete-button:hover, .delete-button:active { color: var(--archive-accent); background: #ffffff0b; }
.delete-button .icon { width: 17px; height: 17px; }
.row-date { display: flex; align-items: baseline; gap: 8px; margin-bottom: 7px; color: var(--archive-muted); font: 13px/1.2 var(--typeface); font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-text { display: grid; min-width: 0; gap: 6px; }
.row-title, .row-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-title { color: #e4dccf; font: 700 22px/1.2 var(--typeface); }
.note-row[aria-current="true"] .row-title { color: #fff8ec; }
.row-preview { min-height: 1.45em; color: var(--archive-muted); font-size: 12px; line-height: 1.45; }
.list-empty {
  position: relative;
  display: flex;
  align-items: center;
  padding: 16px clamp(16px, 2.1vw, 34px);
  color: var(--archive-muted);
  font: 16px/1.5 var(--typeface);
}
.list-empty p { margin: 0; }
.empty-storage-hint, .mobile-create, .list-empty[data-kind="initial"] p, .list-empty[data-kind="initial"]::before { display: none; }

.delete-dialog {
  width: min(380px, calc(100% - 40px));
  max-height: calc(100% - 32px);
  padding: 26px;
  border: 0;
  background: var(--dialog-surface);
  color: var(--ink);
  box-shadow: 0 12px 40px var(--dialog-shadow);
}
.delete-dialog::backdrop { background: var(--dialog-backdrop); }
.delete-dialog h2 { margin: 0 0 10px; font: 700 26px/1.3 var(--typeface); }
.delete-dialog p { margin: 0; color: var(--body); font-size: 14px; line-height: 1.65; overflow-wrap: anywhere; }
.delete-dialog .dialog-error { margin-top: 10px; color: var(--notice-ink); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: 10px; margin-top: 24px; }
.secondary-button { border-color: var(--rule); }
.secondary-button:hover, .secondary-button:active { background: var(--paper-hover); }
#cancel-delete:focus-visible { border-color: var(--muted); outline: none; }

.storage-notice {
  position: fixed;
  z-index: 2;
  bottom: calc(var(--archive-height) + var(--safe-bottom) + 14px);
  left: 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 5px 8px 5px 12px;
  border: 1px solid var(--notice-rule);
  border-left: 3px solid var(--accent);
  transform: translateX(-50%);
  background: var(--notice-surface);
  color: var(--notice-ink);
}
.storage-notice p { margin: 0; font-size: 13px; line-height: 1.5; }
.retry-button { flex: none; padding-inline: 8px; font-weight: 660; }
.retry-button:hover { background: var(--notice-hover); }

@media (max-width: 1100px) {
  :root { --masthead-height: 72px; --archive-height: 132px; --sheet-width: 838px; --writing-top: clamp(72px, 11vh, 96px); }
  .editor-sheet { grid-template-columns: 122px minmax(0, 1fr); }
  .writing-area { padding-left: 32px; }
  .stamp-day { font-size: 88px; }
  .stamp-parts { padding-top: 26px; }
  .stamp-parts::before { width: 11px; height: 11px; }
  .archive-heading h2 { font-size: 19px; }
  .row-title { font-size: 20px; }
}
@media (min-width: 681px) and (max-height: 610px) {
  :root { --masthead-height: 64px; --archive-height: 111px; --writing-top: 51px; }
  .stamp-day { font-size: 80px; }
  .title-field { margin-bottom: 20px; }
  .editor-pane { padding-bottom: 18px; }
}

@media (max-width: 680px) {
  :root { --gutter: 22px; --masthead-height: 65px; }
  body { background: var(--archive); }
  .workspace { grid-template-rows: auto minmax(0, 1fr); background: var(--archive); }
  .workspace[data-view="editor"] { grid-template-rows: minmax(0, 1fr); background: var(--paper); }
  .workspace[data-view="editor"] .masthead, .workspace[data-view="editor"] .archive, .main-pane { display: none; }
  .workspace[data-view="editor"] .main-pane { display: flex; flex-direction: column; }
  .masthead { --accent: var(--archive-accent); color: var(--archive-ink); }
  .masthead-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: var(--masthead-height) 47px;
    gap: 0 8px;
    border-bottom-color: var(--archive-rule);
  }
  .masthead-controls { display: contents; }
  .masthead-actions { grid-row: 1; grid-column: 2; gap: 4px; }
  .brand { color: var(--archive-ink); font-size: 30px; gap: 11px; }
  .brand-mark { width: 28px; height: 28px; }
  .theme-toggle { width: 44px; height: 44px; }
  .masthead .theme-toggle { color: var(--archive-muted); }
  .masthead .theme-toggle:hover, .masthead .theme-toggle:active { color: var(--archive-ink); background: var(--archive-active); }
  .new-button {
    min-height: 44px;
    padding-inline: 10px 1px;
    background: transparent;
    color: var(--archive-accent);
  }
  .new-button:hover, .new-button:active { background: var(--archive-active); }
  .search {
    grid-row: 2;
    grid-column: 1 / -1;
    width: 100%;
    height: 100%;
    padding-inline: 2px 0;
    border-top: 1px solid var(--archive-rule);
    color: var(--archive-ink);
    gap: 9px;
  }
  .search input { font-size: 16px; }
  .search input::placeholder { color: var(--archive-muted); }
  .search kbd { display: none; }
  .clear-search { width: 44px; height: 44px; }
  .clear-search:hover { color: var(--archive-accent); }

  .archive-inner { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .archive-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; width: 100%; }
  .archive-header { padding: 25px var(--gutter) 18px; }
  .archive-heading h2 { font-size: 34px; font-weight: 700; }
  .workspace[data-index="empty"] #note-count { display: none; }
  .archive-controls { display: none; }
  .note-list { display: flex; flex-direction: column; overflow: hidden auto; padding: 0 var(--gutter) 14px; overscroll-behavior: contain; }
  .note-list li { flex: none; border-bottom: 1px solid var(--archive-rule); }
  .note-list li:first-child { border-top: 1px solid var(--archive-rule); }
  .note-list li::before, .list-empty::before { display: none; }
  .note-row {
    display: grid;
    grid-template-columns: 62px minmax(0, 1fr);
    align-items: center;
    min-height: 79px;
    padding: 13px 11px;
  }
  .note-row[aria-current="true"] { padding-right: 52px; }
  .delete-button { top: 4px; right: 3px; width: 44px; height: 44px; }
  .row-date { display: flex; flex-direction: column; gap: 5px; margin: 0; font-size: 13px; }
  .row-date[data-other-year="false"] .row-year { display: none; }
  .row-date[data-other-year="true"] { font-size: 12px; }
  .row-title { font-size: 20px; }
  .row-text { padding-left: 14px; border-left: 1px solid var(--archive-rule); }
  .row-preview { font-size: 13px; }
  .list-empty {
    flex-direction: column;
    align-items: start;
    justify-content: start;
    gap: 10px;
    padding: 32px var(--gutter) 16px;
    overflow: auto;
  }
  .list-empty[data-kind="initial"] { padding-top: clamp(32px, 9vh, 76px); }
  .list-empty[data-kind="initial"] p { display: block; }
  .list-empty[data-kind="initial"] #list-empty-message { color: var(--archive-ink); font: 700 25px/1.35 var(--typeface); }
  .list-empty .empty-storage-hint { font: 13px/1.6 var(--typeface); }
  .mobile-create { display: inline-flex; min-height: 44px; margin-top: 10px; }

  .toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 65px;
    margin-inline: max(var(--gutter), var(--safe-left)) max(var(--gutter), var(--safe-right));
    border-bottom: 1px solid var(--paper-rule);
  }
  .back-button {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    gap: 2px;
    padding: 0 6px 0 0;
    border: 0;
    background: transparent;
    color: var(--ink);
    font: 700 16px/1.25 var(--typeface);
  }
  .back-button:hover, .back-button:active { color: var(--accent-button); }
  .back-button .icon { margin-left: -5px; }
  .editor-pane {
    padding: 27px max(var(--gutter), var(--safe-right)) calc(18px + var(--safe-bottom)) max(var(--gutter), var(--safe-left));
    min-height: 0;
  }
  .editor-sheet { display: flex; flex-direction: column; min-height: 220px; }
  .stamp-parts { flex-direction: row-reverse; justify-content: start; align-items: center; gap: 14px; padding-top: 0; }
  .stamp-parts::before { display: none; }
  .stamp-day { margin-inline-start: 0; font-size: 56px; line-height: .86; }
  .stamp-meta { gap: 3px; border-left: 1px solid var(--rule); padding-left: 13px; font-size: 12px; }
  .stamp-meta [data-date="month"] { font-size: 15px; }
  .stamp-meta [data-date="weekday"] { display: flex; align-items: center; gap: 5px; }
  .stamp-meta [data-date="weekday"]::after {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent);
    content: "";
  }
  .writing-area { flex: 1; padding: 0; margin-top: 28px; }
  .writing-area::before { display: none; }
  #note-title, .title-measure, .empty-writing h1 { font-size: clamp(32px, 9.3vw, 42px); }
  #note-body { font-size: 19px; line-height: 1.78; }
  .title-field { margin-bottom: 22px; }
  .dialog-actions button, .retry-button { min-height: 44px; }
  .storage-notice { bottom: calc(15px + var(--safe-bottom)); }
}
@media (max-width: 680px) and (max-height: 570px) {
  :root { --masthead-height: 54px; }
  .masthead-inner { grid-template-rows: var(--masthead-height) 45px; }
  .archive-header { padding-block: 16px 13px; }
  .archive-heading h2 { font-size: 28px; }
  .list-empty[data-kind="initial"] { padding-top: 21px; }
  .toolbar { min-height: 52px; }
  .workspace[data-view="editor"] .editor-pane { padding-top: 14px; }
  .stamp-day { font-size: 45px; }
  .writing-area { margin-top: 16px; }
  .title-field { margin-bottom: 13px; }
}
@media (max-width: 680px) and (prefers-reduced-motion: no-preference) {
  .workspace[data-view="editor"] .editor-sheet { animation: open-sheet 160ms ease-out both; }
  @keyframes open-sheet {
    from { opacity: .45; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
  }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
