:root {
  --bg: #1E1F22;
  --panel: rgba(30, 31, 34, 0.92);
  --line: #35373C;
  --text: #ECEDEF;
  --muted: #9A9CA3;
  --accent: #FF8A1F;
  --danger: #E5484D;
  --touch: 44px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: var(--bg); }
body { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* touch-action: none keeps the browser from scrolling/zooming the page while orbiting or pinching. */
#unity-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; background: var(--bg); touch-action: none; outline: none; }

#map-screen { position: fixed; inset: 0; z-index: 1; }
body.view-3d #map-screen { visibility: hidden; pointer-events: none; }
#map { position: absolute; inset: 0; }

#search { position: absolute; z-index: 2; display: flex; gap: 8px; left: max(12px, var(--safe-l)); right: max(12px, var(--safe-r)); top: max(12px, var(--safe-t));
          max-width: 420px; }
#search input { flex: 1; min-width: 0; height: var(--touch); padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); outline: none;
                font-size: 16px; /* 16 px stops iOS from zooming on focus */ }
#search input:focus { border-color: var(--accent); }
#search button { min-width: var(--touch); height: var(--touch); padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); }

/* Sits above Mapbox's own attribution and logo, which stay visible at the bottom corners. */
#panel { position: absolute; z-index: 2; display: flex; flex-direction: column; gap: 10px; padding: 12px;
         left: max(12px, var(--safe-l)); right: max(12px, var(--safe-r)); bottom: calc(34px + var(--safe-b));
         max-width: 420px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(6px); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
#size-label { font-weight: 600; font-variant-numeric: tabular-nums; }
#hint { color: var(--muted); font-size: 12px; }
#search-error { margin: 0; color: var(--danger); font-size: 13px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips button { min-width: var(--touch); height: var(--touch); padding: 0 12px; border-radius: 22px; border: 1px solid var(--line); background: transparent; font-variant-numeric: tabular-nums; }
.chips button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

