:root {
  /* Dark chrome (sidebar, toolbars) wraps the light paper content. */
  --chrome: #1c2027;
  --chrome-raised: #272c36;
  --chrome-border: #323845;
  --chrome-ink: #e6e8ee;
  --chrome-muted: #99a0af;

  --bg: #e7e9ee;        /* light content areas (settings, calendar) */
  --desk: #a9afbc;      /* the desk surface the paper pages sit on */
  --panel: #ffffff;
  --ink: #22252c;
  --muted: #5f6675;
  --accent: #4263eb;
  --border: #d4d7df;
  --danger: #e03131;
  --ok: #2f9e44;
  --movelock: #c46be0;  /* distinct from --accent (write-lock) and --ok (word mode) */
  --paper-ink: #1a1a1a; /* default text/ink color on the page (canvas ink set in app.js) */
  --paper: #ffffff;     /* page sheet color; keep in sync with THEMES.paper in app.js */
  --hover: #f2f3f7;     /* subtle hover fill on content surfaces */
  --shadow: 0 1px 2px rgba(15, 18, 25, .08), 0 2px 8px rgba(15, 18, 25, .06);
  --shadow-lg: 0 10px 36px rgba(10, 12, 18, .35);
  --radius: 10px;
}

/* Dark theme: chrome stays dark; the content/paper areas go dark too. Existing
   near-black ink is lifted at display time in app.js (see inkColor). */
html[data-theme="dark"] {
  --bg: #16181d;
  --desk: #101216;
  --panel: #272c36;
  --ink: #e6e8ee;
  --muted: #99a0af;
  --border: #3a4150;
  --paper-ink: #d7dae1;
  --paper: #22262d;
  --hover: #2f3542;
}

/* Low blue light: warm sepia paper + warm-toned chrome and an amber accent, so
   little blue light is emitted. Ink stays dark (paper is light). */
