/* Phone and tablet share one set of controls; the diagram keeps readable people. */
:root { --site-header-height: 5.25rem; }
.pedigree { overflow-anchor: none; }
#strom :is(input, select) { font-size: 1rem; }
#strom .family-network-toolbar select { width: 100%; min-width: 0; min-height: 46px; font-size: 1rem; }

@media screen {
  #person.profile-parity .profile-tools { position: relative; }
  #person.profile-parity .profile-tools > :not(summary) {
    right: 0;
    max-height: min(55dvh, 30rem);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  #person.profile-parity .profile-section-nav { isolation: isolate; }
  #person.profile-parity .profile-panel:focus { outline: none; }
  .profile-center-icon { display: none; }
  #person.profile-parity .profile-classic-zoom button { white-space: nowrap; }
}

@media screen and (max-width: 1199px) {
  /* One full-width family card on tablets, in either orientation. */
  #person.profile-parity { scroll-padding-top: 4rem; }
  #person.profile-parity .profile-hero,
  #person.profile-parity[data-world] .profile-hero {
    min-height: 132px;
    padding-block: 1.1rem;
    grid-template-columns: 80px minmax(0, 1fr) 44px;
    gap: 1rem;
  }
  #person.profile-parity .profile-photo-slot .profile-avatar { width: 80px; }
  #person.profile-parity .profile-identity :is(h2, h3),
  #person.profile-parity[data-world] .profile-identity h2 { font-size: 2rem; }
  #person.profile-parity .profile-content { margin-block: .8rem 1.25rem; }
  #person.profile-parity .profile-tree-heading { margin-bottom: .75rem; }
  #person.profile-parity .profile-tree-heading > h3 { font-size: 1.5rem; }
  #person.profile-parity .profile-tree-hint { font-size: .85rem; }
  #person.profile-parity .profile-family-summary { padding: 1rem; }
  #person.profile-parity .profile-tree-controls:has(> .field) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: end;
    gap: .5rem;
  }
  #person.profile-parity .profile-tree-controls:has(> .field) > .field {
    display: flex;
    align-items: center;
    gap: .6rem;
    width: auto;
    min-width: 0;
  }
  #person.profile-parity .profile-tree-controls:has(> .field) select {
    width: auto;
    min-width: 4.5rem;
    max-width: 12rem;
  }
  #person.profile-parity .profile-section-nav > button { min-height: 46px; }
  #person.profile-parity .profile-relative { min-height: 84px; }

  /* The selected person and view stay together, above the drawing. */
  #strom { padding-top: 1.25rem; }
  #obsah:has(#strom:not([hidden])) > #workspace-bar { display: none; }
  #strom > .world-context-banner { display: none; }
  #strom > .chapter-heading { margin-bottom: 1rem; }
  #strom > .chapter-heading .kicker { display: none; }
  #strom > .chapter-heading h2 { font-size: clamp(1.85rem, 3.5vw, 2.4rem); }
  #strom > .chapter-heading .chapter-intro { font-size: .9rem; margin-top: .4rem; }
  .tree-workbench { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: stretch; gap: .65rem 1rem; }
  .tree-workbench .tree-focus-bar { padding: .6rem .75rem; gap: .6rem; }
  .tree-workbench .tree-focus-person strong { font-size: 1.1rem; }
  .tree-workbench .tree-focus-person .compact-portrait { width: 40px; height: 40px; }
  .tree-workbench .tree-mobile-view { display: grid; align-content: center; margin: 0; }
  .tree-mobile-view .field { display: grid; gap: .25rem; font-size: .78rem; }
  .tree-mobile-view select { width: 100%; min-width: 0; min-height: 48px; padding: .65rem .75rem; border: 1px solid var(--border); border-radius: .65rem; background: var(--surface); color: var(--text); font-size: 1rem; }
  .tree-workbench .tree-settings-row { grid-column: 1 / -1; margin: 0; }
  #strom > #tree-mode-picker,
  :root[data-child-theme] #strom > #tree-mode-picker { display: none; }
  #strom .tree-view-caption { padding-block: .65rem; font-size: .8rem; }
  #strom :is(#pedigree, #tree-descendants-list, .family-network-viewport, #anulka-fan-stage) {
    height: clamp(20rem, 62svh, 44rem);
    min-height: 0;
    max-height: none;
  }
}

