/* Study page: Junction school */
.study { padding-top: clamp(2rem, 5vw, 3rem); }

.back-link {
  display: inline-flex; align-items: center; gap: 0.4rem;
  color: var(--muted); font-size: 0.925rem; font-weight: 500; text-decoration: none;
  transition: color 0.2s;
}
.back-link:hover { color: var(--text); }

.study-head { max-width: 720px; margin: 1.75rem 0 2rem; }
.study-head h1 { font-size: clamp(2.2rem, 5vw, 3.4rem); font-weight: 800; letter-spacing: -0.035em; margin-bottom: 1rem; }
.sub { color: var(--muted); font-size: 1.05rem; max-width: 46em; }

/* Map picker */
.maps {
  display: inline-flex; flex-wrap: wrap; gap: 4px;
  margin: 0 0 2.5rem; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
}
.maps button {
  min-height: 44px; padding: 0 1.15rem;
  background: transparent; color: var(--muted);
  border: 0; border-radius: 10px;
  font: inherit; font-weight: 600; font-size: 0.95rem; cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.maps button:hover { color: var(--text); }
.maps button.on { background: var(--accent-fill); color: #fff; }

.map-panel[hidden] { display: none !important; }
.map-panel h2 { font-size: clamp(1.5rem, 3vw, 2rem); margin-bottom: 0.5rem; }

/* Route and arm buttons */
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 1.25rem 0 1rem; }
.tabs button {
  min-height: 40px; padding: 0 1rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 999px;
  font: inherit; font-weight: 600; font-size: 0.9rem; cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.tabs button:hover { border-color: var(--subtle); }
.tabs button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.tabs button.blue.on { background: #2f80ed; border-color: #2f80ed; color: #fff; }
.tabs button.green.on { background: #22a447; border-color: #22a447; color: #fff; }
.tabs button.orange.on { background: #e07a1c; border-color: #e07a1c; color: #fff; }
.tabs button.clear { margin-left: auto; color: var(--muted); background: transparent; }
.tabs button.clear:hover { color: var(--text); }

/* Diagram */
.stage {
  position: relative; overflow: hidden; line-height: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.8);
  -webkit-user-select: none; user-select: none;
}
.stage > svg { width: 100%; height: auto; display: block; pointer-events: none; }
.draw-layer {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; touch-action: auto; -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
/* Draw mode on: the map takes the finger, so the page does not scroll under it */
.stage.drawing { touch-action: none; overscroll-behavior: none; }
.stage.drawing .draw-layer {
  pointer-events: auto; touch-action: none;
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%23111' d='M3 21l3.6-.9L20.4 6.3a1.5 1.5 0 0 0 0-2.1L19.8 3.6a1.5 1.5 0 0 0-2.1 0L4 17.3 3 21z'/%3E%3Cpath fill='%23fff' d='M17.1 4.3l2.6 2.6-1.1 1.1-2.6-2.6z'/%3E%3C/svg%3E") 2 22, crosshair;
}
.stage.erasing .draw-layer {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='9' fill='%23fff' fill-opacity='.35' stroke='%23111' stroke-width='2'/%3E%3C/svg%3E") 12 12, cell;
}
.draw-hint { margin-top: 0.75rem; color: var(--subtle); font-size: 0.9rem; }
.note {
  margin-top: 1.25rem; max-width: 760px; padding: 1.1rem 1.25rem;
  color: var(--muted); font-size: 0.975rem;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 12px;
}

/* Show one route or arm at a time */
#stageVine[data-arm="south"] [data-arm]:not([data-arm="south"]),
#stageVine[data-arm="north"] [data-arm]:not([data-arm="north"]),
#stageVine[data-arm="east"] [data-arm]:not([data-arm="east"]) { visibility: hidden; }
#stageCross[data-arm="N"] [data-arm]:not([data-arm="N"]),
#stageCross[data-arm="E"] [data-arm]:not([data-arm="E"]),
#stageCross[data-arm="S"] [data-arm]:not([data-arm="S"]),
#stageCross[data-arm="W"] [data-arm]:not([data-arm="W"]) { visibility: hidden; }
.stage[data-show="blue"] #pg,
.stage[data-show="blue"] #po,
.stage[data-show="blue"] .route-pg,
.stage[data-show="blue"] .route-po,
.stage[data-show="green"] #pb,
.stage[data-show="green"] #po,
.stage[data-show="green"] .route-pb,
.stage[data-show="green"] .route-po,
.stage[data-show="orange"] #pb,
.stage[data-show="orange"] #pg,
.stage[data-show="orange"] .route-pb,
.stage[data-show="orange"] .route-pg { visibility: hidden; }

/* Controlled cross */
.cross-status { margin-left: 0.5rem; align-self: center; font-weight: 600; font-size: 0.9rem; color: var(--success); }
.cross-lanes {
  list-style: none; margin: 1.25rem 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem;
}
.cross-lanes > li { padding: 1.1rem 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.cross-lanes h3 { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.5rem; font-size: 1rem; }
.cross-lanes h3 span { color: var(--accent); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.cross-lanes ul { list-style: none; margin: 0; padding: 0; color: var(--muted); font-size: 0.925rem; line-height: 1.5; }
.cross-lanes ul li { margin-bottom: 0.2rem; }

.study-cta { margin-top: 3.5rem; }

@media (max-width: 700px) {
  .maps { display: flex; }
  .maps button { flex: 1 1 auto; }
  .tabs button.clear { margin-left: 0; }
  .cross-status { margin-left: 0; width: 100%; }
  .cross-lanes { grid-template-columns: minmax(0, 1fr); }
  .stage { border-radius: 14px; }
}

@media (prefers-reduced-motion: reduce) { .stage > svg { animation: none; } }

/* Keep the square roundabout from outgrowing the screen on desktop */
#stage { max-width: min(100%, 760px); }

/* Map picker: sliding highlight */
.maps { position: relative; }
.maps button { position: relative; z-index: 1; }
.maps-indicator {
  position: absolute; top: 0; left: 0; z-index: 0;
  background: var(--accent-fill); border-radius: 10px;
  box-shadow: 0 8px 20px -8px rgba(225, 44, 50, 0.7);
}
.maps.ready .maps-indicator { transition: transform 0.35s cubic-bezier(0.3, 0.7, 0.2, 1), width 0.35s cubic-bezier(0.3, 0.7, 0.2, 1); }
.maps.ready button.on { background: transparent; }

.shortcuts { margin: -1.5rem 0 2.5rem; color: var(--subtle); font-size: 0.85rem; }
.shortcuts kbd {
  display: inline-block; min-width: 1.6em; padding: 0.05rem 0.4rem; margin: 0 0.1rem;
  font: inherit; font-size: 0.8rem; font-weight: 600; text-align: center; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px;
}
@media (pointer: coarse) { .shortcuts { display: none; } }

/* Panel switch */
.map-panel:not([hidden]) { animation: panel-in 0.4s cubic-bezier(0.2, 0.7, 0.2, 1); }
@keyframes panel-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Drawing toolbar: Draw, eraser, undo, redo, clear, full screen | colours, sizes */
.draw-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }
.tool-group {
  display: flex; align-items: center; gap: 4px; min-height: 40px; padding: 0 4px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 999px;
}
.pens, .sizes { display: flex; align-items: center; gap: 6px; }
.sizes { margin-left: 4px; padding-left: 8px; border-left: 1px solid var(--border-strong); }
.draw-tools .pen {
  width: 22px; height: 22px; min-height: 0; padding: 0; cursor: pointer;
  background: var(--pen); border: 2px solid rgba(255, 255, 255, 0.25); border-radius: 50%;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.draw-tools .pen:hover { transform: scale(1.12); }
.draw-tools .pen[aria-checked="true"] { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18); }
.draw-tools .size {
  display: grid; place-items: center; width: 28px; height: 32px; min-height: 0; padding: 0;
  background: transparent; border: 0; border-radius: 8px; cursor: pointer; color: var(--muted);
}
.draw-tools .size span { display: block; width: var(--dot); height: var(--dot); border-radius: 50%; background: currentColor; }
.draw-tools .size:hover { color: var(--text); }
.draw-tools .size[aria-checked="true"] { color: #fff; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border-strong); }
.draw-tools .tool-btn, .draw-tools .draw-toggle, .draw-tools .tool-group .clear {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 34px; height: 32px; min-height: 0; padding: 0 8px; margin: 0;
  background: transparent; color: var(--muted); border: 0; border-radius: 999px;
  font: inherit; font-weight: 600; font-size: 0.875rem; cursor: pointer; transition: color 0.2s, background 0.2s;
}
.draw-tools .tool-btn:hover, .draw-tools .draw-toggle:hover, .draw-tools .tool-group .clear:hover { color: var(--text); }
.draw-tools .tool-btn:disabled { opacity: 0.35; cursor: default; }
.draw-tools .tool-btn:disabled:hover { color: var(--muted); }
.draw-tools .draw-toggle { padding: 0 12px 0 10px; color: var(--text); }
.draw-tools .draw-toggle[aria-pressed="true"] { background: var(--accent-fill); color: #fff; }
.draw-tools .eraser-btn[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.draw-tools .fs-btn { border-left: 1px solid var(--border-strong); border-radius: 0 999px 999px 0; }
.tool-btn svg, .draw-toggle svg, .tool-group .clear svg {
  width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* Fade switch in the hint line */
.fade-toggle {
  display: inline-flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 2px; margin-left: 2px;
  background: none; border: 0; color: var(--muted); font: inherit; font-size: 0.9rem; cursor: pointer; vertical-align: middle; line-height: 1.2;
}
.fade-toggle:hover { color: var(--text); }
.fade-toggle .switch {
  position: relative; width: 34px; height: 20px; flex-shrink: 0; border-radius: 999px;
  background: var(--border-strong); transition: background 0.2s;
}
.fade-toggle .switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; transition: transform 0.2s;
}
.fade-toggle[aria-pressed="true"] .switch { background: var(--accent-fill); }
.fade-toggle[aria-pressed="true"] .switch::after { transform: translateX(14px); }
.draw-hint { line-height: 1.5; }

/* Full screen: the toolbar floats over the top of the map */
.draw-tools.floating {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 2;
  justify-content: center; margin: 0; width: max-content; max-width: calc(100% - 24px); line-height: normal;
}
.draw-tools.floating .tool-group { background: rgba(21, 25, 34, 0.92); box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.7); }

/* Full screen */
.stage:fullscreen, #stage:fullscreen {
  max-width: none;
  background: #05060a; border: 0; border-radius: 0;
}
.stage:fullscreen > svg { width: 100vw; height: 100vh; }

.copyright { margin-top: 2rem; color: var(--subtle); font-size: 0.85rem; }

@media (max-width: 700px) {
  .draw-tools { margin-left: 0; }
}

/* Focus rings that show up on the red map highlight and the pen dots */
.maps button:focus-visible { outline: 2px solid #fff; outline-offset: -4px; border-radius: 8px; }
.draw-tools .pen:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 50%; }

/* Less motion: no slide-in when switching maps */
@media (prefers-reduced-motion: reduce) {
  .map-panel:not([hidden]) { animation: none; }
}

/* Phones and touch screens: finger-sized controls (at least 44px) */
@media (max-width: 700px), (pointer: coarse) {
  .back-link { min-height: 44px; }
  .tabs button { min-height: 44px; }
  .tool-group { min-height: 46px; padding: 0 1px; gap: 0; }
  .pens, .sizes { gap: 0; }
  .sizes { margin-left: 0; padding-left: 0; }
  .draw-tools .pen {
    position: relative; width: 44px; height: 44px;
    background: transparent; border: 0; border-radius: 50%;
  }
  .draw-tools .pen::before {
    content: ""; position: absolute; inset: 10px;
    background: var(--pen); border: 2px solid rgba(255, 255, 255, 0.25); border-radius: 50%;
    transition: border-color 0.15s, box-shadow 0.15s;
  }
  .draw-tools .pen[aria-checked="true"] { border: 0; box-shadow: none; }
  .draw-tools .pen[aria-checked="true"]::before { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18); }
  .draw-tools .pen:hover { transform: none; }
  .draw-tools .size { width: 44px; height: 44px; border-radius: 50%; }
  .draw-tools .tool-btn, .draw-tools .tool-group .clear { min-width: 44px; height: 44px; padding: 0 10px; }
  .draw-tools .draw-toggle { height: 44px; }
  .fade-toggle { min-height: 44px; }
}

/* Phones: diagram first, controls just under it within thumb reach */
@media (max-width: 700px) {
  .study { padding-top: 1.25rem; }
  .back-link { min-height: 44px; }
  .study-head { margin: 0.5rem 0 1.25rem; }
  .study-head h1 { margin-bottom: 0.6rem; }
  .sub { font-size: 1rem; }
  .shortcuts { display: none; }

  /* Map picker: the three maps side by side */
  .maps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 1.75rem; }
  .maps button { padding: 0.35rem 0.4rem; font-size: 0.875rem; line-height: 1.2; }

  .map-panel:not([hidden]) { display: flex; flex-direction: column; }
  .map-panel > h2 { margin-bottom: 0.35rem; }
  .map-panel > .sub { margin-bottom: 1rem; }
  .map-panel > .stage { order: 1; }
  .map-panel > .tabs { order: 2; margin: 0.9rem 0 0; }
  .map-panel > .draw-hint, .map-panel > .note, .map-panel > .cross-lanes { order: 3; }
  .tabs .draw-tools { order: 5; width: 100%; }
  .draw-tools .tool-group { flex: 1 1 auto; justify-content: space-between; }
  .cross-status { order: -1; margin: 0 0 0.1rem; }
  .note { padding: 1rem; font-size: 0.95rem; }
  .study-cta { margin-top: 2.5rem; }
}
@media (max-width: 700px) {
  .tool-group .clear .tool-label { display: none; }
}

/* Road signs beside the diagram, only on wide screens where the side space is free */
.sign-rail { display: none; }
@media (min-width: 1440px) {
  .study { overflow-x: clip; }
  .map-panel { position: relative; }
  .map-panel {
    /* panel is 1112px wide here; the rails sit centred in the free space either side */
    --gutter: calc((100vw - 1112px) / 2);
    --rail-w: clamp(120px, calc(var(--gutter) - 72px), 236px);
    --rail-gap: calc((var(--gutter) - var(--rail-w)) / 2);
    --rail-h: 820px;
  }
  #map-standard { --rail-h: 760px; }
  #map-cross { --rail-h: 829px; }
  .sign-rail {
    display: flex; flex-direction: column; justify-content: center; gap: 2.25rem;
    position: absolute; width: var(--rail-w); height: var(--rail-h);
    pointer-events: auto;
  }
  .sign-rail-left { right: calc(100% + var(--rail-gap)); }
  .sign-rail-right { left: calc(100% + var(--rail-gap)); }
  /* The clockwise roundabout is narrower, so its right-hand signs sit in the space beside it */
  #map-standard .sign-rail-right { left: calc(760px + (100% - 760px - var(--rail-w)) / 2); }

  .sign { margin: 0; text-align: center; }
  .sign svg { display: block; width: min(100%, 112px); height: auto; margin: 0 auto 0.75rem; filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.45)); }
  .sign figcaption { color: var(--muted); font-size: 0.8rem; line-height: 1.45; }
  .sign figcaption strong { display: block; margin-bottom: 0.2rem; color: var(--text); font-size: 0.875rem; font-weight: 700; }

  .map-panel:not([hidden]) .sign { animation: sign-in 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both; animation-delay: calc(120ms + var(--i, 0) * 70ms); }
}
@media (min-width: 1440px) and (max-width: 1599px) {
  .sign-rail { gap: 1.5rem; }
  .sign svg { width: min(100%, 92px); }
  .sign figcaption { font-size: 0.75rem; }
}
@keyframes sign-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .map-panel:not([hidden]) .sign { animation: none; }
}

/* Vine Island: approach picker, turning map, compass and lane summary */
.orient { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 1.1rem 0 0; }
.orient-label { margin-right: 2px; color: var(--muted); font-size: 0.9rem; font-weight: 600; }
.orient-arms {
  display: inline-flex; gap: 4px; padding: 3px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 999px;
}
.orient-arms button, .orient-step {
  min-height: 36px; padding: 0 0.9rem;
  background: transparent; color: var(--muted); border: 0; border-radius: 999px;
  font: inherit; font-weight: 600; font-size: 0.9rem; cursor: pointer; transition: background 0.2s, color 0.2s;
}
.orient-arms button:hover, .orient-step:hover { color: var(--text); }
.orient-arms button[aria-pressed="true"] { background: var(--accent-fill); color: #fff; }
.orient-step {
  display: inline-grid; place-items: center; width: 40px; padding: 0;
  background: var(--surface); border: 1px solid var(--border-strong);
}
.orient-step svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.lane-summary { margin: 0.75rem 0 0; max-width: 46em; color: var(--muted); font-size: 0.95rem; line-height: 1.5; }
.lane-summary strong { color: var(--text); }

/* The turned map never zooms: the frame takes the turned map's shape (--ar, set by the script).
   It keeps the south view's height on wider screens and narrows round taller views. */
#stageVine { --ar: 1.3563; max-width: calc(100% * var(--ar) / 1.3563); }
@media (min-width: 701px) { #stageVine { margin-inline: auto; } }
.compass {
  position: absolute; top: 12px; right: 12px; z-index: 1; width: 44px; height: 44px;
  border-radius: 50%; background: rgba(10, 12, 16, 0.72); border: 1px solid rgba(255, 255, 255, 0.25);
  pointer-events: none; line-height: normal;
}
.compass-needle {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0; margin-left: -5px; margin-top: -12px;
  border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 12px solid #e5484d;
  transform-origin: 5px 12px; transform: rotate(var(--turn, 0deg));
  transition: transform 0.7s cubic-bezier(0.3, 0.7, 0.2, 1);
}
.compass-n {
  position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px;
  color: #fff; font-size: 10px; font-weight: 800; text-align: center; line-height: 14px;
  transform: rotate(var(--turn, 0deg)) translateY(-14px) rotate(calc(-1 * var(--turn, 0deg)));
  transition: transform 0.7s cubic-bezier(0.3, 0.7, 0.2, 1);
}
.compass-needle::after {
  content: ""; position: absolute; left: -5px; top: 12px;
  border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 12px solid rgba(255, 255, 255, 0.55);
}
.compass.instant .compass-needle, .compass.instant .compass-n { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .compass-needle, .compass-n { transition: none; }
}

@media (max-width: 700px), (pointer: coarse) {
  .orient-arms button { min-height: 44px; }
  .orient-step { min-height: 44px; width: 44px; }
}
@media (max-width: 700px) {
  .map-panel > .orient, .map-panel > .lane-summary { order: 2; }
  .orient { margin-top: 0.9rem; }
  .orient-label { width: 100%; }
  .orient-arms { flex: 1 1 auto; }
  .orient-arms button { flex: 1 1 0; padding: 0 0.5rem; }
  .compass { top: 8px; right: 8px; width: 36px; height: 36px; }
}
@media (min-width: 1440px) {
  .lane-summary { display: none; }
}
.orient.floating {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 2;
  margin: 0; width: max-content; line-height: normal;
  padding: 4px 8px; background: rgba(21, 25, 34, 0.92); border-radius: 999px; box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.7);
}
.orient.floating .orient-label { width: auto; padding-left: 6px; }

/* Route trails: a faint, wider copy of each line gives the glow */
.trail-glow { fill: none; stroke-linecap: round; stroke-opacity: 0.3; }
#stage .trail-glow { stroke-width: 17; }
#stageVine .trail-glow { stroke-width: 12; }

/* ------------------------------------------------------------------
   Phones: bigger diagrams and a tidier control stack
   ------------------------------------------------------------------ */
.tab-short { display: none; }
@media (max-width: 700px) {
  .tab-long { display: none; }
  .tab-short { display: inline; }
  .maps button { white-space: nowrap; }
  .study-head h1 { font-size: clamp(2rem, 9.5vw, 2.5rem); text-wrap: balance; }
  .sub { text-wrap: pretty; }
  .map-panel h2 { font-size: 1.5rem; }
  .note { line-height: 1.55; }
  .draw-hint { font-size: 0.9rem; color: var(--muted); margin-top: 0.75rem; }
}
/* Portrait phones: the map runs edge to edge, so every pixel of width goes to the diagram */
@media (max-width: 700px) and (orientation: portrait) {
  .map-panel > .stage {
    margin-left: calc(-1 * max(16px, env(safe-area-inset-left)));
    margin-right: calc(-1 * max(16px, env(safe-area-inset-right)));
    border-radius: 0; border-left: 0; border-right: 0;
    box-shadow: none;
  }
  #stage, #stageVine { max-width: none; }
}
/* Phones on their side: keep the whole diagram on screen at once */
@media (max-height: 500px) and (orientation: landscape) {
  .map-panel > .stage { margin-left: auto; margin-right: auto; width: 100%; }
  #stage { max-width: calc(100svh - 76px); }
  #stageVine { max-width: calc((100svh - 76px) * var(--ar)); }
  #stageCross { max-width: calc((100svh - 76px) * 1100 / 820); }
}
/* The smallest phones (320px): pens and sizes a little narrower so the toolbar fits */
@media (max-width: 359px) {
  .draw-tools .pen, .draw-tools .size { width: 39px; }
  .draw-tools .tool-btn, .draw-tools .tool-group .clear { min-width: 40px; padding: 0 8px; }
}

/* Written guide under the roundabouts: key rule, then one card per route */
.route-guide { margin-top: 1.25rem; max-width: 760px; }
.route-guide .rule {
  display: flex; align-items: flex-start; gap: 0.75rem;
  padding: 0.85rem 1rem; margin: 0 0 1rem;
  background: rgba(229, 72, 77, 0.08); border: 1px solid rgba(229, 72, 77, 0.3); border-radius: 12px;
  color: var(--muted); line-height: 1.45;
}
.route-guide .rule strong { color: var(--text); }
.rule-mark {
  display: grid; place-items: center; flex-shrink: 0; width: 24px; height: 24px; margin-top: 1px;
  border-radius: 50%; background: var(--accent-fill); color: #fff; font-weight: 800; font-size: 0.85rem; line-height: 1;
}
.guide-arm { margin: 0 0 0.6rem; font-size: 0.95rem; }
.routes { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.6rem; }
.route { padding: 0.8rem 1rem 0.85rem; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.route-head { display: flex; align-items: center; gap: 0.55rem; margin: 0 0 0.4rem; line-height: 1.3; }
.dots { display: inline-flex; gap: 3px; flex-shrink: 0; }
.dots i { width: 12px; height: 12px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2); }
.route ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.15rem; font-size: 0.925rem; line-height: 1.4; color: var(--text); }
.route .k { display: inline-block; min-width: 3.6rem; color: var(--subtle); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.route-guide .more { margin-top: 0.75rem; background: transparent; border: 0; }
.route-guide .more summary {
  display: inline-flex; align-items: center; gap: 0.6rem; min-height: 44px; padding: 0 0.25rem; color: var(--accent); font-weight: 600; font-size: 0.95rem;
}
.route-guide .more summary::after { border-color: var(--accent); width: 8px; height: 8px; }
.route-guide .more > ul:not(.cross-lanes) { margin: 0.25rem 0 0; padding-left: 1.1rem; color: var(--muted); font-size: 0.925rem; line-height: 1.5; display: grid; gap: 0.25rem; }
@media (max-width: 700px) {
  .map-panel > .route-guide { order: 3; margin-top: 1rem; }
  .route-guide .rule { font-size: 0.95rem; padding: 0.75rem 0.9rem; }
}
.route ul li { display: grid; grid-template-columns: 4.9rem 1fr; align-items: baseline; }
.route .k { min-width: 0; }
.route-guide .rule > div { display: grid; gap: 0.4rem; }
.route-guide .rule p { margin: 0; }
.dots.turn svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; display: block; }
.route-guide .psl { margin: 0.6rem 0 0; color: var(--muted); font-size: 0.925rem; line-height: 1.5; }
.route-guide .more-h { margin: 1rem 0 0.6rem; font-size: 1rem; }
.route-guide .more .cross-lanes { margin-top: 0; }
