:root {
  color-scheme: light;
  --paper: #f6f1e7;
  --paper-dark: #ede4d3;
  --ink: #3a2f24;
  --ink-soft: #6c5c4a;
  --accent: #a15f2b;
  --accent-soft: #c98b4a;
  --accent-blue: #6a8bbd;
  --accent-blue-soft: #5b83b0;
  --line: #c6b7a2;
  --shadow: rgba(58, 47, 36, 0.15);
  --radius: 0px;
  --danger: #a33b32;
  --danger-soft: rgba(163, 59, 50, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Courier Prime", "Courier New", monospace;
  color: var(--ink);
  background: radial-gradient(
      circle at top,
      rgba(255, 255, 255, 0.7),
      transparent 60%
    ),
    linear-gradient(180deg, var(--paper), var(--paper-dark));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.4;
  background-image: linear-gradient(
      90deg,
      rgba(122, 98, 77, 0.05) 0,
      rgba(122, 98, 77, 0.05) 1px,
      transparent 1px,
      transparent 12px
    ),
    linear-gradient(
      0deg,
      rgba(122, 98, 77, 0.04) 0,
      rgba(122, 98, 77, 0.04) 1px,
      transparent 1px,
      transparent 10px
    );
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
  position: relative;
}

header.hero {
  display: grid;
  gap: 1rem;
  padding: 2rem 2.5rem;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.65);
  box-shadow: 0 18px 50px var(--shadow);
  border: 1px solid rgba(198, 183, 162, 0.65);
}

.panel-narrow {
  max-width: 56rem;
  margin-left: auto;
  margin-right: auto;
}

.panel-narrow-intro {
  max-width: 48rem;
  margin-left: auto;
  margin-right: auto;
}

header.hero h1 {
  font-family: "Special Elite", "Courier Prime", monospace;
  font-size: clamp(2rem, 3vw, 2.8rem);
  margin: 0;
  letter-spacing: 0.04em;
}

header.hero p {
  margin: 0;
  max-width: 60rem;
  color: var(--ink-soft);
  font-size: 1rem;
}

header.hero p + p {
  margin-top: 0.75rem;
}

header.hero .hero-credit {
  font-size: 0.9rem;
}

header.hero .hero-credit a {
  color: var(--accent);
}

main {
  margin-top: 2rem;
  display: grid;
  gap: 2.5rem;
}

.panel {
  background: rgba(255, 255, 255, 0.82);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: 0 16px 40px var(--shadow);
  border: 1px solid rgba(198, 183, 162, 0.6);
}

.panel h2 {
  font-family: "Special Elite", "Courier Prime", monospace;
  margin: 0 0 1rem;
  font-size: clamp(1.4rem, 2vw, 1.75rem);
  color: var(--ink);
}

form#form {
  display: grid;
  gap: 1.25rem;
}

.form-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.time-now-group {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

.btn-now {
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}

.form-row-meta {
  flex-wrap: wrap;
}

.form-row-stations {
  flex-wrap: wrap;
  overflow-y: visible;
  width: 100%;
  row-gap: 1rem;
}

.via-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  align-items: flex-start;
  flex: 1 1 18ch;
  min-width: 18ch;
}

.via-scroll {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: nowrap;
  flex: 0 1 auto;
  min-width: 0;
  overflow-y: visible;
  width: 100%;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  align-items: flex-start;
}

label input {
  font-family: inherit;
}

input {
  padding: 0.55rem 0.65rem;
  font-size: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
}

input:focus {
  outline: 2px solid rgba(161, 95, 43, 0.35);
  border-color: var(--accent-soft);
}

.station-field {
  position: relative;
  min-width: 18ch;
  flex: 1 1 18ch;
  width: 100%;
}

.via-scroll .station-field {
  flex: 0 0 auto;
  min-width: 18ch;
  width: 100%;
}

.station-input {
  width: 100%;
  min-width: 18ch;
  text-transform: none;
}

.via-scroll .station-input {
  min-width: 0;
}

.station-field-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
}

.via-row {
  gap: 0.18rem;
}

.via-scroll.is-reordering {
  user-select: none;
}

.via-scroll .station-field.is-dragging {
  opacity: 0.72;
  z-index: 6;
}

