
    :root {
      color-scheme: light dark;
      font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
      --line: color-mix(in srgb, CanvasText 18%, transparent);
      --soft: color-mix(in srgb, CanvasText 7%, Canvas);
      --muted: color-mix(in srgb, CanvasText 65%, transparent);
      --nav-h: 68px;
    }
    * { box-sizing: border-box; }
    html.app-screen,
    html.app-screen body {
      height: 100%;
      overflow: hidden;
      overscroll-behavior-y: none;
    }
    body {
      margin: 0;
      background: Canvas;
      color: CanvasText;
    }
    .app-shell {
      width: min(900px, 100%);
      margin: 0 auto;
      height: 100dvh;
      min-height: 0;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 10px);
    }
    .app-shell main {
      flex: 1;
      min-height: 0;
      overflow-y: auto;
      overscroll-behavior-y: contain;
    }
    .app-header {
      position: sticky;
      top: 0;
      z-index: 20;
      padding: 14px 16px 12px;
      border-bottom: 1px solid var(--line);
      background: color-mix(in srgb, Canvas 92%, transparent);
      backdrop-filter: blur(14px);
    }
    .brand-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
    }
    .brand-main { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
    h1 { margin: 0; font-size: 1.35rem; letter-spacing: .03em; }
    .version { font-size: .78rem; opacity: .55; }
    .header-settings { width: 44px; height: 44px; padding: 0; font-size: 1.25rem; flex: none; }
    .page {
      display: none;
      padding: 16px 14px 8px;
    }
    .page.active-page { display: block; }
    .page-title { margin: 2px 2px 14px; }
    .page-title h2 { margin: 0 0 3px; font-size: 1.25rem; }
    .page-title p { margin: 0; font-size: .88rem; opacity: .65; }
    .organize-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
    .organize-tabs button { flex: 1; min-width: 0; font-size: 1rem; }
    .relation-kinds { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
    .relation-kinds div { border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; }
    .relation-kinds strong { display: block; }
    .relation-kinds span { font-size: .85rem; color: var(--muted); }
    .clearable-search { display: flex; gap: 8px; margin-bottom: 12px; }
    .clearable-search input { min-width: 0; flex: 1; }
    .clearable-search button { flex: none; }
    .card {
      border: 1px solid var(--line);
      border-radius: 16px;
      padding: 16px;
      margin-bottom: 14px;
      background: color-mix(in srgb, CanvasText 2%, Canvas);
    }
    h2, h3 { margin: 0 0 10px; }
    h3 { font-size: 1rem; }
    label {
      display: block;
      font-weight: 700;
      margin: 10px 0 6px;
    }
    textarea, input, select {
      width: 100%;
      border: 1px solid color-mix(in srgb, CanvasText 25%, transparent);
      border-radius: 10px;
      padding: 11px 12px;
      font: inherit;
      background: Canvas;
      color: CanvasText;
    }
    textarea.tag-input { min-height: 48px; }
    .mcp-permission { display: flex; align-items: center; gap: 10px; font-weight: 500; }
    .mcp-permission input { width: auto; margin: 0; }
    .relation-picker { display: flex; flex-wrap: wrap; gap: 7px; max-height: 260px; overflow-y: auto; padding: 4px 0; }
    .relation-picker button { max-width: 100%; overflow-wrap: anywhere; }
    .relation-picker button[aria-pressed="true"] { border: 2px solid #3188dd; background: color-mix(in srgb, #3188dd 18%, Canvas); }
    .relation-selection { display: flex; flex-wrap: wrap; gap: 7px; min-height: 38px; align-items: center; }
    .relation-selection button { max-width: 100%; overflow-wrap: anywhere; }
    .relation-preview { max-height: 260px; overflow-y: auto; padding-left: 22px; }
    .relation-preview li { padding: 5px 0; overflow-wrap: anywhere; }
    .librarian-proposals { max-height: min(60vh, 520px); padding-left: 0; list-style: none; }
    .librarian-proposals li { border-top: 1px solid var(--line); padding: 12px 0; }
    .librarian-proposals label.librarian-pick-label { display: flex; align-items: center; gap: 9px; margin: 0; }
    .librarian-proposals input[type="checkbox"] { width: auto; margin: 0; }
    .librarian-proposals .memo-preview { margin: 8px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
    .librarian-proposals textarea { min-height: 50px; }
    #bulkRelationControls { border: 0; padding: 0; margin: 0; min-width: 0; }
    #bulkRelationControls legend { font-weight: 700; margin-bottom: 10px; }
    textarea { min-height: 160px; resize: vertical; }
    .edit-content { min-height: 110px; }
    .actions, .entry-actions, .tabs {
      display: flex;
      align-items: center;
      gap: 10px;
      flex-wrap: wrap;
    }
    .actions { margin-top: 12px; }
    .actions[hidden] { display: none; }
    .entry-actions { margin-top: 10px; }
    .card-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
    .card-tools button { font-size: .8rem; padding: 5px 8px; }
    .memo-save-actions { display: flex; flex-direction: row; align-items: center; gap: 8px; }
    .memo-save-actions #save { flex: 1; }
    .memo-save-actions #lockToggle { width: 44px; min-width: 44px; height: 44px; padding: 0; font-size: 1.2rem; }
    .lock-caption { font-size: .72rem; color: var(--muted); }
    #status:empty { display: none; }
    #imageSaveDetails:empty { display: none; }
    button {
      border: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
      border-radius: 10px;
      padding: 9px 14px;
      font: inherit;
      font-weight: 700;
      cursor: pointer;
      background: var(--soft);
      color: CanvasText;
    }
    button.primary {
      background: CanvasText;
      color: Canvas;
      border-color: CanvasText;
    }
    button.active { outline: 2px solid color-mix(in srgb, CanvasText 35%, transparent); }
    button:disabled { opacity: .5; cursor: default; }
    .shelf-dialog {
      width: min(380px, calc(100% - 32px));
      max-width: none;
      padding: 22px;
      border: 1px solid var(--line);
      border-radius: 18px;
      background: Canvas;
      color: CanvasText;
      box-shadow: 0 16px 48px color-mix(in srgb, CanvasText 25%, transparent);
    }
    .shelf-dialog::backdrop { background: color-mix(in srgb, CanvasText 45%, transparent); }
    .shelf-dialog h2 { margin-bottom: 6px; }
    .shelf-dialog p { margin: 0 0 20px; color: var(--muted); }
    .shelf-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
    #status { opacity: .75; margin: 5px 0 0; }
    .entry {
      padding: 14px 0;
      border-top: 1px solid color-mix(in srgb, CanvasText 14%, transparent);
    }
    .entry:first-child { border-top: 0; }
    #searchResults { display: grid; gap: 12px; margin-top: 12px; }
    #searchResults .entry, #librarianSearchResults .entry {
      border: 1px solid var(--line);
      border-radius: 12px;
      padding: 14px;
      background: color-mix(in srgb, CanvasText 3%, Canvas);
      box-shadow: 0 2px 8px color-mix(in srgb, CanvasText 7%, transparent);
    }
    .entry-head {
      display: flex;
      gap: 8px;
      align-items: center;
      flex-wrap: wrap;
      font-size: .85rem;
      opacity: .7;
    }
    .badge {
      border: 1px solid currentColor;
      border-radius: 999px;
      padding: 1px 7px;
    }
    .card-body { white-space: normal; }
    .card-preview { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; max-height: 9.3em; overflow-wrap: anywhere; white-space: pre-wrap; user-select: text; -webkit-user-select: text; -webkit-touch-callout: default; }
    .card-body.expanded .card-preview { display: block; max-height: none; }
    .content { white-space: pre-wrap; line-height: 1.55; margin: 8px 0; }
    .tags { display: flex; flex-wrap: wrap; gap: 6px; }
    .tag {
      border-radius: 999px;
      background: color-mix(in srgb, CanvasText 10%, transparent);
      padding: 3px 8px;
      font-size: .85rem;
    }
    .image-grid { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
    .image-grid[hidden] { display: none; }
    .image-preview-toggle { margin-top: 10px; }
    .image-item { display: grid; gap: 5px; max-width: 180px; }
    .image-item img { display: block; max-width: 180px; max-height: 150px; border-radius: 8px; border: 1px solid var(--line); }
    .image-item button { font-size: .8rem; padding: 5px 8px; }
    .image-viewer {
      position: fixed;
      inset: 0;
      width: 100vw;
      max-width: 100vw;
      height: 100dvh;
      max-height: 100dvh;
      margin: 0;
      padding: calc(72px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom));
      border: 0;
      background: #111;
      color: white;
    }
    .image-viewer[open] { display: grid; place-items: center; }
    .image-viewer::backdrop { background: #111; }
    .image-viewer img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
    .image-viewer-close {
      position: absolute;
      z-index: 1;
      top: calc(12px + env(safe-area-inset-top));
      right: calc(12px + env(safe-area-inset-right));
      width: 52px;
      height: 52px;
      padding: 0;
      border: 0;
      border-radius: 50%;
      background: #fff;
      color: #111;
      font-size: 2rem;
      line-height: 1;
    }
    .image-drop-zone { border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; margin-top: 8px; }
    .image-drop-zone.drag-over { border-color: CanvasText; background: var(--soft); }
    .image-drop-zone label { margin-top: 0; }
    .pending-images { display: grid; gap: 8px; margin: 10px 0 0; padding: 0; list-style: none; }
    .pending-images:empty { display: none; }
    .pending-images li { display: flex; align-items: center; gap: 10px; min-width: 0; }
    .pending-images img { width: 48px; height: 48px; object-fit: cover; border-radius: 7px; }
    .pending-images span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
    .tag-suggestions {
      margin-top: 12px;
      display: grid;
      gap: 10px;
    }
    .tag-buttons {
      display: flex;
      flex-wrap: wrap;
      gap: 7px;
      min-height: 30px;
      align-items: center;
    }
    button.tag-chip {
      border-radius: 999px;
      padding: 6px 10px;
      font-size: .82rem;
      font-weight: 600;
      background: color-mix(in srgb, CanvasText 8%, Canvas);
    }
    button.tag-chip:hover {
      background: color-mix(in srgb, CanvasText 13%, Canvas);
    }
    .muted { opacity: .65; }
    .edit-box {
      margin-top: 10px;
      padding: 12px;
      border-radius: 10px;
      background: color-mix(in srgb, CanvasText 5%, Canvas);
    }
    .edit-box label:first-child { margin-top: 0; }
    .section-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      flex-wrap: wrap;
    }
    .search-fields .clearable-search { margin-bottom: 8px; }
    .search-controls { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
    .search-controls button { min-height: 44px; padding: 8px; white-space: nowrap; }
    .search-date-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
    .search-date-panel[hidden] { display: none; }
    .search-date-panel label { min-width: 0; margin: 0; }
    .search-date-panel label span { display: block; margin-bottom: 5px; }
    .search-date-panel input { min-width: 0; }
    .search-date-panel .date-field, .search-date-panel .date-actions { grid-column: 1 / -1; }
    .date-actions { display: flex; gap: 8px; }
    .search-sources {
      display: flex;
      gap: 8px;
      margin-bottom: 10px;
    }
    .search-source {
      flex: 1;
      height: 44px;
      min-height: 44px;
      box-sizing: border-box;
      border-radius: 999px;
      font-weight: 700;
      opacity: .58;
    }
    .search-source.active {
      opacity: 1;
      border-color: color-mix(in srgb, CanvasText 55%, transparent);
      background: color-mix(in srgb, CanvasText 12%, Canvas);
    }
    .search-meta { margin-top: 10px; }
    .librarian-search-toggle { width: 100%; height: 44px; min-height: 44px; box-sizing: border-box; margin-bottom: 12px; font-size: 1rem; border-radius: 999px; }
    #librarianSearchPrompt { min-height: 110px; resize: vertical; }
    #librarianSearchResults { display: grid; gap: 12px; margin-top: 12px; }
    .back-to-top {
      position: fixed;
      right: 18px;
      bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
      z-index: 60;
      border-radius: 999px;
      padding: 10px 14px;
      box-shadow: 0 6px 24px color-mix(in srgb, CanvasText 20%, transparent);
      display: none;
    }
    .back-to-top.visible { display: inline-flex; }
    .settings-grid { display: grid; gap: 12px; }
    .workbench-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
    .workbench-head h2 { margin: 0; }
    .workbench-head button { flex: none; }
    #workbenchEntries .entry { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-top: 12px; }
    .workbench-remove { margin-left: auto; min-width: 44px; min-height: 44px; padding: 0; font-size: 1.3rem; }
    .placeholder-card {
      border: 1px dashed color-mix(in srgb, CanvasText 25%, transparent);
      border-radius: 12px;
      padding: 14px;
    }
    .placeholder-card strong { display: block; margin-bottom: 4px; }
    .bottom-nav {
      position: fixed;
      z-index: 50;
      left: 50%;
      bottom: 0;
      transform: translateX(-50%);
      width: min(900px, 100%);
      min-height: var(--nav-h);
      padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 4px;
      border-top: 1px solid var(--line);
      background: color-mix(in srgb, Canvas 94%, transparent);
      backdrop-filter: blur(16px);
    }
    .bottom-nav button {
      border: 0;
      border-radius: 12px;
      padding: 8px 4px;
      font-size: .82rem;
      background: transparent;
      opacity: .62;
      display: grid;
      gap: 3px;
      justify-items: center;
    }
    .bottom-nav button.active {
      opacity: 1;
      outline: none;
      background: var(--soft);
    }
    .nav-icon { font-size: 1.15rem; line-height: 1; }
    @media (min-width: 700px) {
      .page { padding: 22px 24px 12px; }
      .app-header { padding-left: 24px; padding-right: 24px; }
      .settings-grid { grid-template-columns: 1fr 1fr; }
    }
    @media (max-width: 560px) {
      .actions { align-items: stretch; flex-direction: column; }
      .actions button { width: 100%; }
      .memo-save-actions { flex-direction: row; }
      .memo-save-actions #lockToggle { width: 44px; }
      .entry-actions button { flex: 1; }
      html.memo-screen, html.memo-screen body { height: 100%; overflow: hidden; }
      html.memo-screen .app-shell { height: 100dvh; min-height: 0; display: flex; flex-direction: column; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 10px); }
      html.memo-screen .app-shell main { display: flex; flex: 1; min-width: 0; min-height: 0; }
      html.memo-screen .page[data-page="memo"].active-page { display: flex; flex: 1; width: 100%; min-width: 0; min-height: 0; padding: 8px 10px 0; }
      html.memo-screen .page[data-page="memo"] .card { display: flex; flex: 1; width: 100%; min-width: 0; flex-direction: column; min-height: 0; margin: 0; padding: 10px; overflow-x: hidden; overflow-y: auto; }
      html.memo-screen .page[data-page="memo"] label { margin: 5px 0 4px; }
      html.memo-screen #content { flex: 1; min-height: 64px; resize: none; }
      html.memo-screen .page[data-page="memo"] .tag-suggestions { display: flex; flex: none; width: 100%; min-width: 0; flex-wrap: nowrap; max-height: 42px; overflow-x: auto; overflow-y: hidden; margin-top: 6px; gap: 4px; }
      html.memo-screen .page[data-page="memo"] .tag-buttons { flex: none; flex-wrap: nowrap; white-space: nowrap; }
      html.memo-screen #memoDropZone { flex: none; width: 100%; min-width: 0; margin-top: 6px; padding: 6px 8px; }
      html.memo-screen #memoImages { min-width: 0; max-width: 100%; padding: 6px 8px; }
      html.memo-screen .pending-images { max-height: 42px; overflow-y: auto; }
      html.memo-screen .page[data-page="memo"] .actions { flex: none; margin-top: 8px; gap: 4px; }
      html.memo-screen #status { max-height: 2.8em; overflow-y: auto; }
    }
    @media (max-width: 370px) {
      .search-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
      .search-controls #searchButton { grid-column: 1 / -1; }
    }
  