:root {
  --bg-obsidian: #080b11;
  --bg-panel: #111722;
  --bg-card: #172030;
  --bg-card-hover: #1e293b;
  --border-slate: #283548;
  --text-primary: #f1f5f9;
  --text-muted: #94a3b8;
  --led-amber: #f59e0b;
  --led-emerald: #10b981;
  --led-cyan: #38bdf8;
  --led-crimson: #ef4444;
  --pref-fill: #162032;
  --pref-fill-landlocked: #1c2536;
  --pref-fill-unlocked: #13332a;
  --pref-fill-selected: #2b3b55;
  --pref-stroke: #334155;
  --font-mono: 'JetBrains Mono', monospace;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-obsidian);
  color: var(--text-primary);
  font-family: var(--font-sans);
}

/* PORTRAIT ORIENTATION LOCK OVERLAY */
#orientation-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: radial-gradient(circle at center, #151e2e 0%, #070a0f 100%);
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

@media screen and (orientation: portrait) {
  #orientation-overlay {
    display: flex;
  }
}

.rotate-card {
  max-width: 340px;
  background: var(--bg-panel);
  border: 2px solid var(--led-amber);
  border-radius: 12px;
  padding: 24px 20px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.75);
}

.rotate-icon {
  font-size: 2.6rem;
  margin-bottom: 12px;
}

.rotate-card h2 {
  font-family: var(--font-mono);
  color: var(--led-amber);
  font-size: 1.2rem;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.rotate-card p {
  font-size: 0.9rem;
  color: var(--text-primary);
  line-height: 1.45;
  margin-bottom: 8px;
}

.rotate-card .rotate-sub {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 16px;
}

/* MAIN LANDSCAPE SHELL */
#app-shell {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

/* TOP JR DEPARTURE HEADER BAR */
#jr-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 10px;
  background: linear-gradient(180deg, #161f2e 0%, #0d131d 100%);
  border-bottom: 2px solid var(--border-slate);
  flex-shrink: 0;
  gap: 8px;
}

.jr-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.jr-logo-badge {
  background: var(--led-amber);
  color: #000;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.72rem;
  padding: 3px 6px;
  border-radius: 4px;
  letter-spacing: 0.05em;
}

.jr-title-block h1 {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--text-primary);
  line-height: 1.1;
}

.jr-subtitle {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
}

/* LED READOUT STRIP */
#hud-led-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.led-cell {
  background: #06090e;
  border: 1px solid #223044;
  border-radius: 5px;
  padding: 3px 8px;
  display: flex;
  flex-direction: column;
  min-width: 72px;
}

.led-label {
  font-family: var(--font-mono);
  font-size: 0.52rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
}

.led-value {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.led-value small {
  font-size: 0.62rem;
  opacity: 0.8;
}

.led-amber { color: var(--led-amber); }
.led-emerald { color: var(--led-emerald); }
.led-cyan { color: var(--led-cyan); }
.led-crimson { color: var(--led-crimson); }

.jr-header-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

/* WORKSPACE: MAP + RIGHT INSPECTOR */
#jr-workspace {
  display: flex;
  flex: 1;
  width: 100%;
  height: calc(100dvh - 48px);
  position: relative;
  overflow: hidden;
}

#map-viewport {
  flex: 1;
  position: relative;
  height: 100%;
  background: radial-gradient(circle at 45% 45%, #0f1928 0%, #070b12 100%);
  overflow: hidden;
  touch-action: none; /* Critical for smooth D3 pan & pinch-zoom on Firefox Android */
}

#japan-atlas-svg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#japan-atlas-svg:active {
  cursor: grabbing;
}

/* LOADING BANNER */
#map-loading-banner {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 20;
  background: rgba(17, 23, 34, 0.92);
  border: 1px solid var(--led-amber);
  color: var(--led-amber);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 6px 12px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.spinner-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--led-amber);
  animation: pulseDot 1s infinite alternate;
}

@keyframes pulseDot {
  from { opacity: 0.25; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1.2); }
}

/* SVG PREFECTURE & RAIL STYLING */
.prefecture-path {
  fill: var(--pref-fill);
  stroke: var(--pref-stroke);
  stroke-width: 0.65px;
   vector-effect: non-scaling-stroke;
  transition: fill 0.15s ease;
  cursor: pointer;
}

