/* ==========================================================================
   Split-Flap Board Styles
   ========================================================================== */

:root {
  --bg-page: #111317;
  --bg-console: #1b1f26;
  --bg-panel: #222730;
  --border-panel: #343b48;
  --text-primary: #f1f3f5;
  --text-secondary: #bcc4cc;
  --text-muted: #9ca6b0;
  --ruler-color: #a5b0bc;
  --focus-ring: #ffd43b;
  --warning-color: #ffd43b;
  --error-color: #ff6b6b;

  /* Theme defaults: Classic Charcoal */
  --housing-bg: linear-gradient(160deg, #2a2f37 0%, #171a1f 55%, #0e1014 100%);
  --bezel-bg: #0a0c0f;
  --flap-bg: #1e2126;
  --flap-bg-top: #23272d;
  --flap-bg-bottom: #181b20;
  --flap-border: #0a0b0d;
  --flap-fg: #f7f4eb;
  --flap-fg-accent: #ffd43b;
  --board-accent: #f59f00;
  --board-accent-text: #111317;
  --hinge-color: #060709;
  --pin-color: #495057;
}

body[data-theme="amber"] {
  --flap-bg: #191512;
  --flap-bg-top: #211b17;
  --flap-bg-bottom: #15110e;
  --flap-fg: #ffb649;
  --flap-fg-accent: #ffe08a;
  --board-accent: #ff922b;
  --board-accent-text: #140d06;
  --focus-ring: #ffb649;
}

body[data-theme="retro"] {
  --flap-bg: #161b18;
  --flap-bg-top: #1d2420;
  --flap-bg-bottom: #111613;
  --flap-fg: #ffe066;
  --flap-fg-accent: #74c0fc;
  --board-accent: #fcc419;
  --board-accent-text: #101411;
  --focus-ring: #ffe066;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

/* Visually hidden utility per modern-web-guidance accessibility guide */
.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

.skip-link:focus-within,
.skip-link:active {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 1000;
  padding: 0.75rem 1rem;
  background: var(--board-accent);
  color: var(--board-accent-text);
  font-weight: 700;
  border-radius: 6px;
  text-decoration: none;
}

/* Focus indicators */
:where(a:any-link, button, input, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ==========================================================================
   Header (Single row on desktop & short landscape, compact 2-row on portrait)
   ========================================================================== */

.station-header {
  border-bottom: 1px solid var(--border-panel);
  background: #111317;
  flex-shrink: 0;
}

.header-inner {
  width: 100%;
  margin: 0 auto;
  padding: 0.42rem 0.85rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 0.75rem;
}

.station-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.station-badge {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 0.22rem 0.48rem;
  border-radius: 4px;
  background: var(--board-accent);
  color: var(--board-accent-text);
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.station-brand h1 {
  margin: 0;
  font-size: clamp(0.95rem, 1.4vw, 1.16rem);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-telemetry {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: nowrap;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: auto;
}

.board-actions-bar,
.auth-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.auth-user-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border-panel);
  background: var(--bg-console);
  color: var(--text-secondary);
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.78rem;
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-user-pill[hidden] {
  display: none;
}

.auth-user-pill[data-signed-in="true"] {
  border-color: rgba(64, 192, 87, 0.55);
  color: #8ce99a;
}

.njt-live-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(64, 192, 87, 0.55);
  background: rgba(64, 192, 87, 0.14);
  color: #8ce99a;
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.njt-live-badge[data-simulated="true"] {
  border-color: rgba(245, 159, 0, 0.65);
  background: rgba(245, 159, 0, 0.14);
  color: #ffd43b;
}

.njt-live-badge[data-alert="true"] {
  border-color: rgba(255, 107, 107, 0.7);
  background: rgba(255, 107, 107, 0.16);
  color: #ffa8a8;
}

.njt-live-badge[hidden] {
  display: none;
}

.btn-header {
  min-height: 36px;
  padding: 0.32rem 0.7rem;
  font-size: 0.86rem;
  white-space: nowrap;
}

.btn-compact {
  min-height: 40px;
  padding: 0.42rem 0.9rem;
  font-size: 0.9rem;
  white-space: nowrap;
}

.btn-micro {
  min-height: 32px;
  padding: 0.22rem 0.6rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

#console-toggle-btn[aria-expanded="true"],
#demo-mode-btn[aria-pressed="true"],
#kiosk-demo-btn[aria-pressed="true"],
#mobile-demo-btn[aria-pressed="true"],
#mobile-layout-toggle-btn[aria-pressed="true"] {
  border-color: var(--board-accent);
  color: var(--board-accent);
  background: #262c37;
}

/* Tablet / medium width: keep clean 2-row rhythm */
@media (max-width: 1020px) {
  .header-inner {
    padding: 0.4rem 0.75rem;
    gap: 0.35rem 0.65rem;
  }
}

.kiosk-hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.85rem;
  margin-bottom: 0.55rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.kiosk-hud[hidden] {
  display: none;
}

.kiosk-hud-left,
.kiosk-hud-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.kiosk-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.24rem 0.58rem;
  border-radius: 4px;
  background: var(--board-accent);
  color: var(--board-accent-text);
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.kiosk-sender-badge {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.78rem;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
}

/* Fullscreen Kiosk Mode */
body[data-kiosk="true"] .station-header,
body[data-kiosk="true"] .board-header-bar,
body[data-kiosk="true"] .mobile-board-bar {
  display: none;
}

body[data-kiosk="true"] .app-layout {
  max-width: none;
  width: 100%;
  min-height: 0;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  margin: 0;
  padding: 0;
  justify-content: center;
}

body[data-kiosk="true"] .board-frame {
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: 0;
  border: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding:
    calc(0.55rem + env(safe-area-inset-top, 0px))
    calc(0.75rem + env(safe-area-inset-right, 0px))
    calc(0.75rem + env(safe-area-inset-bottom, 0px))
    calc(0.75rem + env(safe-area-inset-left, 0px));
}

.clock-module,
.status-module {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.28rem 0.58rem;
  border-radius: 6px;
  background: var(--bg-console);
  border: 1px solid var(--border-panel);
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.telemetry-label {
  color: var(--text-muted);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
}

.activity-led {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #40c057;
  box-shadow: 0 0 8px rgba(64, 192, 87, 0.7);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.activity-led[data-state="flipping"] {
  background: #fcc419;
  box-shadow: 0 0 12px rgba(252, 196, 25, 0.9);
}

/* Narrow portrait mobile: strict compact 2-row header (~80px max, ~9.5% of 844px) */
@media (max-width: 680px) {
  .header-inner {
    padding: 0.35rem 0.6rem;
    gap: 0.32rem 0.45rem;
  }

  .station-brand {
    flex: 1 1 auto;
    min-width: 0;
  }

  .station-brand h1 {
    font-size: 0.84rem;
    letter-spacing: 0.02em;
  }

  .station-badge {
    font-size: 0.66rem;
    padding: 0.16rem 0.38rem;
  }

  .header-telemetry {
    gap: 0.3rem;
    flex-shrink: 0;
  }

  .station-header .telemetry-label,
  .station-header .status-module,
  .station-header .btn-demo-header,
  .station-header .auth-user-pill {
    display: none;
  }

  .station-header .clock-module {
    padding: 0.2rem 0.42rem;
    font-size: 0.74rem;
  }

  .station-header .njt-live-badge {
    padding: 0.18rem 0.42rem;
    font-size: 0.66rem;
  }

  .header-controls {
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
    gap: 0.35rem;
  }

  .board-actions-bar,
  .auth-bar {
    gap: 0.35rem;
  }

  .btn-header {
    min-height: 44px;
    padding: 0.3rem 0.62rem;
    font-size: 0.82rem;
  }
}

@media (max-width: 480px) {
  .kiosk-hud {
    gap: 0.35rem 0.5rem;
    margin-bottom: 0.4rem;
    padding-bottom: 0.4rem;
  }

  .kiosk-sender-badge,
  .kiosk-hud .status-module,
  .kiosk-hud .telemetry-label {
    display: none;
  }

  .kiosk-badge {
    font-size: 0.68rem;
    padding: 0.2rem 0.45rem;
  }

  .kiosk-hud .btn-header {
    min-height: 40px;
    padding: 0.25rem 0.55rem;
    font-size: 0.78rem;
  }
}

@media (max-width: 360px) {
  .header-inner {
    padding: 0.32rem 0.45rem;
    gap: 0.28rem 0.35rem;
  }

  .station-brand h1 {
    font-size: 0.78rem;
  }

  .board-actions-bar,
  .auth-bar {
    gap: 0.25rem;
  }

  .btn-header {
    min-height: 44px;
    padding: 0.25rem 0.48rem;
    font-size: 0.76rem;
  }
}

/* Short landscape viewports (e.g. 844x390 phone landscape): single 42px row */
@media (max-height: 480px) {
  .header-inner {
    flex-wrap: nowrap;
    padding: 0.26rem 0.65rem;
    gap: 0.45rem;
  }

  .station-brand h1 {
    font-size: 0.82rem;
  }

  .station-header .telemetry-label,
  .station-header .status-module,
  .station-header .btn-demo-header,
  .station-header .auth-user-pill {
    display: none;
  }

  .station-header .clock-module {
    padding: 0.18rem 0.42rem;
    font-size: 0.74rem;
  }

  .station-header .njt-live-badge {
    padding: 0.16rem 0.42rem;
    font-size: 0.66rem;
  }

  .btn-header {
    min-height: 32px;
    padding: 0.2rem 0.55rem;
    font-size: 0.78rem;
  }

  .board-header-bar {
    display: none !important;
  }

  .board-frame {
    padding: 0.3rem 0.5rem 0.4rem !important;
  }

  .board-bezel {
    padding: 0.3rem !important;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .activity-led[data-state="flipping"] {
    animation: led-pulse 0.7s ease-in-out infinite alternate;
  }

  .board-frame[data-board-state="cleared"] .lamp-dot {
    animation: standby-pulse 2.2s ease-in-out infinite alternate;
  }

  @keyframes led-pulse {
    from {
      opacity: 0.6;
    }
    to {
      opacity: 1;
    }
  }

  @keyframes standby-pulse {
    from {
      opacity: 0.35;
    }
    to {
      opacity: 0.95;
    }
  }
}

/* Main Layout */
.app-layout {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  flex: 1;
  min-height: 0;
}

/* ==========================================================================
   Split-Flap Display Frame
   ========================================================================== */

.board-frame {
  width: 100%;
  flex: 1;
  min-height: 0;
  background: var(--housing-bg);
  border: 0;
  border-radius: 0;
  padding: 0.55rem 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -2px 0 rgba(0, 0, 0, 0.7);
}

.board-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.board-title-plate {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #101216;
  border: 1px solid #303640;
  padding: 0.22rem 0.6rem;
  border-radius: 4px;
  color: var(--board-accent);
  font-weight: 700;
  white-space: nowrap;
}

.plate-screw {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #868e96, #343a40);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.8);
}

.column-ruler {
  flex: 1;
  max-width: var(--board-w, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 28), minmax(0, 1fr));
  gap: var(--grid-gap-x, 4px);
  text-align: center;
  color: var(--ruler-color);
  font-size: 0.68rem;
  font-weight: 600;
}

@media (max-width: 720px) {
  .column-ruler {
    display: none;
  }
}

.board-status-lamp {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.lamp-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--board-accent);
  box-shadow: 0 0 6px var(--board-accent);
}

.board-bezel {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  isolation: isolate;
  contain: layout style;
  background: var(--bezel-bg);
  border-radius: 8px;
  padding: clamp(0.35rem, 0.85vw, 0.65rem);
  border: 2px solid #040507;
  box-shadow:
    inset 0 4px 16px rgba(0, 0, 0, 0.95),
    0 1px 0 rgba(255, 255, 255, 0.08);
}

.board-bezel[data-scrollable="true"] {
  overflow-x: auto;
  overflow-y: hidden;
  align-items: flex-start;
  justify-content: center;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}

.flipboard-grid {
  width: var(--board-w, 100%);
  height: var(--board-h, 100%);
  flex-shrink: 0;
  max-height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 28), minmax(0, 1fr));
  grid-template-rows: repeat(var(--grid-rows, 10), minmax(0, 1fr));
  gap: var(--grid-gap-y, 5px) var(--grid-gap-x, 4px);
}

.board-bezel:not([data-scrollable="true"]) .flipboard-grid {
  max-width: 100%;
}

/* Cleared-board standby overlay so blank drums never look broken */
.board-standby-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 12;
  background: radial-gradient(circle at center, rgba(10, 12, 15, 0.68) 0%, rgba(10, 12, 15, 0.25) 75%);
  pointer-events: none;
}

.board-standby-overlay[hidden] {
  display: none;
}

.standby-card {
  pointer-events: auto;
  background: rgba(20, 24, 30, 0.92);
  border: 1px solid rgba(255, 146, 43, 0.45);
  border-radius: 10px;
  padding: 0.95rem 1.25rem;
  text-align: center;
  max-width: min(400px, calc(100% - 1rem));
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.72);
}

.standby-eyebrow {
  display: block;
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: var(--board-accent);
  margin-bottom: 0.35rem;
}

.standby-copy {
  margin: 0 0 0.8rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.standby-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

/* Mobile portrait helper bar */
.mobile-board-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.45rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  background: rgba(16, 18, 22, 0.85);
  border: 1px solid var(--border-panel);
  flex-shrink: 0;
}

.mobile-board-bar[hidden] {
  display: none;
}

.mobile-board-hint {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.7rem;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

.mobile-board-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

@media (max-width: 600px) and (orientation: portrait) {
  .board-frame {
    padding: 0.4rem 0.5rem 0.5rem;
    justify-content: flex-start;
  }

  .board-header-bar {
    margin-bottom: 0.32rem;
    gap: 0.4rem;
    font-size: 0.64rem;
    letter-spacing: 0.04em;
  }

  .board-title-plate {
    padding: 0.16rem 0.42rem;
    gap: 0.3rem;
    min-width: 0;
    flex: 0 1 auto;
    overflow: hidden;
  }

  .board-title-plate .plate-text {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .board-status-lamp {
    flex-shrink: 0;
  }

  .plate-screw {
    display: none;
  }

  .board-bezel {
    flex: 1 1 auto;
    padding: 0.38rem;
  }
}

/* Individual Split-Flap Cell (flat & zero 3D layers while idle for iPad Safari performance) */
.flap-cell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  contain: layout style paint;
  border-radius: clamp(2px, 0.3vw, 4px);
  background: var(--flap-bg);
  border: 1px solid var(--flap-border);
  box-shadow:
    0 1px 0 rgba(0, 0, 0, 0.85),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.12s ease;
}

@media (hover: hover) {
  .flap-cell:hover {
    border-color: var(--board-accent);
    transform: scale(1.03);
  }
}

.flap-half,
.flap-leaf {
  position: absolute;
  left: 0;
  right: 0;
  font-family: "JetBrains Mono", "SF Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
  font-weight: 700;
  font-size: var(--tile-font-size, 24px);
  line-height: 1;
  letter-spacing: 0;
  color: var(--flap-fg);
  pointer-events: none;
}

.flap-cell[data-accent="true"] .flap-half,
.flap-cell[data-accent="true"] .flap-leaf {
  color: var(--flap-fg-accent);
}

/* Static halves use pure box-clipping (overflow: hidden) — zero clip-path masks on idle tiles */
.top-static {
  top: 0;
  height: 50%;
  overflow: hidden;
  z-index: 1;
  background: linear-gradient(180deg, var(--flap-bg-top) 0%, var(--flap-bg) 100%);
}

.top-static > span {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 200%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bottom-static {
  bottom: 0;
  height: 50%;
  overflow: hidden;
  z-index: 1;
  background: linear-gradient(180deg, var(--flap-bg-bottom) 0%, #121418 100%);
}

.bottom-static > span {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 200%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Moving 3D leaves stay display: none while idle so WebKit creates zero 3D CALayers at rest */
.flap-leaf {
  top: 0;
  bottom: 0;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  transform-origin: 50% 50%;
}

.top-flip {
  z-index: 3;
  -webkit-clip-path: inset(0 0 50% 0);
  clip-path: inset(0 0 50% 0);
  background: linear-gradient(180deg, var(--flap-bg-top) 0%, var(--flap-bg) 50%);
}

.bottom-flip {
  z-index: 4;
  -webkit-clip-path: inset(50% 0 0 0);
  clip-path: inset(50% 0 0 0);
  background: linear-gradient(180deg, var(--flap-bg-bottom) 50%, #121418 100%);
  opacity: 0;
}

/* Center mechanical split hinge & side pins (scaled to actual drum size) */
.flap-hinge {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  margin-top: -0.5px;
  background: var(--hinge-color);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05);
  z-index: 6;
  pointer-events: none;
}

.flap-hinge::before,
.flap-hinge::after {
  content: "";
  position: absolute;
  top: -1px;
  width: 1.5px;
  height: 3px;
  background: var(--pin-color);
  border-radius: 1px;
}

.flap-hinge::before {
  left: 1px;
}

.flap-hinge::after {
  right: 1px;
}

.board-frame[data-tile-size="sm"] .flap-hinge {
  height: 1px;
  margin-top: -0.5px;
  box-shadow: none;
}

.board-frame[data-tile-size="sm"] .flap-hinge::before,
.board-frame[data-tile-size="sm"] .flap-hinge::after {
  display: none;
}

.board-frame[data-tile-size="lg"] .flap-hinge {
  height: 2px;
  margin-top: -1px;
}

.board-frame[data-tile-size="lg"] .flap-hinge::before,
.board-frame[data-tile-size="lg"] .flap-hinge::after {
  top: -2px;
  width: 2px;
  height: 5px;
}

/* 3D Flip Animation (compositor-only transform & opacity; 3D layers exist ONLY while flipping) */
@media (prefers-reduced-motion: no-preference) {
  .flap-cell.is-flipping-a,
  .flap-cell.is-flipping-b {
    perspective: 340px;
  }

  .flap-cell.is-flipping-a .top-flip,
  .flap-cell.is-flipping-a .bottom-flip,
  .flap-cell.is-flipping-b .top-flip,
  .flap-cell.is-flipping-b .bottom-flip {
    display: flex;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    will-change: transform, opacity;
  }

  .flap-cell.is-flipping-a .top-flip {
    animation: flip-top-down-a var(--step-duration, 52ms) ease-in forwards;
  }

  .flap-cell.is-flipping-b .top-flip {
    animation: flip-top-down-b var(--step-duration, 52ms) ease-in forwards;
  }

  .flap-cell.is-flipping-a .bottom-flip {
    animation: flip-bottom-down-a var(--step-duration, 52ms) ease-out forwards;
  }

  .flap-cell.is-flipping-b .bottom-flip {
    animation: flip-bottom-down-b var(--step-duration, 52ms) ease-out forwards;
  }

  @keyframes flip-top-down-a {
    0% {
      transform: rotateX(0deg);
      opacity: 1;
    }
    49% {
      transform: rotateX(-90deg);
      opacity: 1;
    }
    50%,
    100% {
      transform: rotateX(-90deg);
      opacity: 0;
    }
  }

  @keyframes flip-top-down-b {
    0% {
      transform: rotateX(0deg);
      opacity: 1;
    }
    49% {
      transform: rotateX(-90deg);
      opacity: 1;
    }
    50%,
    100% {
      transform: rotateX(-90deg);
      opacity: 0;
    }
  }

  @keyframes flip-bottom-down-a {
    0%,
    49% {
      transform: rotateX(90deg);
      opacity: 0;
    }
    50% {
      transform: rotateX(90deg);
      opacity: 1;
    }
    100% {
      transform: rotateX(0deg);
      opacity: 1;
    }
  }

  @keyframes flip-bottom-down-b {
    0%,
    49% {
      transform: rotateX(90deg);
      opacity: 0;
    }
    50% {
      transform: rotateX(90deg);
      opacity: 1;
    }
    100% {
      transform: rotateX(0deg);
      opacity: 1;
    }
  }
}

/* ==========================================================================
   Modal Dialog Shared Scroll Containment (per modern-web-guidance dialog)
   ========================================================================== */

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(5, 7, 10, 0.8);
  overflow: hidden;
  overscroll-behavior: contain;
}

/* ==========================================================================
   Modal Dispatch Console Dialog (Fits viewport cleanly, tabbed, native focus trap)
   ========================================================================== */

dialog.control-console {
  width: min(860px, calc(100vw - 1.25rem));
  max-height: min(640px, calc(100vh - 1.25rem));
  max-height: min(640px, calc(100svh - 1.25rem));
  padding: 0;
  overflow: hidden;
  background: #181c23;
  color: var(--text-primary);
  border: 1px solid var(--border-panel);
  border-top: 2px solid var(--board-accent);
  border-radius: 12px;
  box-shadow: 0 24px 54px rgba(0, 0, 0, 0.78);
}

dialog.control-console[open] {
  display: flex;
  flex-direction: column;
}

.console-shell {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.console-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border-panel);
  background: #14181f;
  flex-shrink: 0;
}

.console-title-wrap {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  min-width: 0;
  gap: 0.3rem 0.7rem;
}

.console-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.console-tag {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.console-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.4rem 1rem 0;
  border-bottom: 1px solid var(--border-panel);
  background: #14181f;
  flex-shrink: 0;
}

.console-tab {
  min-height: 40px;
  padding: 0.4rem 0.85rem;
  border: 1px solid transparent;
  border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
}

@media (max-width: 520px) {
  dialog.control-console {
    width: calc(100vw - 0.75rem);
    max-height: calc(100svh - 0.75rem);
  }

  .console-header {
    padding: 0.55rem 0.75rem;
  }

  .console-header h2 {
    font-size: 0.96rem;
  }

  .console-tag {
    display: none;
  }

  .console-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.2rem;
    padding: 0.35rem 0.5rem 0;
  }

  .console-tab {
    min-height: 44px;
    padding: 0.35rem 0.25rem;
    font-size: 0.78rem;
    text-align: center;
  }

  .console-body {
    padding: 0.75rem 0.75rem;
  }

  .console-shortcuts {
    padding: 0.45rem 0.75rem;
  }
}

.console-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.console-tab[aria-selected="true"] {
  color: var(--board-accent);
  background: #181c23;
  border-color: var(--border-panel);
  border-bottom-color: var(--board-accent);
}

.console-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  padding: 0.85rem 1.05rem;
}

.console-panel[hidden] {
  display: none;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-block-end: 0.85rem;
}

.label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
}

