/*
 * Journey variant and state surfaces.
 *
 * This file is intentionally scoped to the optional V2 review surfaces. The
 * player, caption and shared-comment styles keep their existing visual system.
 * The selectors accept both semantic classes and data attributes so the
 * renderer can update state without relying on CSS-only interaction.
 */

:where(.version-switcher, [data-variant-switcher]) {
  --variant-ink: #252822;
  --variant-muted: #62695f;
  --variant-line: #d9d9cf;
  --variant-surface: #fffefb;
  --variant-soft: #f7f5ee;
  --variant-accent: #b64810;
  --variant-accent-soft: #fff0e2;
  --variant-focus: #9a4b20;
  container-type: inline-size;
  display: grid;
  gap: 12px;
  min-inline-size: 0;
  padding: clamp(14px, 2vw, 20px);
  border: 1px solid var(--variant-line);
  border-radius: 12px;
  background: var(--variant-surface);
  color: var(--variant-ink);
  box-shadow: 0 8px 24px rgb(37 40 34 / 6%);
}

:where(.version-switcher, [data-variant-switcher]) > :where(header, .variant-switcher__header, [data-variant-header]) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px 12px;
}

:where(.version-switcher, [data-variant-switcher]) :where(h2, h3, .variant-switcher__title, [data-variant-title]) {
  min-inline-size: 0;
  margin: 0;
  color: var(--variant-ink);
  font-size: clamp(15px, 1.7cqi, 19px);
  line-height: 1.25;
  letter-spacing: -.025em;
}

:where(.version-switcher, [data-variant-switcher]) :where(header p, .variant-switcher__hint, [data-variant-hint]) {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--variant-muted);
  font-size: 12px;
  line-height: 1.55;
}

:where(.version-switcher, [data-variant-switcher]) :where(.variant-switcher__status, [data-variant-status], [role='status']) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-block-size: 24px;
  max-inline-size: 100%;
  padding: 3px 8px;
  border: 1px solid #d9c8b6;
  border-radius: 999px;
  background: #fff8ed;
  color: #854014;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}