.via-drag-handle {
  display: inline-grid;
  place-items: center;
  flex: 0 0 0.9rem;
  align-self: center;
  width: 0.9rem;
  height: 1.6rem;
  padding: 0;
  border: 0;
  background:
    radial-gradient(circle, rgba(58, 47, 36, 0.5) 1.5px, transparent 1.8px)
      0.18rem 0.12rem / 0.36rem 0.32rem no-repeat,
    radial-gradient(circle, rgba(58, 47, 36, 0.5) 1.5px, transparent 1.8px)
      0.52rem 0.12rem / 0.36rem 0.32rem no-repeat,
    radial-gradient(circle, rgba(58, 47, 36, 0.5) 1.5px, transparent 1.8px)
      0.18rem 0.44rem / 0.36rem 0.32rem no-repeat,
    radial-gradient(circle, rgba(58, 47, 36, 0.5) 1.5px, transparent 1.8px)
      0.52rem 0.44rem / 0.36rem 0.32rem no-repeat,
    radial-gradient(circle, rgba(58, 47, 36, 0.5) 1.5px, transparent 1.8px)
      0.18rem 0.76rem / 0.36rem 0.32rem no-repeat,
    radial-gradient(circle, rgba(58, 47, 36, 0.5) 1.5px, transparent 1.8px)
      0.52rem 0.76rem / 0.36rem 0.32rem no-repeat,
    radial-gradient(circle, rgba(58, 47, 36, 0.5) 1.5px, transparent 1.8px)
      0.18rem 1.08rem / 0.36rem 0.32rem no-repeat,
    radial-gradient(circle, rgba(58, 47, 36, 0.5) 1.5px, transparent 1.8px)
      0.52rem 1.08rem / 0.36rem 0.32rem no-repeat;
  color: var(--ink-soft);
  cursor: grab;
  touch-action: none;
}

.via-drag-handle:active {
  cursor: grabbing;
}

.via-drag-handle:focus-visible {
  outline: 2px solid rgba(161, 95, 43, 0.35);
  outline-offset: 2px;
}

.rotate-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  z-index: 2000;
}

.rotate-modal[hidden] {
  display: none;
}

.rotate-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(58, 47, 36, 0.5);
}

.rotate-modal__panel {
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(198, 183, 162, 0.8);
  box-shadow: 0 24px 60px var(--shadow);
  padding: 2rem 2.5rem;
  text-align: center;
  max-width: 320px;
  width: 100%;
  display: grid;
  gap: 1rem;
}

.rotate-modal__panel h2 {
  margin: 0;
  font-family: "Special Elite", "Courier Prime", monospace;
}

.rotate-modal__panel p {
  margin: 0;
  color: var(--ink-soft);
}

.rotate-modal__icon {
  display: flex;
  justify-content: center;
}

.rotate-modal__spin {
  width: 160px;
  height: 160px;
  color: var(--accent);
  animation: rotate-phone 2s ease-in-out infinite;
  transform-origin: 50% 50%;
}

@keyframes rotate-phone {
  0%,
  25% {
    transform: rotate(0deg);
  }
  75%,
  100% {
    transform: rotate(90deg);
  }
}

.via-required-toggle {
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: none;
  background: transparent;
  margin: 0;
}

.via-required-toggle input {
  appearance: none;
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 2px;
  border: 1px solid var(--accent);
  background: rgba(255, 255, 255, 0.8);
}

.via-required-toggle input:checked {
  background: var(--accent);
}

.via-row.is-optional .via-required-toggle {
  border-color: transparent;
  background: transparent;
}

.via-row.is-optional .via-required-toggle input {
  border-color: var(--accent-blue);
}

.station-suggest {
  position: absolute;
  min-width: 100%;
  width: max-content;
  max-width: 34rem;
  left: 0;
  top: 0;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line);
  box-shadow: 0 16px 32px var(--shadow);
  max-height: 220px;
  overflow-y: auto;
  overflow-x: hidden;
  display: none;
  z-index: 5;
}

.station-suggest-item {
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  font-weight: 400;
}

.station-suggest-item:hover,
.station-suggest-item.is-active {
  background: rgba(201, 139, 74, 0.2);
}

