:root {
  color-scheme: dark;
  font-family: "Noto Sans JP", "Segoe UI", sans-serif;
  background: #0b0f14;
  color: #e6eef7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(160deg, #0b0f14, #0f1b2e);
  overflow-x: hidden;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  background: #1f2937;
  color: #e6eef7;
  font-weight: 600;
  transition: transform 0.1s ease, background 0.2s ease;
}

button:hover {
  background: #334155;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.layout {
  min-height: 100vh;
}

.mainLayout {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: var(--header-h, 56px) 1fr;
  gap: 16px;
  width: 100%;
  height: 100vh;
  padding: 16px;
  box-sizing: border-box;
}

.mainLayout > .pane {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.mainLayout .pane * {
  min-width: 0;
}

.mainLayout .pane table {
  width: 100%;
  table-layout: fixed;
}

.mainLayout .pane td,
.mainLayout .pane th {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: rgba(12, 20, 32, 0.95);
  border: 1px solid #1c2a40;
  border-radius: 14px;
  padding: clamp(8px, 1.2vw, 10px) clamp(12px, 2vw, 16px);
  height: var(--header-h, 56px);
}

.train-meta {
  display: flex;
  gap: clamp(6px, 1vw, 12px);
  font-weight: 600;
  flex-wrap: wrap;
}

.train-number {
  color: #facc15;
}

.train-type {
  color: #93c5fd;
}

.train-dest {
  color: #e2e8f0;
}

.header-clock {
  font-size: 1.2rem;
  font-weight: 700;
}

.pane {
  background: rgba(13, 21, 32, 0.9);
  border: 1px solid #1c2a40;
  border-radius: 16px;
  padding: clamp(8px, 1.4vw, 12px);
  min-height: 0;
  gap: 12px;
}

.lane h2,
.center h2,
.right h2,
.pane h3 {
  margin: 0;
  font-size: 1rem;
  color: #9cc3ff;
}

.lane-strip {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 360px;
  background: #0d1724;
  border-radius: 12px;
  border: 1px solid #23324b;
  overflow: hidden;
}

.lane-strip::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(to bottom, rgba(120, 160, 210, 0.2) 0 8px, transparent 8px 16px),
    linear-gradient(to right, transparent 48%, rgba(120, 160, 210, 0.35) 48%, rgba(120, 160, 210, 0.35) 52%, transparent 52%);
}

.lane-item {
  position: absolute;
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 0.75rem;
  background: rgba(18, 28, 45, 0.92);
  border: 1px solid #2d3d58;
}

.lane-item.left {
  left: 8px;
  right: 52%;
}

.lane-item.right {
  left: 52%;
  right: 8px;
}

.lane-item.center {
  left: 36%;
  right: 36%;
  text-align: center;
  background: #facc15;
  color: #1f2937;
  font-weight: 700;
}

.lane-item.limit {
  border-left: 3px solid #6ee7b7;
}

.lane-item.grade {
  border-left: 3px solid #fca5a5;
}

.lane-item.signal {
  border-left: 3px solid #93c5fd;
}

.lane-item.signal.active {
  box-shadow: 0 0 0 2px rgba(147, 197, 253, 0.6);
}

.lane-item.station {
  border-left: 3px solid #f9c74f;
}

.lane-item.station.pass {
  border-left: 3px solid #94a3b8;
  opacity: 0.75;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.speed-block h2 {
  margin: 0;
  font-size: 2rem;
}

.warning {
  color: #fca5a5;
  font-weight: 600;
}

.accent {
  color: #6ee7b7;
  font-weight: 600;
}

.debug {
  color: #94a3b8;
  font-size: 0.75rem;
}

.timetable table,
.clear-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.timetable th,
.timetable td,
.clear-table th,
.clear-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #22344f;
  text-align: left;
}

.timetable tr.current {
  background: rgba(68, 120, 196, 0.15);
}

.timetable tr.pass {
  color: #94a3b8;
}

.score-mini {
  background: rgba(17, 27, 44, 0.8);
  border: 1px solid #22344f;
  border-radius: 12px;
  padding: 10px;
  font-size: 0.85rem;
}

.control-panel {
  background: rgba(17, 27, 44, 0.8);
  border: 1px solid #22344f;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

.notch-column {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.notch {
  background: #111827;
  border: 1px solid #2d3d58;
  border-radius: 8px;
  padding: 6px;
  font-size: clamp(0.72rem, 1vw, 0.8rem);
  width: 100%;
}

.notch.active {
  background: #2563eb;
}

.notch.power {
  background: #14532d;
}

.notch.power.active {
  background: #22c55e;
}

.notch.brake {
  background: #7f1d1d;
}

.notch.brake.active {
  background: #ef4444;
}

.notch.cruise.active {
  background: #38bdf8;
}

.control-actions {
  display: grid;
  gap: 8px;
}

.control-actions button {
  width: 100%;
}

.audio {
  background: #0f172a;
  border: 1px solid #334155;
}

.scenario-info {
  background: rgba(17, 27, 44, 0.8);
  border: 1px solid #22344f;
  border-radius: 12px;
  padding: 10px;
  font-size: 0.85rem;
}

.screen {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.screen header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.scenario-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.scenario-card {
  text-align: left;
  background: rgba(17, 27, 44, 0.8);
  border: 1px solid #22344f;
  padding: 14px;
  border-radius: 12px;
}

.scenario-meta {
  margin: 6px 0 0;
  font-size: 0.8rem;
  color: #cbd5f5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.scenario-meta.subtle {
  color: #94a3b8;
  font-size: 0.75rem;
}

.badge {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #1d4ed8;
  font-size: 0.75rem;
}

.error {
  color: #fca5a5;
  white-space: pre-line;
}

.lead {
  color: #b8c4d9;
}

.clear-summary {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.clear-meta {
  background: rgba(17, 27, 44, 0.8);
  border: 1px solid #22344f;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.clear-meta h2 {
  margin: 0;
  font-size: 1.2rem;
}

.clear-summary .score {
  font-size: 2.4rem;
  margin: 0;
}

.clear-actions {
  display: flex;
  justify-content: center;
}

.stop-zoom {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
}

.zoom-label {
  font-size: 0.75rem;
  color: #93c5fd;
}

.zoom-track {
  position: relative;
  flex: 1;
  border-radius: 12px;
  border: 1px solid #23324b;
  background: #0d1724;
  overflow: hidden;
}

.zoom-track::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(to bottom, rgba(120, 160, 210, 0.2) 0 8px, transparent 8px 16px);
}

.zoom-target,
.zoom-train {
  position: absolute;
  left: 10%;
  right: 10%;
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 0.75rem;
  display: flex;
  justify-content: center;
  transform: translateY(-50%);
}

.zoom-target {
  background: rgba(249, 199, 79, 0.2);
  border: 1px solid rgba(249, 199, 79, 0.6);
  color: #f9c74f;
}

.zoom-train {
  background: #facc15;
  color: #1f2937;
  font-weight: 700;
}

.zoom-scale {
  position: absolute;
  left: 12px;
  font-size: 0.7rem;
  color: #94a3b8;
}

.zoom-scale.zoom-min {
  top: 6px;
}

.zoom-scale.zoom-max {
  bottom: 6px;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  .pane {
    min-height: auto;
  }
}