html[data-theme="warm"] {
  --chrome: #2a2622;
  --chrome-raised: #38322b;
  --chrome-border: #473f35;
  --chrome-ink: #efe7d6;
  --chrome-muted: #b6a88f;
  --bg: #efe4cd;
  --desk: #c9bb9c;
  --panel: #faf3e1;
  --ink: #2e2820;
  --muted: #6f6450;
  --accent: #b5722e;
  --border: #ddcfb2;
  --paper-ink: #2a241c;
  --paper: #f6ecd6;
  --hover: #efe4cd;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: rgba(120, 128, 145, .45);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-track { background: transparent; }

.auth-screen { display: none; height: 100%; }
.auth-screen.active { display: flex; }
.panel-view { display: none; height: 100%; flex-direction: column; min-width: 0; }
.panel-view.active { display: flex; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.spacer { flex: 1; }
.error { color: #ff8787; min-height: 1.2em; margin: .4rem 0 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- buttons / inputs ---- */
button, .google-btn, .provider-btn {
  font: inherit;
  font-size: .9rem;
  font-weight: 500;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: .45rem .85rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease, filter .12s ease;
}
button:hover { filter: brightness(1.08); }
button.secondary { background: var(--panel); color: var(--ink); border-color: var(--border); }
button.secondary:hover { filter: none; background: var(--hover); border-color: var(--border); }
button.small { padding: .28rem .55rem; font-size: .85rem; }
button:disabled { opacity: .55; cursor: default; }

input, select, textarea {
  font: inherit;
  padding: .45rem .6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

/* ---- app shell + sidebar ---- */
#app-shell { display: grid; grid-template-columns: 252px 1fr; height: 100%; }
#main { min-width: 0; overflow: hidden; }

#sidebar {
  display: flex;
  flex-direction: column;
  background: var(--chrome);
  color: var(--chrome-ink);
  border-right: 1px solid var(--chrome-border);
  min-height: 0;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .8rem .9rem;
  font-size: 1.02rem;
  letter-spacing: .01em;
  border-bottom: 1px solid var(--chrome-border);
}
.theme-select {
  flex: none; font-size: .78rem; padding: .25rem .4rem; border-radius: 7px;
  background: var(--chrome-raised); color: var(--chrome-ink); border: 1px solid var(--chrome-border);
  cursor: pointer;
}
/* Sidebar sections: Journals and Notebooks, each with its own "Add…" button. */
.nb-section { padding: .35rem 0; }
.nb-section + .nb-section { border-top: 1px solid var(--chrome-border); }
.nb-section-head {
  padding: .35rem .7rem .25rem; font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--chrome-muted);
}
.nb-add {
  display: block; width: calc(100% - .8rem); margin: .25rem .4rem .1rem;
  text-align: left; background: transparent; color: #8da2ff;
  border: 1px dashed var(--chrome-border); border-radius: 8px;
  padding: .4rem .55rem; font-size: .88rem; cursor: pointer;
}
.nb-add:hover { filter: none; background: var(--chrome-raised); color: var(--chrome-ink); }

.side-link {
  display: flex; align-items: center; gap: .5rem; width: 100%;
  background: transparent; color: var(--chrome-ink); border: none;
  border-bottom: 1px solid var(--chrome-border);
  padding: .6rem .9rem; font-size: .95rem; text-align: left; cursor: pointer;
}
.side-link:hover { background: var(--chrome-raised); }
.side-link.active { background: rgba(66, 99, 235, .28); }
.side-link .side-link-icon { font-size: 1.05rem; }

.nb-tree { flex: 1; overflow: auto; padding: .4rem; }
.nb-row { margin-bottom: .1rem; }
.nb-item { display: flex; align-items: center; gap: .25rem; border-radius: 8px; padding: .12rem .25rem; }
.nb-item:hover { background: rgba(255, 255, 255, .05); }
.nb-item.active { background: rgba(66, 99, 235, .28); }
.nb-item .caret { background: none; border: none; color: var(--chrome-muted); padding: .2rem .35rem; cursor: pointer; }
.nb-item .nb-name {
  flex: 1; cursor: pointer; padding: .32rem .2rem; font-size: .92rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nb-item .del { background: none; border: none; color: var(--chrome-muted); cursor: pointer; opacity: 0; padding: .2rem; }
.nb-item:hover .del { opacity: 1; }
.nb-item .del:hover { color: #ff8787; }
/* The customizable journal icon at the start of a journal row. */
.nb-item .nb-icon {
  flex: 0 0 auto; width: 26px; height: 26px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer; font-size: 1.05rem; line-height: 1;
  border-radius: 6px;
}
.nb-item .nb-icon:hover { background: rgba(255, 255, 255, .12); }
.nb-item .nb-icon img { width: 22px; height: 22px; border-radius: 5px; display: block; }

/* Icon picker grid (inside the modal). */
.icon-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem;
  max-height: 60vh; overflow-y: auto;
}
.icon-cell {
  aspect-ratio: 1 / 1; padding: .25rem; cursor: pointer;
  background: var(--panel); border: 2px solid var(--border); border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.icon-cell:hover { border-color: var(--accent); }
.icon-cell.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.icon-cell img { width: 100%; height: 100%; object-fit: contain; border-radius: 6px; }
.icon-cell .icon-glyph { font-size: 1.8rem; }
.nb-pages { display: flex; flex-direction: column; padding-left: 1.4rem; }
.pg-link, .pg-add {
  text-align: left; background: none; border: none; color: var(--chrome-muted);
  font-size: .88rem; font-weight: 400;
  padding: .28rem .4rem; border-radius: 6px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pg-link:hover { background: rgba(255, 255, 255, .05); color: var(--chrome-ink); filter: none; }
.pg-add { color: #8da2ff; }
.pg-add:hover { filter: none; background: rgba(255, 255, 255, .05); }

.sidebar-foot { display: flex; align-items: center; gap: .4rem; padding: .55rem; border-top: 1px solid var(--chrome-border); }
.sidebar-foot .muted { color: var(--chrome-muted); }
.sidebar-foot button.secondary { background: transparent; color: var(--chrome-muted); border-color: var(--chrome-border); }
.sidebar-foot button.secondary:hover { background: var(--chrome-raised); color: var(--chrome-ink); }
.sidebar-foot #who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.backdrop { position: fixed; inset: 0; background: rgba(8, 10, 14, .5); z-index: 40; }
.drawer-toggle { display: none; }

@media (max-width: 800px) {
  #app-shell { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 280px; z-index: 50;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg);
  }
  #sidebar.open { transform: translateX(0); }
  .drawer-toggle { display: inline-block; }
}

/* Full-screen page mode: collapse the sidebar into a slide-in drawer at any
   width (mirrors the narrow-screen rules above). Toggled per session via the
   ⛶ button; stays on across panel switches so day-navigation never exits it. */
#app-shell.fullscreen { grid-template-columns: 1fr; }
#app-shell.fullscreen #sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 280px; z-index: 50;
  transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg);
}
#app-shell.fullscreen #sidebar.open { transform: translateX(0); }
#app-shell.fullscreen .drawer-toggle { display: inline-block; }
/* Maximize the writing area: the Files & photos panel is chrome, not page. */
#app-shell.fullscreen #feed-files { display: none; }
.fullscreen-toggle.active { background: var(--chrome-raised); }

/* ---- top bar (dark chrome) ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 48px;
  padding: .4rem .75rem;
  background: var(--chrome);
  color: var(--chrome-ink);
  border-bottom: 1px solid var(--chrome-border);
}
.topbar strong { font-weight: 600; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .muted { color: var(--chrome-muted); }
.topbar button.secondary { background: transparent; color: var(--chrome-ink); border-color: var(--chrome-border); }
.topbar button.secondary:hover { background: var(--chrome-raised); }
.avatar { width: 26px; height: 26px; border-radius: 50%; }

.content { flex: 1; overflow: auto; padding: 1rem 1.2rem; }
.toolbar { display: flex; gap: .6rem; margin-bottom: .9rem; }
.toolbar input { flex: 1; }

/* ---- feed editor ---- */
.feed { flex: 1; overflow: auto; padding: 1rem; background: var(--desk); }
.page-block { width: min(100%, 900px); margin: 0 auto 1.2rem; }
.block-head { display: flex; align-items: center; gap: .4rem; margin-bottom: .3rem; }
.block-head .page-title {
  flex: 1; min-width: 0; font-weight: 600;
  background: transparent; border-color: transparent; padding: .3rem .4rem;
}
.block-head .page-title::placeholder { color: color-mix(in srgb, var(--ink) 50%, transparent); }
.block-head .page-title:hover { border-color: color-mix(in srgb, var(--ink) 22%, transparent); }
.block-head .page-title:focus { background: var(--panel); border-color: var(--accent); outline: none; }
.block-head .page-type {
  max-width: 110px; font-size: .85rem; padding: .28rem .4rem;
  background: color-mix(in srgb, var(--panel) 70%, transparent); border-color: var(--border);
}
.block-head .del-page { background: none; border: none; color: color-mix(in srgb, var(--ink) 55%, transparent); cursor: pointer; padding: .2rem .4rem; }
.block-head .del-page:hover { color: var(--danger); filter: none; }
.block-head .lock-page { background: none; border: none; cursor: pointer; padding: .2rem .35rem; line-height: 0; display: inline-flex; }
.block-head .lock-page svg { display: block; }
.block-head .lock-page.locked { color: var(--danger); }
.block-head .lock-page.unlocked { color: var(--ok); }
.block-head .wp-page { background: none; border: none; cursor: pointer; padding: .2rem .35rem; line-height: 0; display: inline-flex; color: color-mix(in srgb, var(--ink) 50%, transparent); }
.block-head .wp-page svg { display: block; }
.block-head .wp-page.on { color: var(--ok); }
.block-head .movelock-page { background: none; border: none; cursor: pointer; padding: .2rem .35rem; line-height: 0; display: inline-flex; color: color-mix(in srgb, var(--ink) 50%, transparent); }
.block-head .movelock-page svg { display: block; }
.block-head .movelock-page.on { color: var(--movelock); }
.block-head .save-zoom, .block-head .restore-zoom {
  background: none; border: none; cursor: pointer; padding: .2rem .35rem;
  line-height: 0; display: inline-flex; color: color-mix(in srgb, var(--ink) 50%, transparent);
}
.block-head .save-zoom svg, .block-head .restore-zoom svg { display: block; }
.block-head .restore-zoom { color: var(--accent); }
.block-head .restore-zoom[hidden] { display: none; }
/* Word mode forces zoom to 1x, so the zoom bookmark controls don't apply. */
.page-block.word-mode .save-zoom, .page-block.word-mode .restore-zoom { display: none; }
.canvas-holder {
  position: relative; width: 100%; background: var(--paper); border-radius: 3px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(10, 12, 18, .25), 0 6px 18px rgba(10, 12, 18, .18);
}
.page-block.locked .canvas-holder { outline: 2px solid var(--accent); outline-offset: 2px; }
.page-block.move-locked .canvas-holder { outline: 2px solid var(--movelock); outline-offset: 2px; }
.page-block.word-mode .canvas-holder { outline: 2px solid var(--ok); outline-offset: 2px; }

/* Three stacked layers scaled together by the transform on .page-stack: the paper
   canvas sizes the stack (in flow), the doc and strokes canvas overlay it. */
.page-stack { position: relative; transform-origin: 0 0; }
.paper-canvas { display: block; width: 100%; height: auto; }
.page-doc, .page-canvas { position: absolute; inset: 0; }
.page-canvas { width: 100%; height: 100%; }

.page-doc {
  pointer-events: none; /* draw mode: input falls through to the strokes canvas */
  overflow: hidden;
  padding: 28px 32px;
  color: var(--paper-ink);
  font: 22px/1.5 system-ui, sans-serif;
  word-wrap: break-word;
}
.page-doc:focus { outline: none; }
.page-doc h1 { font-size: 2em; margin: .3em 0; }
.page-doc h2 { font-size: 1.5em; margin: .3em 0; }
.page-doc p { margin: 0 0 .25em; }
.page-doc ul, .page-doc ol { margin: .25em 0; padding-left: 1.6em; }
.page-block.word-mode .page-doc { pointer-events: auto; touch-action: auto; }
.page-block.word-mode .page-doc:empty::before { content: "Start typing…"; color: color-mix(in srgb, var(--paper-ink) 40%, transparent); }
.page-block.word-mode .page-canvas { pointer-events: none; }

.format-tools { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; }
.format-tools button {
  background: transparent; color: var(--chrome-ink); border: 1px solid transparent;
  padding: .2rem .45rem; border-radius: 6px; min-width: 1.9rem; line-height: 1.1;
}
.format-tools button:hover { background: rgba(255, 255, 255, .07); filter: none; }
.format-tools select { font-size: .82rem; padding: .2rem .3rem; max-width: 90px; }
.format-tools input[type="color"] {
  width: 26px; height: 26px; padding: 0; border: none; background: none; cursor: pointer;
}
.feed-adder { width: min(100%, 900px); margin: 0 auto 2rem; display: flex; justify-content: center; }
.feed-hint { width: min(100%, 900px); margin: 0 auto .5rem; text-align: center; color: color-mix(in srgb, var(--ink) 65%, transparent); }

/* ---- empty states ---- */
.empty-state { max-width: 380px; margin: 11vh auto 0; padding: 1rem; text-align: center; }
.empty-art { color: color-mix(in srgb, var(--ink) 38%, transparent); margin-bottom: .5rem; line-height: 0; }
.empty-art svg { width: 92px; height: 92px; }
.empty-state h3 { margin: 0 0 .35rem; font-weight: 600; color: var(--ink); }
.empty-state p { margin: 0 auto; max-width: 32ch; }
.empty-state-grid { grid-column: 1 / -1; margin-top: 6vh; }
.feed-files {
  padding: .7rem 1rem; border-bottom: 1px solid var(--border);
  background: var(--bg); max-height: 40%; overflow: auto;
}

/* ---- auth ---- */
.auth-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(1100px 700px at 75% -10%, #2c3344, #161922 70%);
}
.auth-card {
  background: #20242e;
  color: var(--chrome-ink);
  border: 1px solid var(--chrome-border);
  padding: 2.2rem;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: min(92vw, 380px);
  text-align: center;
}
.auth-card h1 { margin: 0 0 .25rem; letter-spacing: .01em; }
.auth-card .muted { color: var(--chrome-muted); }
.provider-buttons {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  margin-top: 1.2rem;
}
.google-btn, .provider-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  text-decoration: none;
  font-weight: 600;
  padding: .55rem .9rem;
}
.google-btn {
  background: #fff;
  color: #3c4043;
  border: 1px solid #fff;
}

/* ---- card grid (day files) ---- */
.card-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: .8rem;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color .12s ease, transform .12s ease;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card .thumb { height: 104px; background-size: cover; background-position: center; border-bottom: 1px solid var(--border); }
.card .label { padding: .45rem .6rem; display: flex; align-items: center; gap: .4rem; font-size: .88rem; }
.card .label .name { flex: 1; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .del { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0 .2rem; }
.card .del:hover { color: var(--danger); filter: none; }
.badge { font-size: .7rem; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 0 .35rem; }
.card .file-thumb.file-icon { display: flex; align-items: center; justify-content: center; font-size: 2.4rem; }
.memory-card .card-tags { display: flex; flex-wrap: wrap; gap: .25rem; padding: 0 .6rem .55rem; }

/* ---- family memory ---- */
.chip {
  display: inline-flex; align-items: center; gap: .25rem;
  font-size: .72rem; line-height: 1.6;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--border); border-radius: 999px; padding: 0 .55rem;
}
.shared-chip { background: none; color: var(--muted); font-style: italic; }
.tagbar { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0 1rem; }
.filter-chip { cursor: pointer; background: var(--panel); }
.filter-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.memory-detail { max-width: 760px; }
.memory-title-input {
  width: 100%; font-size: 1.2rem; font-weight: 600;
  border: 1px solid transparent; background: none; border-radius: 8px; padding: .3rem .4rem;
}
.memory-title-input:hover:not(:disabled) { border-color: var(--border); }
.memory-title-input:focus { background: var(--panel); border-color: var(--accent); outline: none; }
.memory-media { margin: .6rem 0; }
.memory-media img, .memory-media video {
  max-width: 100%; max-height: 60vh; border-radius: var(--radius); box-shadow: var(--shadow); display: block;
}
.memory-media audio { width: 100%; }
.memory-section { margin: 1.4rem 0; }
.memory-section .section-h { display: flex; align-items: center; gap: .6rem; margin: 0 0 .5rem; }
.tag-editor { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .5rem; }
.tag-chip { background: var(--panel); }
.chip-x {
  background: none; border: none; cursor: pointer; color: var(--muted);
  font-size: 1rem; line-height: 1; padding: 0; margin-left: .1rem;
}
.chip-x:hover { color: var(--danger); filter: none; }
.inline-add { display: flex; gap: .4rem; flex-wrap: wrap; }
.inline-add input[type="email"], .inline-add input { flex: 1; min-width: 12ch; }
#memory-transcript { width: 100%; resize: vertical; font: inherit; }
.share-list { list-style: none; margin: 0 0 .6rem; padding: 0; }
.share-row { display: flex; align-items: center; gap: .5rem; padding: .25rem 0; }
.share-row .share-email { flex: 1; }

/* "Share with everyone" toggle */
.share-all-row { display: flex; align-items: center; gap: .5rem; margin: 0 0 .8rem; }
.share-all-row span { flex: 1; }
.share-all-row input[type="checkbox"] { width: auto; flex: none; }
.section-sub { margin: .2rem 0 .4rem; color: var(--muted); font-size: .8rem; font-weight: 600; }

/* user-search autocomplete for sharing */
.share-search { position: relative; flex: 1; min-width: 12ch; }
.share-search input { width: 100%; }
.share-suggestions {
  position: absolute; left: 0; right: 0; top: calc(100% + 2px); z-index: 20;
  list-style: none; margin: 0; padding: .2rem; max-height: 14rem; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}
.share-suggestion {
  display: flex; flex-direction: column; gap: .05rem;
  padding: .35rem .5rem; border-radius: 6px; cursor: pointer;
}
.share-suggestion:hover { background: var(--bg); }
.share-suggestion .su-name { font-size: .9rem; }

/* spinning sync button */
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin .8s linear infinite; }

/* ---- network status badge ---- */
.net-status {
  position: fixed;
  bottom: 10px;
  right: 10px;
  z-index: 50;
  font-size: .72rem;
  padding: .25rem .55rem;
  border-radius: 999px;
  background: var(--chrome);
  border: 1px solid var(--chrome-border);
  box-shadow: var(--shadow);
  color: var(--chrome-muted);
  pointer-events: none;
}
.net-status:empty { display: none; }
.net-status.offline { color: #ffc078; }
.net-status.syncing { color: #91a7ff; }
.net-status.pending { color: #ffc078; }
.net-status.synced { color: #8ce99a; }

/* ---- settings ---- */
.settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 1rem;
  align-content: start;
  max-width: 1200px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  margin: 0;
}
.panel h3 { margin: 0 0 .5rem; font-size: 1rem; }
.panel label { display: block; margin: .55rem 0 .2rem; font-size: .88rem; color: var(--muted); }
.panel label input { display: block; width: 100%; margin-top: .2rem; }
.panel .row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
.panel .check { display: flex; align-items: center; gap: .5rem; color: var(--ink); margin: .5rem 0; }
.panel .check input { width: auto; margin: 0; }
.targets { border: 1px solid var(--border); border-radius: 8px; margin: .8rem 0 0; padding: .3rem .8rem .7rem; }
.targets legend { font-size: .85rem; color: var(--muted); padding: 0 .3rem; }

/* ---- journal calendar ---- */
.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  max-width: 1100px;
  margin: 0 auto;
}
.cal-head {
  text-align: center;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: .3rem 0;
}
.cal-day {
  aspect-ratio: 1 / 1;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink); /* override the base white button text */
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  padding: .35rem;
  position: relative;
  overflow: hidden;
  font-weight: 500;
}
.cal-day:hover { border-color: var(--accent); filter: none; box-shadow: var(--shadow); }
.cal-day .num { position: relative; z-index: 1; font-size: .88rem; line-height: 1.4; }
.cal-day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.cal-day.today .num { color: var(--accent); font-weight: 700; }
/* photo preview fills the cell; the date gets a chip so it stays readable */
.cal-thumb { position: absolute; inset: 0; background-size: cover; background-position: center; }
.cal-day.has-photo .num {
  background: rgba(16, 18, 24, .55);
  color: #fff;
  padding: 0 .38rem;
  border-radius: 6px;
}
.cal-day.has-photo.today .num { color: #fff; background: var(--accent); }
.cal-day .dot {
  position: relative; z-index: 1;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); margin-top: auto; margin-bottom: 2px; margin-left: 2px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .75);
}

/* ---- calendar looks ----
   A per-journal visual style for the month grid, chosen from the picker in the
   calendar topbar (see CAL_LOOKS in app.js). Each look is a `data-look` value on
   #calendar and restyles cells/today/dot/headers on top of the active theme. */

/* Cards: soft elevated tiles with a gentle accent wash on active days. */
.calendar[data-look="cards"] { gap: 10px; }
.calendar[data-look="cards"] .cal-day {
  border: none; box-shadow: var(--shadow);
  background: linear-gradient(160deg, var(--panel), color-mix(in srgb, var(--panel) 88%, var(--accent)));
}
.calendar[data-look="cards"] .cal-day.today {
  box-shadow: 0 0 0 2px var(--accent), var(--shadow);
}

/* Minimal: flat, borderless, lots of breathing room; today is a filled chip. */
.calendar[data-look="minimal"] { gap: 2px; }
.calendar[data-look="minimal"] .cal-day {
  border: none; background: transparent; border-radius: 0;
  align-items: center; justify-content: center; padding: 0;
}
.calendar[data-look="minimal"] .cal-day:hover { background: var(--hover); box-shadow: none; }
.calendar[data-look="minimal"] .cal-day .num { font-size: .95rem; font-weight: 600; }
.calendar[data-look="minimal"] .cal-day.today { background: none; }
.calendar[data-look="minimal"] .cal-day.today .num {
  background: var(--accent); color: #fff; border-radius: 50%;
  width: 1.9em; height: 1.9em; display: flex; align-items: center; justify-content: center;
}
.calendar[data-look="minimal"] .cal-day .dot {
  position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%); margin: 0;
}

