@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Manrope:wght@400;500;600;700;800&family=Newsreader:opsz,wght@6..72,500;6..72,600&display=swap');

:root {
  --paper: #f7f3ea;
  --paper-deep: #eee7d8;
  --ink: #25221e;
  --muted: #777168;
  --line: #d9d1c2;
  --white: #fffdf8;
  --red: #c84b31;
  --red-dark: #963821;
  --green: #45745a;
  --shadow: 0 18px 60px rgba(57, 45, 28, .11);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { min-height: 100vh; min-height: 100dvh; margin: 0; color: var(--ink); background: var(--paper); font-family: "Manrope", sans-serif; overscroll-behavior: none; touch-action: pan-y; -webkit-tap-highlight-color: transparent; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button, input, textarea { -webkit-appearance: none; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(200, 75, 49, .25); outline-offset: 2px; }
.hidden { display: none !important; }
.eyebrow { margin: 0; color: var(--red); font: 700 11px/1 "DM Mono", monospace; letter-spacing: .16em; text-transform: uppercase; }

.login-view { min-height: 100vh; min-height: 100dvh; display: grid; align-content: end; gap: 30px; padding: max(40px, env(safe-area-inset-top)) 26px max(42px, calc(26px + env(safe-area-inset-bottom))); overflow: hidden; }
.login-view::before { content: ""; position: fixed; inset: 0; z-index: -2; background: radial-gradient(circle at 78% 18%, rgba(200,75,49,.12), transparent 34%), linear-gradient(145deg, transparent 55%, rgba(126,105,73,.09)); }
.login-view::after { content: ""; position: fixed; inset: 0; z-index: -1; opacity: .26; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 120 120' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.1'/%3E%3C/svg%3E"); }
.login-mark { position: absolute; top: max(60px, calc(28px + env(safe-area-inset-top))); right: 26px; width: 112px; height: 112px; border: 1px solid var(--red); border-radius: 50%; transform: rotate(-7deg); }
.login-mark span { position: absolute; left: 26px; right: 26px; height: 1px; background: var(--red); transform-origin: center; }
.login-mark span:nth-child(1) { top: 38px; transform: rotate(45deg); }
.login-mark span:nth-child(2) { top: 55px; }
.login-mark span:nth-child(3) { top: 72px; transform: rotate(-45deg); }
.login-copy h1 { max-width: 520px; margin: 12px 0 14px; font: 600 clamp(52px, 15vw, 88px)/.88 "Newsreader", serif; letter-spacing: -.055em; }
.login-copy > p:last-child { max-width: 390px; margin: 0; color: var(--muted); font-size: 15px; line-height: 1.6; }
.login-form { display: grid; gap: 9px; width: min(100%, 520px); }
.login-form label { color: var(--muted); font-size: 12px; font-weight: 700; }
.password-row { display: grid; grid-template-columns: 1fr auto; padding: 5px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,253,248,.7); box-shadow: var(--shadow); }
.password-row input { min-width: 0; padding: 12px; border: 0; color: var(--ink); background: transparent; font-size: 16px; }
.password-row button { padding: 12px 20px; border: 0; border-radius: 13px; color: white; background: var(--red); font-weight: 800; }
.form-error { min-height: 18px; margin: 0; color: var(--red-dark); font-size: 12px; }

.app-shell { min-height: 100vh; min-height: 100dvh; padding-top: env(safe-area-inset-top); }
.topbar { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; height: 68px; padding: 0 max(17px, calc((100vw - 840px) / 2)); border-bottom: 1px solid rgba(217,209,194,.8); background: rgba(247,243,234,.88); backdrop-filter: blur(18px); }
.round-button { display: grid; place-items: center; width: 42px; height: 42px; padding: 0; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); background: var(--white); font-size: 25px; }
#menuButton { align-content: center; gap: 6px; }
#menuButton span { width: 17px; height: 1.5px; background: currentColor; }
.brand-button { display: flex; align-items: center; justify-content: center; gap: 8px; border: 0; color: var(--ink); background: transparent; font: 600 22px "Newsreader", serif; }
.brand-mark { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 50% 50% 48% 52%; color: var(--paper); background: var(--red); font: 600 16px "Newsreader", serif; transform: rotate(-7deg); }
.sync-button svg, .search-field svg, .bottom-nav svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sync-button.loading svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { width: min(100%, 840px); margin: auto; padding: 0 18px calc(104px + env(safe-area-inset-bottom)); }
.view { display: none; }
.view.active { display: block; animation: appear .22s ease both; }
@keyframes appear { from { opacity: 0; transform: translateY(6px); } }
.date-hero { display: flex; align-items: end; justify-content: space-between; gap: 18px; padding: 34px 4px 25px; }
.date-hero h1, .section-heading h1 { margin: 8px 0 3px; font: 600 clamp(42px, 12vw, 66px)/.94 "Newsreader", serif; letter-spacing: -.045em; }
.date-hero #dateSubtitle { margin: 0; color: var(--muted); font-size: 13px; text-transform: capitalize; }
.date-picker-button { position: relative; display: grid; place-items: center; width: 44px; height: 44px; flex: 0 0 auto; overflow: hidden; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); background: var(--white); cursor: pointer; }
.date-picker-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
#datePicker { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; opacity: 0; cursor: pointer; }
#datePicker::-webkit-calendar-picker-indicator { width: 100%; height: 100%; margin: 0; cursor: pointer; }
.day-switcher { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-bottom: 16px; }
.day-switcher button { height: 42px; border: 0; color: var(--muted); background: transparent; font-size: 12px; font-weight: 700; }
.day-switcher button:first-child { text-align: left; }
.day-switcher button:last-child { text-align: right; }
.day-switcher button span { color: var(--ink); font-size: 17px; }
.day-switcher button small { margin: 0 7px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.day-switcher .current-day { padding: 0 17px; border: 1px solid var(--line); border-radius: 999px; color: var(--red); background: var(--white); }

.editor-card { overflow: hidden; border: 1px solid var(--line); border-radius: 24px; background: var(--white); box-shadow: var(--shadow); }
.editor-meta { display: flex; align-items: center; justify-content: space-between; padding: 15px 17px; border-bottom: 1px solid var(--line); }
.editor-meta > div { display: flex; align-items: center; gap: 9px; min-width: 0; }
.editor-meta strong { overflow: hidden; font: 500 12px "DM Mono", monospace; text-overflow: ellipsis; white-space: nowrap; }
.editor-actions { flex: 0 0 auto; }
.state-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(69,116,90,.12); }
.state-dot.dirty { background: var(--red); box-shadow: 0 0 0 4px rgba(200,75,49,.12); }
.text-button, .icon-action { border: 0; color: var(--muted); background: transparent; }
.text-button { padding: 5px 0 5px 4px; font-size: 11px; font-weight: 700; }
.icon-action { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border-radius: 10px; }
.icon-action svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-action.active { color: var(--red); background: #f7e5df; }
.editor-stack { position: relative; min-height: calc(100dvh - 365px); background: var(--white); }
#editor, .highlight-layer { width: 100%; min-height: calc(100dvh - 365px); margin: 0; padding: 23px 20px; border: 0; border-radius: 0; font: 15px/1.7 "DM Mono", monospace; letter-spacing: normal; tab-size: 2; white-space: pre-wrap; overflow-wrap: break-word; }
.highlight-layer { position: absolute; inset: 0; overflow: hidden; color: #312d28; pointer-events: none; }
#editor { position: relative; display: block; resize: none; color: transparent; background: transparent; caret-color: var(--red); -webkit-text-fill-color: transparent; }
#editor::selection { background: rgba(200,75,49,.22); -webkit-text-fill-color: transparent; }
#editor:focus { outline: 0; }
.md-heading { color: var(--red-dark); font-weight: 700; }
.md-code { color: #386b5c; background: #e7f0eb; }
.md-strong { color: #171512; font-weight: 700; }
.md-link { color: #37689a; text-decoration: underline; }
.md-quote { color: #7e695b; font-style: italic; }
.md-list { color: var(--red); font-weight: 700; }
.md-task { color: var(--green); font-weight: 700; }
.markdown-preview { min-height: calc(100dvh - 365px); padding: 25px 22px 40px; color: #312d28; font-size: 16px; line-height: 1.72; }
.markdown-preview h1, .markdown-preview h2, .markdown-preview h3, .markdown-preview h4, .markdown-preview h5, .markdown-preview h6 { margin: 1.1em 0 .45em; font-family: "Newsreader", serif; line-height: 1.08; letter-spacing: -.025em; }
.markdown-preview h1:first-child, .markdown-preview h2:first-child { margin-top: 0; }
.markdown-preview h1 { font-size: 38px; }
.markdown-preview h2 { font-size: 30px; }
.markdown-preview h3 { font-size: 23px; }
.markdown-preview p { margin: 0 0 1em; }
.markdown-preview ul, .markdown-preview ol { margin: 0 0 1em; padding-left: 24px; }
.markdown-preview li { margin: .35em 0; }
.markdown-preview blockquote { margin: 1em 0; padding: 4px 0 4px 16px; border-left: 3px solid var(--red); color: var(--muted); }
.markdown-preview code { padding: 2px 5px; border-radius: 5px; color: #386b5c; background: #e7f0eb; font: .88em "DM Mono", monospace; }
.markdown-preview pre { overflow-x: auto; padding: 16px; border-radius: 14px; color: #eee9df; background: #292621; }
.markdown-preview pre code { padding: 0; color: inherit; background: transparent; }
.markdown-preview a { color: #37689a; }
.markdown-preview hr { margin: 28px 0; border: 0; border-top: 1px solid var(--line); }
.markdown-preview input { width: 16px; height: 16px; margin: 0 5px 0 0; accent-color: var(--green); }
.editor-footer { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 13px; border-top: 1px solid var(--line); }
#pathLabel { overflow: hidden; padding-left: 5px; color: var(--muted); font: 10px "DM Mono", monospace; text-overflow: ellipsis; white-space: nowrap; }
.save-button { min-height: 44px; padding: 0 17px; border: 0; border-radius: 14px; color: white; background: var(--red); font-size: 12px; font-weight: 800; }
.save-button:disabled { color: #a59e93; background: #e8e2d8; }

.section-heading { display: flex; align-items: end; justify-content: space-between; padding: 34px 4px 24px; }
.section-heading h1 { font-size: 54px; }
.search-field { display: flex; align-items: center; gap: 10px; padding: 0 15px; border: 1px solid var(--line); border-radius: 16px; background: var(--white); }
.search-field input { width: 100%; padding: 15px 0; border: 0; color: var(--ink); background: transparent; font-size: 14px; }
.search-field input:focus { outline: 0; }
.file-filters { display: flex; gap: 7px; margin: 13px 0 18px; overflow-x: auto; scrollbar-width: none; }
.file-filters button { padding: 9px 14px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: transparent; font-size: 11px; font-weight: 700; white-space: nowrap; }
.file-filters button.active { border-color: var(--ink); color: var(--white); background: var(--ink); }
.file-list { display: grid; gap: 8px; }
.file-group { margin: 17px 5px 5px; color: var(--muted); font: 500 10px "DM Mono", monospace; letter-spacing: .1em; text-transform: uppercase; }
.file-item { display: grid; grid-template-columns: 38px minmax(0, 1fr) 20px; align-items: center; gap: 11px; width: 100%; padding: 13px; border: 1px solid var(--line); border-radius: 16px; color: var(--ink); background: var(--white); text-align: left; }
.file-icon { display: grid; place-items: center; width: 38px; height: 42px; border-radius: 7px 12px 7px 7px; color: var(--red); background: #f3dfd8; font: 600 14px "Newsreader", serif; }
.file-copy { min-width: 0; }
.file-copy strong, .file-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-copy strong { font-size: 13px; }
.file-copy small { margin-top: 3px; color: var(--muted); font: 10px "DM Mono", monospace; }
.file-arrow { color: var(--muted); }
.empty-files { padding: 32px 12px; color: var(--muted); text-align: center; }

.bottom-nav { position: fixed; right: 0; bottom: 0; left: 0; z-index: 30; display: grid; grid-template-columns: repeat(2, 1fr); height: calc(67px + env(safe-area-inset-bottom)); padding: 5px max(28px, calc((100vw - 500px) / 2)) env(safe-area-inset-bottom); border-top: 1px solid var(--line); background: rgba(255,253,248,.93); backdrop-filter: blur(18px); }
.bottom-nav button { display: grid; place-items: center; align-content: center; gap: 3px; border: 0; color: #918b81; background: transparent; font-size: 10px; font-weight: 700; }
.bottom-nav button.active { color: var(--red); }
.bottom-nav svg { width: 22px; height: 22px; }

.history-dialog { width: min(calc(100% - 24px), 620px); max-height: min(78dvh, 720px); margin: auto auto 12px; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 27px; color: var(--ink); background: var(--paper); box-shadow: var(--shadow); }
.history-dialog::backdrop { background: rgba(40,33,25,.54); backdrop-filter: blur(5px); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; padding: 20px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 6px 0 0; font: 600 29px "Newsreader", serif; }
.history-list { max-height: 58dvh; overflow: auto; padding: 12px; }
.history-item { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 14px 8px; border-bottom: 1px solid var(--line); }
.history-item strong, .history-item small { display: block; }
.history-item strong { font-size: 13px; }
.history-item small { margin-top: 5px; color: var(--muted); font: 10px "DM Mono", monospace; }
.revert-button { align-self: center; padding: 9px 12px; border: 1px solid #e2b5a9; border-radius: 11px; color: var(--red-dark); background: #fae9e4; font-size: 11px; font-weight: 800; }
.toast, .offline-banner { position: fixed; z-index: 80; right: 14px; bottom: calc(80px + env(safe-area-inset-bottom)); left: 14px; width: min(calc(100% - 28px), 520px); margin: auto; padding: 13px 16px; border-radius: 14px; color: white; background: var(--ink); box-shadow: var(--shadow); text-align: center; font-size: 12px; font-weight: 700; }
.offline-banner { background: var(--red-dark); }

@media (min-width: 720px) {
  main { padding-right: 30px; padding-left: 30px; }
  .date-hero { padding-top: 52px; }
  .history-dialog { margin: auto; }
}

@media (display-mode: standalone) {
  .topbar { height: 61px; }
}

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