/* Functional surfaces float above the map; reading surfaces stay opaque. */
.j-map-options { display: block; max-width: 100%; }
.j-map-options-body { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.j-map-options > summary { display: none; }

@media (max-width: 780px), (max-height: 500px) and (pointer: coarse) {
  .joseon-page {
    --j-ui-font: var(--font-sans);
    --j-sheet-edge: 8px;
    --j-safe-top: env(safe-area-inset-top);
    --j-safe-bottom: env(safe-area-inset-bottom);
    --j-safe-start: env(safe-area-inset-left);
    --j-safe-end: env(safe-area-inset-right);
    --j-sheet-start: max(8px, var(--j-safe-start));
    --j-sheet-end: max(8px, var(--j-safe-end));
    --j-header-size: calc(56px + var(--j-safe-top));
    --j-sheet-gap: 20px;
    --j-sheet-radius: 28px;
    --j-sheet-motion: 220ms cubic-bezier(.2, .8, .2, 1);
    --j-sheet-safe: max(0px, calc(var(--j-safe-bottom) - var(--j-sheet-edge)));
    --j-sheet-chrome: max(var(--j-sheet-handle-size), 4rem);
    --j-control-radius: 14px;
    --j-content-radius: 20px;
    --j-control-fill: var(--joseon-paper-strong);
    --j-glass-fill: var(--joseon-surface);
    --j-glass-line: var(--joseon-line);
    --j-glass-filter: none;
    --j-floating-shadow: 0 4px 18px rgb(44 37 27 / .14);
    --j-sheet-shadow: 0 8px 40px rgb(44 37 27 / .2);
    --j-selection-shadow: 0 1px 5px rgb(44 37 27 / .12);
  }

  .joseon-page :is(.j-panel, .j-map-toolbar, .j-place-dialog, .maplibregl-ctrl) { font-family: var(--j-ui-font); }
  .joseon-page :is(button, summary) { -webkit-tap-highlight-color: transparent; }
  .joseon-page :is(button, summary):focus-visible { outline-width: 3px; outline-offset: 2px; }
  .j-head { height: var(--j-header-size); padding-top: var(--j-safe-top); padding-left: max(12px, var(--j-safe-start)); padding-right: max(12px, var(--j-safe-end)); }
  .j-workspace { height: calc(100dvh - var(--j-header-size)); }

  .j-panel {
    right: var(--j-sheet-end);
    bottom: calc(var(--j-keyboard-inset, 0px) + var(--j-sheet-edge));
    left: var(--j-sheet-start);
    overflow: hidden;
    padding-bottom: var(--j-sheet-safe);
    border: 1px solid var(--j-glass-line);
    border-radius: var(--j-sheet-radius);
    background: var(--joseon-paper);
    box-shadow: var(--j-sheet-shadow);
  }
  .j-panel.is-collapsed { height: calc(var(--j-sheet-chrome) + var(--j-sheet-safe) + 2px); }
  .j-panel-handle {
    height: var(--j-sheet-chrome);
    border-bottom: 0;
    border-radius: var(--j-sheet-radius) var(--j-sheet-radius) 0 0;
    background: var(--j-glass-fill);
    -webkit-user-select: none;
    user-select: none;
    -webkit-backdrop-filter: var(--j-glass-filter);
    backdrop-filter: var(--j-glass-filter);
  }
  .j-panel.is-collapsed .j-panel-handle { border-radius: inherit; }
  .j-panel-handle::before { top: 7px; width: 32px; height: 4px; border-radius: 4px; background: var(--joseon-muted); pointer-events: none; }
  .j-panel-toggle { padding: 14px 14px 5px 18px; }
  .j-panel-toggle:focus-visible { outline-offset: -5px; border-radius: calc(var(--j-sheet-radius) - 2px); }
  .j-panel-heading { gap: 1px; line-height: 1.3; }
  .j-panel-caption { color: var(--joseon-ink); opacity: .78; font-family: var(--joseon-display-font); font-size: .75rem; font-weight: 600; }
  .j-panel-heading strong { font-size: 1rem; letter-spacing: -.02em; }
  .j-panel-expand {
    margin-right: 10px;
    border: 0;
    border-radius: 50%;
    background: var(--joseon-surface);
    color: var(--joseon-ink);
  }
  .j-panel-body {
    height: calc(100% - var(--j-sheet-chrome));
    padding: 8px 16px 28px;
    background: var(--joseon-paper);
    -webkit-overflow-scrolling: touch;
    scroll-padding-top: 68px;
  }
  .j-panel.is-dragging :is(.j-panel-handle, .j-panel-body) { pointer-events: none; }
  /* Keep the handle as the capture target even while its children are inert. */
  .j-panel.is-dragging .j-panel-handle { pointer-events: auto; }

  .j-explore-toolbar {
    top: -8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    margin: 0 -4px 16px;
    padding: 4px;
    border: 0;
    border-radius: 999px;
    background: var(--j-control-fill);
  }
  .j-explore-toolbar :is(button, .j-workspace-views button) {
    min-width: 0;
    min-height: var(--j-control-size);
    padding: 8px 4px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--joseon-muted);
    font-size: .8125rem;
    font-weight: 600;
  }
  .j-explore-toolbar .j-workspace-views button[aria-pressed="true"] { color: var(--joseon-ink); }
  .j-explore-toolbar > button[aria-expanded="true"] {
    background: var(--joseon-surface);
    color: var(--joseon-red);
    box-shadow: var(--j-selection-shadow);
  }
  .j-intro { padding-block: 8px 16px; }
  .j-intro h1 { font-size: 1.5rem; }
  .j-panel-body :is(input, select), .j-place-dialog input { font-size: max(16px, 1rem); }
  .j-panel-body :is(input, select, .j-route-strategy select) { border-color: var(--joseon-line); }
  .j-panel-body :is(input, select) { border-radius: var(--j-control-radius); }
  .j-place-control { border: 1px solid var(--joseon-line); border-radius: var(--j-control-radius); background: var(--joseon-surface); overflow: hidden; }
  .j-place-pair { grid-template-columns: minmax(0, 1fr) 44px; }
  .j-place-control:focus-within { outline: 3px solid var(--joseon-blue); outline-offset: 2px; }
  .j-place-control select { min-height: 48px; border: 0; border-radius: 0; }
  .j-place-search { min-width: 48px; border: 0; border-left: 1px solid var(--joseon-line); border-radius: 0; background: var(--joseon-surface); font-size: .75rem; }
  .j-swap { width: 44px; min-height: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--j-control-fill); }
  .j-modes { gap: 4px; padding: 4px; border: 0; border-radius: 18px; background: var(--j-control-fill); }
  .j-mode { min-height: 48px; border: 0; border-radius: var(--j-control-radius); }
  .j-mode b { font-size: .875rem; }
  .j-mode[aria-pressed="true"] { background: var(--joseon-surface); color: var(--joseon-ink); box-shadow: var(--j-selection-shadow); }
  .j-mode[aria-pressed="true"] small { color: var(--joseon-muted); }
  .joseon-page .j-route-submit { min-height: 50px; border-radius: 999px; padding-inline: 20px; font-size: 1rem; }

  .j-result { padding-top: 0; }
  .j-result-summary { padding: 16px; border: 1px solid var(--joseon-line); border-radius: var(--j-content-radius); background: var(--joseon-surface); }
  .j-result-eyebrow { flex-wrap: wrap; align-items: center; margin-bottom: 8px; font-size: .75rem; }
  .j-result-heading h2 { font-size: 1.375rem; }
  .j-result-heading { padding-bottom: 12px; }
  .j-metrics { display: flex; flex-wrap: wrap; gap: 12px; }
  .j-metrics > div { flex: 1 1 6.75rem; min-width: 0; }
  .j-metrics > div:nth-child(even) { padding-left: 0; }
  .j-metrics > div:nth-child(-n+2) dd { font-size: clamp(1.75rem, 7.8vw, 2.125rem); }
  .j-metrics dt { font-size: .75rem; }
  .j-metrics small, .j-result-route { font-size: .6875rem; }
  .j-result-note { font-size: .75rem; }
  .j-result-modes { gap: 4px; padding: 4px; border-radius: 18px; background: var(--j-control-fill); }
  .j-result-mode { min-height: 44px; border: 0; border-radius: var(--j-control-radius); font-size: .875rem; }
  .joseon-page .j-result-mode[aria-pressed="true"] { border: 0; background: var(--joseon-surface); color: var(--joseon-ink); box-shadow: var(--j-selection-shadow); }
  .joseon-page :is(.j-result-mode, .j-mode, .j-panel-expand):active { background: var(--joseon-paper-strong); }
  .joseon-page .j-route-submit:active { border-color: var(--joseon-ink); background: var(--joseon-ink); }
  .j-result-actions { gap: 8px; }
  .j-result-actions button, .j-share-route, .j-preset, .j-list-more { border-radius: var(--j-control-radius); }
  .j-result-actions button { font-size: .875rem; }
  #result-period { font-size: .6875rem; }
  .joseon-page .j-result-jump { right: 10px; bottom: 8px; left: 10px; border-radius: 18px; padding: 12px 16px calc(12px + var(--j-sheet-safe)); box-shadow: var(--j-floating-shadow); }

  .j-map-toolbar { top: 12px; left: max(12px, calc(var(--j-safe-start) + 8px)); gap: 8px; max-width: calc(100% - 72px - var(--j-safe-start) - var(--j-safe-end)); }
  .j-map-toolbar > [data-explore-action] { display: none; }
  .j-panel.is-collapsed + .j-map-region .j-map-toolbar > [data-explore-action="route"] { display: inline-flex; align-items: center; }
  .j-map-toolbar > #fit-route:disabled { display: none; }
  .j-map-options { position: relative; display: block; }
  .j-map-options > summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: var(--j-control-size);
    min-width: 76px;
    padding: 8px 14px;
    list-style: none;
    border: 1px solid var(--j-glass-line);
    border-radius: 999px;
    background: var(--j-glass-fill);
    -webkit-backdrop-filter: var(--j-glass-filter);
    backdrop-filter: var(--j-glass-filter);
    box-shadow: var(--j-floating-shadow);
    color: var(--joseon-ink);
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
  }
  .j-map-options > summary::-webkit-details-marker { display: none; }
  .j-map-options[open] > summary { background: var(--joseon-surface); }
  .j-map-options-body {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    display: grid;
    gap: 12px;
    width: min(320px, calc(100vw - 32px));
    max-height: min(300px, calc(100dvh - var(--j-header-size) - var(--j-map-sheet-inset, 80px) - 80px));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px;
    border: 1px solid var(--joseon-line);
    border-radius: var(--j-content-radius);
    background: var(--joseon-surface);
    box-shadow: var(--j-sheet-shadow);
  }
  .j-map-options-body :is(.j-map-modes, .j-map-layers) { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; overflow: visible; border: 0; border-radius: 16px; background: var(--j-control-fill); box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
  .j-map-options-body :is(.j-map-modes, .j-map-layers) button { flex: 1 1 4.5rem; min-width: 0; min-height: 44px; padding-inline: 6px; border: 0; border-radius: 12px; font-size: .8125rem; }
  .j-map-modes button[aria-pressed="true"], .j-map-layers button[aria-pressed="true"] { background: var(--joseon-surface); color: var(--joseon-ink); font-weight: 700; box-shadow: var(--j-selection-shadow); }
  .j-map-layers button[aria-pressed="true"]::before { content: "✓"; margin-right: 4px; }
  .j-map-options-body .j-opacity-control { display: flex; flex-wrap: wrap; padding: 0; border: 0; background: transparent; box-shadow: none; }
  .j-map-options-body .j-opacity-control span { position: static; width: auto; height: auto; clip: auto; font-size: .75rem; }
  .j-map-options-body .j-opacity-control input { flex: 1; min-width: 0; min-height: 44px; }
  .joseon-page .j-fit-route { min-height: 44px; border-color: var(--j-glass-line); border-radius: 999px; background: var(--j-glass-fill); -webkit-backdrop-filter: var(--j-glass-filter); backdrop-filter: var(--j-glass-filter); box-shadow: var(--j-floating-shadow); font-size: .8125rem; }
  .j-map-options-body .j-fit-route { width: 100%; border-color: var(--joseon-line); background: var(--joseon-paper); box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
  .j-map .maplibregl-ctrl-group { overflow: hidden; border: 1px solid var(--j-glass-line); border-radius: 24px; background: var(--j-glass-fill); -webkit-backdrop-filter: var(--j-glass-filter); backdrop-filter: var(--j-glass-filter); box-shadow: var(--j-floating-shadow); }
  .j-map .maplibregl-ctrl-group button { width: 44px; height: 44px; }
  .j-map .maplibregl-ctrl-top-right .maplibregl-ctrl-group { margin-right: max(12px, calc(var(--j-safe-end) + 8px)); }
  .j-map .maplibregl-ctrl-bottom-right { right: var(--j-safe-end); }
  .j-map-legend { left: max(12px, calc(var(--j-safe-start) + 8px)); padding: 7px 10px; border-color: var(--joseon-line); border-radius: 12px; background: var(--joseon-surface); }
  .j-map-status { border-radius: var(--j-control-radius); background: var(--joseon-surface); }

  .j-place-dialog { position: fixed; inset: auto var(--j-sheet-end) calc(var(--j-keyboard-inset, 0px) + max(8px, var(--j-safe-bottom))) var(--j-sheet-start); width: calc(100% - var(--j-sheet-start) - var(--j-sheet-end)); max-height: min(720px, calc(var(--j-mobile-viewport, 100dvh) - max(8px, var(--j-safe-top)) - max(8px, var(--j-safe-bottom)))); margin: 0; border: 1px solid var(--joseon-line); border-radius: var(--j-sheet-radius); }
  .j-place-dialog[open] { display: flex; flex-direction: column; }
  .j-place-dialog > :not(.j-place-results) { flex-shrink: 0; }
  .j-place-dialog-head { padding: 18px 16px 12px; border: 0; }
  .j-place-dialog-head::before { content: none; }
  .j-place-dialog-head h2 { font-size: 1.125rem; }
  .j-place-dialog-head button { min-height: 44px; min-width: 44px; border: 0; border-radius: 999px; background: var(--j-control-fill); font-size: .8125rem; }
  .j-place-query input { min-height: 48px; border-radius: var(--j-control-radius); }
  .j-place-query { padding-inline: 16px; }
  .j-place-filter { font-size: .8125rem; }
  .j-place-results { flex: 1 1 auto; min-height: 0; max-height: none; overflow-y: auto; overscroll-behavior-y: contain; }
  .j-place-result { min-height: 64px; padding-inline: 16px; }
  .j-place-result b { font-size: 1rem; }
  .j-place-result small { font-size: .75rem; }
  .joseon-page[data-keyboard-open] .j-place-dialog-head { padding-top: 8px; }
  .joseon-page[data-keyboard-open] :is(.j-place-query > span, .j-place-search-summary) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); margin: -1px; padding: 0; white-space: nowrap; }
}