@media screen and (max-width: 940px) {
  :root { --site-header-height: 4.25rem; }
  .site-header-inner { min-height: var(--site-header-height); }
  .mobile-nav { z-index: 30; }
  .mobile-nav a { min-height: 48px; align-content: center; }
  .nav-world-menu { max-height: calc(100dvh - var(--site-header-height) - 5rem); }
  body { padding-bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
  #person.profile-parity { width: calc(100% - 1rem); max-height: calc(100dvh - 1rem); }
}

@media screen and (max-width: 700px) {
  #strom { padding-top: 1rem; }
  #strom > .chapter-heading { margin-bottom: .75rem; }
  .tree-workbench { grid-template-columns: minmax(0, 1fr); gap: .55rem; }
  .tree-mobile-view .field { grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: .7rem; }
  .tree-workbench .tree-mobile-view select { min-height: 46px; }
  .tree-workbench .tree-settings-row { grid-column: auto; }
  #strom .tree-view-caption { padding-block: .55rem; line-height: 1.45; }
  #strom .pedigree-legend { margin-bottom: .5rem; }

  #person.profile-parity { --profile-inset: .75rem; }
  #person.profile-parity .profile-hero,
  #person.profile-parity[data-world] .profile-hero {
    min-height: 106px;
    padding-block: .85rem;
    grid-template-columns: 54px minmax(0, 1fr) 44px;
    gap: .65rem;
  }
  #person.profile-parity .profile-photo-slot .profile-avatar { width: 54px; }
  #person.profile-parity .profile-identity .kicker { font-size: .65rem; margin-bottom: .45rem; }
  #person.profile-parity .profile-identity :is(h2, h3),
  #person.profile-parity[data-world] .profile-identity h2 { font-size: 1.5rem; }
  #person.profile-parity .profile-actions { padding-block: .4rem; }
  #person.profile-parity .profile-section-nav { gap: .1rem; padding: .3rem .5rem; }
  #person.profile-parity .profile-section-nav > button { padding-inline: .15rem; font-size: .8rem; }
  #person.profile-parity .profile-content { margin-top: .65rem; }
  #person.profile-parity .profile-family-summary { padding: .75rem; }
  #person.profile-parity .profile-tree-heading > h3 { font-size: 1.3rem; margin-bottom: .35rem; }
  #person.profile-parity .profile-tree-hint { font-size: .8rem; line-height: 1.5; }
  #person.profile-parity .profile-tree-modes { margin-bottom: .55rem; padding: .2rem; }
  #person.profile-parity .profile-tree-modes button { min-height: 44px; padding-block: .55rem; }
  #person.profile-parity .profile-tree-controls:has(> .field) { grid-template-columns: minmax(0, 1fr) auto; gap: .45rem; margin-bottom: .6rem; }
  #person.profile-parity .profile-tree-controls:has(> .field) > .field { grid-column: 1 / -1; justify-content: space-between; }
  #person.profile-parity .profile-tree-controls:has(> .field) select { min-width: 5rem; max-width: 60%; }
  #person.profile-parity .profile-classic-zoom { gap: .3rem; }
  #person.profile-parity .profile-classic-zoom button { padding-inline: .6rem; }
  #person.profile-parity .profile-tree-controls > button { padding-inline: .6rem; }
  #person.profile-parity .profile-tree-center { min-width: 44px; }
  #person.profile-parity .profile-center-label { display: none; }
  #person.profile-parity .profile-center-icon { display: inline; font-size: 1.35rem; }
  #person.profile-parity .profile-family-summary .profile-pedigree,
  #person.profile-parity .profile-fan-viewport { height: clamp(20rem, 54svh, 32rem); min-height: 0; max-height: none; }
  .fan-roster > summary { min-height: 44px; align-content: center; }
}

/* A short screen must still leave space for the actual content. */
@media screen and (max-height: 540px) and (max-width: 1199px) {
  .site-header { position: static; }
  .mobile-nav a { display: flex; justify-content: center; gap: .45rem; min-height: 44px; }
  .mobile-nav { padding-block: .2rem calc(.2rem + env(safe-area-inset-bottom)); }
  body { padding-bottom: calc(3.4rem + env(safe-area-inset-bottom)); }
  #strom :is(#pedigree, #tree-descendants-list, .family-network-viewport, #anulka-fan-stage) { height: 72svh; min-height: 13rem; }
  #person.profile-parity .profile-family-summary .profile-pedigree,
  #person.profile-parity .profile-fan-viewport { height: 64svh; min-height: 13rem; }
  #person.profile-parity .profile-tools > :not(summary) { max-height: 55dvh; }
}

/* Immersive view also works when the device has no native fullscreen API. */
@media screen {
  #strom:is(:fullscreen, .tree-expanded) { display: flex; flex-direction: column; z-index: 80; height: 100dvh; background: var(--paper); padding: max(.6rem, env(safe-area-inset-top)) max(.6rem, env(safe-area-inset-right)) max(.6rem, env(safe-area-inset-bottom)) max(.6rem, env(safe-area-inset-left)); }
  #strom:is(:fullscreen, .tree-expanded) > :is(.chapter-heading, .world-context-banner, #tree-mode-picker, .tree-view-caption) { display: none; }
  #strom:is(:fullscreen, .tree-expanded) .tree-workbench { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: .65rem; margin-bottom: .6rem; }
  #strom:is(:fullscreen, .tree-expanded) .tree-focus-bar { display: none; }
  #strom:is(:fullscreen, .tree-expanded) .tree-mobile-view { display: block; margin: 0; }
  #strom:is(:fullscreen, .tree-expanded) .tree-settings-row { grid-column: auto; margin: 0; }
  #strom:is(:fullscreen, .tree-expanded) .tree-mobile-view .field { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: .5rem; }
  #strom:is(:fullscreen, .tree-expanded) .tree-mode-help,
  #strom:is(:fullscreen, .tree-expanded) .pedigree-legend { display: none; }
  #strom:is(:fullscreen, .tree-expanded) :is(#pedigree, #tree-descendants-list, .family-network-viewport, #anulka-fan-stage) { height: calc(100dvh - 9rem); min-height: 12rem; max-height: none; }
  #strom:is(:fullscreen, .tree-expanded) > :is(#tree-classic, #tree-descendants):not([hidden]) { display: flex; flex: 1; flex-direction: column; min-height: 15rem; }
  #strom:is(:fullscreen, .tree-expanded) :is(#pedigree, #tree-descendants-list) { height: auto; flex: 1; }
}
@media screen and (max-width: 560px) {
  #strom:is(:fullscreen, .tree-expanded) .tree-workbench { grid-template-columns: minmax(0, 1fr); }
  #strom:is(:fullscreen, .tree-expanded) :is(.family-network-viewport, #anulka-fan-stage) { height: calc(100dvh - 12rem); }
}
