.brand-lockup { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-emblem { display: block; width: 44px; height: 44px; flex: 0 0 44px; object-fit: contain; }
.brand-lockup h1 { display: grid; gap: 3px; margin: 0; min-width: 0; }
.brand-name { color: var(--gray-13); font-size: var(--fs-3xl); line-height: 1.1; font-weight: 750; }
.brand-name.is-chinese { display: inline-flex; gap: 4px; font-size: var(--fs-3xl); line-height: 1.25; font-weight: 600; }
.brand-subtitle { color: var(--gold-9); font-size: var(--fs-sm); line-height: 1.35; font-weight: 500; }
.header-metadata { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-metadata #statusText, .header-metadata .online-count { margin: 0; font-size: var(--fs-2xs); line-height: 1.4; }
.header-metadata #statusText { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-metadata .online-count { color: var(--gray-11); min-inline-size: 0; flex-shrink: 0; }
.header-metadata:empty { display: none; }
.header-actions-area { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; min-width: 0; }
.header-actions-area > .game-version { text-align: right; font-size: var(--fs-3xs); line-height: 1.4; }
.mobile-header-controls, .mobile-tree-tools { display: none; }
.header-icon-button { display: inline-grid; place-items: center; padding: 0; width: 44px; height: 44px; flex: 0 0 44px; border: 0; border-radius: 4px; background: transparent; color: var(--gray-12); cursor: pointer; }
.header-icon-button:hover { background: var(--green-4-a08); color: var(--white); }
.header-icon-button:focus-visible { outline: 2px solid var(--gold-9); outline-offset: -2px; }
.header-icon-button .nav-icon { width: 20px; height: 20px; }
.header-icon-button .creator-avatar { width: 30px; height: 30px; }
.header-icon-button.has-value { color: var(--gold-14); background: var(--green-4-a08); }
.header-icon-button:disabled { opacity: .45; cursor: default; }
#selectTreeButton { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: auto; min-width: 72px; height: var(--tree-option-height); flex: 0 0 auto; padding: 0 7px; font-size: var(--fs-xs); font-weight: 500; line-height: 20px; white-space: nowrap; color: var(--gray-13); background: transparent; }
#selectTreeButton .select-tree-box { display: grid; place-items: center; width: var(--tree-check-size); height: var(--tree-check-size); flex: 0 0 var(--tree-check-size); box-sizing: border-box; border: 2px solid currentColor; border-radius: 5px; }
#selectTreeButton .nav-icon { width: calc(var(--tree-check-size) - 6px); height: calc(var(--tree-check-size) - 6px); visibility: hidden; }
#selectTreeButton.has-value .nav-icon { visibility: visible; }
#selectTreeButton.has-value { color: var(--gold-14); opacity: 1; }
#selectTreeButton.is-partial .select-tree-box::after { content: ""; width: 10px; height: 2px; background: currentColor; grid-area: 1 / 1; }
#selectTreeButton .select-tree-box .nav-icon { grid-area: 1 / 1; }
#selectTreeButton:hover:not(:disabled) { background: var(--green-4-a08); }
.tree-selection-options { --tree-check-size: 17px; --tree-option-height: 40px; display: flex; align-items: center; gap: 12px; min-width: 0; }
.tree-filters > .tree-selection-options { flex: 0 0 334px; }
.tree-selection-options .planner-option { flex: 1; min-width: 0; min-height: var(--tree-option-height); gap: 8px; }
.tree-selection-options .planner-option input { width: var(--tree-check-size); height: var(--tree-check-size); min-height: var(--tree-check-size); flex: 0 0 var(--tree-check-size); margin: 0; }
.tree-selection-options input[type="checkbox"], #selectTreeButton { box-shadow: none; }
.tree-selection-options input[type="checkbox"]:focus { outline: none; }
.tree-selection-options input[type="checkbox"]:focus-visible { outline: 2px solid var(--gold-9); outline-offset: 3px; }
.tree-selection-options .planner-option span, #selectTreeButton .select-tree-label { min-width: 0; font-size: var(--fs-xs); font-weight: 500; line-height: 20px; overflow-wrap: anywhere; }
.mobile-sheet-body .tree-selection-options { --tree-check-size: 20px; --tree-option-height: 48px; }
.mobile-header-sheet { position: fixed; inset: auto 0 0; width: 100%; max-width: 560px; max-height: calc(100dvh - 20px); margin: auto auto 0; padding: 0 0 env(safe-area-inset-bottom, 0px); border: 1px solid var(--gray-8); border-bottom: 0; border-radius: 16px 16px 0 0; background: var(--gray-3); color: var(--gray-13); box-shadow: 0 -12px 44px var(--black-a32); }
.mobile-header-sheet::backdrop { background: var(--black-a60); backdrop-filter: blur(5px); }
.mobile-sheet-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px 8px 20px; border-bottom: 1px solid var(--gray-6); }
.mobile-sheet-heading h2 { margin: 0; font-size: var(--fs-lg); line-height: 1.4; }
.mobile-sheet-body { display: grid; gap: 18px; padding: 20px; overflow-wrap: anywhere; }
.mobile-sheet-body > label { display: grid; gap: 8px; min-width: 0; font-size: var(--fs-sm); color: var(--gray-12); }
.mobile-sheet-body input[type="search"], .mobile-sheet-body select { width: 100%; min-width: 0; min-height: 46px; padding: 10px 12px; border: 1px solid var(--gray-9); border-radius: 6px; background: var(--gray-2); color: var(--gray-13); }
.mobile-sheet-body > .planner-option { display: flex; align-items: center; gap: 10px; min-height: 44px; width: auto; }
.mobile-sheet-body .planner-option input { width: 20px; height: 20px; flex: 0 0 20px; }
.mobile-sheet-body .topbar-actions { display: grid; grid-template-columns: 1fr; gap: 8px; width: 100%; padding: 0; overflow: visible; }
.mobile-sheet-body .topbar-actions button { min-height: 48px; width: 100%; text-align: left; white-space: normal; }
.mobile-sheet-body .topbar-actions button[hidden] { display: none; }
.mobile-sheet-body .creator-watermark { display: flex; align-items: center; gap: 14px; padding: 4px; color: var(--gray-13); text-decoration: none; }
.mobile-sheet-body .creator-avatar { width: 52px; height: 52px; flex-basis: 52px; }
.mobile-sheet-body .creator-copy { display: grid; gap: 8px; font-size: var(--fs-xs); }
.mobile-sheet-body .creator-profile { display: grid; gap: 3px; color: var(--gray-11); }
.mobile-sheet-body .creator-profile strong { font-size: var(--fs-xl); }
.mobile-sheet-body .creator-game-id { color: var(--gray-11); }
.mobile-search-done { order: 2; min-height: 44px; }

/* Match related controls without changing card bounds or the budget material. */
.topbar-actions button { min-height: 40px; border-radius: 4px; line-height: 20px; }
.country-trigger { min-height: 40px; border-radius: 4px; line-height: 20px; }
.wiki-heading button, .wiki-heading a,
.tree-canvas .unit-modifications-launch,
.folder-popup .unit-modifications-launch { border-radius: 4px; }
.folder-popup .unit-modifications-launch { min-width: 44px; min-height: 44px; }
.unit-modifications-launch > span { display: grid; place-items: center; width: 18px; height: 18px; font-size: var(--fs-xl); line-height: 18px; }
.topbar-actions button, .country-trigger, .header-icon-button,
.unit-wiki-launch, .unit-modifications-launch,
.wiki-heading button, .wiki-heading a { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.topbar-actions button:focus:not(:focus-visible),
.country-trigger:focus:not(:focus-visible),
.unit-modifications-launch:focus:not(:focus-visible),
.unit-wiki-launch:focus:not(:focus-visible) { outline: none; }
.topbar-actions button:focus-visible,
.unit-modifications-launch:focus-visible { outline: 2px solid var(--gold-9); outline-offset: 2px; }
.tree-selection-options .planner-option:active,
#selectTreeButton:active:not(:disabled) { background: var(--green-4-a08); }
@media (hover: hover) and (pointer: fine) {
  .topbar-actions button:hover:not(:disabled),
  .tree-canvas .unit-modifications-launch:hover,
  .folder-popup .unit-modifications-launch:hover { background: var(--gray-6); border-color: var(--gray-10); }
}
@media (prefers-reduced-motion: no-preference) {
  .topbar-actions button, .country-trigger, .header-icon-button,
  .unit-modifications-launch, .wiki-bookmark,
  .wiki-heading button, .wiki-heading a { transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease; }
}

/* Keep the filter controls together without squeezing the research tree itself. */
.tree-filters > label, #mobileFilters .mobile-sheet-body > label, #mobileMore .mobile-sheet-body > label, #mobileSearch .search-label { gap: 6px; min-width: 0; }
.tree-filters > label > span, #mobileFilters .mobile-sheet-body > label > span, #mobileMore .mobile-sheet-body > label > span, #mobileSearch .search-label > span { color: var(--gray-11); font-size: var(--fs-2xs); font-weight: 500; line-height: 16px; }
.tree-filters input[type="search"], .tree-filters select, #mobileFilters select, #mobileMore select, #mobileSearch input[type="search"] { height: 40px; min-height: 40px; border: 1px solid var(--gray-8); border-radius: 4px; background: var(--gray-2); color: var(--gray-13); font-size: var(--fs-sm); font-weight: 500; line-height: 20px; padding: 8px 12px; box-shadow: none; }
.tree-filters input[type="search"]:focus, .tree-filters select:focus, #mobileFilters select:focus, #mobileMore select:focus, #mobileSearch input[type="search"]:focus { border-color: var(--gray-11); outline: 2px solid var(--green-6-a32); outline-offset: 1px; box-shadow: none; }
.tree-filters .search-label, #mobileSearch .search-label { position: relative; }
.tree-filters .search-label::after, #mobileSearch .search-label::after { content: ""; position: absolute; width: 16px; height: 16px; left: 12px; bottom: 12px; background: var(--gray-11); -webkit-mask: url("assets/navigation/search.svg?r=283d371c2e433817") center / contain no-repeat; mask: url("assets/navigation/search.svg?r=283d371c2e433817") center / contain no-repeat; pointer-events: none; }
.tree-filters input[type="search"], #mobileSearch input[type="search"] { padding-left: 36px; }
.tree-filters > .tree-selection-options { border-left: 1px solid var(--green-1); padding-left: 16px; }
.tree-selection-options .planner-option { cursor: pointer; }
.tree-selection-options .planner-option:hover { color: var(--gray-13); }
.tree-selection-options #selectTreeButton { border-radius: 4px; --press-scale: .98; }
.tree-selection-options #selectTreeButton.has-value { background: var(--green-4-a08); }
#mobileFilters .mobile-sheet-heading, #mobileSearch .mobile-sheet-heading { position: sticky; top: 0; z-index: 1; background: var(--gray-3); }
#mobileFilters .mobile-sheet-body, #mobileSearch .mobile-sheet-body { gap: 16px; padding: 16px; }
#mobileFilters .mobile-sheet-body > label { align-content: end; }
#mobileFilters select, #mobileMore select, #mobileSearch input[type="search"] { height: 48px; min-height: 48px; padding-top: 12px; padding-bottom: 12px; }
#mobileSearch .search-label::after { bottom: 16px; }
#mobileFilters .tree-selection-options { grid-column: 1 / -1; border-top: 1px solid var(--green-1); padding-top: 12px; gap: 12px; }
#mobileFilters .tree-selection-options .planner-option { padding-right: 12px; border-right: 1px solid var(--green-1); }
#mobileSearch .mobile-search-done { min-height: 48px; border-radius: 4px; font-size: var(--fs-sm); }
@media (min-width: 480px) {
  #mobileFilters .mobile-sheet-body { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; }
}
@media (min-width: 721px) {
  .tree-filters { display: grid; grid-template-columns: minmax(200px, 1fr) 144px 220px minmax(304px, 340px); align-items: end; gap: 12px; padding: 10px 20px 12px; overflow: visible; background: var(--gray-3); }
  .tree-filters > .language-field { width: auto; }
}
@media (min-width: 721px) and (max-width: 1100px) {
  .tree-filters { grid-template-columns: minmax(200px, 1fr) 144px 220px; row-gap: 10px; }
  .tree-filters > .tree-selection-options { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--green-1); padding: 8px 0 0; }
  .tree-filters > .tree-selection-options .planner-option { flex: 0 1 auto; }
}
@media (prefers-reduced-motion: no-preference) {
  .tree-filters select, .tree-filters input[type="search"], #mobileFilters select, #mobileMore select, #mobileSearch input[type="search"], .tree-selection-options #selectTreeButton { transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease; }
}
/* Slim desktop header: brand with the status line under it, icon actions, author and More.
   Language and version live in the More sheet; planning options live in the Filters sheet.
   The query is the exact complement of the script's mobile query, so landscape phones keep the mobile header. */
@media (min-width: 901px), (min-width: 721px) and (min-height: 501px), (min-width: 721px) and (pointer: fine), (min-width: 721px) and (pointer: none) {
  .topbar { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; column-gap: 4px; padding: 6px 8px 6px 16px; }
  .topbar > .brand-block { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 0 10px; grid-column: 1; grid-row: 1; min-width: 0; }
  /* Emblem, title and status line become cells of the brand grid. */
  .brand-block > .brand-title, .brand-block .brand-lockup { display: contents; }
  .brand-emblem { grid-column: 1; grid-row: 1 / span 2; width: 32px; height: 32px; }
  .brand-lockup h1 { grid-column: 2; grid-row: 1; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .brand-block > .header-metadata { grid-column: 2; grid-row: 2; overflow: hidden; white-space: nowrap; }
  .brand-name, .brand-name.is-chinese { font-size: var(--fs-xl); line-height: 1.3; }
  .brand-name.is-chinese { gap: 2px; margin-right: 8px; }
  .brand-subtitle { font-size: var(--fs-xs); }
  .header-actions-area { grid-column: 2; grid-row: 1; flex-direction: row; align-items: center; }
  .mobile-header-controls { display: flex; grid-column: 3; grid-row: 1; align-items: center; }
  /* Icon-only: the label stays in the DOM as the accessible name and is repeated as the tooltip. */
  .header-actions-area .topbar-actions { gap: 2px; }
  .header-actions-area .topbar-actions button { width: 40px; min-width: 40px; height: 40px; padding: 0; gap: 0; overflow: hidden; font-size: 0; white-space: nowrap; }
  .header-actions-area .topbar-actions button::before { flex-basis: 18px; width: 18px; height: 18px; }

  /* The sheets open as popovers under the header's right edge. */
  #mobileMore, #mobileAuthor, #mobileFilters {
    inset: 58px 12px auto auto; width: 340px; max-width: calc(100vw - 24px); margin: 0; padding-bottom: 0;
    border: 1px solid var(--gray-7); border-radius: 8px; box-shadow: 0 12px 32px var(--black-a32);
  }
  #mobileMore::backdrop, #mobileAuthor::backdrop, #mobileFilters::backdrop { background: transparent; backdrop-filter: none; }
  #mobileFilters .mobile-sheet-body { grid-template-columns: minmax(0, 1fr); }
  .mobile-sheet-body > .game-version { color: var(--gray-11); font-size: var(--fs-xs); line-height: 1.5; }

  /* Search is the only filter left in the bar; its label and result count sit inside the field. */
  .toolbar.has-tree-navigation .tree-filters { display: block; padding: 8px 64px 8px 20px; }
  .tree-filters .search-label { display: block; }
  .tree-filters .search-label .search-heading { position: absolute; top: 0; right: 44px; height: 40px; align-items: center; pointer-events: none; }
  .tree-filters .search-heading > span:not(#searchResultCount) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .tree-filters #searchInput { width: 100%; padding-right: 120px; }
  .toolbar.has-tree-navigation .mobile-tree-tools { display: block; position: absolute; right: 12px; bottom: 6px; }
  .mobile-tree-tools #mobileSearchButton { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .mobile-header-sheet[open] { animation: header-sheet-in 140ms ease-out; }
  @keyframes header-sheet-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
}
@media (max-width: 720px), (max-width: 900px) and (max-height: 500px) and (pointer: coarse) {
  .header-creator { display: none; }
  .topbar.compact-header { display: grid; grid-template-columns: minmax(0, 1fr) 88px; align-items: start; column-gap: 8px; row-gap: 0; padding: 12px 12px 10px; }
  .compact-header .brand-block { display: contents; }
  .compact-header .brand-title { display: contents; }
  .compact-header .header-actions-area { display: contents; }
  .compact-header .header-actions-area > .game-version { grid-column: 1 / -1; grid-row: 1; margin-bottom: 6px; }
  .compact-header .brand-lockup { grid-column: 1; grid-row: 2; gap: 9px; min-height: 44px; }
  .compact-header .brand-emblem { width: 36px; height: 40px; flex-basis: 36px; }
  .compact-header .brand-name { font-size: var(--fs-2xl); white-space: nowrap; }
  .compact-header .brand-name.is-chinese { font-size: var(--fs-2xl); }
  .compact-header .brand-subtitle { font-size: var(--fs-xs); }
  .compact-header .header-metadata { grid-column: 1 / -1; grid-row: 3; gap: 4px 12px; margin-top: 7px; font-size: var(--fs-3xs); }
  .compact-header .game-version, .compact-header .online-count { font-size: var(--fs-3xs); line-height: 1.4; }
  .compact-header .mobile-header-controls { display: flex; grid-column: 2; grid-row: 2; align-self: center; }
  .toolbar.has-tree-navigation .tree-filters { display: none; }
  .tree-navigation { grid-template-columns: 106px minmax(0, 1fr); padding: 6px 12px 0; gap: 7px; }
  .country-trigger { min-height: 44px; padding: 7px; font-size: var(--fs-xs); }
  .country-flag { width: 24px; height: 18px; flex-basis: 24px; }
  .branch-tab { min-width: 76px; min-height: 48px; padding: 8px 10px 10px; gap: 6px; font-size: var(--fs-xs); }
  .branch-tabs { scrollbar-width: none; }
  .branch-tabs::-webkit-scrollbar { display: none; }
  .mobile-tree-tools { display: flex; align-items: center; gap: 10px; padding: 0 10px 0 14px; min-height: 44px; background: var(--gray-3); }
  .mobile-tree-tools .header-metadata { flex: 1; gap: 10px; }
  .mobile-tree-tools #statusText { display: block; color: var(--gray-11); }
  .mobile-tree-tools #statusText, .mobile-tree-tools .online-count { font-size: var(--fs-3xs); line-height: 1.5; }
  .mobile-tree-actions { display: flex; flex: 0 0 auto; gap: 0; order: 2; }
  .mobile-tree-tools .header-metadata { flex-wrap: wrap; gap: 0 8px; }
  .mobile-tree-tools .online-count { white-space: normal; }

  .app-shell { height: 100dvh; }
  .app-shell .rank-block { grid-template-columns: 44px minmax(0, 1fr); }
  .app-shell .rank-rail { padding: 8px 0; }
  .app-shell .rank-owned-trigger { width: 44px; min-height: 44px; }
  .app-shell .rank-name { font-size: var(--fs-xs); line-height: 16px; }
  .app-shell .tree-headings.rank-field { margin-left: 44px; }
  .app-shell .rank-unlock-line { left: 44px; }
  .app-shell .tree-container {
    padding-bottom: calc(var(--mobile-budget-height, 88px) + 44px + env(safe-area-inset-bottom, 0px));
    scroll-padding-bottom: calc(var(--mobile-budget-height, 88px) + 44px + env(safe-area-inset-bottom, 0px));
    scroll-padding-left: 52px;
  }
  .floating-budget {
    width: min(460px, calc(100% - 24px)); max-width: calc(100% - 24px);
    grid-template-columns: minmax(0, 1fr) 104px; align-items: stretch;
    gap: 8px; padding: 8px 10px; border-radius: 16px;
  }
  .floating-budget .budget-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: center; gap: 4px 10px; }
  .floating-budget .budget-count { grid-column: 1 / -1; font-size: var(--fs-2xs); line-height: 16px; }
  .floating-budget .budget-cost { display: grid; justify-content: stretch; align-content: start; gap: 0; min-width: 0; }
  .floating-budget .budget-cost > span { font-size: var(--fs-3xs); line-height: 14px; }
  .floating-budget .budget-cost strong { min-width: 0; font-size: var(--fs-md); line-height: 18px; white-space: normal; overflow-wrap: anywhere; }
  .floating-budget .floating-planner { min-width: 0; padding-left: 8px; }
  .floating-budget .floating-plan-button {
    width: 100%; min-width: 0; max-width: none; height: 100%; min-height: 56px;
    flex-direction: column; gap: 4px; padding: 6px; border-radius: 11px; font-size: var(--fs-xs); line-height: 16px;
  }
}

/* Navigation preview: a compact desktop rail, with the original mobile controls. */
:root {
  --nav-accent: var(--gold-9);
  --nav-active-surface: var(--green-4-a08);
  --nav-active-border: var(--green-6-a32);
}
.topbar { background: var(--gray-2); border-bottom-color: var(--gray-5); }
.header-actions-area { gap: 6px; }
.header-actions-area > .game-version { color: var(--gray-11); }
.header-metadata #statusText, .header-metadata .online-count { color: var(--gray-11); }
.topbar-actions button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 40px; padding: 8px 10px; border-color: transparent; border-radius: 6px;
  background: transparent; color: var(--gray-12); font-weight: 500;
}
.topbar-actions button::before {
  content: ""; display: block; flex: 0 0 17px; width: 17px; height: 17px; background: currentColor;
  mask: var(--header-action-icon) center / contain no-repeat;
  -webkit-mask: var(--header-action-icon) center / contain no-repeat;
}
#guideButton { --header-action-icon: url("assets/navigation/book-open.svg?r=9b9bed0ff057283d"); }
#routeExportButton { --header-action-icon: url("assets/navigation/image-down.svg?r=598f3007626b879e"); }
#clearButton, #refreshDataButton { --header-action-icon: url("assets/navigation/rotate-ccw.svg?r=622685386ab4017e"); }
.topbar-actions #clearButton { color: var(--red-5); }
.topbar-actions button:hover:not(:disabled) { background: var(--gray-5); border-color: transparent; }
.topbar-actions #clearButton:hover { background: var(--green-4-a08); }
.tree-navigation { background: var(--gray-3); border-bottom-color: var(--gray-6); }
.country-trigger {
  background: var(--gray-5); border-color: var(--gray-7); border-radius: 6px; color: var(--gray-13);
  box-shadow: none; font-weight: 500;
}
.country-trigger:hover { background: var(--gray-4); border-color: var(--green-4); }
.branch-tabs { gap: 6px; padding-bottom: 6px; }
.branch-tab {
  min-height: 44px; border: 1px solid transparent; border-radius: 6px;
  padding: 8px 14px; color: var(--gray-11);
}
.branch-tab:hover { background: var(--green-4-a08); color: var(--gray-13); }
.branch-tab[aria-pressed="true"] {
  color: var(--gold-15); background: var(--nav-active-surface); border-color: var(--nav-active-border);
}
.branch-tab[aria-pressed="true"] .nav-icon { color: var(--nav-accent); }
.tree-filters { background: var(--gray-3); }
.tree-filters > label > span, #mobileFilters .mobile-sheet-body > label > span, #mobileMore .mobile-sheet-body > label > span,
#mobileSearch .search-label > span { color: var(--gray-11); font-weight: 500; }
.tree-filters input[type="search"], .tree-filters select,
#mobileFilters select, #mobileMore select, #mobileSearch input[type="search"] {
  background: var(--gray-2); border-color: var(--gray-7); border-radius: 6px; color: var(--gray-13);
}
.tree-filters input[type="search"]::placeholder { color: var(--gray-10); }
.tree-filters input[type="search"]:focus, .tree-filters select:focus,
#mobileFilters select:focus, #mobileMore select:focus, #mobileSearch input[type="search"]:focus {
  outline: 2px solid var(--gold-14-a32); border-color: var(--nav-accent); outline-offset: 1px;
}
.tree-filters > .tree-selection-options { border-left-color: var(--gray-7); }
.tree-selection-options .planner-option { color: var(--gray-12); }
.country-picker, .country-picker-heading { background: var(--gray-3); }
.country-picker { border-color: var(--gray-8); border-radius: 8px; }
.country-choice { background: transparent; border-radius: 6px; }
.country-choice:hover { background: var(--green-4-a08); border-color: var(--green-4); }
.country-choice[aria-pressed="true"] { background: var(--nav-active-surface); border-color: var(--nav-active-border); color: var(--gold-15); }
.country-choice[aria-pressed="true"] > .nav-icon { color: var(--nav-accent); }
.header-icon-button { border-radius: 6px; }
.header-icon-button.has-value { background: var(--nav-active-surface); color: var(--nav-accent); }
.mobile-header-sheet, #mobileFilters .mobile-sheet-heading, #mobileSearch .mobile-sheet-heading {
  background: var(--gray-3); border-color: var(--gray-7);
}
.mobile-header-sheet { border-radius: 8px 8px 0 0; }
.mobile-sheet-heading { border-bottom-color: var(--gray-7); }
.mobile-sheet-body .topbar-actions button { justify-content: flex-start; gap: 12px; }
.mobile-sheet-body .topbar-actions button::before { flex-basis: 20px; width: 20px; height: 20px; }

