/* Compact controls keep the room visible on phones, including landscape. */
.mobile-only {
  display: none;
}
.view-options,
.walk-options {
  display: contents;
}
.view-options #clean-view {
  order: -1;
}
#start-tour {
  order: 1;
}
#stop-walk {
  order: 2;
}
#quality {
  order: 3;
}
#home-position {
  order: 4;
}
#front-view {
  order: 5;
}
#walk-options-toggle {
  order: 6;
}
#walk-status {
  order: 7;
}
@media (max-width: 700px), (pointer: coarse) and (max-height: 500px) {
  html:has(body.walking),
  html:has(body.map-open),
  html:has(.help-panel:not([hidden])) {
    overflow: hidden;
  }
  :root {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    --phone-top: max(8px, env(safe-area-inset-top));
    --phone-bottom: max(10px, env(safe-area-inset-bottom));
    --phone-left: max(10px, env(safe-area-inset-left));
    --phone-right: max(10px, env(safe-area-inset-right));
  }
  #viewport {
    height: 100dvh;
    bottom: auto;
  }
  .masthead,
  .story-inside .masthead,
  .walking .masthead {
    top: var(--phone-top);
    left: var(--phone-left);
    right: var(--phone-right);
    min-height: 60px;
    padding: 7px 8px;
    gap: 4px;
  }
  .wordmark {
    gap: 5px;
    min-height: 44px;
  }
  .brand-symbol {
    width: 23px;
    height: 23px;
  }
  .wordmark .brand-name {
    font-size: 12px;
  }
  .brand-name small,
  .project-meta {
    display: none;
  }
  .preferences {
    margin-left: auto;
    gap: 4px;
  }
  .preferences select {
    font-size: 16px;
    min-height: 44px;
    padding: 7px 4px;
  }
  #language-select {
    max-width: 86px;
  }
  #theme-select {
    max-width: 96px;
  }
  .masthead #help {
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    font-size: 0;
  }
  #help span {
    width: 30px;
    height: 30px;
    margin: 0;
    font-size: 14px;
  }
  .hero {
    top: auto;
    bottom: calc(var(--phone-bottom) + 85px);
    left: var(--phone-left);
    right: var(--phone-right);
    width: auto;
    max-width: none;
    padding: 18px;
  }
  .hero::before,
  .hero .eyebrow,
  .drawing-note {
    display: none;
  }
  .hero h1 {
    font-size: clamp(30px, 8vw, 37px);
    line-height: 1.1;
    margin: 0 0 8px;
  }
  .hero h1 br {
    display: none;
  }
  .hero h1 em::before {
    content: ' ';
  }
  .hero p {
    font-size: 12px;
    line-height: 1.5;
    margin: 0;
  }
  .hero #enter {
    min-height: 48px;
    margin-top: 14px;
    font-size: 14px;
    padding: 12px 14px;
  }
  .hero #direct-explore {
    min-height: 44px;
    margin: 4px 0 0;
    font-size: 12px;
    padding: 10px 0;
  }
  .bottom-bar,
  .story-inside .bottom-bar {
    left: var(--phone-left);
    right: var(--phone-right);
    bottom: var(--phone-bottom);
    width: auto;
    height: 66px;
    min-height: 66px;
    padding: 8px;
    transform: none;
    gap: 5px;
  }
  .scroll-cue,
  .sheet-number {
    display: none;
  }
  .story-navigation {
    flex: 1;
    min-width: 0;
    gap: 2px;
  }
  .story-navigation button,
  .story-inside .story-navigation button {
    width: 44px;
    height: 44px;
  }
  .story-navigation select,
  .story-inside .story-navigation select {
    min-width: 44px;
    max-width: none;
    width: 100%;
    min-height: 44px;
    padding: 8px 14px 8px 3px;
    font-size: 16px;
  }
  #explore-here {
    font-size: 12px;
    min-height: 44px;
    padding: 8px;
  }
  #story-progress {
    height: 28px;
    top: -17px;
    touch-action: pan-x;
  }
  #story-progress::-webkit-slider-thumb {
    width: 12px;
    height: 12px;
    opacity: 1;
    margin-top: -5px;
  }
  #view-tools {
    top: calc(var(--phone-top) + 68px);
    left: var(--phone-left);
    right: var(--phone-right);
    padding: 3px;
    gap: 4px;
    border-radius: 9px;
  }
  #view-tools button {
    min-height: 44px;
    font-size: 12px;
    padding: 8px;
  }
  #view-tools #look-around {
    flex: 1.4;
  }
  #view-tools #view-options-toggle {
    display: block;
    flex: 1;
  }
  #view-tools .view-options {
    display: none;
  }
  .view-options-open #view-tools .view-options {
    display: grid;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: min(280px, 100%);
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--ui-border);
    border-radius: 10px;
    background: var(--ui-surface);
    box-shadow: 0 8px 30px #0002;
  }
  #view-tools #clean-view {
    position: static;
  }
  .chapter,
  .story-inside .chapter {
    bottom: calc(var(--phone-bottom) + 80px);
    left: var(--phone-left);
    right: calc(var(--phone-right) + 83px);
    max-width: none;
    padding: 9px 10px;
    min-height: 52px;
    gap: 8px;
    align-items: center;
  }
  .chapter::before,
  .chapter > span,
  .chapter .eyebrow {
    display: none;
  }
  .chapter > div {
    flex: 1;
    min-width: 0;
  }
  .story-inside .chapter {
    pointer-events: auto;
  }
  .chapter h2,
  .story-inside .chapter h2 {
    font-size: 16px;
    margin: 0;
    line-height: 1.2;
  }
  .chapter p,
  .story-inside .chapter p {
    display: none;
    margin: 8px 0 0;
    font-size: 12px;
    line-height: 1.5;
  }
  .chapter-expanded .chapter p,
  .chapter-expanded.story-inside .chapter p {
    display: block;
  }
  #chapter-details {
    display: block;
    flex: none;
    min-width: 44px;
    min-height: 44px;
    border: 0;
    background: transparent;
    color: var(--ui-accent);
    font-size: 11px;
    padding: 4px;
  }
  #mini-map-button {
    top: auto;
    bottom: calc(var(--phone-bottom) + 80px);
    right: var(--phone-right);
    width: 75px;
    min-height: 52px;
    padding: 8px;
  }
  #mini-map-button .mini-heading,
  #mini-map,
  #mini-room {
    display: none;
  }
  .mobile-map-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
  }
  #map-panel,
  .story-inside:not(.walking) #map-panel,
  .help-panel {
    top: calc(var(--phone-top) + 68px);
    bottom: calc(var(--phone-bottom) + 80px);
    left: var(--phone-left);
    right: var(--phone-right);
    width: auto;
    max-height: none;
    padding: 16px;
    overscroll-behavior: contain;
  }
  .map-title {
    position: sticky;
    top: -16px;
    background: var(--ui-surface);
    z-index: 1;
    padding: 4px 0;
  }
  .map-title h2 {
    font-size: 23px;
    margin: 4px 0 12px;
  }
  .map-title button,
  #close-help {
    min-width: 44px;
    min-height: 44px;
  }
  #room-list button {
    min-height: 48px;
    font-size: 12px;
  }
  .help-panel {
    bottom: var(--phone-bottom);
  }
  .help-panel p {
    font-size: 13px;
    line-height: 1.7;
  }
  .map-open #view-tools,
  .map-open #chapter,
  .map-open #mini-map-button,
  .map-open #touch-controls,
  .walk-options-open #touch-controls,
  .view-options-open #chapter {
    visibility: hidden;
  }
  .arrival {
    left: var(--phone-left);
    right: var(--phone-right);
    bottom: calc(var(--phone-bottom) + 80px);
    padding: 18px;
  }
  .arrival h2 {
    font-size: 26px;
  }
  .explore-hud {
    top: calc(var(--phone-top) + 68px);
    left: var(--phone-left);
    right: var(--phone-right);
    align-items: center;
    gap: 8px;
  }
  .explore-hud > div {
    padding: 9px 12px;
    max-width: 60%;
  }
  .explore-hud span.eyebrow {
    font-size: 8px;
  }
  .explore-hud strong {
    font-size: 17px;
    margin: 3px 0 0;
  }
  .explore-hud #walk-help {
    display: none;
  }
  .explore-hud #leave-explore {
    min-height: 48px;
    max-width: 134px;
    font-size: 12px;
    padding: 8px 10px;
  }
  #walk-toolbar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    bottom: var(--phone-bottom);
    left: var(--phone-left);
    right: var(--phone-right);
    width: auto;
    max-width: none;
    transform: none;
    padding: 6px;
    gap: 4px;
  }
  #walk-toolbar button {
    min-height: 44px !important;
    font-size: 12px;
    padding: 6px !important;
  }
  #walk-toolbar button span {
    margin-left: 3px;
  }
  #walk-options-toggle {
    display: block;
  }
  #walk-toolbar .walk-options {
    display: none;
    order: 10;
  }
  .walk-options-open #walk-toolbar .walk-options {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding-top: 4px;
  }
  #walk-toolbar:has(#stop-walk:not([hidden])) #front-view {
    display: none;
  }
  #walk-status {
    order: 11;
    grid-column: 1 / -1;
    font-size: 10px;
    line-height: 1.4;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #touch-controls {
    bottom: calc(var(--phone-bottom) + 100px);
    left: calc(var(--phone-left) + 4px);
    right: auto;
  }
  .direction-pad {
    display: none;
  }
  #move-pad {
    display: grid;
    justify-items: center;
    gap: 5px;
  }
  #touch-controls #move-stick {
    display: grid;
    place-items: center;
    position: relative;
    width: 116px;
    height: 116px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--ui-border);
    background: var(--ui-surface);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }
  .joystick-thumb {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--ui-accent);
    opacity: 0.8;
    transform: translate(var(--stick-x, 0px), var(--stick-y, 0px));
    pointer-events: none;
  }
  #move-stick.active .joystick-thumb {
    opacity: 1;
  }
  #move-label {
    font-size: 10px;
    padding: 3px 8px;
    background: var(--ui-surface);
    color: var(--ui-text);
    border-radius: 8px;
  }
  #touch-look-hint {
    display: none;
    pointer-events: none;
    position: fixed;
    z-index: 5;
    bottom: calc(var(--phone-bottom) + 124px);
    right: calc(var(--phone-right) + 6px);
    padding: 7px 10px;
    border-radius: 8px;
    background: var(--ui-surface);
    color: var(--ui-text);
    font-size: 11px;
  }
  .walking:not(.map-open):not(.walk-options-open) #touch-look-hint {
    display: block;
  }
  #look-hint {
    top: calc(var(--phone-top) + 126px);
    left: var(--phone-left);
    right: var(--phone-right);
    font-size: 12px;
  }
  body.clean-view #view-tools {
    top: auto;
    bottom: var(--phone-bottom);
    right: var(--phone-right);
    left: auto;
  }
  body.clean-view #view-tools .view-options {
    display: contents;
  }
  body.clean-view #view-tools #clean-view {
    min-width: 150px;
  }
}
@media (max-width: 360px) {
  .brand-symbol {
    display: block;
  }
  .wordmark .brand-name {
    display: none;
  }
  .chapter h2,
  .story-inside .chapter h2 {
    font-size: 14px;
  }
  #explore-here {
    font-size: 11px;
    padding: 6px;
  }
}
@media (pointer: coarse) and (max-height: 500px) {
  .hero {
    width: 285px;
    right: auto;
    padding: 12px 16px;
  }
  .hero h1 {
    font-size: 29px;
    margin-bottom: 6px;
  }
  .hero p {
    display: none;
  }
  .hero #enter {
    margin-top: 4px;
  }
  .hero #direct-explore {
    margin-top: 0;
  }
  #view-tools {
    left: auto;
    width: 285px;
  }
  .chapter,
  .story-inside .chapter {
    max-width: 360px;
  }
  #touch-controls {
    bottom: calc(var(--phone-bottom) + 90px);
  }
  #touch-controls #move-stick {
    width: 100px;
    height: 100px;
  }
  .explore-hud > div {
    max-width: 45%;
  }
  .explore-hud #leave-explore {
    margin-left: auto;
  }
  .map-caption,
  .map-note {
    display: none;
  }
  #floor-map {
    width: 34%;
    float: left;
    margin-right: 3%;
  }
  #room-list {
    grid-template-columns: repeat(3, 1fr);
  }
}
