/* Canonical page and capsule geometry. Load after page styles on every app route. */
:root {
  --ui-frame-top: 16px;
  --ui-frame-left: 64px;
  --ui-frame-right: 18px;
  --ui-frame-bottom: 16px;
  --ui-frame-radius: 18px;
  --ui-inset-x: 24px;
  --ui-inset-y: 18px;
  --ui-row-gap: 16px;
  --ui-header-content-gap: var(--ui-row-gap);
  --ui-capsule-height: 42px;
  --ui-control-height: 34px;
  --ui-capsule-padding: 3px;
  --ui-control-gap: 3px;
  /* Native form dialog geometry, based on the existing inventory dialogs. */
  --ui-dialog-width: 460px;
  --ui-dialog-padding: 30px;
  --ui-dialog-radius: 24px;
  --ui-dialog-gap: 20px;
  --ui-dialog-field-height: 44px;
  --ui-dialog-field-radius: 999px;
  --ui-dialog-textarea-radius: 16px;
  --ui-dialog-close-size: 32px;
  --ui-dialog-small-padding: 26px 22px;
  --ui-dialog-small-radius: 20px;
  --ui-label-size: 12px;
  --ui-icon-size: 16px;
  --ui-frame-surface: #fafafa;
  --ui-page-surface: #f5f5f7;
  --ui-frame-line: rgba(0, 0, 0, .08);
  --capsule-tray: rgba(0, 0, 0, .04);
  --play-pill-height: var(--ui-capsule-height);
  --play-pill-button-height: var(--ui-control-height);
  --play-pill-padding: var(--ui-capsule-padding);
  --play-pill-gap: var(--ui-control-gap);
  --play-pill-button-padding: 14px;
  --play-content-gap: var(--ui-row-gap);
}
:root[data-theme="dark"] {
  --ui-frame-surface: #121214;
  --ui-page-surface: #000;
  --ui-frame-line: rgba(255, 255, 255, .1);
  --capsule-tray: rgba(255, 255, 255, .06);
}
html:has(.app-shell), :root body:has(.app-shell) {
  height: 100%;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  background: var(--ui-page-surface);
}
:root body .app-shell, :root[data-theme] body main.app-shell {
  box-sizing: border-box;
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: calc(100% - var(--ui-frame-left) - var(--ui-frame-right));
  max-width: none;
  height: calc(100dvh - var(--ui-frame-top) - var(--ui-frame-bottom));
  min-height: 0;
  max-height: none;
  margin: var(--ui-frame-top) var(--ui-frame-right) var(--ui-frame-bottom) var(--ui-frame-left);
  padding: var(--ui-inset-y) var(--ui-inset-x);
  border: 1px solid var(--ui-frame-line);
  border-radius: var(--ui-frame-radius);
  background: var(--ui-frame-surface);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: 0 8px 32px #0000000a;
  overflow: auto;
  scrollbar-gutter: stable;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
}
:root body .app-shell > * { flex-shrink: 0; }
:root body .app-shell:has(.chat-header.play-header) { padding-top: var(--ui-inset-y); }
:root body .app-shell > .message-container { flex: 1 1 0; min-height: 0; }
/* Lists use the page scrollport. An auto-height inner overflow:auto would
   capture sticky positioning without ever scrolling, hiding the second row. */