.prefecture-path.is-landlocked {
  fill: var(--pref-fill-landlocked);
}

.prefecture-path.is-unlocked {
  fill: var(--pref-fill-unlocked);
  stroke: #10b981;
}

.prefecture-path.is-selected {
  fill: var(--pref-fill-selected);
  stroke: var(--led-amber);
  stroke-width: 1.5px;
}

.prefecture-path.is-adjacent {
  fill: #1e2d44;
  stroke: var(--led-cyan);
}

.prefecture-path.is-inactive {
  fill: #0d131c;
  opacity: 0.45;
}

/* RAIL CORRIDOR LINES */
.rail-link {
  fill: none;
  stroke-linecap: round;
  pointer-events: none;
}

.rail-local {
  stroke: #38bdf8;
  stroke-width: 1.6px;
  opacity: 0.72;
}

.rail-shinkansen-glow {
  stroke: rgba(245, 158, 11, 0.28);
  stroke-width: 4.2px;
}

.rail-shinkansen {
  stroke: #f59e0b;
  stroke-width: 2.1px;
  stroke-dasharray: 5 2;
}

.rail-ferry {
  stroke: #2dd4bf;
  stroke-width: 1.4px;
  stroke-dasharray: 2.5 3.5;
  opacity: 0.85;
}

.rail-link.highlight-link {
  opacity: 1;
  filter: drop-shadow(0 0 4px currentColor);
}

/* STATION HUB NODES */
.station-node-group {
  cursor: pointer;
}

.station-dot {
  fill: #0b0f17;
  stroke: #94a3b8;
  stroke-width: 1.3px;
  transition: transform 0.15s ease;
}

.station-dot.has-shinkansen {
  stroke: var(--led-amber);
  fill: #1e1b18;
}

.station-dot.is-selected-node {
  fill: var(--led-amber);
  stroke: #ffffff;
  stroke-width: 2px;
}

.station-dot.is-terminus {
  fill: var(--led-emerald);
  stroke: #ffffff;
  stroke-width: 1.8px;
}

.station-label {
  font-family: var(--font-mono);
  font-size: 6.2px;
  font-weight: 700;
  fill: #e2e8f0;
  paint-order: stroke;
  stroke: #070a10;
  stroke-width: 2.2px;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.hide-labels .station-label {
  display: none;
}

/* PLAYER PAWN MARKER */
.player-pawn-ring {
  fill: none;
  stroke: var(--led-emerald);
  stroke-width: 2px;
  animation: pawnPulse 1.6s infinite ease-out;
}

.player-pawn-core {
  fill: var(--led-emerald);
  stroke: #052e16;
  stroke-width: 1.2px;
}

@keyframes pawnPulse {
  0% { r: 4.5px; opacity: 1; }
  100% { r: 12px; opacity: 0; }
}

/* FLOATING MAP CONTROLS & LEGEND */
#map-zoom-controls {
  position: absolute;
  bottom: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 15;
}

.zoom-btn {
  width: 36px;
  height: 34px;
  background: rgba(17, 23, 34, 0.92);
  border: 1px solid var(--border-slate);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
}

.zoom-btn-text {
  font-size: 0.65rem;
}

.zoom-btn:active {
  border-color: var(--led-amber);
  color: var(--led-amber);
}

#map-legend {
  position: absolute;
  bottom: 12px;
  left: 56px;
  background: rgba(11, 15, 23, 0.88);
  border: 1px solid var(--border-slate);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 15;
  pointer-events: none;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-line {
  width: 18px;
  height: 3px;
  display: inline-block;
  border-radius: 2px;
}

.line-shinkansen { background: var(--led-amber); }
.line-local { background: var(--led-cyan); }
.line-ferry {
  background: repeating-linear-gradient(90deg, #2dd4bf, #2dd4bf 3px, transparent 3px, transparent 6px);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
}

.dot-landlocked {
  background: #a855f7;
}

/* RIGHT SIDE STATION INSPECTOR PANEL */
#jr-side-panel {
  width: 310px;
  height: 100%;
  background: var(--bg-panel);
  border-left: 2px solid var(--border-slate);
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 8px;
  overflow-y: auto;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

#jr-side-panel.panel-collapsed {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pref-code-pill {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  background: #1e293b;
  color: var(--led-amber);
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid #334155;
}