.label-row label {
  font-weight: 600;
  font-size: 0.94rem;
}

.char-counter {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.char-counter[data-status="warning"] {
  color: var(--warning-color);
  font-weight: 700;
}

.char-counter[data-status="error"] {
  color: var(--error-color);
  font-weight: 700;
}

.field-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.field-hint code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--bg-panel);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  color: var(--text-primary);
}

.field-warning {
  font-size: 0.84rem;
  color: var(--warning-color);
  font-weight: 600;
}

.field-warning[hidden] {
  display: none;
}

.field-error {
  font-size: 0.85rem;
  color: var(--error-color);
  font-weight: 600;
}

.field-error[hidden] {
  display: none;
}

textarea#message-input {
  width: 100%;
  font: inherit;
  font-size: max(1rem, 0.95rem);
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  line-height: 1.45;
  min-height: 96px;
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  border: 1.5px solid #495057;
  background: #101318;
  color: var(--text-primary);
  resize: vertical;
  transition: border-color 0.15s ease;
}

textarea#message-input:hover {
  border-color: #6c757d;
}

textarea#message-input[data-overflow="warning"] {
  border-color: var(--warning-color);
}

/* Kept separate from :user-invalid so Safari < 16.5 does not discard [aria-invalid="true"] */
textarea#message-input[aria-invalid="true"] {
  border-color: var(--error-color);
}

