:root {
  --mobile-accent: #13afe0;
  --mobile-accent-strong: #0798c5;
  --mobile-drawer: #3f4042;
  --mobile-page: #eef0f4;
  --mobile-card: #fff;
  --mobile-text: #2f3033;
  --mobile-muted: #8d9096;
}

.app-shell { grid-template-rows: auto auto minmax(0, 1fr); }
.app-shell > :is(.app-header, .mobile-header, .mobile-search-bar) { grid-row: 1; }
.app-shell > .todo-filter-bar { grid-row: 2; }
.app-shell > .workspace { grid-row: 3; }

.mobile-header, .mobile-search-bar, .mobile-advanced-panel, .mobile-drawer, .mobile-drawer-backdrop { display: none; }
.item-favorite-star { border: 0; background: transparent; padding: 2px 6px; font-size: 1.35rem; line-height: 1; color: #fff; text-shadow: 0 0 1px #697079; }
.item-favorite-star[aria-pressed="true"] { color: #ffd429; text-shadow: 0 1px 1px #7b6200; }
.item-title-cell { position: relative; }
.item-title-line { display: flex; align-items: center; min-width: 0; gap: 6px; }
.item-title-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mobile-card-preview, .mobile-item-menu, .mobile-find-close { display: none; }
.todo-filter-bar, .todo-detail-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 5px 8px; border-top: 1px solid var(--border); background: var(--surface-2); }
.todo-filter-bar label, .todo-detail-controls label { display: flex; align-items: center; gap: 6px; }
.todo-detail-controls[hidden], .todo-filter-bar[hidden] { display: none; }

@media (max-width: 720px), ((pointer: coarse) and (max-height: 500px)) {
  html, body { min-width: 0; overflow: hidden; }
  :is(.content-viewer, .content-editor, .inline-toc, .contents-panel, .table-wrap, .note-panel, .note-panel textarea, .detail-actions-footer, .mobile-category-list, .mobile-notebook-overview, .image-stage.actual, .rendered-document .code-block > pre) { scrollbar-width: auto; scrollbar-color: auto; }
  :is(.content-viewer, .content-editor, .inline-toc, .contents-panel, .table-wrap, .note-panel, .note-panel textarea, .detail-actions-footer, .mobile-category-list, .mobile-notebook-overview, .image-stage.actual, .rendered-document .code-block > pre)::-webkit-scrollbar { width: 22px; }
  :is(.content-viewer, .content-editor, .inline-toc, .contents-panel, .table-wrap, .note-panel, .note-panel textarea, .detail-actions-footer, .mobile-category-list, .mobile-notebook-overview, .image-stage.actual, .rendered-document .code-block > pre)::-webkit-scrollbar-track { background: var(--mobile-card); }
  :is(.content-viewer, .content-editor, .inline-toc, .contents-panel, .table-wrap, .note-panel, .note-panel textarea, .detail-actions-footer, .mobile-category-list, .mobile-notebook-overview, .image-stage.actual, .rendered-document .code-block > pre)::-webkit-scrollbar-thumb { min-height: 44px; border: 3px solid var(--mobile-card); border-radius: 11px; background: var(--mobile-muted); background-clip: padding-box; }
  :is(.content-viewer, .content-editor, .inline-toc, .contents-panel, .table-wrap, .note-panel, .note-panel textarea, .detail-actions-footer, .mobile-category-list, .mobile-notebook-overview, .image-stage.actual, .rendered-document .code-block > pre)::-webkit-scrollbar-thumb:active { background-color: var(--mobile-accent); }
  :is(.content-viewer, .content-editor, .inline-toc, .contents-panel, .table-wrap, .note-panel, .note-panel textarea, .detail-actions-footer, .mobile-category-list, .mobile-notebook-overview, .image-stage.actual, .rendered-document .code-block > pre)::-webkit-scrollbar-corner { background: var(--mobile-card); }
  body { background: var(--mobile-page); }
  .app-shell { grid-template-rows: auto minmax(0, 1fr); background: var(--mobile-page); padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .app-shell > .workspace { grid-row: 2; }
  .app-shell.mobile-searching { grid-template-rows: auto auto minmax(0, 1fr); }
  .app-shell.mobile-searching > .mobile-header { grid-row: 1; }
  .app-shell.mobile-searching > .mobile-search-bar { grid-row: 2; }
  .app-shell.mobile-searching > .workspace { grid-row: 3; }
  .app-header { display: none; }
  .desktop-workspace-switch, .desktop-advanced-search-button, .desktop-advanced-search-panel, .desktop-search-workspace { display: none !important; }
  .mobile-header { display: grid; grid-template-columns: 52px minmax(0, 1fr) repeat(4, 52px); align-items: center; min-height: 58px; background: #fff; border-bottom: 4px solid var(--mobile-accent); color: var(--mobile-text); z-index: 32; }
  .mobile-header strong { overflow: hidden; color: #2f3033; text-align: center; text-overflow: ellipsis; white-space: nowrap; font-size: 1.1rem; }
  .mobile-search-bar { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; min-height: 56px; background: #fff; border-bottom: 4px solid var(--mobile-accent); color: var(--mobile-text); z-index: 33; }
  .mobile-search-bar[hidden] { display: none; }
  .mobile-search-bar > button { min-height: 44px; border: 0; background: transparent; color: var(--mobile-accent); }
  #mobileAdvancedSearch { display: inline-flex; align-items: center; gap: 5px; padding-inline: 8px; }
  .mobile-search-filter-badge { min-width: 24px; padding: 2px 6px; border-radius: 999px; background: var(--mobile-accent); color: #fff; font-size: .72rem; font-weight: 800; }
  .mobile-search-filter-badge[hidden] { display: none; }
  .mobile-search-bar > label { display: grid; grid-template-columns: 30px minmax(0, 1fr); align-items: center; min-height: 42px; border-radius: 18px; background: #e2e3e6; padding: 0 10px; }
  .mobile-search-bar input { width: 100%; min-width: 0; border: 0; background: transparent; color: #222; }
  .mobile-advanced-panel { position: fixed; inset: 60px 8px auto; z-index: 45; display: grid; gap: 10px; padding: 14px; border-radius: 0 0 14px 14px; background: #fff; color: var(--mobile-text); box-shadow: 0 12px 28px rgb(0 0 0 / .22); }
  .app-shell.mobile-searching .mobile-advanced-panel { inset-block-start: 114px; }
  .mobile-advanced-panel[hidden] { display: none; }
  .mobile-advanced-panel label { display: grid; gap: 4px; }
  .mobile-search-stars { margin: 0; padding: 8px 0 0; border: 0; border-top: 1px solid #d8dbe0; }
  .mobile-search-stars legend { padding: 0; font-weight: 750; }
  .mobile-search-star-options { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; margin-top: 8px; }
  .mobile-search-star-options label { display: grid; place-items: center; gap: 3px; min-height: 48px; border: 1px solid #d8dbe0; border-radius: 8px; background: #f7f8fa; color: #31343a; }
  .mobile-search-star-options input { margin: 0; }
  .mobile-search-star-options span { color: #b28a00; font-weight: 800; }
  .mobile-icon-button, .mobile-panel-switch { display: inline-grid; place-items: center; min-width: 48px; min-height: 48px; border: 0; background: transparent; color: var(--mobile-accent); font-size: 1.75rem; padding: 0; touch-action: manipulation; }
  .mobile-icon-button svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .mobile-binoculars svg { width: 30px; fill: currentColor; stroke: none; }
  .mobile-binoculars[aria-pressed="true"], #mobileSearchButton[aria-pressed="true"] { border-radius: 8px; background: color-mix(in srgb, var(--mobile-accent) 15%, transparent); }
  .mobile-binoculars[aria-pressed="false"], #mobileSearchButton[aria-pressed="false"] { background: transparent; }
  .mobile-add-button svg { width: 31px; height: 31px; }
  .mobile-card-density-button svg { width: 30px; height: 30px; }
  .mobile-card-density-button .mobile-expand-icon { display: none; }
  .mobile-card-density-button[aria-pressed="true"] .mobile-collapse-icon { display: none; }
  .mobile-card-density-button[aria-pressed="true"] .mobile-expand-icon { display: inline; }
  .mobile-icon-button[hidden], .mobile-edit-button[hidden] { display: none; }
  .mobile-panel-switch { justify-self: center; width: 42px; height: 42px; min-width: 42px; min-height: 42px; border: 2px solid var(--mobile-accent); border-radius: 50%; font-size: 1rem; font-weight: 800; }
  .mobile-drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 50; background: rgb(255 255 255 / .08); }
  .mobile-drawer-backdrop[hidden] { display: none; }
  .mobile-drawer { display: flex; position: fixed; inset: 0 auto 0 0; z-index: 51; width: min(82vw, 360px); flex-direction: column; background: var(--mobile-drawer); color: #f5f6f8; transform: translateX(-102%); transition: transform 220ms ease; box-shadow: 8px 0 20px rgb(0 0 0 / .22); padding: max(14px, env(safe-area-inset-top)) 0 max(12px, env(safe-area-inset-bottom)); }
  .mobile-drawer.open { transform: translateX(0); }
  .mobile-drawer-profile { display: grid; grid-template-columns: 50px minmax(0, 1fr) 44px; align-items: center; gap: 10px; padding: 8px 16px 18px; }
  .mobile-drawer-profile small { display: block; color: #b7b8bb; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-profile-icon { display: grid; place-items: center; width: 46px; height: 46px; border: 2px solid #a9aaad; border-radius: 50%; font-weight: 800; }
  .mobile-drawer button { color: inherit; }
  .mobile-drawer-profile button { border: 0; background: transparent; min-width: 48px; min-height: 48px; font-size: 1.55rem; }
  .mobile-drawer-nav { display: grid; }
  .mobile-drawer-nav button, .mobile-category-list button { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: center; gap: 8px; width: 100%; min-height: 58px; border: 0; border-radius: 0; background: transparent; padding: 8px 18px; text-align: left; font-size: 1rem; }
  .mobile-drawer-nav button.active { background: var(--mobile-accent); color: #fff; }
  .mobile-drawer-icon { display: inline-grid; place-items: center; width: 30px; height: 34px; font-family: "Segoe UI Symbol", "Segoe UI", sans-serif; font-size: 1.45rem; line-height: 1; }
  .mobile-count { min-width: 28px; padding: 3px 8px; border-radius: 999px; background: #303134; text-align: center; }
  .mobile-book-icon { display: inline-grid; place-items: center; width: 30px; height: 34px; border-radius: 3px; background: #27b965; color: #fff; box-shadow: inset 5px 0 #108d4a; }
  .mobile-category-list { overflow: auto; border-top: 1px solid #5b5c5f; }
  .mobile-category-list[hidden] { display: none; }
  .mobile-drawer-footer { margin-top: auto; display: grid; border-top: 1px solid #5b5c5f; }
  .mobile-drawer-footer button { min-width: 0; min-height: 44px; padding: 6px 18px; border: 0; background: transparent; font-size: 1rem; text-align: left; justify-content: flex-start; }
  .workspace { min-height: 0; }
  .app-shell:not(.mobile-detail-open) .detail-pane { display: none; }
  .app-shell.mobile-detail-open .workspace { grid-template-rows: minmax(0, 1fr) !important; }
  .app-shell.mobile-detail-open .list-pane { display: none; }
  .app-shell.mobile-detail-open .detail-pane { grid-row: 1 !important; animation: mobile-detail-in 220ms ease both; }
  .app-shell.mobile-detail-open .detail-pane.mobile-detail-closing { animation: mobile-detail-out 200ms ease both; }
  .list-pane { background: var(--mobile-page); }
  .table-wrap { padding: 10px; overflow-x: hidden; }
  .item-table, .item-table tbody { display: block; width: 100%; }
  .item-table thead { display: none; }
  .item-table tr { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); width: 100%; margin: 0 0 12px; border: 1px solid #d8dbe0; background: var(--mobile-card); color: var(--mobile-text); box-shadow: 0 1px 2px rgb(0 0 0 / .04); }
  .item-table tr.selected { outline: 2px solid var(--mobile-accent); outline-offset: -2px; }
  .item-table td { display: none; border: 0; padding: 0; }
  .item-table td.item-title-cell { display: block; height: auto; min-height: 178px; padding: 52px 18px 20px; overflow: visible; white-space: normal; }
  .item-title-cell::before { content: attr(data-meta); position: absolute; inset: 0 0 auto; min-height: 43px; padding: 12px 160px 8px 18px; border-bottom: 0; color: var(--mobile-accent-strong); font-size: .86rem; }
  .item-title-line { align-items: flex-start; }
  .item-title-text { white-space: normal; font-weight: 750; font-size: 1.05rem; }
  .item-table td.item-star-cell, .item-table td.item-heart-cell { display: block; position: absolute; top: 2px; z-index: 2; width: 48px; height: 48px; }
  .item-table td.item-star-cell { right: 98px; }
  .item-table td.item-heart-cell { right: 50px; }
  .item-star-rating, .item-heart-count { width: 48px; height: 48px; }
  .item-star-rating .rating-shape { font-size: 39px; transform: translateY(-4px); }
  .item-heart-count .heart-shape { width: 35px; height: 35px; }
  .item-star-rating .rating-number { font-size: 12px; transform: translateY(-1px); }
  .item-heart-count .heart-number { font-size: 11px; font-variant-numeric: tabular-nums; letter-spacing: 0; transform: translateY(0); }
  .item-heart-count[data-digits="2"] .heart-number { font-size: 9.5px; letter-spacing: -.25px; }
  .item-heart-count[data-digits="3"] .heart-number { font-size: 8px; letter-spacing: -.55px; }
  .detail-actions .item-favorite-star, .detail-actions-footer .item-favorite-star { position: static; }
  .mobile-item-menu { display: grid; place-items: center; position: absolute; right: 2px; top: 2px; z-index: 1; border: 0; background: transparent; color: #c4c6ca; min-width: 48px; min-height: 48px; padding: 0; font-size: 1.5rem; letter-spacing: 1px; }
  .mobile-item-menu[aria-expanded="true"] { background: color-mix(in srgb, var(--mobile-accent) 12%, transparent); color: var(--mobile-accent-strong); }
  .mobile-card-preview { display: -webkit-box; margin-top: 10px; overflow: hidden; color: var(--mobile-muted); line-height: 1.4; white-space: normal; overflow-wrap: anywhere; -webkit-line-clamp: 6; -webkit-box-orient: vertical; }
  .app-shell.mobile-cards-collapsed .item-table tr { margin-bottom: 6px; }
  .app-shell.mobile-cards-collapsed .item-table td.item-title-cell { min-height: 88px; padding-block: 52px 10px; }
  .app-shell.mobile-cards-collapsed .item-title-text { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .app-shell.mobile-cards-collapsed .mobile-card-preview { display: none; }
  .app-shell.mobile-search-waiting .item-table, .app-shell.mobile-search-waiting .list-pager { display: none; }
  .app-shell.mobile-search-waiting #emptyList { display: block !important; }
  .mobile-card-preview mark, .item-title-text mark { border-radius: 2px; background: #ffe66a; color: #242424; padding: 0 .08em; }
  .item-title-cell > .mobile-context-menu { position: static !important; display: grid; left: auto !important; right: auto; top: auto !important; bottom: auto; width: calc(100% + 36px); margin: 18px -18px -20px; padding: 0; border: 0; border-top: 1px solid var(--border); border-radius: 0; overflow: hidden; box-shadow: none; }
  .mobile-context-menu button { width: 100%; min-height: 48px; padding: 10px 18px; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: color-mix(in srgb, var(--surface) 92%, var(--mobile-accent) 8%); }
  .mobile-context-menu button:last-child { border-bottom: 0; }
  .horizontal { display: none; }
  .workspace { grid-template-rows: minmax(0, 1fr); }
  .detail-pane { position: relative; min-height: 0; }
  .detail-content { position: absolute; inset: 0; height: auto; display: flex; flex-direction: column; }
  .detail-content > .todo-detail-controls { flex: 0 0 auto; }
  .detail-content > .smart-view { flex: 1 1 0; min-height: 0; grid-row: auto; }
  .detail-toolbar { display: none !important; }
  .smart-view.mode-split { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; overflow: hidden; }
  .smart-view.mode-split > .smart-panel { grid-column: 1; min-height: 0; }
  .smart-view.mode-split > #textPanel, .smart-view.mode-split > #imagePanel { grid-row: 1 !important; }
  .smart-view.mode-split > .vertical { display: none; }
  .smart-view.mobile-panel-a > #imagePanel, .smart-view.mobile-panel-b > #textPanel { display: none !important; }
  .smart-view.mobile-panel-a > #textPanel, .smart-view.mobile-panel-b > #imagePanel { display: grid !important; }
  .smart-view > .detail-actions-footer { grid-column: 1 !important; grid-row: 2 !important; max-height: 112px; overflow: auto; }
  .panel-heading { min-height: 44px; }
  :is(#tocButton, #panelBTocButton, .panel-type-toggle.mobile-content-switch) { width: 44px; min-width: 44px; height: 32px; min-height: 32px; padding: 0; }
  .panel-type-toggle.mobile-content-switch { display: inline-grid; place-items: center; }
  .panel-type-toggle.mobile-content-switch[hidden] { display: none; }
  .panel-type-toggle.mobile-content-switch-empty:disabled { opacity: 1; cursor: default; }
  .panel-type-toggle.mobile-content-switch svg { width: 27px; height: 27px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .panel-find-bar { position: sticky; top: 0; z-index: 5; }
  .mobile-find-close { display: inline-grid; place-items: center; min-width: 40px; min-height: 40px; border: 0; background: transparent; color: var(--mobile-accent); font-size: 1.8rem; }
  .todo-filter-bar { position: fixed; inset: auto 8px max(8px, env(safe-area-inset-bottom)); z-index: 40; border: 1px solid #d8dbe0; border-radius: 14px; background: #fff; color: var(--mobile-text); box-shadow: 0 12px 30px rgb(0 0 0 / .22); }
  .todo-filter-bar label { width: 100%; justify-content: space-between; }
  .todo-filter-bar select { min-width: 150px; }
  .todo-detail-controls { display: grid; grid-template-columns: 1fr; padding: 10px; background: var(--mobile-card); color: var(--mobile-text); }
  .todo-detail-controls[hidden] { display: none; }
  .todo-detail-controls input, .todo-detail-controls select { min-height: 44px; font-size: 16px; }
  .dialog { width: min(100vw, 100%); max-width: 100vw; max-height: 100dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .community-dialog { height: min(92dvh, 900px); }
  .edit-toolbar { max-height: 96px; display: grid; grid-template-rows: repeat(2, 44px); grid-auto-flow: column; grid-auto-columns: 44px; overflow-x: auto; overflow-y: hidden; overscroll-behavior-inline: contain; }
  .edit-toolbar[hidden] { display: none; }
  .edit-toolbar button, .edit-toolbar select { min-width: 44px; min-height: 44px; }
  input, select, textarea { font-size: 16px; }
  .panel-document, .image-drop-zone { touch-action: pan-y; }
  .item-metadata { padding: 6px 12px; border-bottom-color: #d7d9de; background: var(--mobile-card); color: var(--mobile-muted); font-size: .75rem; }
  .panel-compare-options { width: calc(100vw - 16px) !important; max-width: calc(100vw - 16px); left: 8px !important; right: 8px; overflow-x: hidden; }
  .item-subject { color: var(--mobile-text); font-size: 1.05rem; }
  .panel-picker-search input { width: 100%; min-width: 0; }
  .panel-picker-results { overflow-x: hidden; scrollbar-width: none; }
  .panel-picker-results::-webkit-scrollbar { display: none; }
  .panel-compare-option { align-items: flex-start; min-height: 52px; white-space: normal; }
  .panel-picker-title { min-width: 0; overflow-wrap: anywhere; line-height: 1.35; }
  .panel-picker-subject { display: block; white-space: normal; overflow-wrap: anywhere; }
  .mobile-notebook-overview { display: grid; align-content: start; gap: 1px; min-height: 100%; overflow-y: auto; background: var(--mobile-page); padding: 10px; }
  .mobile-notebook-overview[hidden] { display: none; }
  .app-shell.mobile-notebooks-open .list-pane > .table-wrap { display: none; }
  .mobile-notebook-card { display: grid; grid-template-columns: 54px minmax(0, 1fr); grid-template-rows: auto auto; align-items: center; gap: 2px 12px; width: 100%; min-height: 82px; border: 0; border-bottom: 1px solid #d7d9de; border-radius: 0; background: var(--mobile-card); color: var(--mobile-text); padding: 12px 14px; text-align: left; }
  .mobile-notebook-card .mobile-book-icon { grid-row: 1 / 3; width: 42px; height: 48px; font-size: 1.35rem; }
  .mobile-notebook-name { align-self: end; overflow-wrap: anywhere; font-size: 1.08rem; font-weight: 750; }
  .mobile-notebook-count { align-self: start; color: var(--mobile-muted); }
}

@keyframes mobile-detail-in { from { transform: translateX(100%); opacity: .7; } to { transform: translateX(0); opacity: 1; } }
@keyframes mobile-detail-out { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: .7; } }

@media (prefers-reduced-motion: reduce) {
  .mobile-drawer { transition: none; }
  .app-shell.mobile-detail-open .detail-pane, .app-shell.mobile-detail-open .detail-pane.mobile-detail-closing { animation: none; }
}

html[data-mobile-palette="desktop"] { --mobile-accent: var(--accent); --mobile-accent-strong: var(--accent); --mobile-drawer: var(--surface-2); --mobile-page: var(--surface); --mobile-card: var(--surface-2); --mobile-text: var(--text); --mobile-muted: var(--muted); }
html[data-theme="dark"] { --mobile-page: #17191c; --mobile-card: #22252a; --mobile-text: #f6f7f9; --mobile-muted: #a8abb2; }