.via-remove {
  padding: 0.3rem 0.55rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  font-weight: 700;
  color: var(--ink-soft);
  line-height: 1;
}

input[type="date"] {
  width: 15.5ch;
}

input[type="time"] {
  width: 11ch;
}

button {
  border: none;
  cursor: pointer;
  font-family: "Courier Prime", monospace;
}

.btn {
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: #fff7ea;
  box-shadow: 0 10px 20px rgba(161, 95, 43, 0.3);
}

.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.btn:active {
  transform: translateY(1px);
}

.btn:hover {
  box-shadow: 0 12px 20px rgba(58, 47, 36, 0.2);
}

.btn[disabled] {
  background: #c7bcab;
  color: #6f5e4e;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-toggle {
  background: #f1f6ff;
  color: var(--accent-blue);
  border: 1px solid var(--accent-blue);
}

.btn-toggle.is-active {
  background: var(--accent-blue);
  color: #f8fbff;
  box-shadow: 0 10px 20px rgba(53, 94, 141, 0.3);
}

.btn-toggle[disabled] {
  background: #e3e5e6;
  color: #6a7a90;
  border-color: #9aabbf;
}

#addViaBtn {
  align-self: flex-start;
  transform: none;
}

form label button {
  margin-top: 0.35rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  font-weight: 700;
  color: var(--ink-soft);
}

#status {
  position: relative;
  width: 100%;
  min-height: 3.4rem;
  overflow: hidden;
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  background: rgba(250, 244, 232, 0.8);
  border: 1px dashed rgba(161, 95, 43, 0.25);
  font-family: "Courier Prime", monospace;
  white-space: pre-wrap;
  color: var(--ink-soft);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

#status[hidden] {
  display: none;
}

#status.is-error {
  background: var(--danger-soft);
  border-color: rgba(163, 59, 50, 0.4);
  color: var(--danger);
}

.status-bar {
  position: absolute;
  inset: 0;
  width: 0;
  background: rgba(161, 95, 43, 0.22);
  transition: width 0.2s ease;
}

#status.is-error .status-bar {
  background: rgba(163, 59, 50, 0.2);
}

.status-text {
  position: relative;
  z-index: 1;
  width: 100%;
  text-align: center;
}

.results {
  display: grid;
  gap: 2rem;
}

.table-card {
  background: rgba(255, 255, 255, 0.86);
  border-radius: var(--radius);
  padding: 1.5rem;
  border: 1px solid rgba(198, 183, 162, 0.6);
  box-shadow: none;
  overflow: hidden;
  display: none;
}

.table-card.has-data {
  display: block;
  box-shadow: 0 16px 32px var(--shadow);
}

.table-scroll {
  overflow-x: auto;
  position: relative;
  max-width: 100%;
  width: 100%;
  display: block;
}

.table-key {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  width: 100%;
  margin: 0 0 0.75rem;
  padding: 0.35rem 0;
}

.table-key.is-empty {
  display: none;
}

.table-key-label {
  font-weight: 700;
  color: var(--ink-soft);
  margin-right: 0.35rem;
  font-size: 1rem;
}

.table-key-break {
  flex-basis: 100%;
  height: 0;
}

.table-key-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  font-size: 0.82rem;
  line-height: 1;
  vertical-align: middle;
}

.table-key-sample {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.05rem 0.3rem;
  border-radius: 999px;
  border: 1px solid rgba(58, 47, 36, 0.2);
  font-size: 0.78rem;
  line-height: 1;
}

.table-key-dots {
  display: inline-flex;
  gap: 0.2rem;
  align-items: center;
}

.table-key-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 999px;
  border: 1px solid rgba(58, 47, 36, 0.2);
}

.table-key-dot--early {
  background: #2f7b3d;
}

.table-key-dot--late {
  background: var(--danger);
}

.table-key-sample--highlight {
  background: rgba(248, 232, 197, 0.9);
}

.table-key-sample--early {
  color: #2c6fbe;
}

.table-key-sample--late {
  color: #e53935;
}

.table-key-sample--out-of-order {
  background: #fce3b0;
}

.table-key-sample--dep-before {
  background: #e6d9ff;
}

.table-key-sample--service-misorder {
  background: #f7c9c9;
}

