/* Shared shell and control language. Theme colors remain owned by styles.css. */
:root {
  --ui-font: Lato, Arial, sans-serif;
  --heading-font: Oswald, Lato, sans-serif;
  --heading-case: uppercase;
  --control-radius: 8px;
  --panel-radius: 12px;
  --control-height: 44px;
  --control-weight: 700;
  --control-font-size: .8125rem;
  --control-border: color-mix(in srgb, var(--ink) 22%, var(--card));
  --panel-shadow: 0 8px 24px color-mix(in srgb, var(--ink) 10%, transparent);
  --app-header-height: calc(70px + env(safe-area-inset-top));
}
:root[data-theme="hello-kitty"] {
  --ui-font: "Trebuchet MS", "Segoe UI", Verdana, Lato, sans-serif;
  --heading-font: var(--ui-font); --control-radius: 14px; --panel-radius: 18px;
}
:root[data-theme="cinnamoroll"], :root[data-theme="pompompurin"] { --control-radius: 12px; --panel-radius: 16px; }
:root[data-theme="burger-king"] {
  --ui-font: Flame, "Trebuchet MS", Verdana, Lato, sans-serif;
  --heading-font: var(--ui-font); --control-radius: 14px; --panel-radius: 18px;
}
:root[data-theme="windows-xp"] {
  --ui-font: Tahoma, "Segoe UI", Verdana, Lato, sans-serif;
  --heading-font: var(--ui-font); --control-radius: 4px; --panel-radius: 6px;
}
:root[data-theme="hacker"] {
  --ui-font: Fixedsys, "Fixedsys Excelsior", "Courier New", Consolas, "DejaVu Sans Mono", monospace;
  --heading-font: var(--ui-font); --control-radius: 2px; --panel-radius: 2px;
  --panel-shadow: none;
}

/* One real grid: title | secondary controls | navigation. No overlapping fixed headings. */
:root .app-header *, :root #mapView * { font-family: var(--ui-font); }
:root .app-header {
  position: fixed; z-index: 80; top: var(--app-viewport-top, 0px); inset-inline: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center;
  column-gap: 20px; min-height: calc(70px + env(safe-area-inset-top));
  padding: calc(8px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  background: var(--canvas); border-bottom: 1px solid var(--line);
}
:root .app-header .board-heading { display: contents; }
:root .app-header .heading-title {
  grid-column: 1; grid-row: 1; display: flex; align-items: center; gap: 12px; min-width: 0; margin: 0;
}
:root .app-header .heading-title h1 {
  flex: 1; min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--heading-font); font-size: clamp(1.375rem, 1.8vw, 1.875rem);
  font-weight: 700; line-height: 1.2; letter-spacing: -.015em; text-transform: var(--heading-case); color: var(--navy);
}
:root .app-header .heading-meta {
  grid-column: 2; grid-row: 1; display: flex; align-items: center; gap: 12px; min-width: 0; margin: 0;
}
:root .app-header .board-state { display: flex; flex: 0 1 auto; flex-wrap: nowrap; align-items: center; gap: 8px; margin: 0; }
:root .app-header .clock {
  display: flex; flex: 0 0 auto; flex-direction: column; align-items: flex-end; gap: 2px; margin-left: 4px;
}
:root .app-header .clock time { font: 700 20px/1 var(--ui-font); font-variant-numeric: tabular-nums; }
:root .app-header .clock span { font: 400 10px/1.2 var(--ui-font); white-space: nowrap; }
:root .app-header .product-nav {
  grid-column: 3; grid-row: 1; justify-self: end; align-self: start; display: flex; gap: 4px;
  margin: 0; padding: 3px; border: 1px solid var(--control-border); border-radius: calc(var(--control-radius) + 4px);
  background: var(--card);
}
:root .navigation-status:not(:empty) {
  grid-column: 1 / -1; padding-top: 4px; color: var(--ink); font: 700 12px/1.4 var(--ui-font);
}
:root .navigation-status:empty { display: none; }
:root .app-header :is(.status, .route-count) {
  min-height: 28px; padding: 5px 8px; border: 1px solid var(--line); border-radius: var(--control-radius);
  background: var(--sunken); color: var(--ink); font: 700 11px/1.3 var(--ui-font); white-space: nowrap;
}
:root .app-header .status { display: inline-flex; align-items: center; gap: 7px; }