:root body .app-shell :is(.task-section, .inventory-section, .checkin-section) {
  flex: 0 0 auto;
  overflow: visible;
}
:root body .health-container {
  width: 100%;
  max-width: none;
  align-self: stretch;
  gap: var(--ui-header-content-gap);
}
:root body .sections-layout > *, :root body .section-panel { min-width: 0; }
/* Every first row begins at the same point inside the frame. */
:root body :is(.app-shell > .app-header, .app-shell > .chat-header,
  .health-container > .health-header, .app-shell > .study-header,
  .app-shell > .presence-header, .app-shell > .guides-header,
  .app-shell > .notice-header, .app-shell > .github-header) {
  position: sticky;
  top: 0;
  z-index: 40;
  width: 100%;
  height: auto;
  min-height: var(--ui-capsule-height);
  margin: 0 0 var(--ui-header-content-gap);
  padding: 0;
  border: 0;
  background: var(--ui-frame-surface);
  box-shadow: 0 calc(-1 * var(--ui-inset-y)) 0 var(--ui-frame-surface), 0 var(--ui-header-content-gap) 0 var(--ui-frame-surface);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  align-items: center;
  gap: var(--ui-row-gap);
}
:root body .learning-shell,
:root body .app-shell:has(#sopMenu),
:root body .app-shell:has(#videoContentMenu),
:root:has(.health-container):not([data-asset-tab]),
:root[data-asset-tab="health"] {
  --ui-header-content-gap: 8px;
  --ui-content-top-padding: 0px;
}
:root body .health-container > .health-header { margin-bottom: 0; }
/* Secondary controls follow the header in the outer scrollport, or pin at zero
   inside a content panel that already starts below the header. */
:root body .ui-pinned-switches {
  position: sticky;
  top: var(--ui-switches-top, 0px);
  z-index: 30;
  flex-shrink: 0;
  background-color: var(--ui-frame-surface);
  /* An opaque full-row backdrop keeps cards from showing beside a short pill.
     Stop paint at the bottom of this row; the following gap belongs to cards
     and must remain available for hover borders and shadows. */
  box-shadow: 0 0 0 100vmax var(--ui-frame-surface);
  clip-path: inset(calc(-1 * var(--ui-row-gap)) -100vmax 0 0);
}
:root body .ui-pinned-switches:is(.filter-bar, .routine-tag-bar,
  .podcast-filter-capsules, .storage-pills-bar) {
  background-color: var(--ui-frame-surface) !important;
  background-image: linear-gradient(var(--capsule-tray), var(--capsule-tray)) !important;
}
:root body .chat-header { align-items: stretch; }
:root body .header-main-row { min-height: var(--ui-capsule-height); align-items: center; gap: 12px; }
:root body :is(.header-left, .header-right, .header-actions) { align-items: center; gap: 8px; min-width: 0; }
:root body .header-left { flex-shrink: 1; }
:root body .health-header { display: flex; flex-wrap: nowrap; justify-content: space-between; }
:root body .health-header .header-right { margin-left: auto; }
:root body .assets-top-toolbar { margin: 0; min-width: 0; }
:root body .ai-mode-toolbar { padding: 0; }

/* Navigation and filter trays share one geometry at every level. */
:root body :is(.segmented-control, .filter-bar, .filter-capsules-group,
  .routine-tag-bar, .inventory-type-tabs, .inventory-category-tabs, .meal-tabs-row, .anniversary-filter-capsules,
  .podcast-filter-capsules,
  .github-filters, .capsules) {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  flex: 0 1 auto;
  flex-wrap: nowrap;
  align-self: flex-start;
  width: fit-content;
  min-width: 0 !important;
  max-width: 100%;
  height: var(--ui-capsule-height) !important;
  min-height: var(--ui-capsule-height) !important;
  padding: var(--ui-capsule-padding) !important;
  gap: var(--ui-control-gap) !important;
  margin-inline: 0 !important;
  border: 1px solid var(--line) !important;
  border-radius: 999px;
  background: var(--capsule-tray, var(--backdrop)) !important;
  overflow-x: auto;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
:root body :is(.seg-btn, .filter-button, .filter-capsule-btn, .routine-tag-btn,
  .inventory-tag-btn, .inventory-type-tab, .inventory-category-tab, .meal-tab-btn, .anni-pill,
  .github-filter, .capsules > button) {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto !important;
  width: auto !important;
  min-width: max-content !important;
  height: var(--ui-control-height) !important;
  min-height: var(--ui-control-height) !important;
  padding: 0 14px !important;
  gap: 6px;
  border: 0;
  border-radius: 999px;
  font-family: inherit;
  font-size: var(--ui-label-size) !important;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  background: transparent;
  color: var(--muted);
}
:root body :is(.seg-btn, .filter-button, .filter-capsule-btn, .routine-tag-btn,
  .inventory-tag-btn, .inventory-type-tab, .inventory-category-tab, .meal-tab-btn, .anni-pill,
  .github-filter, .capsules > button).active {
  font-weight: 600;
}
:root body :is(.segmented-control, .filter-bar, .filter-capsules-group,
  .routine-tag-bar, .inventory-type-tabs, .inventory-category-tabs, .meal-tabs-row, .anniversary-filter-capsules,
  .podcast-filter-capsules,
  .github-filters, .capsules) svg {
  width: var(--ui-icon-size);
  height: var(--ui-icon-size);
  flex-shrink: 0;
}
:root body .routine-category-icon-slot { width: var(--ui-icon-size); height: var(--ui-icon-size); flex-basis: var(--ui-icon-size); }
/* The action capsule has the same outer height as the category capsule. */
:root[data-theme] body .header-control-capsule {
  box-sizing: border-box;
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  height: var(--ui-capsule-height);
  min-height: var(--ui-capsule-height);
  padding: var(--ui-capsule-padding) 5px;
  gap: var(--ui-control-gap);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--capsule-tray, var(--backdrop));
}
:root body .header-control-capsule :is(.compact-search-toggle, .header-action-icon,
  .capsule-icon-btn, .btn-icon, .date-btn, .icon-button, .global-theme-toggle,
  .header-action-add, .header-add-action) {
  box-sizing: border-box;
  width: var(--ui-control-height) !important;
  height: var(--ui-control-height) !important;
  min-width: var(--ui-control-height) !important;
  min-height: var(--ui-control-height) !important;
  max-width: var(--ui-control-height) !important;
  flex: 0 0 var(--ui-control-height) !important;
  display: inline-grid;
  place-items: center;
  padding: 0 !important;
  margin: 0;
  border: 0 !important;
  border-radius: 50% !important;
}
:root body .header-control-capsule svg { width: var(--ui-icon-size) !important; height: var(--ui-icon-size) !important; }
:root body .header-control-capsule :is(.chat-action-capsule, .chat-sub-toolbar,
  .todo-top-toolbar, .todo-top-actions, .inventory-top-actions) {
  height: var(--ui-control-height);
  min-height: 0;
  padding-block: 0;
  gap: var(--ui-control-gap);
  margin-block: 0;
}
:root body .header-control-capsule [hidden] { display: none !important; }
:root body .header-control-capsule .device-icon-slot { width: 100%; height: 100%; }
:root body .compact-search-panel, :root body #playSearchPanel {
  box-sizing: border-box;
  height: var(--ui-capsule-height);
}
:root body .compact-search-panel .search-box, :root body .compact-search-panel .search-box input { height: var(--ui-control-height); }
:root body :is(.routine-time-capsule, .anni-choice-capsule) {
  min-height: var(--ui-capsule-height);
  padding: var(--ui-capsule-padding) !important;
  gap: var(--ui-control-gap);
}
:root body :is(.routine-time-option, .anni-choice-option) {
  height: var(--ui-control-height) !important;
  min-height: var(--ui-control-height) !important;
  font-size: var(--ui-label-size) !important;
}

/* Equal vertical rhythm between navigation levels and their content. */
:root body .app-shell > :is(.filter-bar, .github-filters, .capsules), :root body :is(.task-section > .filter-bar, .inventory-section > .inventory-tag-bar,
  .routine-section > .routine-tag-bar) {
  margin-block: 0 var(--ui-row-gap);
}
:root body :is(.task-section, .inventory-section, .checkin-section, .routine-section) { padding-top: 0; margin-top: 0; }
:root body .video-library-header-row { width: 100%; margin: var(--ui-row-gap) 0 0; }
:root body .play-container { width: 100%; max-width: none; margin: 0; padding: 0 0 80px; gap: var(--ui-row-gap); }
:root body :is(.podcast-filter-capsules) { margin-top: 0; }
:root body .ui-page-context { margin: 0 0 var(--ui-row-gap); }
:root body .ui-page-context h1 { margin: 7px 0 0; font-size: 23px; font-weight: 600; }
:root body .ui-page-context h1 span { margin-left: 14px; color: var(--muted); font-size: 16px; font-weight: 400; }
:root body .github-tools .github-search { height: var(--ui-control-height); border: 0; background: transparent; }
:root body .github-header > .github-tools { width: auto; flex: 0 0 auto; }
:root body .github-header .github-filters { margin: 0; }
:root body .header-left > .filter-bar { margin-block: 0; }
:root body .notice-header > .capsules { margin: 0; }
:root body :is(.segmented-control, .filter-bar, .filter-capsules-group, .routine-tag-bar,
  .inventory-type-tabs, .inventory-category-tabs, .meal-tabs-row, .anniversary-filter-capsules,
  .podcast-filter-capsules, .github-filters, .capsules)[hidden] { display: none !important; }
:root body :is(.study-header, .presence-header, .github-header) > .segmented-control { margin: 0; }
:root body .study-header > .study-tabs { margin: 0; }
:root body :is(.presence-header, .study-header, .github-header) { display: flex; justify-content: space-between; }
:root body .header-control-capsule .date-controller { height: var(--ui-control-height); margin: 0; border: 0; padding-block: 0; background: transparent; }

@media (max-width: 640px) {
  :root body .sections-layout { grid-template-columns: minmax(0, 1fr); }
  :root {
    --ui-frame-top: 8px;
    --ui-frame-left: 8px;
    --ui-frame-right: 8px;
    --ui-frame-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    --ui-inset-x: 12px;
    --ui-inset-y: 12px;
    --ui-row-gap: 12px;
  }
  :root body .app-shell, :root[data-theme] body main.app-shell {
    padding-bottom: var(--ui-inset-y);
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  :root body :is(.app-header, .header-main-row, .health-header, .study-header, .github-header) { gap: 8px; }
  :root body :is(.app-header > .header-left, .header-main-row > .header-left, .assets-top-toolbar) { min-width: 0; flex: 1 1 0; overflow: hidden; }
  :root body .header-left > .segmented-control { min-width: 0; max-width: 100%; }
  :root body .assets-subtabs { width: 100%; }
  :root body :is(.seg-btn, .filter-button, .filter-capsule-btn, .routine-tag-btn,
    .inventory-tag-btn, .inventory-type-tab, .inventory-category-tab, .meal-tab-btn, .anni-pill,
    .github-filter, .capsules > button) { padding-inline: 11px !important; }
  :root body .header-actions > [role="status"] { display: none; }
  :root body .header-left > .count-badge { display: none; }
}

/* Filter wrappers do not add another tray or another layer of spacing. */
:root body .inventory-tag-bar { display: block; width: 100%; height: auto; padding: 0; border: 0; border-radius: 0; background: transparent; }
:root body .inventory-filter-row { padding: 0; }
:root body :is(.task-section, .inventory-section, .checkin-section, .routine-section) { gap: var(--ui-row-gap); }
:root body :is(.task-section > .filter-bar, .inventory-section > .inventory-tag-bar, .routine-section > .routine-tag-bar) { margin-block: 0; }
:root body .chat-header.play-header { gap: 0; }
:root body #mediaGrid { gap: var(--ui-row-gap); }
:root body #digitalCategories { order: -1; }
:root body #storageSection { gap: var(--ui-row-gap); }
:root body #storageRoomPills { order: -3; margin-block: 0; }
:root body #storageCategoryPills { order: -2; margin-block: 0; }
:root[data-theme] body :is(.segmented-control, .filter-bar, .filter-capsules-group,
  .routine-tag-bar, .inventory-type-tabs, .inventory-category-tabs, .meal-tabs-row,
  .anniversary-filter-capsules, .podcast-filter-capsules,
  .github-filters,
  .capsules) > :is(.active, [aria-selected="true"], [aria-pressed="true"]) {
  background: var(--capsule-selected) !important;
  color: var(--ink) !important;
  box-shadow: var(--capsule-shadow);
  font-weight: 600;
}

@media (max-width: 640px) {
  :root body .study-header > .study-tabs { min-width: 0; flex: 1 1 0; }
  :root body .study-header > .header-actions { flex: 0 0 auto; }
  :root body .github-header { flex-wrap: nowrap; }
  :root body .health-header { container-type: inline-size; }
  :root body .health-header:has(#dateController:not([hidden]):not([style*="display: none"])) {
    align-items: flex-start;
    padding-bottom: calc(var(--ui-capsule-height) + var(--ui-row-gap));
  }
  :root body .health-header .header-control-capsule .date-controller {
    position: absolute;
    top: calc(100% + var(--ui-row-gap) + 1px);
    right: -1px;
    width: 100cqw;
    height: var(--ui-capsule-height);
    box-sizing: border-box;
    padding: var(--ui-capsule-padding) 5px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--capsule-tray);
    justify-content: center;
  }
}

/* Phones give navigation its own row instead of squeezing it behind tools. */
@media (max-width: 640px) {
  :root {
    --ui-capsule-height: 50px;
    --ui-control-height: 42px;
  }
  :root body .app-shell {
    scrollbar-gutter: auto;
    scrollbar-width: none;
  }
  :root body .app-shell::-webkit-scrollbar { display: none; }
  :root body .app-shell > * { min-width: 0; }
  :root body :is(.app-header, .header-main-row, .chat-header.play-header, .health-header, .study-header,
    .presence-header, .github-header, .notice-header) {
    flex-wrap: wrap;
    row-gap: 8px;
  }
  :root body :is(.app-header, .header-main-row, .chat-header.play-header) > .header-left, :root body .header-main-row > .segmented-control, :root body .health-header > .assets-top-toolbar, :root body .study-header > .study-tabs, :root body .presence-header > .presence-tabs, :root body .notice-header > .capsules {
    flex: 0 0 100%;
    width: 100%;
    min-width: 0;
  }
  :root body .header-left > .segmented-control { max-width: 100%; }
  :root body :is(.app-header, .header-main-row, .chat-header.play-header, .health-header) > .header-right, :root body .study-header > .header-actions, :root body .presence-header > .presence-tools, :root body .notice-header > .header-right {
    margin-left: auto;
    flex: 0 0 auto;
  }
  :root body .study-header > .header-actions {
    width: 100%;
    justify-content: flex-end;
  }
  :root[data-theme] body .header-control-capsule { padding-inline: 4px; }
  :root body .header-control-capsule .todo-top-toolbar .header-action-add {
    width: var(--ui-control-height) !important;
    height: var(--ui-control-height) !important;
    min-width: var(--ui-control-height) !important;
    min-height: var(--ui-control-height) !important;
    max-width: var(--ui-control-height) !important;
    flex-basis: var(--ui-control-height) !important;
  }
  :root body .compact-search-panel, :root body .chat-header.play-header .header-control-capsule.is-search-open > .compact-search-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: auto;
    right: -1px;
    width: calc(100vw - var(--ui-frame-left) - var(--ui-frame-right) - 2 * var(--ui-inset-x) - 2px);
    max-width: none;
    transform: none;
  }
  :root body .header-actions .study-metrics {
    margin: 0;
    height: var(--ui-capsule-height);
    gap: 0;
  }
  :root body .header-actions .study-metric {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    min-height: var(--ui-control-height);
    padding: 0 10px;
  }
  :root body .header-actions .study-metric b { font-size: 12px; }
  :root body .notice-header > .capsules:empty { display: none; }
  :root body :is(.segmented-control, .study-tabs, .filter-bar, .github-filters) {
    scroll-padding-inline: 6px;
    overscroll-behavior-x: contain;
  }
  :root body .health-header:has(#dateController:not([hidden]):not([style*="display: none"])) {
    padding-bottom: 0;
  }
  :root body .health-header .header-control-capsule .date-controller {
    position: static;
    top: auto;
    right: auto;
    width: auto;
    height: var(--ui-control-height);
    padding: 0;
    border: 0;
    flex: 1 1 auto;
    min-width: 0;
    gap: 2px;
  }
  :root body .health-header .date-label { min-width: 0; font-size: 12px; }
  :root body .health-header .date-today-btn { padding-inline: 6px; min-height: 40px; }
  :root body .health-header:has(#dateController:not([hidden]):not([style*="display: none"])) > .header-right, :root body .health-header:has(#dateController:not([hidden]):not([style*="display: none"])) .assets-header-actions {
    width: 100%;
  }
  :root body .round-add.floating-add-btn {
    right: 20px !important;
    bottom: calc(var(--ui-frame-bottom) + 12px) !important;
  }
}

