:root {
  color-scheme: light;
  --mobile-scroll-top: calc(env(safe-area-inset-top, 0px) + 150px);
  --bg: #f3f0e8;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #21201d;
  --muted: #686158;
  --line: #d7cec0;
  --accent: #2f6b62;
  --accent-strong: #24554e;
  --danger: #a34040;
  --shadow: 0 18px 45px rgba(58, 48, 36, 0.13);
  --topbar-bg: rgba(255, 253, 248, 0.64);
  --panel-bg: rgba(255, 253, 248, 0.66);
  --tree-bg: rgba(251, 250, 245, 0.84);
  --grid-line: rgba(47, 107, 98, 0.08);
  --relation-bg: #f8f4eb;
  --male-bg: #effaf3;
  --female-bg: #fff1f7;
  --generation-bg: rgba(255, 253, 248, 0.42);
  --generation-ink: rgba(36, 85, 78, 0.58);
  --generation-line: rgba(47, 107, 98, 0.16);
  --focus-ring: rgba(47, 107, 98, 0.15);
  --map-position-bg: rgba(255, 253, 248, 0.88);
  --map-position-border: rgba(47, 107, 98, 0.24);
  --tree-line: #8d7d67;
  --male-line: #2f8a64;
  --female-line: #d94f86;
  --female-ink: #c43f78;
  --spouse-line: #d63b3b;
  --family-line: #2f8a64;
}

body.theme-dark {
  color-scheme: dark;
  --bg: #071426;
  --surface: #0d2038;
  --surface-strong: #132b49;
  --ink: #edf6ff;
  --muted: #a9bed4;
  --line: #294761;
  --accent: #5ca8d8;
  --accent-strong: #84c4ea;
  --danger: #d46b7b;
  --shadow: 0 18px 45px rgba(0, 8, 20, 0.34);
  --topbar-bg: rgba(7, 20, 38, 0.82);
  --panel-bg: rgba(13, 32, 56, 0.78);
  --tree-bg: rgba(8, 22, 40, 0.92);
  --grid-line: rgba(92, 168, 216, 0.12);
  --relation-bg: #102743;
  --male-bg: #102f32;
  --female-bg: #351f3a;
  --generation-bg: rgba(13, 32, 56, 0.5);
  --generation-ink: rgba(190, 222, 245, 0.62);
  --generation-line: rgba(92, 168, 216, 0.2);
  --focus-ring: rgba(92, 168, 216, 0.22);
  --map-position-bg: rgba(13, 32, 56, 0.9);
  --map-position-border: rgba(92, 168, 216, 0.28);
  --tree-line: #6e8ba5;
  --male-line: #62c3a1;
  --female-line: #d782ba;
  --female-ink: #f0a3cb;
  --spouse-line: #ff7777;
  --family-line: #62c3a1;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(16px, 4vw, 44px);
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(6px);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(17px, 2.2vw, 24px);
  font-style: italic;
  line-height: 1.2;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.08;
}

h2 {
  margin-bottom: 4px;
  font-size: 22px;
}

.topbar__actions,
.form-actions,
.panel__header-actions,
.panel__header,
.workspace__header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar__actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.info-board {
  border-bottom: 1px solid var(--line);
  padding: 18px clamp(16px, 4vw, 44px);
  background: var(--surface);
  box-shadow: 0 16px 35px rgba(58, 48, 36, 0.08);
}

.info-board__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.info-board__list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.info-board__item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--panel-bg);
  color: var(--ink);
}

.info-board__item strong {
  display: block;
  margin-bottom: 4px;
}

.info-board__meta,
.info-board__empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

#infoBoardButton {
  position: relative;
}

#infoBoardButton.has-info-board-count::after {
  position: absolute;
  top: -8px;
  right: -8px;
  display: grid;
  min-width: 20px;
  height: 20px;
  place-items: center;
  border: 2px solid var(--surface);
  border-radius: 999px;
  padding: 0 5px;
  background: var(--danger);
  color: white;
  content: attr(data-count);
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 4px 10px rgba(103, 29, 29, 0.2);
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0 16px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
}

.button:hover {
  background: var(--accent-strong);
}

.button--ghost {
  background: transparent;
  color: var(--accent);
}

.button--ghost:hover {
  background: rgba(47, 107, 98, 0.09);
}

.button--danger {
  border-color: var(--danger);
  background: var(--danger);
}

.button--danger:not([hidden]) {
  display: inline-flex;
}

.button--small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 14px;
}