/* View bounds follow the measured header, including text zoom and safe areas. */
:root .app-view, :root #mapView {
  position: fixed; top: calc(var(--app-viewport-top, 0px) + var(--app-header-height));
  left: 0; right: 0; bottom: auto; width: auto;
  height: calc(var(--app-viewport-height, 100dvh) - var(--app-header-height)); min-height: 0;
}
:root .app-view[hidden], :root .app-header [hidden] { display: none !important; }
:root #boardView .screen { position: absolute; inset: 0; height: 100%; width: auto; }
:root #boardView :is(.landing-menu, .filter-menu) {
  top: calc(var(--app-viewport-top, 0px) + var(--app-header-height));
  height: calc(var(--app-viewport-height, 100dvh) - var(--app-header-height));
}
:root #boardView.sidebar-docked .landing-menu { right: auto; }
:root #boardView.sidebar-docked #landingMenuClose { display: none; }
:root #boardView .landing-menu-head { padding-top: 14px; }
:root #boardView .board { padding-top: 8px; }
:root #mapView { grid-template-rows: minmax(0, 1fr); }
:root #mapView .map-frame, :root #mapView .bottom-sheet { grid-row: 1; }
:root #mapMenuButton { display: grid; }
:root #mapView .map-route-menu {
  top: calc(var(--app-viewport-top, 0px) + var(--app-header-height));
  height: calc(var(--app-viewport-height, 100dvh) - var(--app-header-height));
  z-index: 100;
}
:root #mapView .map-route-menu[hidden] { display: none !important; }
:root #mapView .map-route-menu .landing-menu-panel { animation: none; }
:root #mapView .map-route-menu .landing-menu-head { padding-top: 14px; }
:root #mapView .map-route-menu .route-filter-bar {
  display: flex; flex-direction: column; align-items: stretch; overflow: auto; min-height: 0;
}
:root #mapView .map-route-menu .route-filter-pill {
  flex: 0 0 auto; justify-content: flex-start; white-space: normal; text-align: left; padding: 12px;
}
:root #mapView .map-route-menu .pill-name { display: inline; }
:root #mapRouteMessage { margin: 16px; color: var(--muted); }
:root #mapRouteMessage[hidden] { display: none; }