@media (prefers-reduced-motion: no-preference) {
  .branch-tab, .branch-tab .nav-icon, .country-choice, .country-choice .nav-icon,
  .topbar-actions button, .country-trigger, .header-icon-button {
    transition: background-color 120ms ease-out, border-color 120ms ease-out, color 120ms ease-out;
  }
  .country-picker[open], .country-picker[open]::backdrop, .mobile-header-sheet[open]::backdrop {
    animation: navigation-fade-in 140ms ease-out;
  }
  @keyframes navigation-fade-in { from { opacity: 0; } to { opacity: 1; } }
}

@media (min-width: 1200px) {
  /* One header row: brand | country | search | filters | actions | author and More.
     The header and toolbar dissolve so their children share the shell's grid. */
  .app-shell:has(.toolbar.has-tree-navigation) {
    grid-template-columns: minmax(92px, max-content) 140px 184px minmax(0, 1fr) auto auto auto;
    grid-template-rows: 56px minmax(0, 1fr);
  }
  .app-shell:has(.toolbar.has-tree-navigation)::before { content: ""; grid-column: 1 / -1; grid-row: 1; background: var(--gray-2); border-bottom: 1px solid var(--gray-6); }
  .app-shell:has(.toolbar.has-tree-navigation) > .topbar,
  .toolbar.has-tree-navigation, .toolbar.has-tree-navigation .tree-navigation,
  .toolbar.has-tree-navigation .mobile-tree-tools { display: contents; }
  .app-shell:has(.toolbar.has-tree-navigation) .brand-block { grid-column: 1 / span 2; grid-row: 1; align-self: center; padding: 0 12px 0 16px; }
  .app-shell:has(.toolbar.has-tree-navigation) .mobile-tree-actions { grid-column: 5; grid-row: 1; align-self: center; }
  .app-shell:has(.toolbar.has-tree-navigation) .header-actions-area { grid-column: 6; grid-row: 1; align-self: center; }
  .app-shell:has(.toolbar.has-tree-navigation) .mobile-header-controls { grid-column: 7; grid-row: 1; align-self: center; padding-right: 8px; }
  .toolbar.has-tree-navigation .branch-tabs {
    grid-column: 1; grid-row: 2; display: grid; grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: minmax(72px, max-content); align-content: start; gap: 8px;
    min-height: 0; padding: 16px 8px; overflow-x: hidden; overflow-y: auto;
    background: var(--gray-2); border-right: 1px solid var(--gray-6);
  }
  .toolbar.has-tree-navigation .branch-tab {
    flex-direction: column; width: 100%; min-width: 0; min-height: 72px; gap: 6px;
    padding: 10px 4px; white-space: normal; font-size: var(--fs-2xs); line-height: 16px;
    border-left-width: 3px;
  }
  .toolbar.has-tree-navigation .branch-tab[aria-pressed="true"] { border-left-color: var(--nav-accent); }
  .toolbar.has-tree-navigation .branch-tab .nav-icon { width: 22px; height: 22px; flex-basis: 22px; }
  .toolbar.has-tree-navigation .branch-label { min-width: 0; max-width: 100%; white-space: nowrap; }
  .toolbar.has-tree-navigation .country-trigger {
    grid-column: 3; grid-row: 1; align-self: center; width: auto; height: 40px;
    margin: 0; padding: 8px 10px;
  }
  .toolbar.has-tree-navigation .tree-filters {
    grid-column: 4; grid-row: 1; align-self: center; padding: 0 4px 0 12px; background: transparent;
  }
  .app-shell:has(.toolbar.has-tree-navigation) > .workspace { grid-column: 2 / -1; grid-row: 2; }
}