/* Bubbly: rounded pill cells, pastel fills, chunky colorful day dots. */
.calendar[data-look="bubbly"] { gap: 8px; }
.calendar[data-look="bubbly"] .cal-day {
  border: 2px solid transparent; border-radius: 18px;
  background: color-mix(in srgb, var(--panel) 80%, var(--accent));
}
.calendar[data-look="bubbly"] .cal-day .num { font-weight: 700; }
.calendar[data-look="bubbly"] .cal-day.today {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--panel) 55%, var(--accent));
}
.calendar[data-look="bubbly"] .cal-day .dot {
  width: 9px; height: 9px;
  background: var(--movelock);
  box-shadow: 0 0 0 2px var(--panel);
}

/* Paper planner: ruled grid with dashed separators, like a printed agenda. */
.calendar[data-look="paper"] { gap: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.calendar[data-look="paper"] .cal-head {
  border-bottom: 1px solid var(--border); padding-bottom: .45rem;
}
.calendar[data-look="paper"] .cal-day {
  border: none; border-right: 1px dashed var(--border); border-bottom: 1px dashed var(--border);
  border-radius: 0; background: transparent;
}
.calendar[data-look="paper"] .cal-day:hover { background: var(--hover); box-shadow: none; }
.calendar[data-look="paper"] .cal-day .num {
  font-family: Georgia, "Times New Roman", serif; font-size: .95rem;
}
.calendar[data-look="paper"] .cal-day.today { box-shadow: inset 0 0 0 2px var(--accent); }

/* Neon: dark glassy cells with a glowing accent ring on today + active dots. */
.calendar[data-look="neon"] .cal-day {
  background: rgba(10, 14, 26, .82); border: 1px solid rgba(120, 140, 255, .25);
  color: #e8ecff;
}
.calendar[data-look="neon"] .cal-day:hover { border-color: var(--accent); box-shadow: 0 0 10px var(--accent); }
.calendar[data-look="neon"] .cal-day .num { color: #e8ecff; }
.calendar[data-look="neon"] .cal-day.today {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset, 0 0 14px color-mix(in srgb, var(--accent) 70%, transparent);
}
.calendar[data-look="neon"] .cal-day.today .num { color: #fff; }
.calendar[data-look="neon"] .cal-day .dot {
  background: #4be0c0; box-shadow: 0 0 8px #4be0c0;
}

/* The look picker in the calendar topbar. */
.cal-look-select {
  background: var(--chrome-raised); color: var(--chrome-ink);
  border: 1px solid var(--chrome-border); border-radius: 8px;
  padding: .25rem .4rem; font-size: .85rem; cursor: pointer;
}

.section-h { margin: .1rem 0 .6rem; color: var(--muted); font-weight: 600; font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; }
.file-thumb {
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; background: #f4f5f8;
}
.file-thumb.file-icon { color: var(--muted); }

/* ---- lightbox (attachment preview) ---- */
/* ---- modal dialogs (create / type-to-confirm delete) ---- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 110; /* above lightbox (100) and drawer (50) */
  background: rgba(10, 12, 17, .55);
  display: flex; align-items: center; justify-content: center; padding: 1.2rem;
}
.modal {
  width: min(420px, 100%); background: var(--panel); color: var(--ink);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  padding: 1.1rem 1.2rem 1rem;
}
.modal-title { margin: 0 0 .6rem; font-size: 1.05rem; }
.modal-msg { margin: 0 0 .8rem; color: var(--muted); font-size: .9rem; line-height: 1.45; }
.modal-label { display: block; margin: 0 0 .25rem; font-size: .82rem; color: var(--muted); }
.modal-label strong { color: var(--ink); }
.modal-input { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.1rem; }
.modal-confirm.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 12, 17, .85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .8rem;
  padding: 1.5rem;
}
.lightbox-body { display: flex; align-items: center; justify-content: center; min-height: 60px; max-width: 100%; }
.lightbox-body img, .lightbox-body video {
  max-width: 92vw;
  max-height: 78vh;
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
}
.lightbox-body audio { width: min(92vw, 480px); }
.lightbox-body .lightbox-error { color: #ff8787; }
.lightbox-meta { display: flex; align-items: center; gap: 1rem; color: #cfd3db; font-size: .9rem; max-width: 92vw; }
.lightbox-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox-download { color: #8da2ff; text-decoration: none; font-weight: 500; white-space: nowrap; }
.lightbox-download:hover { text-decoration: underline; }
.lightbox-close {
  position: absolute;
  top: .8rem;
  right: .8rem;
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .2);
  color: #fff;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}
.lightbox-close:hover { background: rgba(255, 255, 255, .22); filter: none; }

/* ---- editor toolbar ---- */
.editor-bar { flex-wrap: wrap; }
.tools {
  display: flex; align-items: center; gap: .25rem;
  background: var(--chrome-raised);
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
  padding: .18rem .3rem;
}
.tool { background: transparent; color: var(--chrome-ink); border: 1px solid transparent; padding: .25rem .5rem; border-radius: 7px; }
.tool:hover { background: rgba(255, 255, 255, .07); filter: none; }
.tool.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tool:disabled { opacity: .35; cursor: default; }
.tool:disabled:hover { background: transparent; }
#undo-stroke { font-size: 1.2rem; line-height: 1; }
.tools input[type="color"] {
  width: 30px; height: 30px; padding: 2px;
  background: transparent; border-color: var(--chrome-border); border-radius: 7px;
}
/* Pen thickness: a row of tap-to-select dots (thinnest → thickest). */
.size-picker { display: flex; align-items: center; gap: .15rem; }
.size-dot {
  background: transparent; border: 1px solid transparent; cursor: pointer;
  width: 30px; height: 30px; padding: 0; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
}
.size-dot:hover { background: rgba(255, 255, 255, .07); filter: none; }
.size-dot.active { background: var(--accent); border-color: var(--accent); }
.size-dot span { display: block; border-radius: 50%; background: var(--chrome-ink); }
.size-dot.active span { background: #fff; }
.tools .check { display: flex; align-items: center; gap: .3rem; color: var(--chrome-ink); padding: 0 .3rem; }

.canvas-wrap {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 1rem;
  position: relative;
  background: var(--desk);
}
#canvas {
  background: #fff;
  box-shadow: var(--shadow);
  touch-action: none; /* let us handle stylus/touch via pointer events */
  border-radius: 3px;
  max-width: 100%;
  height: auto;
}
.text-input {
  position: fixed;
  z-index: 60;
  border: 1px solid rgba(66, 99, 235, .5); /* thin guide at the box edges */
  background: transparent;                 /* so ruled paper shows through */
  padding: 0;
  margin: 0;
  resize: none;
  overflow: hidden;
  min-width: 140px;
  font-family: system-ui, -apple-system, sans-serif;
  white-space: pre-wrap;
  word-wrap: break-word;
  outline: none;
}
