/* Palette: plum #1F0322 · olive #484538 · amber #F4AC32 · mist #F3F4F6 · sage #D4EAC8 */
:root {
  --plum: #1f0322;
  --olive: #484538;
  --amber: #f4ac32;
  --mist: #f3f4f6;
  --sage: #d4eac8;

  --bg: var(--mist);
  --surface: #ffffff;
  --text: #333333;
  --heading: var(--plum);
  --muted: #6b6756;            /* olive tint, ≥4.5:1 on white and mist */
  --border: #e2e0d7;           /* olive tint */
  --link: #6b2470;             /* plum tint */
  --accent: var(--amber);
  --accent-hover: #e2961a;     /* amber shade */
  --on-accent: var(--plum);
  --accent-soft: var(--sage);
  --on-accent-soft: #2f4a22;   /* sage shade */
  --mark: #fbdc9f;             /* amber tint */
  --bar-bg: var(--plum);
  --bar-text: var(--mist);
  --bar-muted: #c9bfcb;
  --code-bg: #f6f5f1;
  --danger: #b3261e;

  --badge-project-bg: var(--sage);  --badge-project: #2f4a22;
  --badge-lesson-bg: #efe4f0;       --badge-lesson: #5a1d5f;
  --badge-reading-bg: #fdebc9;      --badge-reading: #7a4c00;
  --badge-bg: #e9e7df;              --badge: var(--olive);

  --radius: 8px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #150217;             /* plum shade */
    --surface: #230a28;
    --text: #e9e7e1;
    --heading: #f8f3ea;
    --muted: #b3ae9c;
    --border: #3d2442;
    --link: var(--amber);
    --accent-hover: #f7bd57;
    --accent-soft: #2b3a24;    /* sage shade */
    --on-accent-soft: var(--sage);
    --mark: #6a4a0c;
    --bar-bg: #0d000e;
    --code-bg: #1b051f;
    --danger: #f2a199;

    --badge-project-bg: #2b3a24;  --badge-project: var(--sage);
    --badge-lesson-bg: #3a1840;   --badge-lesson: #e3c4e6;
    --badge-reading-bg: #3d2a08;  --badge-reading: #f7c56c;
    --badge-bg: #322f26;          --badge: #d8d4c4;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 16px/1.6 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
h1 { font-size: 1.85rem; font-weight: 600; line-height: 1.2; letter-spacing: -.01em; color: var(--heading); margin: 0 0 .75rem; }
h2 { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 1.25rem 0 .5rem; }
h3 { font-weight: 600; color: var(--heading); }
code, pre { font-family: var(--mono); font-size: .88em; }
mark { background: var(--mark); color: inherit; padding: 0 .1em; border-radius: 2px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
button, input, select, textarea { font: inherit; }

/* ---------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.25rem;
  padding: .65rem 1.25rem; background: var(--bar-bg); color: var(--bar-text);
  border-bottom: 3px solid var(--accent);
}
.brand { font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; color: var(--bar-text); white-space: nowrap; }
.brand:hover { color: var(--accent); text-decoration: none; }
.topsearch { flex: 1; max-width: 520px; }
.topsearch input {
  width: 100%; padding: .42rem .8rem; border: 1px solid rgb(255 255 255 / .14); border-radius: var(--radius);
  background: rgb(255 255 255 / .08); color: var(--bar-text);
}
.topsearch input::placeholder { color: var(--bar-muted); font-weight: 300; }
.topsearch input:focus { background: rgb(255 255 255 / .14); outline: 2px solid var(--accent); outline-offset: 0; }
.topnav { display: flex; align-items: center; gap: 1.1rem; margin-left: auto; font-weight: 500; font-size: .95rem; }
.topnav > a:not(.button) { color: var(--bar-text); }
.topnav > a:not(.button):hover { color: var(--accent); text-decoration: none; }
.topnav form { margin: 0; }
.bigsearch input {
  width: 100%; padding: .45rem .8rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.linkish { background: none; border: 0; padding: 0; color: var(--link); cursor: pointer; font-weight: inherit; }
.linkish:hover { text-decoration: underline; text-underline-offset: 2px; }

.page { max-width: 1180px; margin: 0 auto; padding: 1.75rem 1.25rem 4rem; }
.flash { background: var(--accent-soft); color: var(--on-accent-soft); font-weight: 500; padding: .6rem .9rem; border-radius: var(--radius); }

/* ---------- layout */
.with-sidebar { display: grid; grid-template-columns: 230px 1fr; gap: 2rem; }
.filters h2:first-child { margin-top: 0; }
.facet { list-style: none; margin: 0; padding: 0; }
.facet a { display: flex; justify-content: space-between; padding: .22rem .55rem; border-radius: 6px; color: var(--text); }
.facet a:hover { background: var(--surface); text-decoration: none; }
.facet a.on { background: var(--accent-soft); color: var(--on-accent-soft); font-weight: 600; }
.facet span, .tag span { color: var(--muted); font-size: .8em; font-weight: 300; }
.facet a.on span { color: inherit; }

/* ---------- cards */
.cards { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1.1rem; transition: border-color .15s; }
.card:hover { border-color: #cfccc0; }
@media (prefers-color-scheme: dark) { .card:hover { border-color: #5a3a60; } }
.card-title { font-weight: 500; font-size: 1.08rem; color: var(--heading); }
.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: .3rem; font-size: .85rem; }
.snippet { margin: .45rem 0 0; color: var(--muted); font-size: .93rem; }
.badge { padding: .08rem .55rem; border-radius: 99px; background: var(--badge-bg); color: var(--badge); font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.type-project { background: var(--badge-project-bg); color: var(--badge-project); }
.type-lesson { background: var(--badge-lesson-bg); color: var(--badge-lesson); }
.type-reading { background: var(--badge-reading-bg); color: var(--badge-reading); }
.course { font-weight: 500; }
.status { color: var(--muted); }
.status::before { content: "● "; color: var(--accent); }
.tags { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .55rem; }
.tag { font-size: .78rem; font-weight: 500; padding: .05rem .5rem; border: 1px solid var(--border); border-radius: 99px; color: var(--muted); }
.tag:hover { border-color: var(--link); color: var(--link); text-decoration: none; }
.tag.on { background: var(--accent-soft); border-color: transparent; color: var(--on-accent-soft); }
.empty { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; }

/* ---------- search */
.bigsearch { display: flex; gap: .5rem; margin-bottom: .75rem; }
.active-filters { display: flex; gap: .4rem; margin: 0 0 .5rem; }
.chip { font-size: .85rem; font-weight: 500; padding: .1rem .65rem; border-radius: 99px; background: var(--accent-soft); color: var(--on-accent-soft); }
.count { color: var(--muted); font-size: .85rem; font-weight: 300; margin: 0 0 .5rem; }

/* ---------- item page */
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .75rem; display: flex; flex-wrap: wrap; gap: .3rem; }
.item-head { margin-bottom: 1.25rem; }
.item-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 2rem; align-items: start; }
.item-main { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem 1.6rem; }
.item-side section:first-child h2 { margin-top: 0; }
.linklist, .filelist { list-style: none; margin: 0; padding: 0; }
.linklist li, .filelist li { padding: .2rem 0; }
.filelist li { display: flex; gap: .5rem; align-items: baseline; }
.filelist li > a:first-child { flex: 1; word-break: break-all; font-family: var(--mono); font-size: .85rem; }
.filelist .muted { font-size: .78rem; font-weight: 300; white-space: nowrap; }
.video { margin: 0 0 1.25rem; }
.video iframe { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: var(--radius); background: #000; }
.video figcaption { font-size: .85rem; color: var(--muted); margin-top: .3rem; }

.prose { max-width: 72ch; }
.prose > :first-child { margin-top: 0; }
.prose h2 { font-size: 1.35rem; font-weight: 600; text-transform: none; letter-spacing: -.005em; color: var(--heading); margin: 1.9rem 0 .5rem; }
.prose h3 { font-size: 1.1rem; margin: 1.5rem 0 .4rem; }
.prose h4 { font-weight: 600; margin: 1.25rem 0 .3rem; }
.prose strong { font-weight: 600; }
.prose .heading-permalink { margin-left: .35rem; color: var(--border); font-weight: 400; }
.prose h2:hover .heading-permalink, .prose h3:hover .heading-permalink { color: var(--accent); }
.prose pre { background: var(--code-bg); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 6px; padding: .8rem 1rem; overflow-x: auto; }
.prose :not(pre) > code { background: var(--code-bg); border: 1px solid var(--border); padding: .05em .3em; border-radius: 4px; }
.prose img { max-width: 100%; border-radius: 6px; }
.prose table { border-collapse: collapse; }
.prose th { font-weight: 600; background: var(--code-bg); }
.prose th, .prose td { border: 1px solid var(--border); padding: .4rem .7rem; text-align: left; }
.prose blockquote { margin: 1rem 0; padding: .1rem 1rem; border-left: 3px solid var(--sage); color: var(--muted); font-style: italic; }
.prose iframe { max-width: 100%; border: 0; }
.prose ul.contains-task-list { list-style: none; padding-left: 1.2rem; }
.prose input[type=checkbox] { accent-color: var(--plum); }

/* ---------- login */
.login { max-width: 360px; margin: 12vh auto 0; background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--accent); border-radius: 12px; padding: 1.9rem; }
.login h1 { font-size: 1.35rem; }
.login label { display: block; font-size: .9rem; font-weight: 500; margin-bottom: .3rem; }
.login input { width: 100%; padding: .5rem .7rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text); margin-bottom: .9rem; }
.login button { width: 100%; }
.error { color: var(--danger); margin: -.4rem 0 .8rem; font-size: .9rem; }

/* ---------- buttons & forms */
.button, button.primary, .todo-add button, .upload button {
  display: inline-block; padding: .38rem .9rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: .9rem; font-weight: 500; line-height: 1.4;
}
.button:hover, .todo-add button:hover, .upload button:hover { text-decoration: none; border-color: var(--olive); }
/* Primary = amber with plum text (white on amber is too low-contrast). */
.button.primary, button.primary, .bigsearch button, .login button {
  padding: .42rem 1rem; border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--accent); color: var(--on-accent); font-weight: 600; cursor: pointer;
}
.button.primary:hover, button.primary:hover, .bigsearch button:hover, .login button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button.small { padding: .2rem .7rem; font-size: .85rem; }
.danger { color: var(--danger) !important; }
.stack { display: grid; gap: .95rem; }
.narrow { max-width: 560px; }
.stack label { display: grid; gap: .3rem; font-size: .9rem; font-weight: 500; color: var(--heading); }
.stack input, .stack select, .stack textarea, .todo-add input, .todo-add select, .upload input[type=text], .token {
  font: inherit; font-weight: 400; padding: .45rem .65rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); width: 100%;
}
.hint { font-weight: 400; font-size: .8rem; color: var(--muted); }
.actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: .75rem; }
.error-box { background: #fbe7e5; color: #7d1a14; padding: .6rem .9rem; border-radius: var(--radius); border-left: 3px solid var(--danger); }
@media (prefers-color-scheme: dark) { .error-box { background: #3d1418; color: #f6c2bc; } }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.15rem; margin-bottom: 1.25rem; }
.panel > h2:first-child { margin-top: 0; }
.panel h2 a { color: inherit; }

/* ---------- top menu */
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 0 .4rem; font-size: 1.2rem; color: var(--bar-muted); }
.menu summary:hover { color: var(--accent); }
.menu summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: 2.1rem; min-width: 210px; display: grid; gap: .6rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem;
  box-shadow: 0 10px 28px rgb(31 3 34 / .18); font-weight: 400;
}
.menu-panel form { margin: 0; }
.menu-panel .linkish { text-align: left; }

/* ---------- home */
.home-main { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.5rem; align-items: start; }

/* ---------- to-dos */
.todos { list-style: none; margin: 0 0 .5rem; padding: 0; }
.todo { display: flex; align-items: flex-start; gap: .6rem; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.todo:last-child { border-bottom: 0; }
.todo form { margin: 0; }
.check {
  width: 1.1rem; height: 1.1rem; margin-top: .22rem; padding: 0; border: 1.5px solid var(--muted); border-radius: 4px;
  background: transparent; cursor: pointer; position: relative;
}
.check:hover { border-color: var(--accent); }
.todo.done .check { background: var(--accent); border-color: var(--accent); }
.todo.done .check::after { content: "✓"; color: var(--plum); font-weight: 700; font-size: .75rem; position: absolute; inset: 0; line-height: 1rem; text-align: center; }
.todo-body { flex: 1; min-width: 0; }
.todo.done .todo-text { text-decoration: line-through; color: var(--muted); font-weight: 300; }
.todo-meta { display: flex; gap: .6rem; font-size: .8rem; color: var(--muted); }
.todo-meta:empty { display: none; }
.due { font-weight: 500; }
.due.overdue { color: var(--danger); font-weight: 600; }
.todo-edit { font-size: .8rem; opacity: 0; }
.todo .linkish.danger { opacity: 0; font-size: .8rem; }
.todo:hover .todo-edit, .todo:hover .linkish.danger, .todo:focus-within .todo-edit, .todo:focus-within .linkish.danger { opacity: 1; }
.todo-add { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0 1rem; }
.todo-add input[type=text] { flex: 1 1 200px; width: auto; }
.todo-add input[type=date], .todo-add select { width: auto; flex: 0 1 auto; }
.panel .todo-add input[type=date] { flex-basis: 9.5rem; }
.todo-group h2 { margin-top: 1.6rem; }
.todo-group h2 .muted { font-weight: 300; }

/* ---------- item page extras */
.title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.filelist form { margin: 0; }
.upload { display: grid; gap: .4rem; margin-top: .6rem; font-size: .85rem; }
.item-side .todo-add { margin-bottom: 0; }

/* ---------- editor */
.editor-form textarea { width: 100%; font-family: var(--mono); font-size: .9rem; padding: .75rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.EasyMDEContainer .CodeMirror { border-radius: 0 0 var(--radius) var(--radius); font-family: var(--mono); font-size: .9rem; color: var(--text); }
.editor-toolbar { border-color: var(--border) !important; background: var(--surface); }
.editor-preview, .editor-preview-side { font-family: var(--font); }
.help { margin-top: 1.5rem; font-size: .9rem; }
.help summary { font-weight: 500; cursor: pointer; }
.help pre { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; overflow-x: auto; }
@media (prefers-color-scheme: dark) {
  .EasyMDEContainer .CodeMirror, .editor-toolbar { background: var(--surface); color: var(--text); border-color: var(--border); }
  .editor-toolbar button { color: var(--text) !important; }
  .editor-toolbar button.active, .editor-toolbar button:hover { background: var(--bg); }
  .CodeMirror-cursor { border-color: var(--text); }
  .editor-preview, .editor-preview-side { background: var(--bg); }
}

/* ---------- clips */
.clip .card-meta { gap: .35rem; }
.clip-actions { margin-left: auto; display: flex; gap: .75rem; font-size: .8rem; opacity: 0; }
.clip:hover .clip-actions, .clip:focus-within .clip-actions { opacity: 1; }
.clip-actions form { margin: 0; }
.pager { display: flex; justify-content: space-between; margin-top: 1rem; font-weight: 500; }
.bookmarklet { cursor: grab; font-weight: 600; }
.token { font-family: var(--mono); font-size: .85rem; max-width: 520px; }

.sync-log { padding-left: 1.1rem; margin: .75rem 0; }
.sync-log li { padding: .1rem 0; }

@media (max-width: 820px) {
  .with-sidebar, .item-layout, .home-main { grid-template-columns: 1fr; }
  .todo-edit, .todo .linkish.danger, .clip-actions { opacity: 1; }
  .filters { order: 2; }
  .topbar { flex-wrap: wrap; gap: .75rem 1rem; }
  .topsearch { order: 3; flex-basis: 100%; max-width: none; }
  .item-main { padding: 1rem; }
}