textarea#message-input:user-invalid {
  border-color: var(--error-color);
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-block-end: 0.85rem;
}

button {
  font: inherit;
  font-size: max(0.95rem, 0.92em);
  cursor: pointer;
  border-radius: 8px;
  min-height: 40px;
  padding: 0.45rem 0.95rem;
  border: 1px solid transparent;
  font-weight: 600;
  translate: 0px;
  rotate: 0deg;
  scale: 1;
  transition: background-color 0.15s ease, border-color 0.15s ease, scale 0.1s ease;
}

button:active {
  scale: 0.98;
}

@supports not (translate: 0px) {
  button {
    transform: scale(1);
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  }
  button:active {
    transform: scale(0.98);
  }
}

.btn-primary {
  background: var(--board-accent);
  color: var(--board-accent-text);
  font-weight: 700;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-secondary {
  background: var(--bg-panel);
  color: var(--text-primary);
  border-color: var(--border-panel);
}

.btn-secondary:hover {
  background: #2b313c;
  border-color: #4c5667;
}

.btn-small {
  min-height: 38px;
  padding: 0.4rem 0.85rem;
  font-size: 0.88rem;
  background: #2b313c;
  color: var(--text-primary);
  border: 1px solid #495057;
  margin-top: 0.4rem;
  width: fit-content;
}

.btn-small:hover {
  background: #363e4c;
}

.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 0.75rem;
  align-items: start;
}

