/* Layout: one narrow writing column. Today's composer on top, then entries grouped by day, newest first. */
:root {
  --paper: #f2f3f0;
  --sheet: #fbfbf9;
  --ink: #1c2230;
  --muted: #5d6475;
  --rule: #d9dbd6;
  --accent: #2c4a8c;      /* blue-black fountain pen ink */
  --accent-ink: #ffffff;
  --danger: #a3322b;
  --seal: #7b8193;
  --font-read: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #13161c; --sheet: #1a1e26; --ink: #dde0e7; --muted: #9aa1b2; --rule: #2c313c;
    --accent: #93aee8; --accent-ink: #10141c; --danger: #e8837b; --seal: #7e8597;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #13161c; --sheet: #1a1e26; --ink: #dde0e7; --muted: #9aa1b2; --rule: #2c313c;
  --accent: #93aee8; --accent-ink: #10141c; --danger: #e8837b; --seal: #7e8597;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; -webkit-text-size-adjust: 100%; background: var(--paper); color: var(--ink); font-family: var(--font-ui); font-size: 15px; line-height: 1.5; }
.wrap { max-width: 680px; margin: 0 auto; padding-inline: 16px; padding-block: 28px 48px; display: flex; flex-direction: column; gap: 28px; }

.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--rule); padding-bottom: 14px; }
.top h1 { font-family: var(--font-read); font-weight: 600; font-size: 30px; line-height: 1.1; margin: 0; letter-spacing: -0.01em; }
.top .sub { margin: 4px 0 0; color: var(--muted); font-family: var(--font-mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }

button { font: inherit; cursor: pointer; border-radius: 6px; border: 1px solid var(--rule); background: transparent; color: var(--ink); padding: 7px 14px; }
button:hover { border-color: var(--muted); }
button:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 500; }
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: .5; cursor: default; filter: none; }
button.link { border: 0; padding: 2px 0; color: var(--muted); font-size: 13px; }
button.link:hover { color: var(--ink); }
button.link.danger { color: var(--danger); }