.auth-button {
  width: 46px;
  min-height: 46px;
  border-radius: 999px;
  padding: 4px;
  background: var(--surface-strong);
}

.auth-button:hover {
  background: var(--surface);
}

.auth-button--unlocked {
  border-color: var(--accent-strong);
}

.auth-button__icon {
  display: block;
  width: 34px;
  height: 34px;
  object-fit: contain;
  pointer-events: none;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  gap: 24px;
  padding: 16px clamp(16px, 4vw, 44px) 40px;
  transition: grid-template-columns 0.24s ease, gap 0.24s ease, padding-left 0.24s ease;
}

body.form-panel-collapsed.personal-panel-collapsed.files-panel-collapsed .layout {
  grid-template-columns: 0 minmax(0, 1fr);
  gap: 0;
  padding-left: 54px;
}

body.edit-locked .layout {
  grid-template-columns: minmax(0, 1fr);
}

body.edit-locked .sidebar,
body.edit-locked .panel-tab {
  display: none;
}

body.edit-locked .panel--personal {
  display: none;
}

body.viewer-mode .workspace,
body.viewer-mode .tree-canvas,
body.viewer-mode .tree-world,
body.viewer-mode .person-card {
  display: block;
  visibility: visible;
}

body.tree-mode-linear {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

body.tree-mode-linear .topbar {
  flex: 0 0 auto;
}

body.tree-mode-linear .layout {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

body.tree-mode-linear:not(.edit-locked) .sidebar {
  max-height: 100%;
  overflow: auto;
}

body.tree-mode-linear .workspace {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

body.tree-mode-linear .workspace__header {
  flex: 0 0 auto;
}

body.tree-mode-linear .tree-canvas {
  flex: 1 1 auto;
  min-height: 0;
}

.sidebar {
  display: grid;
  align-self: start;
  gap: 18px;
  min-width: 0;
}

.panel-tab {
  position: fixed;
  top: calc(50% - 140px);
  left: 0;
  z-index: 20;
  min-height: 116px;
  border: 1px solid var(--accent);
  border-left: 0;
  border-radius: 0 8px 8px 0;
  padding: 12px 8px;
  background: rgba(47, 107, 98, 0.96);
  color: white;
  cursor: pointer;
  font-weight: 800;
  writing-mode: vertical-rl;
  transform: translateY(-50%);
  box-shadow: 0 12px 28px rgba(58, 48, 36, 0.18);
}

.panel-tab:hover {
  background: var(--accent-strong);
}

.panel-tab--personal {
  top: 50%;
}

.panel-tab--files {
  top: calc(50% + 140px);
}

.panel-tab[hidden] {
  display: none;
}

.panel,
.workspace {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
  backdrop-filter: blur(5px);
  box-shadow: var(--shadow);
}

.panel {
  align-self: start;
  padding: 20px;
  min-width: 0;
  transform: translateX(0);
  transition: opacity 0.24s ease, transform 0.24s ease, visibility 0.24s ease;
}

body.form-panel-collapsed .panel--form {
  display: none;
}

body.personal-panel-collapsed .panel--personal {
  display: none;
}

body.files-panel-collapsed .panel--files {
  display: none;
}

.panel__header {
  justify-content: space-between;
  margin-bottom: 18px;
}

.panel__header-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.person-form {
  display: grid;
  gap: 15px;
}

.files-actions {
  display: grid;
  gap: 12px;
}

.files-actions .button {
  width: 100%;
}

.personal-data-form {
  display: grid;
  gap: 12px;
}

.personal-data-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.personal-data-status.is-success {
  color: var(--accent);
}

.personal-data-status.is-error {
  color: var(--danger);
}

.relation-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--relation-bg);
}

.relation-summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.relation-summary strong {
  color: var(--ink);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--surface-strong);
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

textarea {
  resize: vertical;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.workspace {
  position: relative;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  min-width: 0;
  overflow: visible;
}

.workspace__header {
  justify-content: space-between;
  gap: 18px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  margin-top: 18px;
  padding: 18px 20px;
  background: var(--panel-bg);
  backdrop-filter: blur(5px);
  box-shadow: var(--shadow);
}

.map-settings-toggle {
  position: absolute;
  top: -16px;
  left: 16px;
  z-index: 45;
  min-height: 34px;
  border: 1px solid var(--accent);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  padding: 7px 14px 8px;
  background: rgba(47, 107, 98, 0.96);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 12px 26px rgba(58, 48, 36, 0.18);
}

body.linear-settings-collapsed .map-settings-toggle {
  top: -16px;
  left: 16px;
  box-shadow: 0 10px 24px rgba(0, 8, 20, 0.16);
}

.map-settings-toggle:hover {
  background: var(--accent-strong);
}

.mobile-page-scroll {
  display: none;
}

body.linear-settings-collapsed .workspace__header {
  display: none;
}

body.linear-settings-collapsed .tree-canvas {
  border-radius: 8px;
  margin-top: 18px;
}

.workspace__tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

#statusLine {
  margin-bottom: 0;
  color: var(--muted);
}

.search {
  width: min(280px, 100%);
}

.zoom-value {
  min-width: 52px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  text-align: center;
}

.tree-canvas {
  position: relative;
  min-height: 640px;
  border: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
  overflow: hidden;
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    var(--tree-bg);
  background-size: 36px 36px, 36px 36px, auto;
  cursor: grab;
  touch-action: none;
  box-shadow: var(--shadow);
}

.tree-canvas:active,
.tree-canvas.is-panning {
  cursor: grabbing;
}

.empty-state {
  display: grid;
  min-height: 440px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.map-position {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 30;
  border: 1px solid var(--map-position-border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--map-position-bg);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
  pointer-events: none;
  box-shadow: 0 8px 20px rgba(58, 48, 36, 0.1);
}

.generation-label-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.generation-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 2px dashed var(--generation-line);
  filter: blur(0.25px);
}

.generation-label {
  position: absolute;
  left: 12px;
  z-index: 1;
  min-width: 134px;
  border: 1px solid var(--generation-line);
  border-radius: 8px;
  padding: 6px 9px;
  background: var(--generation-bg);
  color: var(--generation-ink);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  filter: blur(0.15px);
  opacity: 0.72;
  transform: scale(var(--label-scale, 1));
  transform-origin: left top;
}

.linear-name-label-layer {
  position: absolute;
  inset: 0;
  z-index: 24;
  overflow: hidden;
  pointer-events: none;
}

.linear-name-label {
  position: absolute;
  max-width: var(--linear-name-max-width, 104px);
  border: 1px solid var(--map-position-border);
  border-radius: var(--linear-name-radius, 7px);
  padding: var(--linear-name-padding-y, 4.5px) var(--linear-name-padding-x, 7px);
  background: var(--map-position-bg);
  color: var(--ink);
  font-size: var(--linear-name-font-size, 13px);
  font-weight: 900;
  line-height: var(--linear-name-line-height, 15px);
  text-align: center;
  overflow-wrap: anywhere;
  box-shadow: 0 8px 18px rgba(58, 48, 36, 0.12);
  transform: translate(-50%, 0);
}

.tree-canvas.has-fixed-name-labels .person-card__name {
  visibility: hidden;
}

.tree-world {
  position: relative;
  z-index: 10;
  width: 18000px;
  height: 12000px;
  transform-origin: 0 0;
  backface-visibility: hidden;
  contain: layout paint style;
  will-change: transform;
}

.tree-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.tree-lines path {
  fill: none;
  stroke: var(--tree-line);
  stroke-linecap: round;
  stroke-width: calc(3px + var(--line-boost, 0px));
}

.tree-lines .spouse-line {
  stroke: var(--spouse-line);
  stroke-width: calc(4px + var(--line-boost, 0px));
}

.tree-lines .child-line {
  stroke: var(--family-line);
  stroke-width: calc(3px + var(--line-boost, 0px));
}

.tree-lines circle {
  fill: var(--accent);
}

.tree-lines .child-dot {
  fill: var(--family-line);
}

.tree-lines .family-dot {
  fill: var(--family-line);
}

.tree-lines .spouse-dot {
  fill: var(--spouse-line);
}

.person-card {
  position: absolute;
  width: 210px;
  user-select: none;
  z-index: 12;
  contain: layout style;
}

.person-card--birthday-today::before {
  position: absolute;
  top: -86px;
  left: 50%;
  z-index: 20;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f59e0b;
  content: "";
  box-shadow:
    0 -42px 0 4px #f59e0b,
    30px -30px 0 3px #e9547b,
    42px 0 0 4px #4fb3e8,
    30px 30px 0 3px #7bd88f,
    0 42px 0 4px #f7d154,
    -30px 30px 0 3px #b57cff,
    -42px 0 0 4px #ff8a4c,
    -30px -30px 0 3px #4fd1c5;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px) scale(0.12);
  animation: birthday-firework-burst 1.8s ease-out infinite;
}

.person-card--birthday-today::after {
  position: absolute;
  top: -18px;
  left: 50%;
  z-index: 19;
  width: 7px;
  height: 26px;
  border-radius: 999px;
  background: linear-gradient(#fff4a8, #f59e0b 42%, transparent);
  content: "";
  pointer-events: none;
  transform: translate(-50%, 0);
  animation: birthday-firework-rocket 1.8s ease-out infinite;
}

.person-card__birthday-balloons {
  position: absolute;
  top: -92px;
  left: 50%;
  z-index: 18;
  width: 88px;
  height: 54px;
  pointer-events: none;
  transform: translateX(-50%);
}

.person-card__birthday-balloons::before {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 35% 28%, rgba(255, 255, 255, 0.65) 0 10%, transparent 12%),
    radial-gradient(ellipse at 50% 42%, #e9547b 0 34%, transparent 35%),
    radial-gradient(ellipse at 35% 35%, #f7d154 0 30%, transparent 31%),
    radial-gradient(ellipse at 66% 36%, #4fb3e8 0 30%, transparent 31%);
  content: "";
}

.person-card__birthday-balloons::after {
  position: absolute;
  left: 17px;
  top: 31px;
  width: 54px;
  height: 61px;
  border-right: 1px solid rgba(104, 82, 53, 0.5);
  border-left: 1px solid rgba(104, 82, 53, 0.5);
  background:
    linear-gradient(105deg, transparent 0 31%, rgba(104, 82, 53, 0.45) 32% 34%, transparent 35%),
    linear-gradient(75deg, transparent 0 65%, rgba(104, 82, 53, 0.45) 66% 68%, transparent 69%);
  content: "";
}

@keyframes birthday-firework-rocket {
  0% {
    opacity: 0;
    transform: translate(-50%, 0) scale(0.7);
  }
  14% {
    opacity: 1;
  }
  42% {
    opacity: 1;
    transform: translate(-50%, -74px) scale(1);
  }
  54%,
  100% {
    opacity: 0;
    transform: translate(-50%, -82px) scale(0.3);
  }
}

@keyframes birthday-firework-burst {
  0%,
  42% {
    opacity: 0;
    transform: translate(-50%, 8px) scale(0.12);
  }
  54% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, 0) scale(1.55);
  }
}

.person-card__button {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 128px;
  border: 1px solid var(--line);
  border-top: 5px solid var(--accent);
  border-radius: 999px;
  padding: 18px 22px;
  background: var(--surface-strong);
  color: var(--ink);
  cursor: pointer;
  text-align: center;
  box-shadow: 0 9px 24px rgba(58, 48, 36, 0.08);
}

.person-card--deceased .person-card__button::before {
  content: "";
  position: absolute;
  top: 45px;
  left: 50%;
  z-index: 4;
  width: 74px;
  height: 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.86);
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(31deg);
  transform-origin: center;
}

.person-card--male .person-card__button {
  border-color: #8cc9a8;
  border-top-color: var(--male-line);
  background: var(--male-bg);
}

.person-card--male .person-card__years {
  color: var(--male-line);
}

.person-card--male .person-card__avatar {
  display: block;
  background-image: url("../images/male.png");
}

.person-card--female .person-card__button {
  border-color: #edacc8;
  border-top-color: var(--female-line);
  background: var(--female-bg);
}

.person-card--female .person-card__avatar {
  display: block;
  border-color: rgba(217, 79, 134, 0.28);
  background-color: var(--female-bg);
  background-image: url("../images/female.png");
}

.person-card--female .person-card__years {
  color: var(--female-ink);
}

.person-card.is-dragging {
  z-index: 5;
}

.person-card.is-dragging .person-card__button {
  cursor: grabbing;
  transform: translateY(-2px);
}

.missing-mother-card {
  position: absolute;
  z-index: 11;
  display: grid;
  width: 124px;
  height: 124px;
  place-items: center;
  border: 2px dashed rgba(71, 83, 98, 0.55);
  border-radius: 50%;
  background: color-mix(in srgb, var(--surface-strong) 82%, transparent);
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  font-weight: 850;
  line-height: 1.15;
  text-align: center;
  box-shadow: 0 10px 22px rgba(58, 48, 36, 0.08);
}

.missing-mother-card:hover,
.missing-mother-card:focus-visible {
  border-color: var(--accent);
  color: var(--ink);
  outline: none;
  box-shadow: 0 14px 26px rgba(47, 107, 98, 0.18);
}

.missing-mother-card__plus {
  display: block;
  margin-bottom: -8px;
  color: var(--accent);
  font-size: 36px;
  line-height: 1;
}

.person-card__button:hover,
.person-card__button.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring), 0 12px 26px rgba(58, 48, 36, 0.12);
}

