:root {
  color-scheme: light dark;
  font-family: Inter, system-ui, sans-serif;
  color: #202923;
  background: #f7f7f0;
  --line: #d9ded1;
  --green: #28543d;
}
* { box-sizing: border-box; }
body { margin: 0; }
.top { border-bottom: 1px solid var(--line); }
.top-inner, main { width: min(760px, calc(100% - 40px)); margin-inline: auto; }
.top-inner { display: flex; align-items: center; justify-content: space-between; min-height: 64px; }
a { color: var(--green); }
.brand { color: inherit; text-decoration: none; font-weight: 700; }
.brand span { color: var(--green); margin-right: 6px; }
.nav { text-underline-offset: 4px; }
main { padding-block: clamp(32px, 7vw, 80px); }
h1 { font-size: clamp(2.6rem, 8vw, 4.6rem); margin: 0; letter-spacing: -.06em; line-height: 1; }
.intro { color: #46554b; margin: 16px 0 26px; }
.card, #entries li { background: #fffefa; border: 1px solid var(--line); border-radius: 16px; padding: clamp(16px, 4vw, 24px); }
label { font-weight: 700; display: block; margin-bottom: 12px; }
textarea { display: block; width: 100%; min-height: 142px; resize: vertical; padding: 14px; color: inherit; background: #fafaf6; border: 1px solid #bfc9bc; border-radius: 10px; font: inherit; line-height: 1.5; }
.form-footer, .section-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.form-footer { margin-top: 14px; }
button { border: 0; border-radius: 9px; padding: 11px 16px; min-height: 44px; background: var(--green); color: var(--on-action); font: inherit; font-weight: 600; cursor: pointer; }
button:disabled { opacity: .65; cursor: wait; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
.muted, .meta { color: var(--secondary); font-size: .875rem; }
#status { color: var(--green); margin-bottom: 0; }
#status:empty { margin: 0; }
#status.error { color: var(--danger); }
#journal { margin-top: 42px; }
h2 { margin: 0; font-size: 1.65rem; letter-spacing: -.035em; }
#entries { display: grid; gap: 10px; list-style: none; padding: 0; }
#entries p { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; margin: 9px 0 0; }
.analysis { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.analysis h3 { font-size: 1rem; margin: 0; }
.analysis button { margin: 10px 8px 0 0; }
.analysis-error { color: var(--danger); }
#entries .analysis-error:empty { margin: 0; }
.analysis-editor fieldset { border: 1px solid var(--line); border-radius: 9px; margin: 0 0 12px; }
.analysis-editor input, .analysis-editor select {
  display: block; width: 100%; margin-top: 4px; padding: 8px;
  font: inherit; border: 1px solid #bfc9bc; border-radius: 7px; background: #fafaf6;
}
#memory { margin-top: 36px; }
#memory h2 { margin-bottom: 12px; }
#memory-query { width: 100%; padding: 12px; font: inherit; border: 1px solid #bfc9bc; border-radius: 8px; }
#memory .form-footer { justify-content: flex-start; }
#memory-answer, #source-text { white-space: pre-wrap; overflow-wrap: anywhere; }
#memory-status:empty, #memory-answer:empty { display: none; }
#source { margin: auto; width: min(640px, calc(100% - 32px)); max-height: 80vh; }
#source::backdrop { background: rgb(20 35 27 / .45); }
.source-icons { display: inline-block; white-space: nowrap; }
button.source-icon {
  display: inline-grid; place-items: center; width: 28px; min-height: 24px;
  padding: 0; margin-left: 4px; vertical-align: middle;
  color: var(--green); background: transparent;
}
button.source-icon:hover { background: var(--surface-hover); }
.source-icon span {
  display: block; width: 12px; height: 15px; border: 1.5px solid currentColor;
  border-radius: 2px; position: relative;
}
.source-icon span::after {
  content: ""; position: absolute; inset: 4px 2px auto;
  height: 3px; border-block: 1px solid currentColor;
}
#tasks { margin-top: 36px; }
#task-list { list-style: none; }
#task-list li { display: flex; align-items: baseline; gap: 6px; }
#task-list li + li { border-top: 1px solid var(--line); padding-top: 10px; }
#task-list label { display: flex; gap: 9px; flex: 1; font-weight: 400; }
#task-list input:checked + span { text-decoration: line-through; color: #505e54; }
.library { margin-top: 36px; }
.library ul { list-style: none; }
.library li + li { margin-top: 10px; }
#project-list { display: grid; gap: 10px; }
#project-list summary { cursor: pointer; font-weight: 700; }
#project-list ul { padding-left: 0; margin-bottom: 0; }
@media (max-width: 540px) {
  .top-inner { align-items: flex-start; flex-direction: column; gap: 8px; padding-block: 12px; }
  .top-inner nav { line-height: 1.7; }
}
.task-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.task-row > span:first-child { flex: 1 1 12em; }
.task-row > button:not(.source-icon) { min-height: 30px; padding: 4px 9px; }
.task-done > span:first-child, .task-rejected > span:first-child { text-decoration: line-through; }
#move-task { width: min(420px, calc(100% - 32px)); }
#move-task::backdrop { background: rgb(20 35 27 / .45); }
#move-form { margin-top: 12px; }
#move-group { width: 100%; padding: 8px; font: inherit; }
#move-error:empty { margin: 8px 0; }
.project-scope { display: grid; gap: 10px; }
.project-scope h3, .project-scope p { margin: 0; }
.project-scope details > button { margin-top: 12px; }
#journal-filters { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; align-items: end; }
#journal-filters label { margin: 0; flex: 1 1 145px; }
#journal-filters input, #journal-filters select {
  display: block; width: 100%; margin-top: 5px; min-height: 40px;
  font: inherit; padding: 6px; border: 1px solid var(--line); border-radius: 6px;
}
.journal-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.task-archive { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
#revision-dialog { width: min(640px, calc(100% - 32px)); max-height: 80vh; }
#revision-dialog::backdrop { background: rgb(20 35 27 / .45); }
#revision-content { margin: 14px 0; overflow-wrap: anywhere; }
#revision-content details { padding: 8px 0; border-bottom: 1px solid var(--line); }
#revision-content summary { cursor: pointer; }
button.revision-link {
  color: var(--green); background: transparent; padding-inline: 0; text-decoration: underline;
}
#journal > summary { cursor: pointer; font-size: 1.65rem; font-weight: 700; }
#edit-item { width: min(480px, calc(100% - 32px)); }
#edit-item::backdrop { background: rgb(20 35 27 / .45); }
#edit-item-form { margin-top: 12px; }
button.item-edit { min-height: 30px; padding: 3px 8px; margin-inline: 4px; }
#settings { margin-top: 36px; }
#settings > summary { cursor: pointer; font-size: 1.65rem; font-weight: 700; }
.settings-card { margin-top: 12px; }
.download-links { display: flex; flex-wrap: wrap; gap: 10px 20px; margin: 14px 0 28px; }
#usage-models dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; }
#usage-models dd { margin: 0; text-align: right; }
#idea-archive summary { cursor: pointer; }
#budget-limit { font: inherit; max-width: 12em; padding: 8px; }
#memory-answer { max-height: 32rem; overflow: auto; }
.memory-turn { padding-bottom: 12px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.memory-turn h3 { font-size: 1rem; margin: 0; }
#memory-followup-label:not([hidden]) { display: flex; gap: 8px; }

.project-scope[hidden], #project-list [hidden] { display: none; }
.material { margin-bottom: 10px; }
.material > :is(button, a, input) { margin: 4px; }
.material > p { margin-top: 0; overflow-wrap: anywhere; }
.material details p { white-space: pre-wrap; overflow-wrap: anywhere; }
.material input { max-width: 100%; padding: 8px; font: inherit; }
.material-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; width: 100%; }
button.material-tile {
  display: grid; grid-template-rows: minmax(0, 1fr) auto; align-items: center; aspect-ratio: 1;
  min-width: 0; padding: 0; overflow: hidden; color: inherit; background: var(--surface-control);
  border: 1px solid var(--line); text-align: center;
}
.material-tile > img { width: 100%; height: 100%; object-fit: cover; }
.material-tile > span { padding: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; }
#material-dialog { width: min(760px, calc(100% - 32px)); max-height: 85vh; }
#material-dialog::backdrop { background: rgb(20 35 27 / .45); }
#material-detail > img { display: block; max-width: 100%; max-height: 55vh; margin: 12px auto; object-fit: contain; }
#material-detail > :is(button, a, input, select) { margin: 5px; max-width: 100%; }
.task-row { position: relative; padding-right: 48px; }
.task-row > .task-menu { position: absolute; top: 5px; right: 8px; z-index: 2; }
.task-menu summary { list-style: none; cursor: pointer; padding: 3px 8px; font-size: 1.3rem; }
.task-menu[open] { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 4px; box-shadow: 0 4px 14px #0002; }
.task-menu button { display: block; margin: 3px; min-height: 32px; }
.task-actions { display: flex; justify-content: flex-end; gap: 8px; width: 100%; margin-right: -36px; margin-left: 36px; }
.task-actions button { min-height: 36px; padding: 4px 12px; }
.task-actions .task-action-done { background: #256044; color: white; }
.task-actions .task-action-rejected { background: #a52b37; color: white; }

.project-materials { margin-top: 24px; padding-top: 12px; border-top: 1px solid var(--line); }
.project-materials h3 { margin: 0 0 12px; }
.project-materials > p { padding: 12px; border: 1px dashed var(--line); border-radius: 8px; }
.project-card { position: relative; }
.project-card > .project-menu { position: absolute; top: 10px; right: 12px; z-index: 3; }
#materials { margin-top: 24px; padding: 12px; border: 1px dashed var(--line); border-radius: 12px; }
.material-drop { outline: 2px dashed var(--green); outline-offset: 2px; }
.entry-tabs { display: flex; gap: 6px; margin: 18px 0 12px; }
.entry-tabs button { flex: 1; background: var(--surface-control); color: var(--green); }
.entry-tabs button[aria-selected="true"] { background: var(--green); color: var(--on-action); }
#memory[role="tabpanel"] { margin-top: 0; }
button.refresh-icon {
  display: inline-grid; place-items: center; width: 40px; min-height: 40px;
  padding: 0; background: transparent; color: var(--green); border: 1px solid var(--line);
  font-size: 24px; line-height: 1;
}
button.refresh-icon:hover { background: var(--surface-control); }
.journal-filter-panel { margin-top: 12px; }
.journal-filter-panel > summary { cursor: pointer; font-weight: 600; }
#idea-archive-list { display: grid; gap: 8px; padding: 0; list-style: none; }
#notes li.task-row {
  padding: 12px 48px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9f5;
}
#notes .task-row > span:first-child { flex: 1 0 100%; overflow-wrap: anywhere; }
.task-action-deleted { background: #a82836; }
.material-heading { position: relative; padding-right: 44px; }
.material-heading > h2 { overflow-wrap: anywhere; }
.material-menu { position: absolute; top: 0; right: 0; z-index: 2; max-width: min(290px, 70vw); }
.material-menu > div { display: grid; gap: 6px; padding: 6px; }
.material-menu select { width: 100%; min-width: 0; font: inherit; }

/* App shell and home */
:root {
  color: var(--text);
  background: var(--canvas);
  --canvas: #f5f6f8;
  --surface: #fff;
  --surface-raised: #fff;
  --text: #18181b;
  --on-action: #fff;
  --line: #e5e7eb;
  --green: #26282b;
  --surface-muted: #f4f4f4;
  --secondary: #66696d;
  --surface-hover: #e9eaec;
  --surface-control: #ededee;
  --danger: #a22937;
  --positive: #256044;
  --positive-muted: #e8f4eb;
  --danger-muted: #fbeaec;
  --task-done-surface: #f3f8f4;
  --task-shadow: 0 4px 14px rgba(0,0,0,.07);
  --viewer-mat: #dfe1e5;
}
[hidden] { display: none !important; }
.app-shell {
  width: min(880px, 100%);
  min-height: calc(100dvh - 48px);
  margin: 24px auto;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
}
.top-inner, main { width: auto; }
.top-inner { flex-direction: row; align-items: center; padding: 0 20px; }
.brand { display: inline-flex; align-items: center; gap: 9px; }
.top-search { display: grid; place-items: center; width: 44px; min-height: 44px; color: var(--secondary); }
.app-shell svg { width: 22px; height: 22px; flex: none; }
main { padding: 24px 20px calc(100px + env(safe-area-inset-bottom)); }
.screen, #memory, #tasks, #journal, #settings { margin-top: 0; }
.screen > h1 { margin-bottom: 20px; font-size: clamp(1.95rem, 5.8vw, 2.65rem); line-height: 1.12; letter-spacing: -.045em; }
.bottom-nav {
  position: fixed; z-index: 5; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(878px, 100%); display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: center; padding: 5px max(5px, env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom)) max(5px, env(safe-area-inset-left));
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px 16px 0 0;
}
.bottom-nav a { display: flex; flex-direction: column; gap: 3px; align-items: center; justify-content: center; min-height: 49px; font-size: .68rem; text-align: center; text-decoration: none; color: var(--secondary); }
.bottom-nav a[aria-current="page"] { color: var(--text); font-weight: 700; }
.bottom-nav .nav-compose { border: 1px solid var(--line); width: 44px; min-height: 44px; border-radius: 50%; justify-self: center; color: var(--text); }
.bottom-nav .nav-compose[aria-current="page"] { color: var(--on-action); background: var(--green); }
.inbox-links { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.inbox-links a { padding: 11px; border-radius: 10px; background: var(--surface-muted); text-decoration: none; }
#journal, #settings { margin-top: 16px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; }
#journal > summary, #settings > summary { font-size: 1rem; }
.card, #entries li, textarea, .analysis-editor :is(input, select) { background: var(--surface); }
textarea, #memory-query, .analysis-editor :is(input, select) { border-color: var(--line); }
input, select, textarea { font-size: max(16px, 1em); max-width: 100%; }
#notes li.task-row { background: var(--surface-muted); }
#notes .task-row { scroll-margin-top: 12px; }
.task-actions button, .task-menu summary, .task-menu button { min-height: 44px; }
.task-menu summary { display: grid; place-items: center; min-width: 44px; }
dialog { max-height: min(82dvh, calc(100dvh - env(safe-area-inset-bottom) - 24px)); }
@media (max-width: 600px) {
  .app-shell { margin: 0; min-height: 100dvh; border: 0; border-radius: 0; }
  .top { padding-top: env(safe-area-inset-top); }
  .top-inner { padding-inline: max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-right)); min-height: 56px; }
  main { padding-inline: max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-right)); padding-top: 19px; }
  .bottom-nav { border-radius: 0; border-inline: 0; }
}

/* Compact actions, with full-size touch targets. */
#task-list, #notes-list, #idea-archive-list {
  display: grid;
  gap: 8px;
  list-style: none;
  padding: 0;
}
#task-list.card { border: 0; }
#task-list li.task-row, #notes-list li.task-row, #notes li.task-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: start;
  gap: 2px 4px;
  margin: 0;
  padding: 8px 8px 6px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-muted);
}
.task-row > span:first-child {
  min-width: 0;
  align-self: center;
  font-weight: 400;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.task-row > .task-menu { position: relative; inset: auto; z-index: auto; grid-column: 2; grid-row: 1; }
.task-row > .material-grid, .task-row > small, .task-row > .task-actions { grid-column: 1 / -1; }
.task-actions { margin: 0; gap: 0; }
.task-actions button { width: 44px; padding: 0; font-size: 1.15rem; }
.task-actions button, .task-actions .task-action-done, .task-actions .task-action-rejected {
  background: transparent;
  color: var(--secondary);
}
.task-actions .task-action-done { color: var(--positive); }
.task-actions .task-action-rejected, .task-actions .task-action-deleted { color: var(--danger); }
.task-menu[open] { background: transparent; border: 0; padding: 0; box-shadow: none; z-index: 4; }
.task-menu > summary { border-radius: 9px; }
.task-menu > summary::-webkit-details-marker { display: none; }
.task-menu[open] > summary, .task-menu > summary:hover, .task-actions button:hover { background: var(--surface-hover); }
.task-menu > .menu-options {
  position: absolute;
  top: calc(100% + 2px);
  right: 0;
  width: min(220px, calc(100vw - 44px));
  max-height: min(66vh, 340px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px;
  z-index: 5;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: 0 6px 24px #0002;
}
.task-menu button, .task-menu a {
  display: flex;
  align-items: center;
  margin: 0;
  padding: 8px 10px;
  min-height: 44px;
  width: 100%;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-decoration: none;
  text-align: left;
  font-size: .9rem;
  font-weight: 500;
}
.task-menu :is(button, a):hover { background: var(--surface-muted); }

#material-detail { min-width: 0; }
#material-detail .material-menu { position: static; max-width: none; }
.material-menu > summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
}
#material-title { font-size: 1.2rem; font-weight: 650; overflow-wrap: anywhere; }
.material-menu > div {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  border-radius: 12px;
  margin: 10px 0 4px;
  padding: 6px;
}
.material-menu select { margin: 0; min-height: 44px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
.material-menu p:empty { display: none; }
.material-preview { min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.material-preview > img { display: block; width: auto; max-width: 100%; max-height: 52dvh; margin: 12px auto 0; border-radius: 10px; object-fit: contain; }

.app-shell dialog.card {
  box-sizing: border-box;
  color: inherit;
  overflow: auto;
  overscroll-behavior: contain;
  max-height: 86dvh;
  padding: 18px;
}
.app-shell dialog.card h2 { font-size: 1.25rem; line-height: 1.3; overflow-wrap: anywhere; }
.app-shell dialog.card::backdrop { background: rgb(20 23 25 / .36); }
dialog input, dialog select, dialog textarea { min-height: 44px; font-size: 16px; }
dialog button { font-weight: 500; }
dialog :is(form[method="dialog"] button, button[id^="cancel-"]) { background: var(--surface-muted); color: inherit; }
#material-dialog > form { display: flex; justify-content: flex-end; }
.project-card > .project-menu { top: 5px; right: 7px; }
.project-materials > p { font-size: .9rem; color: var(--secondary); }
#notes-status:empty, #projects-status:empty { display: none; }
@media (max-width: 600px) {
  .app-shell dialog.card {
    position: fixed;
    inset: auto 0 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 14px max(15px, env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) max(15px, env(safe-area-inset-left));
    border-radius: 19px 19px 0 0;
  }
  .project-materials { margin-top: 16px; }
  textarea, #memory-query, #move-group, #journal-filters input, #journal-filters select { font-size: 16px; }
}

.icon-action {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  color: var(--text);
  background: var(--surface-control);
}
.icon-action svg, .viewer-header svg, .material-choice svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.project-add { position: absolute; top: 5px; right: 51px; background: transparent; }
.project-add:hover, .icon-action:hover { background: var(--surface-hover); }
#journal.screen { padding: 0; border: 0; margin-top: 0; }
#notes li.task-row { list-style: none; }
#notes ul { padding-left: 0; }
#notes #idea-archive-list > li { margin: 0; }
#notes #idea-archive-list > li + li { margin-top: 8px; }
#create-task textarea { min-height: 96px; }

.app-shell #material-dialog {
  padding: 0;
  overflow: visible;
  width: min(760px, calc(100% - 32px));
  max-height: none;
}
#material-detail {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  height: min(80dvh, 760px);
  border-radius: inherit;
  background: var(--surface-muted);
}
.viewer-header, .viewer-footer {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
}
.viewer-header { z-index: 1; }
.viewer-header h2 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}
.viewer-header .task-menu { position: relative; }
.viewer-header .task-menu > summary { height: 44px; border-radius: 50%; background: var(--surface-control); }
.viewer-header .menu-options :is(a, button) { gap: 8px; }
.viewer-footer button:last-child { grid-column: 3; color: var(--danger); }
.material-preview, .material-picker { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 8px 16px; }
.material-preview > img { width: 100%; max-height: 100%; margin: 0 auto; }
.material-preview:has(> img:only-child) { display: grid; place-items: center; }
.material-preview > p { margin: 8px 0; }
.viewer-feedback { margin: 5px 16px; color: var(--danger); font-size: .875rem; }
.viewer-feedback:empty { display: none; }
.material-picker h3 { margin: 16px 0 8px; font-size: .86rem; color: var(--secondary); }
.material-choice {
  display: grid;
  width: 100%;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 5px;
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  text-align: left;
  overflow-wrap: anywhere;
}
.material-choice:hover { background: var(--surface-hover); }
@media (max-width: 600px) {
  .app-shell #material-dialog { inset: 0; width: 100%; border: 0; border-radius: 0; }
  #material-detail { height: 100dvh; }
  .viewer-header { padding-top: calc(10px + env(safe-area-inset-top)); }
  .viewer-footer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}