/* Entertainment primary and secondary navigation share the frame inset. */
:root body .chat-header.play-header .header-main-row { max-width: none; width: 100%; margin-inline: 0; }
/* Rewards use the same neutral icon hierarchy as other header actions. */
:root body .app-header .header-control-capsule .reward-coin, :root body .app-header .header-control-capsule .reward-coin > svg { color: var(--muted); }
:root body .app-header .header-control-capsule .reward-coin:hover, :root body .app-header .header-control-capsule .reward-coin:focus-visible { color: var(--ink); }

/* Article actions share the same button boxes and spacing as their capsule peers. */
/* Category counts follow the todo convention: only the selected option shows its count. */
:root body button > .filter-option-count {
  display: none;
  font-size: 0.7rem;
  font-weight: 550;
  line-height: 1;
  opacity: 0.68;
  font-variant-numeric: tabular-nums;
}
:root body button:is(.active, [aria-pressed="true"], [aria-selected="true"]) > .filter-option-count {
  display: inline;
  margin-inline-start: 6px;
}

@media (max-width: 640px) {
  /* Let entertainment search use the space beside the collapsed section switch. */
}

/* Local experimental mobile dock: desktop geometry remains untouched. */
@media(max-width:640px){
 :root:has(body.mobile-dock-active){--ui-capsule-height:40px;--ui-control-height:34px;--ui-control-gap:1px;--ui-label-size:12px;--ui-icon-size:15px;--ui-row-gap:10px;--ui-frame-bottom:calc(68px + env(safe-area-inset-bottom,0px));}
 :root body.mobile-dock-active .left-rail{display:flex!important;position:fixed;left:10px;right:10px;bottom:calc(8px + env(safe-area-inset-bottom,0px));top:auto;width:auto;height:52px;min-height:52px;max-height:52px;box-sizing:border-box;padding:4px;gap:2px;border:1px solid var(--line);background:var(--surface-solid);border-radius:999px;z-index:1000;overflow:visible;flex-direction:row;align-items:center;justify-content:space-between;}
 :root body.mobile-dock-active .mobile-dock-slot{display:flex;align-items:center;flex:1 1 0;min-width:0;height:44px;gap:0;}
 :root body.mobile-dock-active .mobile-dock-slot>.rail-tab{flex:1 1 0;min-width:0;width:auto;height:44px;min-height:44px;gap:2px;padding:3px 1px;box-sizing:border-box;justify-content:center;transition:background .16s,color .16s;}
 :root body.mobile-dock-active .rail-tab-icon{width:20px;height:20px;}
 :root body.mobile-dock-active .rail-tab-icon svg{width:20px;height:20px;}
 :root body.mobile-dock-active .rail-tab-label{max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:10px;line-height:12px;}
 :root body.mobile-dock-active .mobile-dock-menu {
   display:flex; flex:0 0 100%; order:10; min-width:0; gap:6px; align-items:center;
   overflow-x:auto; scrollbar-width:none;
 }
 :root[data-app="life"] body.mobile-dock-active .mobile-dock-menu { display:none; }
 :root body.mobile-dock-active :is(.learning-header,.play-header .header-main-row) > .mobile-dock-menu { display:none; }
 :root body.mobile-dock-active .mobile-dock-owner{min-width:0; max-width:100%;}
 :root body.mobile-dock-active .mobile-dock-owner>.brand-icon{display:none;}
 :root body.mobile-dock-active .mobile-dock-menu .mobile-dock-now-playing:not([hidden]) {
   display:inline-flex; flex:none; align-items:center; gap:4px; border:0;
   border-radius:999px; background:var(--capsule-tray); color:var(--ink); padding:6px;
 }
 .mobile-dock-now-playing svg{width:16px;height:16px;}
 :root body.mobile-dock-active .mobile-dock-tools{display:flex!important;flex:0 0 auto!important;margin-left:auto!important;width:auto!important;max-width:100%!important;}
 :root body.mobile-dock-active :is(.health-header,.study-header,.app-header,.header-main-row){min-height:40px!important;padding-bottom:0!important;row-gap:6px!important;}
 :root body.mobile-dock-active .media-player-bar:not([hidden]){display:flex!important;}
}