/* Neutral controls share typography and geometry; active states use the theme's strong surface. */
:root :is(.product-nav a, .route-filter-pill, .map-tools button, .card-close, .card-action-btn,
  .landing-confirm-actions button, .sheet-handle-zone, .menu-button, .nearest-button,
  .filter-button, .sort-option, .date-step, .date-current, .clock-toggle, .landing-menu-close, .filter-menu-close) {
  min-height: var(--control-height); min-width: var(--control-height);
  font-family: var(--ui-font); font-size: var(--control-font-size); font-weight: var(--control-weight); line-height: 1.2;
  letter-spacing: 0; text-transform: none; box-sizing: border-box;
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
:root :is(.product-nav a, .route-filter-pill, .map-tools button, .card-close, .card-action-btn,
  .landing-confirm-actions button, .menu-button, .nearest-button, .filter-button, .clock-toggle,
  .sort-option, .landing-menu-close, .filter-menu-close) {
  border: 1px solid var(--control-border); border-radius: var(--control-radius); box-shadow: none;
  color: var(--navy); background: var(--card);
}
:root .product-nav a { display: inline-flex; padding: 0 12px; min-width: 58px; border-color: transparent; text-decoration: none; }
:root :is(.route-filter-pill.is-active, .product-nav a[aria-current], .card-action-btn,
  .landing-confirm-actions .confirm-departures, .sort-option[aria-pressed="true"]) {
  background: var(--navy); color: var(--card); border-color: var(--navy);
}
:root :is(.clock-toggle[aria-pressed="true"], .filter-button.is-filtering, .nearest-button[data-state="ready"]) {
  border-color: var(--blue); background: var(--sunken); color: var(--navy);
}
:root .nearest-button[data-state="ready"] .nearest-icon { stroke: var(--navy); }
:root .nearest-button[data-state="error"] { border-color: #c8102e; color: #c8102e; }
@media (hover: hover) {
  :root :is(.product-nav a, .route-filter-pill, .map-tools button, .card-close, .landing-confirm-actions button,
    .menu-button, .nearest-button, .filter-button, .clock-toggle, .sort-option):hover:not(:disabled) {
    box-shadow: inset 0 0 0 999px color-mix(in srgb, var(--ink) 7%, transparent);
  }
}
:root :is(.app-header, #mapView, .board-footer) :is(button, a):active:not(:disabled) { opacity: 1; filter: brightness(.94); }
:root :is(.app-header, #mapView, .board-footer) :is(button, a, input):focus-visible {
  outline: 3px solid var(--blue); outline-offset: 3px;
}
:root :is(.app-header, #mapView) button:disabled { opacity: .5; cursor: not-allowed; }
:root :is(.map-tools button, .card-close, .menu-button, .nearest-button, .filter-button) { width: 44px; height: 44px; padding: 0; }

/* Map typography is explicit, including native form controls and compact SVG labels. */
:root #mapView { font: 400 14px/1.45 var(--ui-font); }
:root #mapView :is(button, input, a, .dock-label, .street-label, .place-label text,
  .boat-label, .boat-number, .bridge-clearance-badge, .seamark-label) { font-family: var(--ui-font); }
:root #mapView :is(.fleet-heading h2, .card-vessel-name, .landing-confirm h2) {
  color: var(--navy); font: 700 18px/1.25 var(--ui-font); letter-spacing: -.015em;
}
:root #mapView .route-filter-bar { padding: 12px 16px; gap: 8px; background: var(--canvas); }
:root #mapView .route-filter-pill { gap: 8px; padding: 0 12px; }
:root #mapView .pill-code { font-weight: 800; }
:root #mapView .pill-name { font-size: 13px; font-weight: 400; }
:root #mapView .pill-dot { flex-shrink: 0; }
:root #mapView .sheet-header { padding: 20px 16px 16px; }
:root #mapView .fleet-heading { gap: 12px; align-items: center; }
:root #mapView :is(.fleet-heading > span, .fleet-footer, .card-hull-number) { font-size: 11px; line-height: 1.4; }
:root #mapView .fleet-description { margin: 6px 0 16px; font-size: 13px; line-height: 1.5; }
:root :is(#boatSearch, .landing-search input) {
  min-height: 44px; font: 400 max(16px, 1rem)/1.4 var(--ui-font); color: var(--ink);
  background: var(--card); border: 1px solid var(--control-border); border-radius: var(--control-radius);
}
:root #mapView .search-input::placeholder { color: var(--muted); opacity: 1; }
:root #mapView .sheet-scrollable { padding: 0 16px 16px; }
:root #mapView .boats { gap: 8px; }
:root #mapView .boat-row {
  padding: 14px 12px; gap: 8px 10px; border-radius: var(--panel-radius);
  border-color: var(--line); background: var(--card); font-size: 13px; line-height: 1.45;
}
:root #mapView .boat-row[aria-pressed="true"] {
  border-color: var(--blue); background: var(--sunken); box-shadow: inset 3px 0 var(--blue);
}
:root #mapView .boat-name { font-size: 14px; font-weight: 700; color: var(--navy); }
:root #mapView .boat-doing { font-size: 12px; color: var(--muted); }
:root #mapView .boats .empty {
  padding: 20px 16px; border: 1px solid var(--line); border-radius: var(--panel-radius);
  background: var(--sunken); color: var(--ink); font-size: 13px; line-height: 1.6;
}
:root #mapView .empty-title { display: block; margin-bottom: 6px; font-size: 14px; color: var(--navy); }
:root #mapView .empty p { margin: 0; }
:root #mapView :is(.vessel-card, .bridge-card, .seamark-card, .landing-confirm) {
  padding: 20px; border: 1px solid var(--control-border);
  border-radius: var(--panel-radius); box-shadow: var(--panel-shadow); background: var(--card);
}
:root #mapView .card-close { top: 12px; right: 12px; font-size: 22px; }
:root #mapView .card-title-row { min-height: 36px; padding-right: 48px; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
:root #mapView .card-meta-row { gap: 12px; flex-wrap: wrap; font-size: 12px; }
:root #mapView .card-status-line { line-height: 1.5; }
:root #mapView .card-action-btn { display: flex; align-items: center; justify-content: center; width: 100%; padding: 12px; margin-top: 16px; }
:root #mapView .landing-confirm-actions { margin-top: 16px; gap: 8px; }
:root #mapView .map-tools { top: 16px; right: 16px; gap: 8px; }
:root #mapView .map-tools #zoomIn, :root #mapView .map-tools #zoomOut { font-size: 22px; font-weight: 400; }
:root #mapView .map-context { top: 16px; left: 16px; padding: 12px; border-radius: var(--panel-radius); box-shadow: none; }
:root #mapView .map-context strong { font-size: 15px; line-height: 1.3; margin: 4px 0; }
:root #mapView .map-key { left: 16px; border-radius: var(--control-radius); }
:root #mapView .sheet-handle-zone { font-size: 13px; padding: 0 16px; color: var(--navy); }
:root #mapView .map-message { font-family: var(--ui-font); border-radius: var(--panel-radius); }
:root[data-theme="kuromi"] #chart :is(.dock-label, .boat-label) { fill: #f0abfc; }
:root[data-theme="kuromi"] #chart :is(.street-label, .place-label text) { fill: #cdb4e0; }

