/* Markov Ticker — restrained, professional finance look.
   Nexus-derived palette: neutral surfaces + one teal accent. */

:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-alt: #fbfbf9;
  --border: #e3e0d8;
  --border-strong: #d4d1ca;
  --text: #1f1d17;
  --text-muted: #6e6c66;
  --text-faint: #a8a6a0;
  --accent: #01696f;
  --accent-hover: #0c4e54;
  --accent-soft: #e3f0f0;
  --up: #437a22;
  --down: #a13544;
  --flat: #6e6c66;
  --shadow-sm: 0 1px 2px rgba(20, 20, 20, 0.04);
  --shadow-md: 0 4px 16px rgba(20, 20, 20, 0.06);
  --radius: 10px;
  --radius-sm: 6px;
  --font-sans: "Satoshi", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ----- Header ----- */

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-mark {
  color: var(--accent);
}

.brand-name {
  font-size: 17px;
}

.site-nav .badge {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

/* ----- Hero / form ----- */

.main {
  padding: 40px 24px 64px;
}

.hero {
  margin-bottom: 32px;
}

.eyebrow {
  margin: 0 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.title {
  margin: 0 0 16px;
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 700;
  max-width: 22ch;
}

.accent {
  color: var(--accent);
}

.lede {
  margin: 0 0 24px;
  font-size: 17px;
  color: var(--text-muted);
  max-width: 60ch;
}

.ticker-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.input-row {
  display: flex;
  gap: 10px;
}

#ticker-input {
  flex: 1;
  font-family: var(--font-sans);
  font-size: 17px;
  padding: 14px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  letter-spacing: 0.02em;
}

#ticker-input::placeholder {
  color: var(--text-faint);
}

#ticker-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(1, 105, 111, 0.15);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 22px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease, opacity 0.15s ease;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: 104px;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

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

.btn-primary:disabled {
  opacity: 0.78;
  cursor: not-allowed;
}

.btn-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.36);
  border-top-color: #fff;
  border-radius: 999px;
  animation: spin 0.75s linear infinite;
}

.btn-primary.is-loading .btn-spinner {
  display: inline-block;
}

.input-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-top: 14px;
  font-size: 14px;
  color: var(--text-muted);
}

.meta-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.meta-field select {
  font-family: inherit;
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
}

.hint {
  font-size: 13px;
  color: var(--text-faint);
}

/* ----- Explainer ----- */

.explainer {
  margin-top: 28px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}

.explainer-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.explainer p {
  margin: 8px 0;
  color: var(--text);
  font-size: 15px;
}

.state-legend {
  list-style: none;
  padding: 0;
  margin: 12px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  font-size: 14px;
}

.state-legend li {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.dot-up {
  background: var(--up);
}
.dot-down {
  background: var(--down);
}
.dot-flat {
  background: var(--flat);
}

.disclaimer {
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px dashed var(--border-strong);
  padding-top: 12px;
  margin-top: 12px;
}

/* ----- Ads ----- */

.ad {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-faint);
  text-align: center;
  padding: 16px;
}

.ad-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-faint);
}

.ad-placeholder {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.ad-leaderboard {
  min-height: 96px;
  margin: 32px 0;
}

.ad-sidebar {
  min-height: 260px;
}

.ad-footer {
  min-height: 90px;
  margin: 24px auto 16px;
}

/* ----- Results layout ----- */

.results-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}

@media (min-width: 960px) {
  .results-layout {
    grid-template-columns: minmax(0, 1fr) 320px;
    align-items: start;
  }
}

.results {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.empty {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}

.card h3 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.005em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.ticker-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.ticker-symbol {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.ticker-meta {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 16px 0 8px;
}

@media (min-width: 540px) {
  .kpi-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.kpi {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 18px;
  font-weight: 600;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

.kpi-value.state-up {
  color: var(--up);
}
.kpi-value.state-down {
  color: var(--down);
}
.kpi-value.state-flat {
  color: var(--flat);
}

/* Transition matrix table */
.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 13px;
  margin-top: 8px;
}

.matrix-table th,
.matrix-table td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  font-feature-settings: "tnum" 1, "lnum" 1;
}

.matrix-table th:first-child,
.matrix-table td:first-child {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 12px;
}

.matrix-table thead th {
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  border-bottom: 2px solid var(--border-strong);
}

.matrix-table tbody tr:last-child td {
  border-bottom: 0;
}

.cell-strong {
  color: var(--accent);
  font-weight: 600;
}

/* Sequence chips */
.sequence {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
}

.chip.state-up {
  color: var(--up);
  border-color: rgba(67, 122, 34, 0.3);
  background: rgba(67, 122, 34, 0.06);
}
.chip.state-down {
  color: var(--down);
  border-color: rgba(161, 53, 68, 0.3);
  background: rgba(161, 53, 68, 0.06);
}
.chip.state-flat {
  color: var(--flat);
}

.chip.is-start {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Distribution bars */
.dist {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.dist-row {
  display: grid;
  grid-template-columns: 64px 1fr 60px;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.dist-label {
  font-weight: 600;
  text-transform: capitalize;
}

.dist-bar {
  height: 8px;
  background: var(--surface-alt);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.dist-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.4s ease;
}

.dist-fill.state-up {
  background: var(--up);
}
.dist-fill.state-down {
  background: var(--down);
}
.dist-fill.state-flat {
  background: var(--flat);
}

.dist-pct {
  font-family: var(--font-mono);
  font-feature-settings: "tnum" 1, "lnum" 1;
  text-align: right;
  color: var(--text-muted);
}

/* Loading skeleton */
.loading {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.skeleton {
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.04) 0%,
    rgba(0, 0, 0, 0.08) 50%,
    rgba(0, 0, 0, 0.04) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: 6px;
  height: 14px;
}

.skeleton.lg {
  height: 24px;
  width: 50%;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

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

/* Error */
.error-card {
  background: #fdf4f5;
  border: 1px solid rgba(161, 53, 68, 0.3);
  color: #7a2532;
  border-radius: var(--radius);
  padding: 16px 18px;
  font-size: 14px;
}

.error-card strong {
  display: block;
  margin-bottom: 4px;
}

/* ----- Footer ----- */

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: 32px;
}

.footer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 24px;
  font-size: 13px;
  color: var(--text-muted);
}

.footer-note {
  color: var(--text-faint);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
