/* Small-screen controls occupy real rows, rather than overlapping the canvas. */
#rankClose{display:none}
#mapSheetBackdrop{display:none}
.mapSheetHeader{display:contents}
@media(max-width:700px),(max-width:1000px) and (max-height:500px){
    html{overflow:auto}
    body{display:grid;grid-template-areas:"nav" "heading" "controls" "back" "map" "summary" "source";grid-template-rows:32px auto 44px auto minmax(180px,1fr) auto auto;gap:6px;height:100dvh;min-height:520px;box-sizing:border-box;padding:8px 10px max(8px,env(safe-area-inset-bottom));overflow:visible}
    #siteMapNav{grid-area:nav;position:static;inset:auto;padding:0;gap:8px}
    #siteMapNav a{padding:8px;min-height:32px;box-sizing:border-box}
    #header{grid-area:heading;position:static;inset:auto;padding:0;display:block;width:auto}
    #header .brand{padding:0;width:auto}
    #header h1{font-size:19px;margin:0}
    #dataSummary{font-size:10px;margin:4px 0 0;line-height:1.5}
    #mapLeftControls{grid-area:controls;position:static;inset:auto;width:auto;max-height:none;overflow:visible;display:grid;grid-template-columns:minmax(0,1fr) 110px;gap:8px;z-index:auto;pointer-events:auto}
    #mapLeftControls #timeDrawer,#mapLeftControls #panelToggle{position:static;width:100%;height:44px;margin:0;box-sizing:border-box}
    #mapLeftControls #timeCtl{height:42px;margin:0}
    #mapLeftControls #timeCtl select{height:42px;font-size:14px;padding:8px;min-width:0}
    #mapLeftControls #panelToggle{padding:8px;text-align:center;font-size:12px}
    #topCenter{grid-area:back;position:static;inset:auto;transform:none;justify-content:center;max-width:100%;gap:8px;min-width:0;z-index:auto}
    #backBtn{min-height:44px;white-space:nowrap;padding:8px 12px;box-shadow:none}
    #crumb2{padding:8px;font-size:12px;box-shadow:none;min-width:0;overflow-wrap:anywhere}
    #chart{grid-area:map;position:relative;inset:auto!important;top:auto!important;width:100%;height:100%!important;min-height:180px;padding:0;box-sizing:border-box}
    #mapSummary{grid-area:summary;position:static;inset:auto;transform:none;width:100%;padding:0;gap:4px;z-index:auto}
    #mapSummary #stats{gap:20px;width:auto;justify-content:center}
    #mapSummary #stats b{font-size:21px}
    #mapSummary #segCtl{width:100%;max-width:430px;box-sizing:border-box}
    #mapSummary #segCtl button{min-height:44px;font-size:12px}
    #sourceNote{grid-area:source;position:static;inset:auto;width:auto;max-width:none;text-align:center;line-height:1.5;font-size:9px;padding:0;z-index:auto}
    #snapshotNote{margin-left:8px}
    #mapSheetBackdrop{position:fixed;inset:0;width:100%;height:100%;border:0;background:rgba(23,44,73,.32);z-index:2999;cursor:pointer}
    body.sheet-open #mapSheetBackdrop{display:block}
    #mapLeftControls #panel,#infoCard{position:fixed;inset:auto 10px max(10px,env(safe-area-inset-bottom));width:auto;margin:0;padding:14px 16px;max-height:calc(100dvh - 48px);box-sizing:border-box;overflow-y:auto;overscroll-behavior:contain;z-index:3000;background:#fff;border-radius:16px;box-shadow:0 8px 32px rgba(23,44,73,.2);backdrop-filter:none}
    .mapSheetHeader{position:sticky;top:-14px;display:flex;justify-content:space-between;align-items:center;z-index:2;background:#fff;margin:-14px -16px 10px;padding:8px 12px;border-bottom:1px solid #e0e8f3;min-height:44px}
    #infoCard .mapSheetHeader{justify-content:flex-end}
    #rankClose,#infoCard .close{display:block;position:static;float:none;min-width:44px;min-height:44px;margin:0;border:0;border-radius:10px;background:#fff;color:#315ca5;font-size:18px;cursor:pointer}
    #panel .mapSheetHeader h2{margin:0;padding:0}
    #panel h2,#infoCard h2{padding-top:8px;line-height:1.5}
    #infoCard .cityline,.rank{min-height:38px;box-sizing:border-box;align-items:center;padding:8px 4px}
    #infoCard .enter{min-height:44px;width:100%;margin-top:12px}
    #infoCard .party{font-size:13px;overflow-wrap:anywhere;padding:10px 0}
    #emptyHint{max-width:calc(100% - 50px);box-sizing:border-box;pointer-events:none}
}
@media(max-width:1000px) and (max-height:500px) and (orientation:landscape){
    body{grid-template-areas:"nav nav" "heading controls" "map back" "map summary" "source source";grid-template-columns:minmax(0,1fr) 290px;grid-template-rows:28px 44px auto minmax(160px,1fr) auto;min-height:360px;gap:4px 10px}
    #header h1{font-size:17px}
    #mapLeftControls{grid-template-columns:minmax(0,1fr) 104px;gap:6px}
    #mapSummary{justify-content:center}
    #mapSummary #stats{gap:14px}
    #chart{min-height:180px}
}
