/* ==========================================================================
   MiniRR: phone fixes (D4, 3 Dec 2026)
   Loaded AFTER style.css and about.css, so these rules win.
   Everything here is inside a "phone" media query: desktop is untouched.
   Goals: nothing off-screen, nothing on top of something else, and every
   button at least 44 px tall (Apple's and Google's minimum for a thumb).
   See docs/MOBILE.md for what was found and why.
   ========================================================================== */

/* ------------------------------------------------------------------ app page */
@media (max-width: 640px) {
	/* --- bottom sheet (the sidebar): respect the iPhone home bar */
	#panel {
		padding-bottom: calc(12px + env(safe-area-inset-bottom));
	}
	/* panel buttons were 20-30 px tall */
	#panel .seg button,
	#panel summary,
	#radioBtn,
	#chiefPreview,
	#credits,
	#aboutLink {
		min-height: 44px;
	}
	#aboutLink {
		display: inline-flex;
		align-items: center;
	}

	/* --- train info bar: the name column was squeezed to 0 px wide and the
	   Details / Close buttons were pushed off the right edge of the screen.
	   Now: row 1 = name + Details + Close, row 2 = story player + Locomotive. */
	#trainBar {
		top: max(12px, env(safe-area-inset-top));
	}
	#trainBar .tbTop {
		flex-wrap: wrap;
		row-gap: 8px;
	}
	#tbHead {
		order: 0;
		flex: 1 1 140px;
	}
	#trainBar .fold {
		order: 1;
		height: 44px;
	}
	#tbClose {
		order: 1;
		width: 44px;
		height: 44px;
		margin-right: -6px;
		font-size: 24px;
	}
	#story {
		order: 2;
		flex: 1 1 160px;
		min-width: 0;
		max-width: none;
	}
	#storyPlay {
		width: 44px;
		height: 44px;
	}
	#tbHolo {
		order: 3;
		min-height: 44px;
	}
	#tbLock,
	#tbViews button {
		min-height: 44px;
	}
	.tbLocos summary {
		padding: 12px 0;
	}
	/* "Details" open: the bar grew to 426 px and slid under the corner map
	   and camera pad. Let it scroll above the sheet and hide those two
	   while the details are open. */
	#trainBar:not(.collapsed) {
		z-index: 4;
		max-height: calc(58% - 24px);
		overflow-y: auto;
		overscroll-behavior: contain;
	}
	#trainBar:not(.collapsed) #tbStats {
		max-height: none;
	}
	body:has(#trainBar:not(.collapsed):not([hidden])) #radarCorner,
	body:has(#trainBar:not(.collapsed):not([hidden])) #nav {
		visibility: hidden;
	}

	/* --- camera pad: on a phone it covered two thirds of the map. Fingers
	   already pan (one finger), zoom (pinch) and turn/tilt (two-finger drag),
	   so keep only compass, reset view, look and sound, at thumb size. */
	#nav {
		gap: 6px;
	}
	#nav .pad {
		display: flex;
	}
	#nav .pad button:not([data-act="home"]),
	#nav .zoom {
		display: none;
	}
	#nav .pad button,
	#nav .lookBtn {
		width: 44px;
		height: 44px;
		font-size: 18px;
	}
	#compassRose {
		width: 44px;
		height: 44px;
	}
	/* the look panel opens to the left of the pad; keep it on screen */
	#lookPanel {
		width: min(220px, calc(100vw - 100px));
		max-height: 60vh;
		overflow-y: auto;
	}

	/* --- replay bar: it sat at the top, hidden under the train bar.
	   Move it to the bottom of the screen, in thumb reach, over the sheet. */
	body #replayBar,
	body.replaying #replayBar,
	body.hasTrainBar #replayBar {
		top: auto;
		bottom: calc(12px + env(safe-area-inset-bottom));
		left: 12px;
		right: 12px;
		width: auto;
		min-width: 0;
		margin-left: 0;
		transform: none;
		z-index: 8;
		padding: 8px 10px;
		gap: 6px 8px;
	}
	/* row 1: REPLAY tag, play, time + scrubber; row 2: speeds, Follow, Live */
	#replayBar .rmain {
		flex: 1 1 200px;
	}
	body.replaying #panel {
		padding-bottom: 170px;
	}
	#rbPlay {
		width: 44px;
		height: 44px;
	}
	#replayBar .rates button,
	#replayBar .ghost,
	#replayBar .live {
		min-height: 44px;
	}
	#rbScrub {
		height: 32px;
	}

	/* --- video pin card: it was 340 px wide, pinned 200 px from the right,
	   so on a phone half of it was off the left edge. */
	#spotCard {
		left: 12px;
		right: 12px;
		width: auto;
		top: auto;
		bottom: calc(12px + env(safe-area-inset-bottom));
		max-height: calc(100% - 24px);
		z-index: 9;
	}
	#spotCard .close,
	#placeCard .close {
		width: 44px;
		height: 44px;
		top: 2px;
		right: 2px;
		font-size: 22px;
	}
	#spotCard form button {
		min-height: 44px;
	}
	/* iPhone zooms the whole page into any text box under 16 px */
	#spotCard input,
	#panel input,
	#lookPanel select {
		font-size: 16px;
	}
	/* the camera pins are 26 px dots; give them an invisible 44 px finger area */
	.spot::after {
		content: "";
		position: absolute;
		inset: -9px;
		border-radius: 50%;
	}
	#placeCard {
		width: min(320px, calc(100vw - 24px));
	}

	/* --- hologram: close / enlarge were 30 px; part chips were 19 px */
	#hClose {
		width: 44px;
		height: 44px;
	}
	#holo .hSize {
		height: 44px;
	}
	/* bigger chips in ONE sideways-scrolling row, so they don't cover the model */
	#holo .hParts {
		flex-wrap: nowrap;
		overflow-x: auto;
		scrollbar-width: none;
	}
	.hParts button {
		flex: none;
		min-height: 34px;
		padding: 4px 12px;
		font-size: 12px;
		white-space: nowrap;
	}
}