.options-col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.option-fieldset {
  margin: 0;
  padding: 0.65rem 0.8rem 0.75rem;
  border: 1px solid var(--border-panel);
  border-radius: 8px;
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.alignment-inline-fieldset {
  margin-bottom: 0.85rem;
}

.option-fieldset legend {
  padding: 0 0.4rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--board-accent);
}

.choice-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.choice-list-inline {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.35rem 1.1rem;
}

.choice-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 32px;
}

.choice-item input[type="radio"],
.choice-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  min-height: 18px;
  margin: 0;
  accent-color: var(--board-accent);
  cursor: pointer;
}

.choice-item label {
  cursor: pointer;
  font-size: 0.9rem;
  padding: 4px 0;
}

.volume-control {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-top: 0.2rem;
}

.volume-control label {
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.volume-slider-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.volume-slider-row input[type="range"] {
  flex: 1;
  min-height: 28px;
  accent-color: var(--board-accent);
  cursor: pointer;
}

.volume-slider-row output {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  min-width: 3.5ch;
  text-align: right;
  color: var(--text-primary);
}

.speed-control output {
  min-width: 11ch;
  white-space: nowrap;
}

.col-delay-control output,
.pitch-control output {
  min-width: 5.5ch;
  white-space: nowrap;
}

.cols-control output,
.rows-control output {
  min-width: 8ch;
  white-space: nowrap;
}

.size-preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.size-preset-btn {
  min-height: 36px;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  background: #14171c;
  border: 1px solid #3c434f;
  color: var(--text-primary);
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 600;
}

.size-preset-btn:hover {
  border-color: var(--board-accent);
  background: #1f242d;
}

.size-preset-btn[aria-pressed="true"] {
  background: var(--board-accent);
  color: var(--board-accent-text);
  border-color: var(--board-accent);
}

.dimensions-summary {
  margin: 0.2rem 0 0;
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.76rem;
}

/* Live NJT Transit Feed Bar */
.njt-live-bar {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.njt-live-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem 1rem;
}

.njt-live-bar h3 {
  margin: 0;
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--board-accent);
}