@media (max-height: 500px) and (pointer: coarse) {
  .j-panel { --j-sheet-ratio: 1; }
  .j-panel:not(.is-collapsed):not(.is-dragging) + .j-map-region { visibility: hidden; }
}

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) and (background: color-mix(in srgb, white, transparent)) {
  @media (max-width: 780px), (max-height: 500px) and (pointer: coarse) {
    .joseon-page { --j-control-fill: color-mix(in srgb, var(--joseon-ink) 6%, var(--joseon-paper)); --j-glass-fill: color-mix(in srgb, var(--joseon-surface) 86%, transparent); --j-glass-line: color-mix(in srgb, var(--joseon-line-strong) 40%, transparent); --j-glass-filter: blur(18px) saturate(1.15); }
    .j-panel { background: transparent; }
  }
}

@media (prefers-reduced-transparency: reduce), (prefers-contrast: more), (forced-colors: active) {
  .joseon-page { --j-glass-fill: var(--joseon-surface); --j-glass-line: var(--joseon-ink); --j-glass-filter: none; --j-floating-shadow: none; --j-sheet-shadow: none; --j-selection-shadow: none; }
  .j-panel { background: var(--joseon-paper); }
  .j-place-dialog::backdrop { -webkit-backdrop-filter: none; backdrop-filter: none; }
}

@media (prefers-contrast: more), (forced-colors: active) {
  .j-panel-caption { opacity: 1; }
  .joseon-page :is(.j-result-mode, .j-mode, [data-map-mode], [data-map-layer])[aria-pressed="true"]:not(:focus-visible),
  .j-explore-toolbar > button[aria-expanded="true"]:not(:focus-visible) { outline: 2px solid currentColor; outline-offset: -2px; }
}

@media (prefers-reduced-motion: reduce) {
  .joseon-page { --j-sheet-motion: 0s; }
  .joseon-page :is(.j-panel, .j-panel-body, button, summary) { transition: none; }
}
