:root {
  color-scheme: dark;
  --brand-blue: #0060b9;
  --brand-blue-strong: #004f9a;
  --brand-blue-deep: #002d5a;
  --brand-cream: #fdf8ee;
  --bg: #004f9a;
  --bg-soft: #005aab;
  --panel: rgba(253, 248, 238, 0.1);
  --panel-strong: rgba(253, 248, 238, 0.16);
  --text: var(--brand-cream);
  --muted: rgba(253, 248, 238, 0.72);
  --line: rgba(253, 248, 238, 0.2);
  --accent: var(--brand-cream);
  --ok: #8af0c4;
  --closed: #ff8b84;
  --unknown: #dce8f4;
  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 0%, rgba(253, 248, 238, 0.18), transparent 34rem),
    radial-gradient(circle at 92% 12%, rgba(0, 150, 255, 0.22), transparent 30rem),
    linear-gradient(145deg, var(--brand-blue-deep) 0%, var(--brand-blue) 52%, #003f7a 100%);
  color: var(--text);
  font-family: var(--font-sans);
}

body.modal-open {
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.page-shell {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  padding: 14px 14px 32px;
}

.topbar {
  position: sticky;
  top: 10px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: min(100%, 760px);
  min-height: 52px;
  margin: 0 auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 55, 108, 0.78);
  box-shadow: 0 18px 50px rgba(0, 33, 70, 0.3);
  backdrop-filter: blur(18px);
}

.migration-notice {
  position: absolute;
  top: 24px;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 8px;
  color: var(--text);
  font-size: 12px;
  line-height: 16px;
}

.migration-notice svg {
  flex: 0 0 22px;
  color: #ffd78a;
}

.migration-notice p {
  margin: 0;
}

.migration-notice a {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.migration-notice a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
  padding-left: 8px;
  font-size: 0.95rem;
  font-weight: 760;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand:focus-visible,
.share-button:focus-visible,
.analytics-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.brand-mark {
  width: 44px;
  height: 32px;
  flex: 0 0 auto;
  object-fit: contain;
}

.share-button {
  display: inline-grid;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.share-button[hidden] {
  display: none;
}

.share-button:hover,
.share-button:active {
  background: var(--panel-strong);
}

.share-button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.share-feedback {
  position: fixed;
  z-index: 60;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  width: max-content;
  max-width: calc(100% - 28px);
  margin: 0;
  padding: 12px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--brand-blue-deep);
  color: var(--text);
  font-size: 0.92rem;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.share-feedback:empty {
  opacity: 0;
}

.hero {
  position: relative;
  display: grid;
  width: min(100%, 760px);
  min-height: min(640px, calc(100svh - 84px));
  margin: 0 auto;
  padding: 34px 0 44px;
  align-items: center;
}

.hero-panel {
  position: relative;
  isolation: isolate;
  display: grid;
  gap: 18px;
  width: 100%;
  max-width: 720px;
  padding: clamp(22px, 7vw, 44px);
  border: 1px solid var(--line);
  border-radius: 28px;
  background:
    linear-gradient(150deg, rgba(253, 248, 238, 0.16), rgba(253, 248, 238, 0.05)),
    rgba(0, 57, 112, 0.64);
  box-shadow: 0 32px 90px rgba(0, 33, 70, 0.38);
  overflow: hidden;
  animation: panel-rise 620ms ease-out both;
}

.hero-panel::before {
  content: "";
  position: absolute;
  inset: auto -18% -24% 34%;
  z-index: -1;
  height: 58%;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(253, 248, 238, 0.2), transparent 66%);
  filter: blur(18px);
}

.app-title {
  max-width: 720px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(1.35rem, 7vw, 3rem);
  font-weight: 820;
  line-height: 0.98;
  letter-spacing: 0;
  text-wrap: balance;
}

.status {
  display: grid;
  gap: 12px;
  max-width: 720px;
  font-weight: 860;
  letter-spacing: 0;
}

.status-line {
  max-width: 100%;
  text-wrap: balance;
}

.status-line:first-child {
  max-width: 12ch;
  font-size: clamp(2.45rem, 11.5vw, 5.4rem);
  line-height: 0.92;
}

.status-line:not(:first-child) {
  max-width: 24ch;
  font-size: clamp(1.15rem, 5.4vw, 2.2rem);
  font-weight: 760;
  line-height: 1.04;
}

.status-ok {
  color: var(--ok);
}

.status-closed {
  color: var(--closed);
}

.status-unknown {
  color: var(--unknown);
}

.time-card {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  align-items: baseline;
  gap: 10px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(0, 45, 90, 0.26);
  color: var(--muted);
  font-size: 0.95rem;
}

.time-card strong {
  color: var(--text);
  font-size: 1.16rem;
}

.schedule-warning {
  display: block;
  max-width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(253, 248, 238, 0.34);
  border-radius: 18px;
  background: rgba(253, 248, 238, 0.13);
  color: var(--brand-cream);
  font-size: 0.95rem;
  line-height: 1.35;
}

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

.meta-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  width: min(100%, 760px);
  margin: -24px auto 0;
}

.meta-card {
  min-height: 84px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
}

.meta-card b {
  display: block;
  margin-bottom: 6px;
  font-size: 0.92rem;
}

