/* Full-bleed map with floating Apple Maps-style controls and an info sheet
   (bottom sheet on phones, floating card on wide screens). */
:root {
  --ground: #E8E7E3;           /* outside campus; also what the browser shows under its own bars */
  --ink: #1B2A33;
  --ink-2: #56626A;
  --ink-3: #858D93;
  --glass: rgba(255, 255, 255, 0.86);
  --hair: rgba(0, 0, 0, 0.1);
  --blue: #007AFF;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(0, 0, 0, 0.12);
  --map-font: 'Noto Sans TC', 'Noto Sans CJK TC', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  --ui-font: -apple-system, BlinkMacSystemFont, 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
  --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);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
html { background: var(--ground); }
body {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--ui-font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }

/* Map runs under the status bar and the browser's toolbars: size it to the large viewport. */
#viewport {
  position: fixed; left: 0; top: 0;
  width: 100%; height: 100%; height: 100lvh;
  touch-action: none;
  cursor: grab;
  overflow: hidden;
  user-select: none; -webkit-user-select: none;
}
#viewport.dragging { cursor: grabbing; }
#map-host, #map-host svg { width: 100%; height: 100%; display: block; }
#map-host svg { font-family: var(--map-font); text-rendering: geometricPrecision; transform-origin: 0 0; }
#viewport.moving #map-host svg { will-change: transform; }

/* current location */
#me-dot {
  position: absolute; left: 0; top: 0;
  width: 22px; height: 22px; margin: -11px 0 0 -11px;
  border-radius: 50%;
  background: var(--blue);
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  will-change: transform;
}
#me-dot.stale { background: #8E8E93; }

/* floating controls */
.controls {
  position: fixed;
  display: flex; flex-direction: column;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 10;
}
.controls-top { top: calc(var(--safe-t) + 12px); right: calc(var(--safe-r) + 12px); }
.controls-zoom { right: calc(var(--safe-r) + 12px); bottom: calc(var(--safe-b) + 24px); }
@media (pointer: coarse) { .controls-zoom { display: none; } }
.ctl {
  width: 44px; height: 44px;
  touch-action: manipulation;
  display: grid; place-items: center;
  border: 0; padding: 0; margin: 0;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.ctl svg { width: 22px; height: 22px; }
.ctl svg path { stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; fill: none; }
#btn-north svg path { stroke: none; }
#btn-north .n-red { fill: #E5463A; }
#btn-north .n-grey { fill: #9AA0A6; }
.ctl:active { background: rgba(0, 0, 0, 0.06); }
.ctl:focus-visible { outline: 2px solid var(--blue); outline-offset: -3px; border-radius: 10px; }
.ctl-sep { height: 1px; margin: 0 8px; background: var(--hair); }
#btn-locate.on { color: var(--blue); }
#btn-locate.follow .loc-arrow { fill: var(--blue); stroke: var(--blue); }
#btn-locate.busy .loc-arrow { animation: blink 1s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.35; } }

/* toast */
#toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 14px);
  transform: translateX(-50%);
  max-width: min(420px, calc(100vw - 140px));
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(30, 30, 32, 0.88);
  color: #fff;
  font-size: 14px; line-height: 1.4;
  box-shadow: var(--shadow);
  z-index: 20;
  text-align: center;
}

/* info sheet: bottom sheet on phones */
#sheet {
  position: fixed;
  left: calc(var(--safe-l) + 8px); right: calc(var(--safe-r) + 8px);
  bottom: calc(var(--safe-b) + 8px);
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-radius: 16px;
  box-shadow: var(--shadow);
  z-index: 15;
  display: flex; flex-direction: column;
  max-height: calc(100% - var(--safe-t) - var(--safe-b) - 80px);
}
#sheet-handle {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 18px 18px 14px;
  border: 0; background: transparent;
  font: inherit; color: inherit; text-align: left;
  cursor: pointer;
}
#sheet-handle:focus-visible { outline: 2px solid var(--blue); outline-offset: -4px; border-radius: 16px; }
.grabber {
  position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  width: 36px; height: 5px; border-radius: 3px; background: rgba(0, 0, 0, 0.18);
}
.sheet-title { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.t-sub { font-size: 12px; color: var(--ink-3); }
.t-main { font-size: 20px; font-weight: 700; letter-spacing: 0.02em; }
.chev {
  width: 10px; height: 10px; margin-right: 4px;
  border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3);
  transform: rotate(-135deg) translate(-2px, -2px);
  transition: transform 0.2s;
}
#sheet.open .chev { transform: rotate(45deg); }
#sheet-body {
  display: none;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 0 18px 18px;
  -webkit-overflow-scrolling: touch;
}
#sheet.open #sheet-body { display: grid; gap: 18px; }
#sheet-body section { min-width: 0; padding-top: 14px; border-top: 1px solid var(--hair); }
h2 { margin: 0 0 6px; font-size: 15px; font-weight: 700; }
h2 span { font-weight: 400; color: var(--ink-3); font-size: 13px; margin-left: 4px; }
p { margin: 0; font-size: 14px; line-height: 1.65; color: var(--ink-2); }
.fine p { font-size: 12.5px; color: var(--ink-3); }

.code { display: flex; gap: 10px; align-items: flex-end; margin: 6px 0 10px; }
.code div { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.code b { font-family: var(--map-font); font-size: 26px; font-weight: 800; line-height: 1.1; padding-bottom: 4px; border-bottom: 1.5px solid var(--ink-3); color: var(--ink); }
.code div:first-child b { font-size: 19px; font-weight: 700; }
.code b.wing { color: #6A97AB; }
.code i { font-style: normal; font-size: 12px; color: var(--ink-3); }

.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 14px; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 10px; }
.sw { width: 26px; height: 14px; border-radius: 2px; flex: none; }
.sw-teach { background: linear-gradient(90deg, #173A4C 0 33%, #2D5C73 33% 66%, #4A7C93 66%); }
.sw-bldg { background: #D5D2CC; }
.sw-dorm { background: #E1DED9; }
.sw-water { background: #C8DEEA; }
.sw-green { background: #DAE8D0; box-shadow: inset 0 0 0 1px #C4D8B6; }
.sw-me { width: 14px; height: 14px; margin: 0 6px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 2px #fff, 0 0 0 7px rgba(0, 122, 255, 0.18); }

/* wide screens: floating card top-left */
@media (min-width: 760px) {
  #sheet {
    left: calc(var(--safe-l) + 16px); right: auto;
    top: calc(var(--safe-t) + 16px); bottom: auto;
    width: 340px;
    max-height: calc(100% - var(--safe-t) - var(--safe-b) - 32px);
  }
  .grabber { display: none; }
  #sheet-handle { padding: 16px 18px; }
  .controls-top { top: calc(var(--safe-t) + 16px); right: calc(var(--safe-r) + 16px); }
  .controls-zoom { right: calc(var(--safe-r) + 16px); bottom: calc(var(--safe-b) + 24px); }
}

@media (prefers-reduced-motion: reduce) {
  .chev { transition: none; }
  #btn-locate.busy .loc-arrow { animation: none; }
}
