/* 지하철 노선도 만들기 (/tools/subway-map/).
   A map editor: the sheet takes the width, the editing panel sits beside it
   (below it on a phone). Horizon tokens only, so every theme follows the site.
   Element ids are the contract with static/js/subway-map-maker.js. */
body.smm-body { --smm-side: clamp(340px, 28vw, 430px); --smm-radius: 14px; margin: 0; }
.smm-shell { box-sizing: border-box; min-height: 100dvh; padding-top: var(--header-height); }
.smm-main { --hz-control-h: var(--control-h-s); --hz-control-px: var(--control-px-s); --hz-control-font: var(--control-font-s); display: flex; flex-direction: column; min-width: 0; height: calc(100dvh - var(--header-height)); min-height: 560px; word-break: keep-all; overflow-wrap: anywhere; }
.smm-main .hz-icon, .smm-dialog .hz-icon { font-size: 18px; line-height: 1; }
.smm-body :is(.smm-main, .smm-dialog) .btn { min-height: var(--control-h-s); padding: 0 var(--control-px-s); font-size: var(--control-font-s); line-height: 1.2; border: 1px solid transparent; gap: 6px; white-space: nowrap; }
.smm-body :is(.smm-main, .smm-dialog) .btn-sm { min-height: calc(var(--control-h-s) - 4px); padding: 0 10px; }
.smm-body :is(.smm-main, .smm-dialog) .btn-outline { border-color: var(--border); }
.smm-body :is(.smm-main, .smm-dialog) .btn:hover:not(:disabled) { transform: none; box-shadow: none; }
.smm-body :is(.smm-main, .smm-dialog) :is(.input, .select) { width: 100%; min-width: 0; box-sizing: border-box; min-height: var(--control-h-s); font-size: max(var(--control-font-s), var(--input-font-min, 0px)); color: var(--foreground); padding-block: 0; line-height: 1.2; }
.smm-body .smm-main textarea.input { height: auto; resize: vertical; padding-block: var(--space-2); line-height: var(--lh-body); }
.smm-danger { color: var(--destructive); }

/* Toolbar */
.smm-toolbar { display: flex; justify-content: space-between; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--border); }
.smm-toolbar-heading, .smm-toolbar-actions { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); }
.smm-toolbar-heading h1 { margin: 0; font-size: var(--fs-h3); line-height: var(--lh-h3); }
.smm-history { display: flex; gap: 2px; padding-right: 8px; margin-right: 4px; border-right: 1px solid var(--border); }
.smm-iconbtn { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 999px; background: transparent; color: var(--foreground); cursor: pointer; flex: none; }
.smm-iconbtn--s { width: 28px; height: 28px; }
.smm-iconbtn:hover:not(:disabled) { background: var(--secondary); }
.smm-iconbtn:disabled { color: var(--muted-foreground); opacity: .4; cursor: default; }
.smm-banner { margin: 12px 20px 0; padding: 10px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--card); font-size: var(--fs-sm); }
.smm-hint { font-size: var(--fs-xs); line-height: 1.5; color: var(--muted-foreground); margin: 6px 0; }
.smm-hint[data-error="true"] { color: var(--destructive); }