button.primary { height: var(--touch); padding: 0 18px; border-radius: 10px; border: 0; background: var(--accent); color: #1E1F22; font-weight: 700; }
button:disabled { opacity: 0.5; cursor: default; }

/* Square corner handles: a 44 px hit area around a small visible square. */
.handle { width: var(--touch); height: var(--touch); display: grid; place-items: center; cursor: nwse-resize; touch-action: none; }
.handle::after { content: ""; width: 16px; height: 16px; background: #fff; border: 3px solid var(--accent); border-radius: 3px; }

#overlay { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
#overlay > * { pointer-events: auto; }
#toast { position: absolute; left: 50%; top: max(12px, var(--safe-t)); transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 8px 14px; border-radius: 10px;
         background: var(--panel); border: 1px solid var(--line); font-size: 13px; text-align: center; pointer-events: none; }
#toast.error { border-color: var(--danger); color: var(--danger); pointer-events: auto; }

#splash { position: fixed; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center;
          padding: max(24px, var(--safe-t)) max(16px, var(--safe-r)) max(24px, var(--safe-b)) max(16px, var(--safe-l));
          background: radial-gradient(ellipse at 50% 40%, #2A2C31 0%, #1E1F22 70%); color: var(--muted); text-align: center; }
#splash h1 { margin: 0 0 24px; font-size: clamp(24px, 5vw, 36px); font-weight: 700; color: var(--text); }
#bar { width: min(72vw, 320px); height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
#fill { width: 0; height: 100%; background: var(--accent); transition: width 0.2s; }
#status { margin-top: 10px; font-size: 13px; font-variant-numeric: tabular-nums; }
#error { max-width: 440px; margin-top: 16px; color: var(--danger); }
#error small { display: block; margin-top: 6px; color: #7C7F87; word-break: break-word; }
#splash-back { margin-top: 20px; height: var(--touch); padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: transparent; }

.mapboxgl-ctrl-bottom-right, .mapboxgl-ctrl-bottom-left { margin-bottom: var(--safe-b); }

/* Map settings: a right column on desktop, a bottom sheet on phones. */
#settings { position: absolute; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
            backdrop-filter: blur(6px); overflow: hidden;
            top: max(12px, var(--safe-t)); right: max(12px, var(--safe-r)); bottom: max(12px, var(--safe-b)); width: 320px; }
#settings header { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
#settings h2 { margin: 0; font-size: 15px; font-weight: 600; }
#settings h3 { margin: 18px 0 8px; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
#settings h3:first-child { margin-top: 4px; }
#settings .body { flex: 1; overflow-y: auto; padding: 12px 16px; }
#settings footer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
#settings footer button:not(.primary) { height: var(--touch); padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: transparent; }
#settings footer .primary { flex: 1; }
#settings-toggle { width: var(--touch); height: var(--touch); border: 0; background: transparent; border-radius: 10px; }
#settings-toggle::before { content: ""; display: block; width: 10px; height: 10px; margin: auto; border-right: 2px solid var(--text); border-bottom: 2px solid var(--text); transform: rotate(-45deg); }
#settings.collapsed { bottom: auto; width: auto; min-width: 200px; }
#settings.collapsed .body, #settings.collapsed footer { display: none; }
#settings.collapsed header { border-bottom: 0; }
#settings.collapsed #settings-toggle::before { transform: rotate(45deg); }

#map-types { display: flex; flex-direction: column; gap: 8px; }
.card { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 8px; text-align: left; border-radius: 10px; border: 1px solid var(--line); background: transparent; }
.card svg { flex: none; width: 64px; height: 48px; border-radius: 6px; }
.card b { display: block; font-size: 14px; font-weight: 600; }
.card small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; line-height: 1.3; }
.card[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.card:disabled { opacity: 0.45; cursor: default; }

.switch { display: flex; align-items: center; gap: 12px; min-height: var(--touch); cursor: pointer; }
.switch input { appearance: none; flex: none; width: 40px; height: 22px; margin: 0; border-radius: 11px; background: var(--line); position: relative; transition: background 0.15s; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }
#sea-note, .note { margin: 0 0 4px; color: var(--muted); font-size: 12px; }
.num.wide { width: 100%; }
.num.wide input { flex: 1; width: auto; }

/* Desktop: the model gets the area left of the settings column, on a neutral backdrop. */
body.view-3d { background: #D1D4D9; }
body.view-3d #unity-canvas { background: #D1D4D9; }
@media (min-width: 721px) {
  /* A canvas is a replaced element: `width: auto` would keep its pixel width, so the width is explicit. */
  body.view-3d #unity-canvas { inset: 0 auto 0 0; width: calc(100% - max(12px, var(--safe-r)) - 332px); }
}

.slider { display: flex; align-items: center; gap: 12px; }
.slider input[type="range"] { flex: 1; min-width: 0; height: var(--touch); accent-color: var(--accent); }
.num { display: flex; align-items: center; gap: 4px; height: 36px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; }
.num input { width: 52px; border: 0; background: transparent; text-align: right; outline: none; font-size: 16px; }
.num i { font-style: normal; color: var(--muted); }

#to-2d { position: absolute; width: var(--touch); height: var(--touch); border-radius: 22px; border: 1px solid var(--line); background: var(--panel); font-weight: 600;
         bottom: max(16px, var(--safe-b)); right: calc(max(12px, var(--safe-r)) + 320px + 12px); }

@media (max-width: 720px) {
  #settings { top: auto; left: max(12px, var(--safe-l)); right: max(12px, var(--safe-r)); bottom: max(12px, var(--safe-b)); width: auto; max-height: 58vh; }
  #settings.collapsed { left: auto; }
  #settings-toggle::before { transform: rotate(45deg); }
  #settings.collapsed #settings-toggle::before { transform: rotate(-135deg); }
  #to-2d { top: max(12px, var(--safe-t)); right: max(12px, var(--safe-r)); bottom: auto; }
  #toast { left: max(12px, var(--safe-l)); transform: none; max-width: calc(100vw - 88px); text-align: left; }
}