/* ---------------------------------------------------------- landscape phone
   A phone on its side is 812 x 375 or so: wider than 640, so it got the
   desktop layout squeezed into 375 px of height (sidebar, train bar, corner
   map and camera pad all on top of each other). Treat it as "watch mode". */
@media (max-height: 480px) and (orientation: landscape) {
	#panel {
		top: 8px;
		bottom: auto;
		right: auto;
		left: max(8px, env(safe-area-inset-left));
		width: 280px;
		border-radius: 14px;
		max-height: calc(100% - 16px);
	}
	/* watching a train: the sidebar steps aside, the train gets the screen.
	   Closing the train bar (x) brings the sidebar back. */
	body.hasTrainBar #panel {
		display: none;
	}
	#trainBar {
		left: max(8px, env(safe-area-inset-left));
		bottom: 8px;
		top: auto;
		width: calc(100vw - 16px - 136px);
		margin-left: 0;
		transform: none;
		padding: 6px 10px;
	}
	#trainBar:not(.collapsed) {
		max-height: calc(100% - 16px);
		overflow-y: auto;
	}
	#trainBar .tbTop {
		flex-wrap: wrap;
	}
	#tbClose,
	#trainBar .fold,
	#storyPlay,
	#tbHolo,
	#tbLock,
	#tbViews button {
		min-height: 40px;
	}
	#tbClose {
		width: 40px;
	}
	/* camera pad as a short row in the top-right corner */
	#nav {
		top: 8px;
		right: max(8px, env(safe-area-inset-right));
		bottom: auto;
		flex-direction: row;
		padding: 4px 6px;
		gap: 4px;
	}
	#nav .seg,
	#nav .zoom,
	#nav .pad button:not([data-act="home"]) {
		display: none;
	}
	#nav .pad {
		display: flex;
	}
	#nav .pad button,
	#nav .lookBtn {
		width: 44px;
		height: 44px;
		font-size: 18px;
	}
	#compassRose {
		width: 40px;
		height: 40px;
	}
	#compassHeading {
		display: none;
	}
	#lookPanel {
		top: calc(100% + 6px);
		right: 0;
		max-height: calc(100vh - 80px);
		overflow-y: auto;
	}
	#radarCorner {
		right: max(8px, env(safe-area-inset-right));
		bottom: 8px;
		width: 120px;
	}
	#radarMini {
		width: 120px;
		height: 120px;
	}
	#replayBar,
	body.replaying #replayBar,
	body.hasTrainBar #replayBar {
		top: 8px;
		bottom: auto;
		left: max(8px, env(safe-area-inset-left));
		width: calc(100vw - 16px - 240px);
		min-width: 0;
		margin-left: 0;
		transform: none;
		padding: 6px 10px;
	}
	body.replaying #panel {
		display: none;
	}
	body.replaying #nav {
		top: 8px;
	}
	#spotCard {
		right: 8px;
		bottom: 8px;
		top: 8px;
		width: min(340px, calc(100vw - 16px));
		max-height: none;
	}
}

/* ---------------------------------------------------------------- about deck */
@media (max-width: 640px) {
	/* the "Open the live app" pill sat on top of each slide's first line */
	.slide {
		padding-top: 64px;
		padding-bottom: 170px;
	}
	#exitDeck {
		top: max(12px, env(safe-area-inset-top));
		right: 12px;
		min-height: 44px;
	}

	/* progress rail: ten stops were squeezed into a 61 px strip (7 px apart,
	   16 px targets) and the current stop's name ran off the left edge.
	   Now the track gets its own full-width row above the buttons. */
	#rail {
		flex-wrap: wrap;
		height: auto;
		row-gap: 0;
		column-gap: 10px;
		justify-content: flex-end;
		padding: 0 16px calc(10px + env(safe-area-inset-bottom));
	}
	#rail .track {
		order: -1;
		flex: 1 1 100%;
		margin: 0 8px;
	}
	#railStops button::after {
		content: "";
		position: absolute;
		inset: -14px -10px;
	}
	#rail .count {
		margin-right: auto;
	}
	#rail button#prev,
	#rail button#next,
	#rail .vo {
		width: 44px;
		height: 44px;
	}

	/* sources slide: a one-column list with a max height overflowed sideways
	   (off-screen) instead of scrolling */
	#sourceList {
		columns: auto;
		column-count: auto;
		max-height: none;
		overflow: visible;
	}
}