/* Frame: sheet + side panel fill the viewport; the panel scrolls on its own. */
.smm-work { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) var(--smm-side); min-height: 0; }
.smm-stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 12px 16px 8px 20px; background: color-mix(in srgb, var(--secondary) 55%, var(--background)); }
.smm-stage-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 10px; }
.smm-stage-title { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); min-width: 0; }
.smm-appearance { display: flex; align-items: center; gap: var(--space-2); color: var(--muted-foreground); font-size: var(--fs-sm); white-space: nowrap; }
.smm-appearance .select-wrapper { width: auto; }
.smm-body .smm-main .smm-appearance .select { width: auto; padding-inline-start: var(--space-2); }
.smm-stage-title h2 { margin: 0; font-size: 15px; font-weight: 700; }
.smm-stage-title .smm-hint { margin: 0; }
.smm-busy { font-size: var(--fs-xs); color: var(--primary); font-weight: 600; }
.smm-stage-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.smm-zoom { display: flex; align-items: center; gap: 2px; padding: 2px; border-radius: 999px; background: var(--card); border: 1px solid var(--border); }
.smm-body .smm-zoom .btn { border-radius: 999px; padding-inline: 10px; }
.smm-body .smm-zoom .btn:has(svg) { width: calc(var(--control-h-s) - 4px); padding-inline: 0; }
.smm-zoom svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
#previewZoom { min-width: 3rem; text-align: center; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.smm-zoom [aria-pressed="true"] { background: var(--secondary); }
.smm-export { display: flex; gap: 6px; }
.smm-canvas { position: relative; flex: 1; min-height: 220px; overflow: hidden; padding: 16px; box-sizing: border-box; background-color: var(--card); background-image: radial-gradient(color-mix(in srgb, var(--foreground) 9%, transparent) 1px, transparent 1px); background-size: 14px 14px; border: 1px solid var(--border); border-radius: var(--smm-radius); }
.smm-canvas[data-ready="true"] { touch-action: none; cursor: grab; user-select: none; }
.smm-canvas.is-grabbing { cursor: grabbing; }
.smm-canvas[data-ready="true"] #diagramPreview { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.smm-canvas[data-empty="true"]::after { content: '노선 탭에서 노선을 추가하고 역 이름을 넣어 보세요'; position: absolute; inset: 0; display: grid; place-content: center; padding: 24px; text-align: center; color: var(--muted-foreground); font-size: var(--fs-sm); }
#diagramPreview > svg { display: block; width: 100%; height: auto; border-radius: 6px; box-shadow: 0 1px 2px rgba(15, 15, 15, .08), 0 8px 24px rgba(15, 15, 15, .08); text-rendering: geometricPrecision; }
.tmm-hit { cursor: pointer; stroke: transparent; stroke-width: 2; }
.tmm-hit:hover { stroke: color-mix(in srgb, #2f6bff 55%, transparent); }
.tmm-hit.is-pinned { stroke: color-mix(in srgb, #2f6bff 45%, transparent); stroke-width: 1.4; }
.tmm-hit.is-selected { stroke: #2f6bff; stroke-width: 2.2; stroke-dasharray: 5 3; }
.tmm-ghost { fill: color-mix(in srgb, #2f6bff 22%, transparent); stroke: #2f6bff; stroke-width: 2; pointer-events: none; }
.smm-canvas.is-dragging-station { cursor: grabbing; }
.smm-stage-foot { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 16px; }
.smm-stage-foot > * { margin: 6px 0 0; }
.smm-stage-foot #previewGestureHelp { margin-right: auto; }
.smm-stage-foot [hidden] { display: none; }

/* Side panel */
.smm-side { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-left: 1px solid var(--border); background: var(--background); }
.smm-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; padding: 8px 12px 0; border-bottom: 1px solid var(--border); flex: none; }
.smm-tab { display: flex; align-items: center; justify-content: center; gap: 5px; min-height: 40px; padding: 0 6px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted-foreground); font: inherit; font-size: var(--fs-sm); font-weight: 600; cursor: pointer; white-space: nowrap; }
.smm-tab:hover { color: var(--foreground); }
.smm-tab[aria-selected="true"] { color: var(--foreground); border-bottom-color: var(--foreground); }
.smm-panel { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px 28px; display: flex; flex-direction: column; gap: 12px; }
.smm-panel[hidden] { display: none; }
.smm-card { margin: 0; padding: 14px 16px 16px; background: var(--card); border: 1px solid var(--border); border-radius: var(--smm-radius); min-width: 0; }
.smm-card[hidden] { display: none; }
.smm-card h2 { margin: 0; font-size: 15px; font-weight: 700; }
.smm-card h3 { margin: 0; font-size: 14px; font-weight: 700; }
.smm-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.smm-head .smm-hint { margin: 0; }
.smm-subhead { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 16px 0 8px; padding-top: 14px; border-top: 1px solid var(--border); }
.smm-subhead .smm-hint { margin: 0; }
.smm-field { display: grid; min-width: 0; gap: 6px; font-size: var(--fs-sm); color: var(--muted-foreground); margin: 0 0 10px; }
.smm-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.smm-pair--mark { grid-template-columns: minmax(0, 1fr) 6.5rem; }
.smm-toggle { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); min-height: var(--control-h-s); color: var(--foreground); }
.smm-toggle input { accent-color: var(--primary); flex: none; }
.smm-inline { display: flex; gap: 6px; align-items: center; min-width: 0; }
.smm-inline > :first-child { flex: 1; min-width: 0; }
.smm-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.smm-actions:not(:has(> :not([hidden]))) { display: none; }
.smm-more { margin-top: 10px; }
.smm-more > summary { cursor: pointer; font-size: var(--fs-sm); color: var(--foreground); font-weight: 600; padding-block: 6px; }
.smm-more[open] > summary { margin-bottom: 8px; }

/* Segmented choices */
.smm-seg { display: flex; flex-wrap: wrap; gap: 4px; }
.smm-seg button { flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: var(--control-h-s); padding: 0 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--foreground); font: inherit; font-size: var(--fs-sm); cursor: pointer; white-space: nowrap; }
.smm-seg button:hover { border-color: color-mix(in srgb, var(--foreground) 35%, var(--border)); }
.smm-seg button[aria-pressed="true"] { background: var(--secondary); border-color: var(--foreground); font-weight: 600; }
.smm-seg svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.smm-range { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.smm-range input { grid-column: 1; width: 100%; accent-color: var(--primary); }
.smm-range output { grid-column: 2; grid-row: 2; min-width: 3.2rem; text-align: right; font-size: var(--fs-xs); font-variant-numeric: tabular-nums; color: var(--foreground); }
.smm-range input { grid-row: 2; }

/* Line marks */
.smm-badge { display: inline-grid; place-items: center; flex: none; min-width: 22px; height: 22px; padding: 0 2px; box-sizing: border-box; border-radius: 999px; background: var(--line, #5c6670); color: var(--ink, #fff); font-size: 12px; font-weight: 700; line-height: 1; }
.smm-badge[data-wide="true"] { padding: 0 7px; font-size: 11px; }
.smm-line-list, .smm-station-list, .smm-stop-list, .smm-library { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.smm-line-row, .smm-station-row { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 40px; padding: 6px 10px; border: 1px solid transparent; border-radius: 10px; background: none; color: var(--foreground); font: inherit; font-size: var(--fs-sm); text-align: left; cursor: pointer; }
.smm-line-row:hover, .smm-station-row:hover { background: var(--secondary); }
.smm-line-row[aria-pressed="true"], .smm-station-row[aria-pressed="true"] { border-color: var(--foreground); background: var(--secondary); }
.smm-line-row strong, .smm-station-row strong { font-weight: 600; min-width: 0; }
.smm-line-row .smm-hint { margin: 0 0 0 auto; white-space: nowrap; }
.smm-station-list { max-height: 46dvh; overflow-y: auto; margin-top: 8px; }
.smm-pin { margin-left: auto; color: var(--primary); }
.smm-dots { display: inline-flex; gap: 3px; flex: none; }
.smm-dots i { width: 10px; height: 10px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }
.smm-swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.smm-swatch { width: 28px; height: 28px; padding: 0; border: 2px solid var(--card); border-radius: 50%; background: var(--swatch); box-shadow: 0 0 0 1px var(--border); cursor: pointer; }
.smm-swatch[aria-pressed="true"], .smm-swatch--custom[data-active="true"] { box-shadow: 0 0 0 2px var(--foreground); }
.smm-swatch--custom { position: relative; overflow: hidden; background: conic-gradient(#e6186c, #f5a200, #00a84d, #00a5de, #996cac, #e6186c); }
.smm-swatch--custom input { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); padding: 0; border: 0; opacity: 0; cursor: pointer; }
.smm-swatch--custom[data-active="true"] input { opacity: 1; }

/* Stops of the selected line */
.smm-stop { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 4px; padding: 2px 0; border-radius: 10px; }
.smm-stop.is-over { box-shadow: 0 -2px 0 var(--primary); }
.smm-stop.is-dragging { opacity: .45; }
.smm-grip { display: grid; place-items: center; width: 22px; color: var(--muted-foreground); cursor: grab; }
.smm-stop-tools { display: flex; }
.smm-add-stop { display: flex; gap: 6px; margin-top: 8px; }
.smm-add-stop .input { flex: 1; }
.smm-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.smm-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 10px 0 5px; border: 1px solid var(--border); border-radius: 999px; background: var(--card); color: var(--foreground); font: inherit; font-size: 13px; cursor: pointer; }
.smm-chip:hover { border-color: var(--foreground); }

/* Station position */
.smm-position { display: flex; gap: 14px; align-items: flex-start; }
.smm-position-actions { min-width: 0; }
.smm-position-actions .smm-hint { margin-top: 2px; }
.smm-nudge { display: grid; grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(3, 34px); flex: none; }
.smm-nudge button { display: grid; place-items: center; border: 1px solid var(--border); background: var(--card); color: var(--foreground); border-radius: 9px; cursor: pointer; }
.smm-nudge button:hover { background: var(--secondary); }
.smm-nudge button:nth-child(1) { grid-area: 1 / 2; }
.smm-nudge button:nth-child(2) { grid-area: 2 / 1; }
.smm-nudge button:nth-child(3) { grid-area: 2 / 3; }
.smm-nudge button:nth-child(4) { grid-area: 3 / 2; }
.smm-label-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; max-width: 220px; }
.smm-label-grid button { min-height: 34px; border: 1px solid var(--border); border-radius: 9px; background: var(--card); color: var(--foreground); font: inherit; font-size: var(--fs-xs); cursor: pointer; position: relative; }
.smm-label-grid button:not([data-label-pos="auto"])::after { content: ''; position: absolute; left: 50%; top: 50%; width: 14px; height: 3px; margin: -1.5px 0 0 -7px; border-radius: 2px; background: var(--muted-foreground); }
.smm-label-grid button[aria-pressed="true"] { border-color: var(--foreground); background: var(--secondary); font-weight: 600; }
.smm-label-grid button[aria-pressed="true"]::after { background: var(--foreground); }

/* Dialogs */
.smm-dialog { width: min(520px, calc(100vw - 32px)); max-height: min(80dvh, 640px); padding: 0; border: 1px solid var(--border); border-radius: 16px; background: var(--card); color: var(--foreground); box-shadow: 0 24px 64px rgba(0, 0, 0, .24); }
.smm-dialog::backdrop { background: rgba(10, 12, 16, .45); }
.smm-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.smm-dialog-head h2 { margin: 0; font-size: 16px; }
.smm-dialog-body { padding: 14px 18px 18px; overflow-y: auto; }
.smm-library { margin-top: 8px; }
.smm-library-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 6px; padding: 8px 0; border-top: 1px solid var(--border); }
.smm-library-row div { display: grid; min-width: 0; }
.smm-library-row .smm-hint { margin: 0; }
.smm-server-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--space-2); padding-block: var(--space-3); border-top: 1px solid var(--border); }
.smm-server-row .smm-actions { margin: 0; }
.smm-body [hidden]#classicMarkers, .smm-dialog [hidden] { display: none; }

/* Narrow screens: the sheet stays on top and the panel scrolls under it, so
   the map is always in view while it is being edited. */
@media (max-width: 960px) {
  .smm-main { min-height: 540px; }
  .smm-work { display: flex; flex-direction: column; }
  .smm-toolbar { padding: 8px 16px; flex-wrap: nowrap; }
  .smm-toolbar-heading h1 { font-size: 17px; white-space: nowrap; }
  .smm-toolbar-heading .btn { display: none; }
  .smm-toolbar-actions { flex-wrap: nowrap; gap: 4px; }
  .smm-history { padding-right: 4px; margin-right: 0; }
  .smm-stage { flex: none; padding: 8px 16px 6px; border-bottom: 1px solid var(--border); }
  .smm-canvas { flex: none; height: clamp(200px, 36dvh, 420px); min-height: 0; }
  .smm-stage-head { margin-bottom: 8px; }
  .smm-stage-title .smm-hint, #previewGestureHelp { display: none; }
  .smm-stage-foot > * { margin-top: 4px; }
  .smm-side { flex: 1; border-left: 0; }
  .smm-panel { padding-inline: 16px; }
  .smm-station-list { max-height: none; }
}
@media (max-width: 640px) {
  .smm-toolbar { padding-inline: var(--space-3); }
  .smm-toolbar-heading { min-width: 0; flex: 1; }
  .smm-toolbar-heading h1 { white-space: normal; }
  .smm-toolbar-actions { flex: none; }
  .smm-toolbar-actions .smm-label, .smm-stage-actions .smm-label { display: none; }
  .smm-stage { padding-inline: var(--space-3); }
  .smm-body .smm-stage-actions .btn, .smm-body .smm-toolbar-actions .btn { padding-inline: var(--space-2); }
  .smm-body .smm-stage-actions .btn { min-height: var(--control-h-s); }
  #previewZoom { display: none; }
  .smm-stage-title h2 { display: none; }
  .smm-stage-actions { width: 100%; justify-content: space-between; gap: 6px; }
  .smm-tab .hz-icon { display: none; }
}
@media (max-width: 360px) {
  .smm-toolbar { flex-wrap: wrap; }
  .smm-toolbar-heading { flex-basis: 100%; }
  .smm-toolbar-actions { margin-left: auto; }
}
@media print { .smm-toolbar, .smm-side, .smm-stage-head, .smm-stage-foot, #gisHeader { display: none; } }