.panel { background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.panel h2 { font-family: var(--font-read); font-weight: 600; font-size: 21px; margin: 0; }
.panel p { margin: 0; color: var(--muted); max-width: 60ch; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
input[type="password"] { font: inherit; font-size: 16px; padding: 9px 11px; border-radius: 6px; border: 1px solid var(--rule); background: var(--paper); color: var(--ink); width: 100%; }
.warn { border-left: 3px solid var(--danger); padding: 6px 0 6px 12px; color: var(--ink) !important; font-size: 14px; }
.error { color: var(--danger) !important; font-size: 14px; min-height: 1.4em; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Composer */
.composer { background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px; padding: 16px 18px 12px; display: flex; flex-direction: column; gap: 8px; }
.composer-head { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.composer-head .clock { font-family: var(--font-mono); letter-spacing: 0; text-transform: none; font-variant-numeric: tabular-nums; }
textarea { width: 100%; resize: none; border: 0; background: transparent; color: var(--ink); font-family: var(--font-read); font-size: 18px; line-height: 1.6; min-height: 120px; padding: 4px 0; overflow: hidden; }
textarea::placeholder { color: var(--muted); font-style: italic; opacity: .8; }
.composer-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--rule); padding-top: 10px; }
.hint { font-size: 12.5px; color: var(--muted); }
kbd { font-family: var(--font-mono); font-size: 11.5px; border: 1px solid var(--rule); border-radius: 4px; padding: 0 4px; }

/* Entries */
.day { display: flex; flex-direction: column; gap: 0; }
.day-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding-bottom: 6px; border-bottom: 1px solid var(--ink); }
.day-head h3 { margin: 0; font-family: var(--font-read); font-weight: 600; font-size: 17px; text-wrap: balance; }
.day-head .state { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.day-head .state.open { color: var(--accent); }
.entry { display: flex; flex-direction: column; gap: 6px; padding: 16px 0; border-bottom: 1px solid var(--rule); }
.entry .time, .segment .time { font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; display: flex; gap: 12px; flex-wrap: wrap; }
.entry .main { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.entry .body { font-family: var(--font-read); font-size: 17px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.entry .body.unreadable { font-style: italic; color: var(--danger); font-size: 15px; }
.entry .meta { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.entry .meta .edited { font-family: var(--font-mono); font-size: 12px; }
.entry textarea { background: var(--sheet); border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px; font-size: 17px; min-height: 90px; }
.confirm { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13.5px; }
.seal { display: inline-flex; align-items: center; gap: 5px; color: var(--seal); }
.seal svg, .state svg { width: 12px; height: 12px; }

.export-opt { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; padding-top: 14px; border-top: 1px solid var(--rule); }
.export-opt > div { flex: 1 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.export-opt h4 { margin: 0; font-size: 15px; font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
.export-opt strong { color: var(--ink); font-weight: 600; }
.tag { font-family: var(--font-mono); font-size: 11.5px; font-weight: 400; color: var(--muted); }
.search { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--rule); padding: 4px 2px 8px; color: var(--muted); margin-bottom: -12px; }
.search svg { width: 16px; height: 16px; flex: none; }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 16px; padding: 4px 0; }
.search input::placeholder { color: var(--muted); }
.search input:focus-visible { outline: none; }
.search:focus-within { border-bottom-color: var(--accent); color: var(--accent); }
.q-count { font-family: var(--font-mono); font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 2px; padding: 0 1px; }
.empty { text-align: left; color: var(--muted); padding: 8px 0; font-family: var(--font-read); font-style: italic; font-size: 16px; }
.foot { font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--rule); padding-top: 14px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: 6px; font-size: 13.5px; }

@media (max-width: 480px) {
  .top h1 { font-size: 26px; }
}
@media (prefers-reduced-motion: no-preference) {
  .entry.fresh { animation: settle .4s ease-out; }
  @keyframes settle { from { background: color-mix(in srgb, var(--accent) 10%, transparent); } to { background: transparent; } }
}

/* A sealed day reads as one page: entries in writing order, each under its own time. */
.day-page { display: flex; flex-direction: column; gap: 22px; padding: 18px 0 22px; border-bottom: 1px solid var(--rule); }
.segment { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.segment .body { font-family: var(--font-read); font-size: 17px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.segment .body.unreadable { font-style: italic; color: var(--danger); font-size: 15px; }
.segment .edited { opacity: .85; }

/* ---- self-hosted additions ---- */
[hidden] { display: none !important; }
img { max-width: 100%; }
.stack { display: flex; flex-direction: column; gap: 32px; }
.who { font-size: 13px; color: var(--muted); }
.who b { color: var(--ink); font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--rule); margin-bottom: 4px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 12px; color: var(--muted); font-weight: 500; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
input[type="text"], input[type="file"] { font: inherit; font-size: 16px; padding: 9px 11px; border-radius: 6px; border: 1px solid var(--rule); background: var(--paper); color: var(--ink); width: 100%; }
input[type="file"] { font-size: 14px; }
.panel h3 { margin: 0; font-size: 15px; font-weight: 600; }
.sub-section { display: flex; flex-direction: column; gap: 12px; padding-top: 16px; border-top: 1px solid var(--rule); }
.progress { font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); }
.small { font-size: 13px; }
.stack-sm { display: flex; flex-direction: column; gap: 14px; }
.muted { color: var(--muted); margin: 0; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); }
.danger-btn { color: var(--danger); border-color: var(--danger); }
.danger-btn:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: var(--danger); }
.composer-head label { cursor: text; }
.top { flex-wrap: wrap; position: relative; }

/* Header actions: a row on wide screens, a hamburger menu on phones. */
.top-actions { display: flex; align-items: center; }
.top-menu { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.menu-btn { display: none; align-items: center; justify-content: center; width: 42px; height: 42px; padding: 0; }
.menu-btn svg { width: 20px; height: 20px; }
@media (max-width: 600px) {
  .top { flex-wrap: nowrap; align-items: flex-start; }
  .menu-btn { display: inline-flex; }
  .top-menu { display: none; position: absolute; right: 0; top: 52px; z-index: 20; min-width: 220px;
    flex-direction: column; align-items: stretch; gap: 6px; padding: 12px;
    background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px;
    box-shadow: 0 10px 30px color-mix(in srgb, var(--ink) 18%, transparent); }
  .top-menu.open { display: flex; }
  .top-menu .who { padding: 2px 4px 8px; border-bottom: 1px solid var(--rule); margin-bottom: 2px; }
  .top-menu button { text-align: left; padding: 10px 12px; }
  .menu-btn[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
}
/* Keyboard shortcut hint is pointless on touch screens. */
@media (hover: none) and (pointer: coarse) { .kbd-hint { display: none; } }