.meta-card span {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.content {
  display: grid;
  gap: 18px;
  width: min(100%, 760px);
  margin: 40px auto 0;
}

.schedule-block {
  border: 1px solid var(--line);
  border-radius: 26px;
  background: rgba(253, 248, 238, 0.08);
  overflow: hidden;
}

.motion-ready .schedule-block {
  opacity: 0;
  transform: translateY(18px) scale(0.985);
  transition: opacity 520ms ease, transform 520ms ease;
}

.motion-ready .schedule-block.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.schedule-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 16px 14px;
}

.schedule-header h2 {
  margin: 0;
  font-size: clamp(1.35rem, 7vw, 2.25rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.schedule-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.25;
  text-align: right;
}

.schedule-updated,
.schedule-routing-note {
  margin: 0;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.schedule-routing-note a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: clamp(0.8rem, 3.35vw, 0.94rem);
}

th,
td {
  padding: 11px 8px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  overflow-wrap: anywhere;
  word-break: normal;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 760;
  text-transform: uppercase;
}

td:first-child,
th:first-child {
  padding-left: 12px;
  white-space: nowrap;
}

.trains-table th:nth-child(1),
.trains-table td:nth-child(1) {
  width: 20%;
}

.trains-table th:nth-child(2),
.trains-table td:nth-child(2) {
  width: 20%;
}

.trains-table th:nth-child(3),
.trains-table td:nth-child(3) {
  width: 60%;
}

.trains-table th:nth-child(2),
.trains-table td:nth-child(2) {
  text-align: center;
}

.sapsan-table th,
.sapsan-table td {
  width: 50%;
  text-align: left;
}

tr.active {
  background: rgba(253, 248, 238, 0.18);
  color: var(--brand-cream);
  font-weight: 800;
}

.empty-row td {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
  white-space: normal;
}

.footer {
  width: min(100%, 760px);
  margin: 28px auto 0;
  padding: 22px 4px 8px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
  text-align: center;
}

.footer a {
  color: var(--text);
  font-weight: 760;
}

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

.analytics-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
}

.analytics-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 23, 48, 0.72);
  backdrop-filter: blur(8px);
}

.analytics-dialog {
  position: relative;
  z-index: 1;
  width: min(100%, 420px);
  max-height: min(620px, calc(100svh - 36px));
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(0, 57, 112, 0.96);
  box-shadow: 0 32px 90px rgba(0, 33, 70, 0.46);
}

.analytics-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 10px;
}

.analytics-header h2 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.analytics-close {
  display: inline-grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 10px 18px 18px;
}

.analytics-stat {
  font: inherit;
  text-align: left;
  cursor: pointer;
  min-width: 0;
  min-height: 118px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(253, 248, 238, 0.08);
}

.analytics-stat span,
.analytics-stat small {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.25;
}

.analytics-stat strong {
  display: block;
  margin: 8px 0 3px;
  color: var(--text);
  font-size: 2.35rem;
  line-height: 0.95;
  letter-spacing: 0;
}

.analytics-grid[hidden],
.analytics-detail[hidden],
.analytics-chart[hidden] {
  display: none;
}

.analytics-stat:hover,
.analytics-back:hover,
.analytics-retry:hover {
  background: var(--panel-strong);
}

.analytics-stat:focus-visible,
.analytics-back:focus-visible,
.analytics-retry:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.analytics-stat .analytics-stat-link {
  margin-top: 14px;
  color: var(--text);
}

.analytics-dialog:has(.analytics-detail:not([hidden])) {
  width: min(100%, 720px);
}

.analytics-detail {
  padding: 8px 18px 20px;
}

.analytics-back,
.analytics-retry {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.analytics-detail h3 {
  margin: 20px 0 8px;
  font-size: 1.6rem;
}

.analytics-summary,
.analytics-message,
.analytics-point,
.analytics-note {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
}

.analytics-point { min-height: 2.6em; color: var(--text); }
.analytics-note { font-size: 0.75rem; }
.analytics-chart { overflow-x: auto; }
.analytics-chart svg { display: block; width: 100%; }
.analytics-chart text { fill: var(--muted); font: 12px var(--font-sans); }
.analytics-chart-grid { stroke: var(--line); }
.analytics-chart-bar { fill: var(--ok); }
.analytics-chart-missing { fill: var(--muted); }
.analytics-chart-point { cursor: pointer; }
.analytics-chart-point:focus { outline: none; }
.analytics-chart-point:hover .analytics-chart-hit,
.analytics-chart-point:focus .analytics-chart-hit { fill: var(--panel-strong); }

@keyframes panel-rise {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (min-width: 680px) {
  .page-shell {
    padding: 18px 20px 48px;
  }

  .meta-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .content {
    gap: 22px;
  }
}

@media (max-width: 430px) {
  .topbar {
    gap: 6px;
  }

  .brand {
    max-width: none;
    gap: 7px;
    padding-left: 5px;
    font-size: 0.9rem;
  }

  .status {
    gap: 10px;
  }

  .status-line:first-child {
    max-width: 11ch;
    font-size: clamp(2.25rem, 12vw, 3.65rem);
  }

  .analytics-grid {
    grid-template-columns: 1fr;
  }

  .analytics-stat {
    min-height: 96px;
  }
}

@media (max-height: 600px) {
  .migration-notice {
    top: 10px;
  }

  .hero {
    padding-top: 52px;
  }
}