.geo-badge, .lock-badge {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

.badge-coastal {
  background: rgba(56, 189, 248, 0.14);
  color: var(--led-cyan);
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.badge-landlocked {
  background: rgba(168, 85, 247, 0.16);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.4);
}

.badge-locked {
  background: rgba(239, 68, 68, 0.15);
  color: var(--led-crimson);
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.badge-unlocked {
  background: rgba(16, 185, 129, 0.15);
  color: var(--led-emerald);
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.station-title-card {
  background: var(--bg-card);
  border: 1px solid var(--border-slate);
  border-radius: 6px;
  padding: 8px 10px;
}

.station-title-card h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.station-title-card h2 small {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-left: 4px;
}

.hub-station-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  margin-top: 2px;
}

.hub-label {
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.hub-value {
  font-family: var(--font-mono);
  color: var(--text-primary);
  font-weight: 600;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.metric-box {
  background: #090d14;
  border: 1px solid #1e293b;
  border-radius: 5px;
  padding: 5px 6px;
  text-align: center;
}

.metric-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.5rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.metric-val {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
}

.panel-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 90px;
}

.section-heading {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  margin-bottom: 5px;
}

.connections-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow-y: auto;
}

.conn-item {
  background: var(--bg-card);
  border: 1px solid var(--border-slate);
  border-radius: 5px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.74rem;
  cursor: pointer;
}

.conn-item:hover, .conn-item:active {
  background: var(--bg-card-hover);
  border-color: var(--led-cyan);
}

.conn-dest {
  font-weight: 600;
  color: var(--text-primary);
}

.conn-badges {
  display: flex;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
}

.pill-local {
  background: rgba(56, 189, 248, 0.15);
  color: var(--led-cyan);
  padding: 1px 5px;
  border-radius: 3px;
}

.pill-shink {
  background: rgba(245, 158, 11, 0.18);
  color: var(--led-amber);
  padding: 1px 5px;
  border-radius: 3px;
}

.pill-ferry {
  background: rgba(45, 212, 191, 0.18);
  color: #2dd4bf;
  padding: 1px 5px;
  border-radius: 3px;
}

.panel-footer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: auto;
}

/* BUTTONS */
.jr-btn {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-slate);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.jr-btn-sm {
  padding: 4px 8px;
  font-size: 0.66rem;
}

.jr-btn-full {
  width: 100%;
  text-align: center;
}

.jr-btn-amber {
  background: var(--led-amber);
  color: #090d14;
  border-color: var(--led-amber);
}

.jr-btn-emerald {
  background: var(--led-emerald);
  color: #052e16;
  border-color: var(--led-emerald);
}

.jr-btn-outline {
  background: transparent;
  border-color: var(--led-cyan);
  color: var(--led-cyan);
}

/* TRANSIENT WELCOME TO PREFECTURE MODAL */
.jr-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(5, 8, 14, 0.84);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.jr-modal.hidden {
  display: none;
}

.jr-modal-card {
  width: 100%;
  max-width: 620px;
  max-height: 90dvh;
  background: var(--bg-panel);
  border: 2px solid var(--led-amber);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.85);
}

.modal-top-strip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.dossier-warning-tag {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--led-crimson);
  background: rgba(239, 68, 68, 0.12);
  padding: 2px 7px;
  border-radius: 4px;
}

#modal-pref-title {
  font-size: 1.15rem;
  color: var(--text-primary);
}

.modal-subtitle {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--led-cyan);
  margin-bottom: 10px;
}

.dossier-facts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.dossier-fact-box {
  background: var(--bg-card);
  border: 1px solid var(--border-slate);
  border-radius: 6px;
  padding: 8px 10px;
}

.dossier-fact-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--led-amber);
  letter-spacing: 0.06em;
  display: block;
  margin-bottom: 3px;
}

.dossier-fact-text {
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--text-primary);
}