:where(.version-switcher, [data-variant-switcher]) :where(fieldset, .variant-group, [data-variant-group]) {
  display: grid;
  gap: 8px;
  min-inline-size: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

:where(.version-switcher, [data-variant-switcher]) :where(legend, .variant-group__title, [data-variant-group-title]) {
  inline-size: 100%;
  margin-block-end: 1px;
  padding: 0;
  color: var(--variant-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

:where(.version-switcher, [data-variant-switcher]) :where(.variant-options, .variant-list, [data-variant-options], [data-variant-list]) {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  gap: 8px;
  min-inline-size: 0;
}

/* Radio/checkbox cards stay native and remain reachable in the tab order. */
:where(.version-switcher, [data-variant-switcher]) :where(label.variant-card, .variant-card, [data-variant-card], [data-variant-option]) {
  position: relative;
  display: grid;
  align-content: start;
  gap: 5px;
  min-inline-size: 0;
  min-block-size: 72px;
  padding: 12px;
  border: 1px solid #d6d8cc;
  border-radius: 9px;
  background: #fffefb;
  color: var(--variant-ink);
  text-align: start;
  transition: border-color 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}

:where(.version-switcher, [data-variant-switcher]) :where(label.variant-card, .variant-card, [data-variant-card], [data-variant-option]):hover {
  border-color: #b7a38d;
  background: #fffaf3;
}

:where(.version-switcher, [data-variant-switcher]) :where(label.variant-card, .variant-card, [data-variant-card], [data-variant-option]):focus-within,
:where(.version-switcher, [data-variant-switcher]) :where(button[data-variant], [role='radio'], [role='option']):focus-visible {
  outline: 2px solid var(--variant-focus);
  outline-offset: 2px;
}

:where(.version-switcher, [data-variant-switcher]) :where(label.variant-card, .variant-card, [data-variant-card], [data-variant-option]):has(:checked),
:where(.version-switcher, [data-variant-switcher]) :where(.variant-card, [data-variant-card], [data-variant-option])[aria-checked='true'],
:where(.version-switcher, [data-variant-switcher]) :where(.variant-card, [data-variant-card], [data-variant-option])[aria-selected='true'],
:where(.version-switcher, [data-variant-switcher]) :where(.variant-card, [data-variant-card], [data-variant-option])[data-selected='true'],
:where(.version-switcher, [data-variant-switcher]) :where(.variant-card, [data-variant-card], [data-variant-option])[data-current='true'] {
  border-color: var(--variant-accent);
  background: var(--variant-accent-soft);
  box-shadow: inset 0 0 0 1px rgb(182 72 16 / 18%);
}

:where(.version-switcher, [data-variant-switcher]) :where(.variant-card, [data-variant-card], [data-variant-option])[data-current='true']::after,
:where(.version-switcher, [data-variant-switcher]) :where(.variant-card, [data-variant-card], [data-variant-option])[aria-current='true']::after {
  content: '当前';
  position: absolute;
  inset-block-start: 9px;
  inset-inline-end: 9px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--variant-accent);
  color: #fffaf2;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
}

:where(.version-switcher, [data-variant-switcher]) :where(.variant-card input[type='radio'], .variant-card input[type='checkbox'], [data-variant-card] input[type='radio'], [data-variant-card] input[type='checkbox']) {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

:where(.version-switcher, [data-variant-switcher]) :where(.variant-card__title, [data-variant-title], .variant-card strong, [data-variant-card] > strong) {
  display: block;
  min-inline-size: 0;
  padding-inline-end: 38px;
  color: var(--variant-ink);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

:where(.version-switcher, [data-variant-switcher]) :where(.variant-card__description, [data-variant-description], .variant-card p, [data-variant-card] > p) {
  margin: 0;
  color: var(--variant-muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

:where(.version-switcher, [data-variant-switcher]) :where(.variant-card__meta, [data-variant-meta], .variant-card small, [data-variant-card] > small) {
  color: #8a5a3c;
  font-size: 10px;
  line-height: 1.4;
}

:where(.version-switcher, [data-variant-switcher]) :where(button, input, select, textarea, summary):focus-visible,
:where(.journey-debug, .station-map-status, [data-map-status]) :where(button, input, select, textarea, summary):focus-visible {
  outline: 2px solid var(--variant-focus, #9a4b20);
  outline-offset: 2px;
}

:where(.version-switcher, [data-variant-switcher]) :where(button[data-variant], [data-variant-action], .variant-card[role='button']) {
  inline-size: 100%;
  min-block-size: 72px;
  padding: 12px;
  border: 1px solid #d6d8cc;
  border-radius: 9px;
  background: var(--variant-surface);
  color: var(--variant-ink);
  font: inherit;
  text-align: start;
  cursor: pointer;
}

:where(.version-switcher, [data-variant-switcher]) :where(button[data-variant], [data-variant-action], .variant-card[role='button']):hover,
:where(.version-switcher, [data-variant-switcher]) :where(button[data-variant], [data-variant-action], .variant-card[role='button'])[aria-pressed='true'],
:where(.version-switcher, [data-variant-switcher]) :where(button[data-variant], [data-variant-action], .variant-card[role='button'])[aria-selected='true'] {
  border-color: var(--variant-accent);
  background: var(--variant-accent-soft);
}

:where(.version-switcher, [data-variant-switcher]) :where(button[disabled], [aria-disabled='true']) {
  opacity: .58;
  cursor: not-allowed;
}

/* Branch choices share the same card language while preserving player layout. */
:where(.branch-card, [data-branch-card], .route-card, [data-route-card], [data-choice-card]) {
  position: relative;
  display: grid;
  gap: 6px;
  min-inline-size: 0;
  padding: 12px;
  border: 1px solid #d4d6c9;
  border-radius: 9px;
  background: #fffdf6;
  color: #293128;
  text-align: start;
}

:where(.branch-card, [data-branch-card], .route-card, [data-route-card], [data-choice-card]) :where(h3, h4, strong) {
  margin: 0;
  color: inherit;
  font-size: 14px;
  line-height: 1.35;
}

:where(.branch-card, [data-branch-card], .route-card, [data-route-card], [data-choice-card]) :where(p, small) {
  margin: 0;
  color: #62695f;
  font-size: 12px;
  line-height: 1.5;
}

:where(.branch-card, [data-branch-card], .route-card, [data-route-card], [data-choice-card]):has(:checked),
:where(.branch-card, [data-branch-card], .route-card, [data-route-card], [data-choice-card])[aria-selected='true'],
:where(.branch-card, [data-branch-card], .route-card, [data-route-card], [data-choice-card])[aria-pressed='true'],
:where(.branch-card, [data-branch-card], .route-card, [data-route-card], [data-choice-card])[data-selected='true'] {
  border-color: var(--variant-accent, #b64810);
  background: var(--variant-accent-soft, #fff0e2);
  box-shadow: inset 0 0 0 1px rgb(182 72 16 / 16%);
}

:where(.branch-card, [data-branch-card], .route-card, [data-route-card], [data-choice-card]) :where(button, a, input, select) {
  position: relative;
  z-index: 1;
}

:where(.branch-card, [data-branch-card], .route-card, [data-route-card], [data-choice-card]) :where(button, a) {
  min-block-size: 38px;
  padding: 8px 10px;
  border: 1px solid #c6c9bc;
  border-radius: 6px;
  background: #f3f1e8;
  color: #303e32;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

:where(.branch-card, [data-branch-card], .route-card, [data-route-card], [data-choice-card]) :where(button, a):hover {
  border-color: #a96139;
  background: #fff6e9;
}

/* Current site/map context is intentionally compact and readable over the stage. */
:where(.station-map-status, [data-map-status], .map-status) {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 7px 9px;
  min-inline-size: 0;
  padding: 8px 10px;
  border: 1px solid #d6d6ca;
  border-radius: 8px;
  background: rgb(255 253 246 / 94%);
  color: #3f493e;
  box-shadow: 0 3px 14px rgb(48 40 28 / 9%);
  font-size: 12px;
  line-height: 1.45;
}

:where(.station-map-status, [data-map-status], .map-status) :where(strong, [data-map-title], .map-status__title) {
  min-inline-size: 0;
  color: #293128;
  font-size: 12px;
  font-weight: 750;
  overflow-wrap: anywhere;
}

:where(.station-map-status, [data-map-status], .map-status) :where(p, span, [data-map-detail], .map-status__detail) {
  min-inline-size: 0;
  margin: 0;
  color: #62695f;
  overflow-wrap: anywhere;
}

:where(.station-map-status, [data-map-status], .map-status)[data-state='active'],
:where(.station-map-status, [data-map-status], .map-status)[aria-live='polite'] {
  border-color: #c7d0c0;
}

:where(.station-map-status, [data-map-status], .map-status)[data-state='complete'] {
  border-color: #a8c5b1;
  background: #f3faf2;
}

:where(.station-map-status, [data-map-status], .map-status)[data-state='error'] {
  border-color: #d9b6a4;
  background: #fff6f1;
  color: #7d3d1c;
}

/* Debug entry remains quiet until the user opens it. */
:where(.journey-debug, [data-journey-debug]) {
  display: grid;
  gap: 8px;
  min-inline-size: 0;
  padding: 10px 12px;
  border: 1px solid #d1d6cc;
  border-radius: 9px;
  background: #f4f5ef;
  color: #465046;
  font-size: 11px;
  line-height: 1.5;
}

:where(.journey-debug, [data-journey-debug])[hidden] {
  display: none;
}

:where(.journey-debug, [data-journey-debug]) :where(header, .debug-header, [data-debug-header]) {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 10px;
}

:where(.journey-debug, [data-journey-debug]) :where(h2, h3, strong) {
  margin: 0;
  color: #303e32;
  font-size: 12px;
  line-height: 1.35;
}

:where(.journey-debug, [data-journey-debug]) :where(dl, .debug-grid, [data-debug-grid]) {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 10px;
  min-inline-size: 0;
  margin: 0;
}

:where(.journey-debug, [data-journey-debug]) :where(dt, dd, p) {
  min-inline-size: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

:where(.journey-debug, [data-journey-debug]) :where(dt) {
  color: #697267;
  font-weight: 650;
}

:where(.journey-debug, [data-journey-debug]) :where(dd) {
  color: #303e32;
  font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

:where(.journey-debug, [data-journey-debug]) :where(button, summary) {
  min-block-size: 34px;
  padding: 6px 9px;
  border: 1px solid #c7cec0;
  border-radius: 6px;
  background: #fffefb;
  color: #3d4a3e;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

:where(.journey-debug, [data-journey-debug]) :where(button, summary):hover {
  border-color: #a96139;
  background: #fff8ed;
}

@container (max-width: 30rem) {
  :where(.version-switcher, [data-variant-switcher]) {
    padding: 12px;
  }

  :where(.version-switcher, [data-variant-switcher]) > :where(header, .variant-switcher__header, [data-variant-header]) {
    grid-template-columns: 1fr;
  }

  :where(.version-switcher, [data-variant-switcher]) :where(.variant-switcher__status, [data-variant-status], [role='status']) {
    justify-self: start;
  }

  :where(.version-switcher, [data-variant-switcher]) :where(.variant-options, .variant-list, [data-variant-options], [data-variant-list]) {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 740px) {
  :where(.version-switcher, [data-variant-switcher]) {
    border-radius: 10px;
    box-shadow: 0 5px 18px rgb(37 40 34 / 6%);
  }

  :where(.station-map-status, [data-map-status], .map-status) {
    max-inline-size: calc(100vw - 28px);
  }

  :where(.journey-debug, [data-journey-debug]) :where(dl, .debug-grid, [data-debug-grid]) {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  :where(.journey-debug, [data-journey-debug]) :where(dt) {
    margin-block-start: 4px;
  }
}

@media (pointer: coarse) {
  :where(.version-switcher, [data-variant-switcher]) :where(label.variant-card, .variant-card, [data-variant-card], [data-variant-option], button[data-variant], [data-variant-action]) {
    min-block-size: 78px;
    padding: 13px;
  }

  :where(.journey-debug, [data-journey-debug]) :where(button, summary) {
    min-block-size: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  :where(.version-switcher, [data-variant-switcher]) :where(.variant-card, [data-variant-card], [data-variant-option], button[data-variant], [data-variant-action]) {
    transition: none;
  }
}

@media (forced-colors: active) {
  :where(.version-switcher, [data-variant-switcher], .journey-debug, [data-journey-debug], .station-map-status, [data-map-status], .map-status, .branch-card, [data-branch-card], .route-card, [data-route-card], [data-choice-card]) {
    border-color: CanvasText;
    background: Canvas;
    color: CanvasText;
    box-shadow: none;
  }

  :where(.version-switcher, [data-variant-switcher]) :where(.variant-card, [data-variant-card], [data-variant-option])[data-current='true']::after,
  :where(.version-switcher, [data-variant-switcher]) :where(.variant-card, [data-variant-card], [data-variant-option])[aria-current='true']::after {
    border: 1px solid CanvasText;
    background: Highlight;
    color: HighlightText;
  }
}

.branch-switcher {
  display: grid;
  gap: 10px;
  margin-top: 2px;
  padding-top: 10px;
  border-top: 1px solid var(--variant-line, #d9d9cf);
}
.branch-switcher[hidden] { display: none; }
.branch-group { display: grid; gap: 6px; min-width: 0; }
.branch-group h3 { margin: 0; color: var(--variant-muted, #62695f); font-size: 11px; letter-spacing: .04em; }
.branch-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 8px; }
.branch-card { min-height: 72px; cursor: pointer; }
.branch-card[aria-pressed='true'] { border-color: var(--variant-accent, #b64810); background: var(--variant-accent-soft, #fff0e2); }
.branch-card strong { display: block; }
.branch-card span, .branch-card small { display: block; }
.branch-card small { color: var(--variant-muted, #62695f); font-size: 10px; }
