:root {
  --bg: #0a0f1c;
  --surface: #111a2e;
  --surface-raised: #16223d;
  --hairline: #253758;
  --text: #e8edf9;
  --text-muted: #7c8cae;
  --amber: #f5a623;
  --green: #33d17a;
  --red: #ff5d5d;
  --blue: #5da9ff;
  --mono: ui-monospace, "SFMono-Regular", "IBM Plex Mono", "Consolas",
    "Liberation Mono", monospace;
  --sans: -apple-system, "Segoe UI", "Inter", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  background-image: radial-gradient(
    ellipse at top,
    rgba(93, 169, 255, 0.06),
    transparent 60%
  );
}

a {
  color: var(--blue);
}

.masthead {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface);
  font-family: var(--mono);
}

.masthead-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.masthead-icon {
  color: var(--amber);
}

.masthead-route {
  color: var(--text-muted);
  font-size: 0.85rem;
  flex: 1;
  letter-spacing: 0.04em;
}

.masthead-clock {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}

.board {
  max-width: 980px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ---- Hero / split-flap state ---- */

.hero {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 2.25rem 2rem;
  text-align: center;
  isolation: isolate;
}

.hero-sweep {
  position: absolute;
  inset: -40%;
  z-index: -1;
  opacity: 0;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    rgba(245, 166, 35, 0.18) 25deg,
    transparent 70deg
  );
  transition: opacity 0.4s ease;
}

.hero.state-checking .hero-sweep {
  opacity: 1;
  animation: sweep 2.4s linear infinite;
}

@keyframes sweep {
  to {
    transform: rotate(360deg);
  }
}

.hero-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  margin-bottom: 0.9rem;
}

.flap {
  display: inline-block;
  perspective: 600px;
}

.flap-text {
  display: block;
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(2rem, 6vw, 3.4rem);
  letter-spacing: 0.06em;
  padding: 0.15em 0.35em;
  border-radius: 6px;
  background: #05070d;
  border: 1px solid var(--hairline);
  color: var(--amber);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.5);
  transform-origin: center;
}

.flap-text.flip {
  animation: flip 0.5s ease;
}

@keyframes flip {
  0% {
    transform: rotateX(0deg);
  }
  45% {
    transform: rotateX(90deg);
  }
  55% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0deg);
  }
}

.hero.state-waiting .flap-text {
  color: var(--blue);
}
.hero.state-checking .flap-text {
  color: var(--amber);
}
.hero.state-error .flap-text {
  color: var(--red);
}
.hero.state-stopped .flap-text {
  color: var(--text-muted);
}
.hero.state-found .flap-text {
  color: var(--green);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.5), 0 0 40px rgba(51, 209, 122, 0.35);
}

.hero-sub {
  margin-top: 1rem;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.95rem;
}

.hero-appointment {
  margin-top: 0.35rem;
  color: var(--text);
  font-size: 0.9rem;
}

/* ---- Stat tiles ---- */

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
}

.stat-value {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 700;
}

.stat-value.chip {
  font-size: 0.95rem;
}

.stat-label {
  margin-top: 0.3rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.dot {
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  border-radius: 50%;
  margin-right: 0.4em;
}
.dot.on {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}
.dot.off {
  background: var(--red);
}

/* ---- Lower panels ---- */

.lower {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 1rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  min-height: 260px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--hairline);
}

.panel-header h2 {
  margin: 0;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel-body {
  padding: 1.1rem;
  font-size: 0.95rem;
}

.muted {
  color: var(--text-muted);
}

.slot-panel.found {
  border-color: var(--green);
  box-shadow: 0 0 0 1px var(--green), 0 0 30px rgba(51, 209, 122, 0.15);
}

.slot-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px dashed var(--hairline);
}
.slot-row:last-child {
  border-bottom: none;
}
.slot-row .k {
  color: var(--text-muted);
}
.slot-row .v {
  font-family: var(--mono);
}

.log-console {
  flex: 1;
  margin: 0;
  padding: 1rem 1.1rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: #b9c6e6;
  overflow-y: auto;
  max-height: 320px;
}

.btn {
  background: var(--surface-raised);
  border: 1px solid var(--hairline);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.8rem;
  padding: 0.45rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
}
.btn:hover {
  border-color: var(--blue);
}
.btn:focus-visible,
a:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.board-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding-top: 0.5rem;
}

@media (max-width: 720px) {
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .lower {
    grid-template-columns: 1fr;
  }
  .masthead-route {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hero.state-checking .hero-sweep {
    animation: none;
    opacity: 0.5;
  }
  .flap-text.flip {
    animation: none;
  }
}