@media(max-width:640px){
 :root body.mobile-dock-active .health-header .date-controller{position:static!important;width:auto!important;background:transparent!important;}
}

/* Shared AI is second after a visible creation control, otherwise first. */
:root body .header-control-capsule :is(.header-action-add,.header-add-action){order:-100;}
:root body .header-control-capsule .global-ai-toggle{order:-95;}
:root body .header-control-capsule > :is(#themeBtn, #themeToggle){order:100;}

:root body .header-control-capsule .global-ai-toggle{background:transparent!important;color:var(--ink)!important;box-shadow:none!important;}
:root body .header-control-capsule .global-ai-toggle:hover{background:transparent!important;color:var(--app-accent,var(--accent))!important;}
:root body .header-control-capsule .global-ai-toggle[aria-expanded="true"]{background:var(--capsule-selected,#303036)!important;color:var(--app-accent,var(--accent))!important;}

/* Home controls share the same right-aligned header anchor as every other page. */
:root body .home-shell>.app-header{display:flex;flex-wrap:nowrap;align-items:center;justify-content:space-between;}
:root body .home-shell>.app-header>.header-left{flex:0 1 auto;min-width:0;}
.home-page-title{margin:0;font-size:16px;font-weight:650;color:var(--ink);}
:root body .home-shell>.app-header>.header-right{display:flex;flex:0 0 auto;margin-left:auto;justify-content:flex-end;}
/* Only mobile view choices place the icon above its label. */
@media(max-width:640px){
:root body :is(.app-header,.header-main-row,.health-header,.study-header) .segmented-control>.seg-btn{flex-direction:column;gap:2px;line-height:12px;padding-block:2px;}
:root body :is(.app-header,.header-main-row,.health-header,.study-header) .segmented-control>.seg-btn>span{font-size:11px;line-height:12px;}
}

:root body .home-shell>.app-header>.header-right{align-items:center;gap:6px;}

@media(max-width:640px){
 :root body.mobile-dock-active .play-header>.header-main-row{display:flex;align-items:center;justify-content:flex-end;}
}

:root body .header-control-capsule .global-ai-toggle svg{color:inherit!important;fill:none!important;stroke:currentColor!important;}

/* Mobile filters always share the action row; overflow belongs to the filter itself. */
@media(max-width:640px){
 :root body.mobile-dock-active .mobile-inline-toolbar{display:flex!important;flex-direction:row!important;flex-wrap:nowrap!important;align-items:center!important;justify-content:space-between!important;gap:8px!important;}
 :root body.mobile-dock-active .mobile-inline-toolbar>.mobile-inline-filter{position:static!important;inset:auto!important;flex:0 1 auto!important;width:max-content!important;max-width:100%!important;min-width:0!important;margin:0!important;overflow-x:auto!important;overflow-y:hidden!important;scrollbar-width:none;overscroll-behavior-x:contain;touch-action:pan-x pan-y;}
 :root body.mobile-dock-active .mobile-inline-toolbar>.header-right{flex:0 0 auto!important;width:auto!important;margin:0 0 0 auto!important;}
}

/* X is the only category represented by its icon without a visible label. */
:root body #memoTab{justify-content:center!important;}
:root body .header-control-capsule .memo-search-toggle{order:-1;background:transparent;color:var(--muted);}
:root body .header-control-capsule .memo-search-toggle:hover{color:var(--app-accent,var(--accent));}

/* Retain journal count rules after the live filter is placed beside page actions. */
:root body .mobile-inline-filter .diary-filter-count{display:none;}
:root body .mobile-inline-filter .filter-button.active .diary-filter-count{display:inline;margin-left:6px;font-size:.9em;}



@media(max-width:640px){
 :root{--ui-control-gap:1px;}
 :root body .mobile-inline-filter::-webkit-scrollbar{display:none;}
 :root body .mobile-inline-filter .inventory-filter-row{width:max-content!important;max-width:none!important;flex-wrap:nowrap!important;}
}

/* Mobile chrome sits above, outside the content surface, using the full frame width. */
@media(max-width:640px){
 :root body .app-shell.mobile-separated-chrome, :root[data-theme] body main.app-shell.mobile-separated-chrome{margin-top:calc(var(--ui-frame-top) + var(--mobile-chrome-height,40px) + var(--ui-header-content-gap));height:calc(100dvh - var(--ui-frame-top) - var(--mobile-chrome-height,40px) - var(--ui-header-content-gap) - var(--ui-frame-bottom));padding-top:var(--ui-content-top-padding,var(--ui-inset-y));}
 :root body .mobile-separated-chrome .mobile-separated-chrome-row{position:fixed!important;top:var(--ui-frame-top)!important;left:var(--ui-frame-left)!important;right:var(--ui-frame-right)!important;width:auto!important;max-width:none!important;margin:0!important;padding:0!important;background:var(--ui-page-surface)!important;border:0!important;box-shadow:none!important;z-index:100;}
 :root body .mobile-separated-chrome>.play-header:has(>.mobile-separated-chrome-row){min-height:0;margin:0;padding:0;gap:0;}
}

@media(max-width:640px){
 :root body.mobile-dock-active .left-rail :is([data-mobile-playing],.native-player-mini) .rail-tab-label{white-space:nowrap;font-size:10px;line-height:12px}
}

@media(max-width:640px){
 :root:has(body:is(.has-media-player,.native-has-player-bar)){--ui-frame-bottom:calc(132px + env(safe-area-inset-bottom,0px));}
 :root body.mobile-dock-active :is(.video-kind-btn,.reading-content-type){font-size:var(--ui-label-size);}
}

/* Mobile content remains scrollable without a visible scrollbar or reserved strip. */
@media(max-width:640px){
 :root body :is(.app-shell,#aiTodaySection){scrollbar-width:none;scrollbar-gutter:auto;}
 :root body :is(.app-shell,#aiTodaySection)::-webkit-scrollbar{display:none;width:0;height:0;}
}

/* Subject back navigation shares the first slot of the category capsule. */
:root body .study-tabs > .study-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 var(--ui-control-height);
  width: var(--ui-control-height);
  min-width: var(--ui-control-height);
  padding: 0;
  text-decoration: none;
  color: var(--muted);
}
:root body .study-tabs > .study-back svg { flex: none; }
:root body .study-tabs > .study-back:hover { color: var(--ink); }

/* Progress groups contain two elements; do not inherit single-icon button geometry. */
:root body .header-control-capsule > .learning-progress { display:inline-flex; flex:0 0 auto; align-items:center; align-self:center; flex-wrap:nowrap; height:var(--ui-control-height); }
:root body .header-control-capsule .learning-progress > .learning-progress-item { display:inline-flex; flex-direction:row; flex:0 0 auto; align-items:center; justify-content:center; width:auto; min-width:0; height:var(--ui-control-height); min-height:0; gap:5px; padding:0; margin:0; border:0; border-radius:0; background:transparent; white-space:nowrap; }
:root body .header-control-capsule .learning-progress-item > svg { flex:0 0 var(--ui-icon-size); }
:root body .header-control-capsule .learning-progress-value { flex:0 0 32px; width:32px; height:32px; line-height:1; margin:0; }
@media(max-width:640px){:root body .header-control-capsule .learning-progress > .learning-progress-item{gap:3px}:root body .header-control-capsule .learning-progress-value{flex-basis:28px;width:28px;height:28px}}

:root body .header-control-capsule .learning-focus-countdown { font-size:12px; line-height:1; font-weight:550; font-variant-numeric:tabular-nums; color:var(--app-accent,var(--accent)); min-width:38px; }

@media(min-width:641px){.mobile-dock-slot{display:contents}.mobile-dock-menu{display:contents}}

.mobile-category-path, .mobile-course-path { display: none; }
@media (max-width:640px) {
 :is(.mobile-category-path,.mobile-course-path) { display:flex; align-items:center; min-width:0; gap:4px; color:var(--muted); font-size:12px; font-weight:400; white-space:nowrap; }
 .mobile-category-path { flex:1 1 auto; }
 .mobile-category-path [hidden] { display:none; }
 .mobile-category-path :is(button,a:not([hidden])) { display:inline-flex; align-items:center; gap:2px; min-height:44px; min-width:0; padding:0 3px; border:0; background:transparent; color:inherit; font:inherit; cursor:pointer; text-decoration:none; }
 :is(.mobile-category-path,.mobile-course-path) svg { width:12px; height:12px; flex:none; stroke-width:1.5; }
 .mobile-category-path :is([data-category-parent],[aria-current]) { overflow:hidden; text-overflow:ellipsis; }
 .mobile-course-path a { display:inline-flex; align-items:center; min-height:44px; color:inherit; text-decoration:none; }
 .mobile-course-path .mobile-course-back { justify-content:center; width:36px; }
 .mobile-category-path.mobile-course-views { flex:0 0 auto; }
 .mobile-course-views { display:none; }
 .mobile-course-views + #mobileDockMenu .study-back { display:none!important; }
 :root body.mobile-dock-active .course-shell:is([data-course="japanese"],[data-course="world"]) .mobile-dock-menu { display:none; }
}

 :root body .category-strip:not([hidden]) {
   display:flex;
   align-items:center;
   flex:none;
   min-width:0;
   margin:0 0 var(--ui-row-gap);
 }
 :root body .category-strip .category-options {
   position:static;
   display:flex;
   align-items:center;
   flex-direction:row;
   flex-wrap:wrap;
   width:max-content;
   max-width:100%;
   max-height:none;
   gap:4px;
   margin:0;
   padding:3px;
   overflow:visible;
   border:1px solid var(--line);
   border-radius:999px;
   background:var(--capsule-tray);
   box-shadow:none;
 }
 :root body .category-options :is(.video-menu-primary,.video-menu-genres) {
   display:flex;
   flex:0 1 auto;
   flex-wrap:wrap;
   gap:4px;
 }
 :root body .category-options :is(button,a) {
   position:relative;
   display:inline-flex;
   align-items:center;
   justify-content:center;
   flex:none;
   width:auto;
   min-height:32px;
   margin:0;
   padding:4px 12px;
   border:0;
   border-radius:999px;
   background:transparent;
   color:var(--muted);
   font:inherit;
   font-size:var(--ui-label-size);
   text-decoration:none;
   white-space:nowrap;
 }
 :root body .category-options :is(button,a):is([aria-checked="true"],[aria-pressed="true"],.active) {
   color:var(--ink);
   background:var(--capsule-selected);
   font-weight:600;
 }
 :root body .category-options .diary-filter-count { position:static; margin-inline-start:5px; }


@media (max-width:640px) {
 :root body .category-strip:not([hidden]) { overflow-x:auto; scrollbar-width:none; }
 :root body .category-strip .category-options { flex:none; max-width:none; flex-wrap:nowrap; }
 :root body .category-options :is(.video-menu-primary,.video-menu-genres) { flex-wrap:nowrap; }
}

@media (max-width: 640px) {
  .today-card-dots { display:flex; }
  :is(.today-card-dots,.card-page-dots) { justify-content:center; gap:1px; flex:none; }
  :is(.today-card-dots,.card-page-dots) button {
    display:grid;
    place-items:center;
    width:22px;
    height:22px;
    padding:0;
    border:0;
    background:none;
    color:var(--line);
    cursor:pointer;
  }
  :is(.today-card-dots,.card-page-dots) button::before { content:""; width:4px; height:4px; border-radius:999px; background:currentColor; }
  :is(.today-card-dots,.card-page-dots) button[aria-current="true"] { color:var(--day-accent,var(--accent)); }
  :is(.today-card-dots,.card-page-dots) button[aria-current="true"]::before { width:14px; }
}