.person-card__name {
  display: block;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
}

.person-card__avatar {
  display: none;
  width: 58px;
  height: 58px;
  margin: -4px auto 6px;
  border: 2px solid rgba(47, 138, 100, 0.28);
  border-radius: 50%;
  background-color: var(--male-bg);
  background-position: center top;
  background-repeat: no-repeat;
  background-size: cover;
}

.person-card__years {
  display: block;
  margin-top: 5px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
}

.person-card__notes {
  display: -webkit-box;
  margin-top: 8px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@media (max-width: 900px) {
  body.tree-mode-linear {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body.tree-mode-linear .layout {
    flex: 0 0 auto;
    min-height: auto;
    overflow: visible;
    padding-bottom: 28px;
  }

  body.tree-mode-linear:not(.edit-locked) .sidebar {
    max-height: none;
  }

  body.tree-mode-linear .workspace {
    min-height: auto;
  }

  body.tree-mode-linear .tree-canvas {
    flex: 0 0 auto;
    height: clamp(560px, 78dvh, 820px);
    min-height: 560px;
  }

  .topbar,
  .layout,
  .workspace__header {
    align-items: stretch;
    flex-direction: column;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .topbar__actions,
  .workspace__header {
    justify-content: flex-start;
  }

  .tree {
    flex-direction: column;
  }
}

@media (max-width: 1100px), (pointer: coarse) {
  body.tree-mode-linear .topbar,
  body.tree-mode-radial .topbar {
    position: sticky;
    top: 0;
    z-index: 90;
  }

  body.tree-mode-linear {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body.tree-mode-linear .topbar {
    gap: 12px;
    padding: 10px 12px;
  }

  body.tree-mode-linear h1 {
    font-size: 22px;
  }

  body.tree-mode-linear .subtitle {
    margin-top: 4px;
    font-size: 15px;
  }

  body.tree-mode-linear .layout {
    flex: 0 0 auto;
    grid-template-columns: 1fr;
    gap: 12px;
    min-height: auto;
    overflow: visible;
    padding: 8px 8px 28px;
  }

  body.tree-mode-linear.form-panel-collapsed.personal-panel-collapsed.files-panel-collapsed .layout {
    grid-template-columns: 1fr;
    padding-left: 8px;
  }

  body.tree-mode-linear:not(.edit-locked) .sidebar {
    max-height: none;
  }

  body.tree-mode-linear .workspace {
    min-height: auto;
  }

  body.tree-mode-linear .workspace__header {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  body.tree-mode-linear .workspace__tools {
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-start;
    overflow: visible;
  }

  body.tree-mode-linear .topbar__actions .button {
    flex: 0 0 auto;
    width: auto;
  }

  body.tree-mode-linear .workspace__tools .search {
    flex: 0 1 280px;
    width: min(280px, 100%);
  }

  body.tree-mode-linear .workspace__tools .search input {
    min-height: 38px;
    padding: 0 12px;
  }

  body.tree-mode-linear .tree-canvas {
    flex: 0 0 auto;
    height: clamp(560px, 78dvh, 820px);
    min-height: 560px;
    touch-action: pan-y pinch-zoom;
  }

  .mobile-page-scroll {
    position: fixed;
    top: var(--mobile-scroll-top);
    right: 8px;
    bottom: 14px;
    z-index: 120;
    display: block;
    width: 20px;
    pointer-events: none;
  }

  .mobile-page-scroll[hidden] {
    display: none;
  }

  .mobile-page-scroll__track {
    position: fixed;
    top: var(--mobile-scroll-top);
    right: 14px;
    bottom: 14px;
    width: 6px;
    border: 1px solid color-mix(in srgb, var(--accent), transparent 38%);
    border-radius: 999px;
    background: color-mix(in srgb, var(--panel), transparent 36%);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(8px);
  }

  .mobile-page-scroll__thumb {
    position: absolute;
    top: 0;
    right: 0;
    width: 20px;
    min-height: 30px;
    border: 1px solid var(--accent);
    border-radius: 999px;
    background: var(--accent);
    box-shadow: 0 10px 24px rgba(0, 8, 20, 0.22);
    cursor: grab;
    pointer-events: auto;
    touch-action: none;
  }

  .mobile-page-scroll__thumb:active {
    cursor: grabbing;
  }
}

@media (max-width: 520px) {
  .two-col {
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }
}