.viewer-header { grid-row: 1; }
.material-picker, .material-preview { grid-row: 2; }
.viewer-feedback { grid-row: 3; }
.viewer-footer { grid-row: 4; }

.top-actions { display: flex; gap: 4px; }
#settings.screen { padding: 0; margin: 0; border: 0; }
#material-title:focus { outline: none; }
.material-preview:has(> img) {
  background: var(--viewer-mat);
  border-block: 1px solid var(--line);
  padding: 18px;
}
.material-preview > img {
  width: auto;
  max-width: 100%;
  outline: 1px solid #20233335;
  outline-offset: -1px;
  box-shadow: 0 4px 18px #2426362b;
}
.project-materials .section-header { margin-bottom: 8px; }
.project-materials .section-header h3 { margin: 0; }
.upload-status {
  position: fixed;
  z-index: 10;
  inset: auto 16px calc(76px + env(safe-area-inset-bottom));
  width: fit-content;
  max-width: calc(100% - 32px);
  margin-inline: auto;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 4px 18px #0002;
  overflow-wrap: anywhere;
}
.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 18px; }
.login-wrap { width: min(100%, 390px); padding: 0; }
.login-wrap h1 { font-size: 2rem; margin-bottom: 18px; }
.login-form input { width: 100%; min-height: 44px; margin-bottom: 16px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.login-form button { width: 100%; }
#login-error { color: var(--danger); }

.capture-attachments { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.capture-file-label { display: inline-flex; align-items: center; min-height: 44px; margin: 0; font-size: .9rem; cursor: pointer; }
.capture-attachments:focus-within .capture-file-label { text-decoration: underline; }
#recent-notes { display: grid; gap: 10px; margin-top: 20px; }
#recent-notes h2 { font-size: 1rem; }
.recent-original { margin-top: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.upload-status progress { display: block; width: min(260px, 62vw); margin-top: 8px; accent-color: #61646a; }
.project-card > .project-menu,
.project-card > .project-add { top: 5px; }
.project-card > .project-menu > summary { height: 44px; padding: 0; line-height: 1; }
.project-task-count { margin-left: 7px; font-size: .8rem; font-weight: 500; color: var(--secondary); }
.project-unread { display: inline-block; width: 7px; height: 7px; margin: 0 0 2px 7px; background: #717479; border-radius: 50%; }
.bottom-nav a[data-screen="inbox"] { position: relative; }
.inbox-count { position: absolute; top: 0; left: calc(50% + 6px); min-width: 16px; padding: 2px 4px; border-radius: 12px; background: var(--surface-control); color: var(--text); font-size: .63rem; line-height: 1; }
#inbox-archive ul, #archive-list { list-style: none; padding: 0; display: grid; gap: 10px; }
#inbox-archive li, #archive-list li { background: var(--surface-muted); padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.entry-tabs button[aria-pressed="true"] { background: var(--green); color: var(--on-action); }
.viewer-document { display: grid; justify-items: center; align-content: center; gap: 10px; min-height: min(300px, 48dvh); text-align: center; overflow-wrap: anywhere; }
.viewer-document > svg { width: 64px; height: 64px; color: var(--secondary); stroke-width: 1.15; }
.viewer-document audio { width: min(100%, 360px); }
#recent-notes .material-grid, #entries .material-grid { margin-top: 10px; }

.project-menu > summary svg { fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; }

#entries > li { display: grid; gap: 8px; padding: 8px; background: var(--surface-control); }
.journal-source, #entries .analysis, #recent-notes .analysis {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 0;
}
.journal-source { background: var(--surface); }
#entries .analysis, #recent-notes .analysis { background: var(--surface-muted); border-color: var(--line); }
.journal-source > header, .analysis-header, .analysis-controls { display: flex; align-items: center; gap: 4px; }
.journal-source > header, .analysis-header { justify-content: space-between; min-height: 44px; }
.journal-source h3 { margin: 0; font-size: 1rem; }
.analysis .icon-action, .journal-source .icon-action {
  width: 44px;
  min-height: 44px;
  margin: 0;
  background: transparent;
}
.analysis .icon-action:hover, .journal-source .icon-action:hover { background: var(--surface-hover); }
#edit-item.card { inset: 0; width: min(480px, calc(100% - 32px)); margin: auto; border-radius: 16px; }
#edit-item-title:focus { outline: none; }
#edit-item-project { width: 100%; padding: 9px; border: 1px solid var(--line); border-radius: 8px; }
.edit-project-label { margin-top: 12px; }
.project-actions {
  position: absolute;
  top: 5px;
  right: 7px;
  display: flex;
  align-items: center;
  gap: 0;
}
.project-actions > .project-add { position: static; }
.project-actions > .project-menu { position: relative; }
.project-actions .project-menu > summary {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
}
.file-glyph {
  position: relative;
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin: auto;
  border-radius: 13px;
  color: #586070;
  background: #e9ebef;
  overflow: visible;
}
.file-glyph svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.file-glyph small {
  position: absolute;
  bottom: 3px;
  right: 3px;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: .63rem;
  color: inherit;
  background: #ffffffdd;
}
.file-sheet { color: #187248; background: #e0f2e8; }
.file-word { color: #255ba7; background: #deebfb; }
.file-pdf { color: #ac3740; background: #f9e4e6; }
.file-audio { color: #6c4fa6; background: #eee7f9; }
.material-tile > .file-glyph { overflow: visible; }
.viewer-document { min-height: 0; padding: 12px 8px 18px; gap: 9px; }
.viewer-open { display: inline-flex; align-items: center; gap: 8px; background: var(--surface-control); color: var(--text); font-size: .92rem; }
.viewer-open svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.viewer-document-preview { margin-bottom: 12px; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.viewer-document-preview pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: .9rem/1.55 system-ui, sans-serif; }
.viewer-document-preview select { min-height: 44px; width: 100%; margin-bottom: 8px; }
.viewer-table-scroll { max-width: 100%; overflow: auto; overscroll-behavior-inline: contain; }
.viewer-table-scroll table { border-collapse: collapse; white-space: nowrap; font: .84rem/1.3 system-ui, sans-serif; }
.viewer-table-scroll td { padding: 6px 9px; border: 1px solid var(--line); }
.viewer-table-scroll tr:nth-child(even) { background: var(--surface-muted); }
.pdf-controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.pdf-page { display: block; width: 100%; height: auto; }

.project-layout { display: grid; align-items: start; gap: 9px; min-width: 0; }
.project-scope[data-scope="work"] .project-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.project-scope[data-scope="work"] .project-layout > :last-child:nth-child(odd) { grid-column: 1 / -1; }
#project-list .project-card {
  --project-radius: 17px;
  --project-header-inset: 10px;
}
.project-disclosure { display: inline-flex; flex: 0 0 auto; opacity: .7; }
.project-disclosure svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#project-list .project-heading, .project-hero .project-heading {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  list-style: none;
  padding: var(--project-header-inset) 100px var(--project-header-inset) 14px;
  min-height: 64px;
  border-radius: var(--project-radius);
}
#project-list .project-heading {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}
.project-cover-image, .project-heading::before {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.project-cover-image { z-index: -2; object-fit: cover; object-position: center; }
.project-heading::before { content: ""; z-index: -1; }
.project-heading.has-cover::before { background: linear-gradient(110deg, #0b111bd9, #12182258 76%, #0b111b6e); }
.project-visual {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
}
.project-visual svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.project-caption { min-width: 0; overflow-wrap: anywhere; }
#project-list [data-scope="personal"] .project-caption {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  line-height: 20px;
}
.project-heading .project-task-count { flex: 0 0 auto; margin: 0; }
.project-heading .project-unread { flex: 0 0 auto; margin: 0; }
.project-scope[data-scope="work"] { margin-bottom: 14px; }
#project-list [data-scope="work"] .project-heading {
  min-height: clamp(122px, 27vw, 201px);
  align-items: flex-start;
  justify-content: flex-start;
  flex-direction: column;
  padding: var(--project-header-inset) 14px 36px;
  color: #fff;
  background: #293946;
}
:is(#project-list [data-scope="work"], .project-hero) .project-heading.project-theme-blue { background: linear-gradient(140deg, #253a58, #526e87); }
:is(#project-list [data-scope="work"], .project-hero) .project-heading.project-theme-green { background: linear-gradient(145deg, #17352f, #365c52); }
:is(#project-list [data-scope="work"], .project-hero) .project-heading.project-theme-plum { background: linear-gradient(145deg, #362e4e, #725970); }
:is(#project-list [data-scope="work"], .project-hero) .project-heading.project-theme-brain {
  background: radial-gradient(ellipse at 86% 111%, #3b80727a 0 21%, #1e574e70 22% 33%, transparent 34%),
              linear-gradient(130deg, #0c2029, #123b3b);
}
#project-list [data-scope="work"] .project-card:last-child:nth-child(odd) .project-heading { min-height: clamp(112px, 25vw, 171px); }
#project-list [data-scope="work"] .project-visual {
  width: 44px;
  height: 44px;
  border-radius: 18px;
  background: #ffffff29;
}
#project-list [data-scope="work"] .project-caption {
  font-size: clamp(1rem, 4.5vw, 1.55rem);
  text-shadow: 0 1px 7px #0008;
}
#project-list [data-scope="work"] .project-task-count {
  position: absolute;
  right: 10px;
  bottom: 9px;
  min-width: 25px;
  padding: 3px 7px;
  border-radius: 20px;
  text-align: center;
  color: #fff;
  background: #1217228c;
}
#project-list [data-scope="work"] .project-unread { position: absolute; bottom: 17px; right: 43px; background: #fff; }
#project-list .project-actions { top: calc(var(--project-header-inset) + 1px); }
#project-list [data-scope="work"] .project-disclosure { position: absolute; left: 15px; bottom: 12px; }
#project-list [data-scope="work"] .project-actions { right: 9px; color: #fff; gap: 0; }
#project-list [data-scope="work"] .project-actions > .project-add { display: none; }
#project-list [data-scope="work"] .project-actions .project-menu > summary { background: #1017208c; border-radius: 50%; }
#project-list [data-scope="personal"] .has-cover { color: white; }
#project-list [data-scope="personal"] .has-cover .project-task-count { color: #fff; }
.project-card:has(.project-menu[open]) { z-index: 5; }
#move-task.card, #project-design.card {
  inset: 0;
  width: min(480px, calc(100% - 28px));
  margin: auto;
  border-radius: 16px;
}
#move-title:focus, #project-design-title:focus { outline: none; }
.move-options { display: grid; gap: 5px; max-height: 44dvh; overflow: auto; margin: 10px 0; overscroll-behavior: contain; }
.move-options h3 { margin: 8px 0 2px; font-size: .85rem; color: var(--secondary); }
.move-option { background: var(--surface-muted); color: inherit; text-align: left; }
.move-option[aria-pressed="true"] { background: var(--green); color: var(--on-action); }
#move-custom-label { margin-top: 12px; }
#project-design-form { margin-top: 12px; }
#project-name { width: 100%; padding: 8px 9px; border-radius: 8px; border: 1px solid var(--line); }
.project-icons { display: flex; flex-wrap: wrap; gap: 6px; }
.project-icons .icon-action[aria-pressed="true"] { color: var(--on-action); background: var(--green); }
.project-cover-preview { margin-top: 12px; }
.project-cover-preview img { width: 100%; height: 105px; border-radius: 10px; object-fit: cover; }
.project-cover-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.project-cover-controls label, .project-cover-controls button { margin: 0; padding: 10px; border-radius: 8px; background: var(--surface-muted); color: var(--text); cursor: pointer; font-size: .9rem; }

/* Project page */
.app-shell:has(:is(#home, #project-detail):not([hidden])) { background: var(--canvas); }
.app-shell:has(#project-detail:not([hidden])) > :is(.top, .bottom-nav) { display: none; }
.app-shell:has(#project-detail:not([hidden])) > main {
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}
.app-shell:has(#project-detail:not([hidden])) .upload-status { bottom: calc(12px + env(safe-area-inset-bottom)); }
.project-back {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding-inline: 8px 14px;
  margin-bottom: 12px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}
.project-back::before {
  content: "";
  width: 8px;
  height: 8px;
  border: solid currentColor;
  border-width: 0 0 2px 2px;
  transform: rotate(45deg);
}
.project-back:hover { background: var(--surface-hover); }
#project-status:empty { display: none; }
.project-hero {
  --project-radius: 22px;
  --project-header-inset: 16px;
}
.project-hero .project-heading {
  height: clamp(200px, 31vw, 255px);
  align-items: flex-start;
  justify-content: flex-end;
  flex-direction: column;
  gap: 8px;
  padding: 16px clamp(16px, 4vw, 32px) 21px;
  color: #fff;
  background: #293946;
}
.project-hero .project-heading.has-cover::before {
  background: linear-gradient(180deg, #0001 12%, #0009 100%);
}
.project-hero .project-visual {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: #ffffff26;
}
.project-hero .project-caption {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: clamp(1.75rem, 5.7vw, 2.65rem);
  line-height: 1.06;
  letter-spacing: -.035em;
  text-shadow: 0 1px 6px #000a;
}
.project-detail-count {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 1rem;
}
.project-detail-count svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#project-list .project-card:has(> .has-cover) .project-actions > .project-add,
#project-list .project-card:has(> .has-cover) .project-menu > summary,
.project-hero .project-menu > summary {
  background: #101720a6;
  color: #fff;
  border-radius: 14px;
}
.project-hero .project-actions { top: 12px; right: 12px; }
@media (max-width: 600px) {
  .project-hero .project-heading { height: 175px; padding-bottom: 16px; }
}
.project-tasks { margin-top: 24px; }
#project-view h2 { font-size: 1.25rem; }
.project-task-tabs { display: flex; gap: 16px; }
.project-task-tabs .project-task-tab {
  min-height: 44px;
  padding: 6px 0;
  border-radius: 0;
  background: transparent;
  color: var(--secondary);
  font-size: 1.25rem;
  font-weight: 600;
}
.project-task-tabs .project-task-tab[aria-pressed="true"] { color: var(--text); }
.project-task-tabs .project-task-tab:hover { text-decoration: underline; text-underline-offset: 4px; }
#project-task-panel > p, .project-notes > p { color: var(--secondary); }
.project-notes { margin-top: 28px; }
:is(.project-task-list, .project-note-list) {
  display: grid;
  gap: 10px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}
:is(.project-task-list, .project-note-list) .task-row {
  position: relative;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: start;
  gap: 2px 4px;
  padding: 7px 8px 7px 4px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface);
  box-shadow: var(--task-shadow);
}
.project-task-list .task-done { background: var(--task-done-surface); }
.project-task-list .task-row > span:first-child {
  grid-column: 2;
  grid-row: 1;
  align-self: start;
  padding-block: 10px;
  font-size: 1rem;
  font-weight: 400;
  color: var(--text);
  white-space: pre-wrap;
}
.project-task-list :is(.task-done, .task-rejected) > span:first-child,
.project-task-list .task-row > small { color: var(--secondary); }
.project-task-list .task-row > small { grid-column: 2; padding-bottom: 6px; }
.project-task-list .task-row > .task-menu { grid-column: 3; }
:is(.project-task-list, .project-note-list) .task-row:has(> .task-menu[open]) { z-index: 2; }
.project-task-list .task-row > .material-grid { grid-column: 2 / -1; margin-bottom: 4px; }
.project-note-list .task-row { grid-template-columns: minmax(0, 1fr) 44px; padding-left: 16px; }
.project-note-list .task-row > span:first-child {
  grid-column: 1;
  padding-block: 10px;
  white-space: pre-wrap;
}
.project-note-list .task-row > .material-grid { margin-bottom: 4px; }
.project-task-checkbox {
  display: grid;
  place-items: center;
  grid-column: 1;
  grid-row: 1;
  width: 44px;
  height: 44px;
  margin: 0;
  cursor: pointer;
}
.project-task-checkbox input {
  appearance: none;
  display: grid;
  place-items: center;
  margin: 0;
  width: 21px;
  height: 21px;
  border: 1.5px solid var(--secondary);
  border-radius: 5px;
  background: var(--surface);
  cursor: inherit;
}
.project-task-checkbox input:checked { border-color: #167343; background: #167343; }
.project-task-checkbox input:checked::before {
  content: "";
  width: 8px;
  height: 4px;
  margin-top: -2px;
  border: solid #fff;
  border-width: 0 0 2px 2px;
  transform: rotate(-45deg);
}
.project-task-checkbox input:disabled { opacity: .65; cursor: wait; }

.material-compact {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 7px;
}
.material-compact .material-tile {
  display: flex;
  align-items: center;
  min-width: 44px;
  max-width: min(100%, 300px);
  padding: 0 10px 0 0;
  aspect-ratio: auto;
  border: 0;
  border-radius: 10px;
  background: var(--surface-muted);
}
.material-compact .material-tile:hover { background: var(--surface-hover); }
.material-compact .file-glyph {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  margin: 0;
  border-radius: 10px;
}
.material-compact .file-glyph svg { width: 22px; height: 22px; }
.material-compact .material-name { padding: 0 0 0 8px; font-weight: 500; }
.material-compact .material-photo {
  width: min(100%, 132px);
  aspect-ratio: 4 / 3;
  padding: 0;
}
.material-compact .material-photo img { width: 100%; height: 100%; object-fit: cover; }
#project-view .project-materials { margin-top: 28px; padding-top: 0; border: 0; }

#project-list .project-archive > summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  gap: 8px;
  list-style: none;
  cursor: pointer;
}
#project-list .project-archive > summary::-webkit-details-marker { display: none; }
#project-list .project-archive > summary::before {
  content: "";
  width: 6px;
  height: 6px;
  margin-right: 3px;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(-45deg);
}
#project-list .project-archive[open] > summary::before { transform: rotate(45deg); }
#project-list .project-archive { margin-top: 12px; border-top: 1px solid var(--line); }
#project-list .project-archive .project-layout { gap: 14px; }
.project-archive-footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: 6px;
}
.project-archive-footer button { margin-left: auto; background: var(--surface-control); color: var(--text); }
.project-archive-footer button:hover { background: var(--surface-hover); }
.project-archive-footer time { color: var(--danger); font-size: .875rem; }
.menu-options .project-delete { color: var(--danger); }

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #151518;
    --surface: #212125;
    --surface-raised: #2a2a30;
    --surface-muted: #252529;
    --surface-control: #303035;
    --surface-hover: #3b3b42;
    --text: #f1f1f4;
    --secondary: #b7b7c0;
    --line: #38383f;
    --green: #e2e2e9;
    --on-action: #18181c;
    --danger: #ffabb3;
    --positive: #a5dbb7;
    --positive-muted: #233b31;
    --danger-muted: #412b32;
    --task-done-surface: #1e2b25;
    --task-shadow: 0 4px 14px #0004;
    --viewer-mat: #17171b;
  }
  .file-glyph { color: #bec8db; background: #303743; }
  .file-glyph small { background: var(--surface); }
  .file-sheet { color: #a5dbb7; background: #243d32; }
  .file-word { color: #a9cafa; background: #26374d; }
  .file-pdf { color: #ffabb3; background: #412b32; }
  .file-audio { color: #d1bdf6; background: #372e48; }
  .app-shell dialog.card::backdrop { background: #0009; }
}