.table-key--crs {
  margin-top: 0.75rem;
  padding: 0.5rem;
  background: rgba(248, 244, 235, 0.7);
  font-size: 1rem;
}

table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: 0.9rem;
  color: var(--ink);
}

th,
td {
  padding: 0.35rem 0.5rem;
  text-align: center;
}

th {
  border: 1px solid var(--line);
  background: rgba(240, 232, 219, 0.9);
  font-weight: 700;
}

thead tr:first-child th {
  border-bottom: none;
}

thead tr:nth-child(2) th {
  border-top: none;
}

td {
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-top: none;
  border-bottom: none;
}

tbody tr:nth-child(even) td {
  background: rgba(250, 246, 239, 0.6);
}

tr.row-sep-top > td {
  border-top: 1px solid var(--line);
}

th.sticky-top {
  position: sticky;
  top: 0;
  background: rgba(240, 232, 219, 0.98);
  z-index: 2;
}

th.sticky-left,
td.sticky-left {
  position: sticky;
  left: 0;
  background: rgba(248, 244, 235, 0.98);
  text-align: right;
  z-index: 3;
}

th.sticky-left {
  background: rgba(240, 232, 219, 0.98);
}

td.sticky-left.station-row-label {
  white-space: nowrap;
  width: max-content;
  min-width: max-content;
  text-align: right;
  padding-right: 0.5rem;
  font-weight: 700;
}

th.corner {
  z-index: 4;
}

.time-empty {
  color: rgba(58, 47, 36, 0.2);
}

.time-italic {
  font-style: italic;
}

.time-bold {
  font-weight: 700;
}

.time-muted {
  color: var(--ink-soft);
}

.time-early {
  color: #2f7b3d;
}

.time-late {
  color: var(--danger);
}

.time-cancelled {
  text-decoration: line-through;
}

.platform-tag {
  display: inline-block;
  margin-left: 0.2rem;
}

.platform-confirmed {
  font-weight: 700;
}

.platform-changed {
  color: #8243a8;
}

.service-header {
  font-weight: 700;
  white-space: nowrap;
  color: inherit;
  text-decoration: none;
}

.service-header:hover {
  text-decoration: underline;
  color: var(--accent);
}

th.icon-row {
  font-weight: 700;
  padding: 0.15rem 0.4rem;
}

.icon-wrap {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  justify-content: center;
}

.fc-icon {
  display: inline-flex;
  width: 1.2rem;
  height: 1.2rem;
  border: 1px solid #6f5a44;
  border-radius: 999px;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  line-height: 1;
}

.bed-icon {
  display: inline-flex;
  width: 1.2rem;
  height: 1.2rem;
  align-items: center;
  justify-content: center;
}

.bed-icon svg {
  width: 1.1rem;
  height: 1.1rem;
  display: block;
}

.bus-icon {
  display: inline-flex;
  width: 1.2rem;
  height: 1.2rem;
  align-items: center;
  justify-content: center;
}

.bus-icon svg {
  width: 1.1rem;
  height: 1.1rem;
  display: block;
}

.walk-icon {
  display: inline-flex;
  width: 1.2rem;
  height: 1.2rem;
  align-items: center;
  justify-content: center;
}

.walk-icon svg {
  width: 1.1rem;
  height: 1.1rem;
  display: block;
}

.connection-mode-icon {
  display: inline-flex;
  width: 1.2rem;
  height: 1.2rem;
  align-items: center;
  justify-content: center;
}

.connection-mode-icon svg {
  width: 1.1rem;
  height: 1.1rem;
  display: block;
}

.actions {
  display: grid;
  gap: 1rem;
  margin-top: 1.25rem;
}

.action-buttons {
  display: flex;
  gap: 1rem;
  width: 100%;
  flex-wrap: wrap;
}

.action-buttons .btn {
  flex: 1 1 12rem;
  min-width: 12rem;
}

@media (max-width: 900px) {
  header.hero {
    padding: 1.5rem;
  }

  .panel {
    padding: 1.5rem;
  }

  .form-row-stations {
    flex-wrap: wrap;
    align-items: stretch;
  }

  .form-row-stations > label,
  .form-row-stations .via-group {
    flex: 1 1 100%;
  }

  .action-buttons .btn {
    flex: 1 1 100%;
    min-width: 0;
  }
}