.njt-live-status {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.njt-live-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

#njt-live-toggle-btn[aria-pressed="true"] {
  border-color: rgba(64, 192, 87, 0.75);
  background: rgba(64, 192, 87, 0.16);
  color: #8ce99a;
}

.njt-footer-editor {
  margin-top: 0.35rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border-panel);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

textarea#custom-footer-input {
  width: 100%;
  font: inherit;
  font-size: max(1rem, 0.95rem);
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  line-height: 1.4;
  min-height: 60px;
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  border: 1.5px solid #495057;
  background: #101318;
  color: var(--text-primary);
  resize: vertical;
  transition: border-color 0.15s ease;
}

textarea#custom-footer-input:hover {
  border-color: #6c757d;
}

/* Presets Bar */
.presets-bar {
  padding-top: 0.7rem;
  border-top: 1px solid var(--border-panel);
}

.presets-bar h3 {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.preset-chip {
  min-height: 36px;
  padding: 0.32rem 0.75rem;
  border-radius: 999px;
  background: #14171c;
  border: 1px solid #3c434f;
  color: var(--text-primary);
  font-size: 0.86rem;
  font-weight: 500;
  translate: 0px;
  rotate: 0deg;
  scale: 1;
  transition: border-color 0.15s ease, background-color 0.15s ease, scale 0.12s ease;
}

.preset-chip:hover {
  border-color: var(--board-accent);
  background: #1f242d;
  scale: 1.03;
}

@supports not (translate: 0px) {
  .preset-chip:hover {
    transform: scale(1.03);
  }
}

/* Console Shortcuts Footer */
.console-shortcuts {
  margin: 0;
  padding: 0.55rem 1.05rem;
  border-top: 1px solid var(--border-panel);
  background: #14181f;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
  flex-shrink: 0;
}

.console-shortcuts kbd {
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  border-radius: 4px;
  padding: 0.08rem 0.32rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.82em;
  color: var(--text-primary);
}

/* Coarse pointer touch target bump */
@media (pointer: coarse) {
  dialog.control-console button:not(.console-tab),
  dialog.api-dialog button,
  .preset-chip,
  .size-preset-btn {
    min-height: 44px;
  }
  .choice-item {
    min-height: 44px;
  }
  .choice-item input[type="radio"],
  .choice-item input[type="checkbox"] {
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
  }
}

/* API & Token / Sign-In Modal Dialogs */
dialog.api-dialog {
  width: min(640px, calc(100vw - 1.5rem));
  max-height: calc(100vh - 1.5rem);
  max-height: calc(100svh - 1.5rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  border: 1px solid var(--border-panel);
  border-top: 2px solid var(--board-accent);
  border-radius: 12px;
  background: var(--bg-console);
  color: var(--text-primary);
  padding: 1.15rem;
  box-shadow: 0 24px 54px rgba(0, 0, 0, 0.78);
}

dialog.fallback-login-dialog {
  width: min(460px, calc(100vw - 1.5rem));
}

/* Fallback modal presentation for browsers without HTMLDialogElement.showModal (Safari < 15.4) */
dialog.dialog-fallback-open {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  z-index: 1200;
}

.dialog-fallback-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1190;
  background: rgba(5, 7, 10, 0.78);
}

.api-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.7rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border-panel);
}