@media (max-width: 1100px) {
  :root .app-header .route-count { display: none; }
  :root #mapView .pill-name { display: none; }
}
/* Phone header: a row of controls over a line of status text.
   Row one is floored by the 44px controls, not by the title, so the title has to stay on one line —
   wrapped to two it pushed the whole board down for a name the reader already knows. Row two carries
   no controls at all, which is what lets it collapse to text height. */
@media (max-width: 820px) {
  /* 88px: 52 for the control row — the nav's 44px links inside its 3px padding and 1px border are
     the tallest thing on it — plus the status line, the row gap and the padding. app-shell.js
     re-measures this into the custom property, so the literal only has to be close enough that the
     first paint does not jump. */
  :root { --app-header-height: calc(88px + env(safe-area-inset-top)); }
  :root .app-header {
    grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: minmax(44px, auto) auto;
    column-gap: 12px; row-gap: 4px; min-height: calc(88px + env(safe-area-inset-top));
    padding: calc(6px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
  }
  :root .app-header .heading-title { gap: 8px; }
  /* Sentence case and one line: uppercase Oswald at this width spends its characters on height
     rather than on the part of the name that tells two landings apart. Ellipsis over wrap. */
  :root .app-header .heading-title h1 { font-size: .9375rem; text-transform: none; letter-spacing: 0; }
  :root .app-header .product-nav { grid-column: 2; align-self: start; }
  :root .app-header .product-nav a { min-width: 46px; padding: 0 8px; }
  :root .app-header .heading-meta { grid-column: 1 / -1; grid-row: 2; min-height: 0; justify-content: flex-start; gap: 8px; }
  /* Truncate rather than widen: the date is the last thing here worth its pixels, and an overflowing
     header scrolls the whole document sideways. */
  :root .app-header .board-heading .board-state { flex: 1 1 auto; min-width: 0; flex-wrap: nowrap; justify-content: flex-start; gap: 8px; overflow: hidden; }
  :root .app-header .board-state > :not(:first-child):not(.clock)::before { content: "·"; margin-right: 8px; color: var(--muted); }
  /* The status keeps its surface. The visual-polish check reads backgroundColor for contrast and
     scores a transparent one as black, so this chip cannot become bare text. The count can. */
  :root .app-header :is(.status, .route-count) { min-height: 0; padding: 2px 7px; font-size: 11px; }
  :root .app-header .route-count { display: inline-flex; padding: 0; border: 0; background: none; color: var(--muted); }
  :root .app-header .clock { flex: 0 1 auto; flex-direction: row; flex-wrap: nowrap; justify-content: flex-end; align-items: baseline; gap: 6px; margin-left: auto; min-width: 0; }
  :root .app-header .clock time { flex-shrink: 0; font-size: 12px; }
  :root .app-header .clock time::after { content: "·"; margin-left: 6px; color: var(--muted); }
  :root .app-header .clock span { min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: right; font-size: 11px; color: var(--muted); }
  :root .app-header .navigation-status:not(:empty) { grid-row: 3; }
}
@media (max-width: 700px) {
  :root #mapView { grid-template-rows: minmax(0, 1fr) auto; }
  :root #mapView .bottom-sheet { grid-row: 2; }
  :root #mapView .route-filter-bar { padding: 8px 12px; }
  :root #mapView .map-context { top: 12px; left: 12px; max-width: calc(100% - 88px); padding: 8px 10px; }
  :root #mapView .map-context strong { font-size: 13px; margin: 0; }
  :root #mapView .map-tools { top: 12px; right: 12px; }
  :root #mapView .sheet-header { padding: 12px; }
  :root #mapView .fleet-description { display: none; }
  :root #mapView .fleet-heading { margin-bottom: 10px; }
  :root #mapView .sheet-scrollable { padding: 0 12px 12px; }
  :root #mapView :is(.vessel-card, .bridge-card, .seamark-card, .landing-confirm) { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  :root :is(.app-header, #mapView, .board-footer) * { transition: none !important; animation: none !important; }
}