@media (max-width: 720px), (max-width: 900px) and (max-height: 500px) and (pointer: coarse) {
  .tree-navigation { gap: 8px; padding: 8px 12px; }
  .country-trigger { margin-bottom: 0; }
  .branch-tabs { gap: 4px; padding-bottom: 0; }
  .branch-tab { min-height: 44px; padding: 8px 10px; }
  .mobile-tree-tools { background: var(--gray-2); border-bottom: 1px solid var(--gray-6); }
  .mobile-tree-actions { gap: 4px; }
  .country-picker { border-radius: 8px 8px 0 0; }
}

/* Desktop budget: a full-width bar docked below the workspace instead of a floating capsule,
   so it never covers cards. The plan summary that used to pop up over the tree sits inline.
   Same query as the slim header: landscape phones keep the mobile dock. */
@media (min-width: 901px), (min-width: 721px) and (min-height: 501px), (min-width: 721px) and (pointer: fine), (min-width: 721px) and (pointer: none) {
  :root { --budget-dock-height: 60px; }
  .app-shell { padding-bottom: var(--budget-dock-height); }
  .floating-budget {
    left: 0; right: 0; bottom: 0; transform: none;
    width: auto; max-width: none; min-height: var(--budget-dock-height);
    grid-template-columns: auto minmax(0, 1fr) auto; gap: 24px;
    padding: 8px 16px 8px 20px;
    border-width: 1px 0 0; border-radius: 0;
    box-shadow: 0 -6px 18px var(--black-a32);
  }
  .floating-budget .budget-summary { flex-wrap: nowrap; gap: 24px; }
  .floating-budget .floating-planner { display: contents; }
  .floating-budget .floating-planner .floating-planner-copy {
    grid-column: 2; grid-row: 1; position: static; width: auto; min-width: 0;
    display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 14px;
    padding: 0 0 0 20px; border: 0; border-left: 1px solid var(--gray-7); border-radius: 0;
    background: transparent; box-shadow: none; opacity: 1; visibility: visible; transform: none; pointer-events: auto;
  }
  .floating-budget .floating-planner-copy small { color: var(--gray-10); }
  .floating-budget .floating-plan-button { grid-column: 3; grid-row: 1; border-radius: 6px; }
}