.api-dialog-header h2 {
  margin: 0;
  font-size: 1.08rem;
}

.api-dialog-desc {
  margin: 0 0 0.9rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.api-auth-callout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.95rem;
  padding: 0.8rem 0.95rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 146, 43, 0.45);
  background: rgba(255, 146, 43, 0.1);
}

.api-auth-callout[hidden] {
  display: none;
}

.api-auth-callout p {
  margin: 0;
  flex: 1 1 240px;
  font-size: 0.88rem;
  color: var(--text-primary);
}

.token-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.token-row input,
dialog.api-dialog input[type="text"],
dialog.api-dialog input[type="password"],
dialog.api-dialog textarea {
  flex: 1;
  min-width: 200px;
  font: inherit;
  font-size: 0.82rem;
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  line-height: 1.45;
  white-space: pre;
  overflow-x: auto;
  padding: 0.6rem 0.75rem;
  min-height: 42px;
  border-radius: 8px;
  border: 1.5px solid #495057;
  background: #101318;
  color: var(--text-primary);
}

dialog.api-dialog input[aria-invalid="true"] {
  border-color: var(--error-color);
}

.api-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.api-dialog-status {
  font-size: 0.86rem;
  color: var(--board-accent);
}

.auth-invite-note {
  margin: 0.85rem 0 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-panel);
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-secondary);
}
