:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef3f5;
  --ink: #1d252c;
  --muted: #60707c;
  --line: #d8e0e5;
  --green: #147a52;
  --green-soft: #dcefe7;
  --blue: #1f5f99;
  --blue-soft: #dceafa;
  --red: #a94336;
  --amber: #b56b16;
  --shadow: 0 16px 40px rgba(24, 39, 50, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

button,
input {
  font: inherit;
}

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

.app-shell {
  width: 100%;
  margin: 0 auto;
  padding: 14px;
}

.topbar {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 14px;
  font-size: 16px;
}

.topbar-metrics {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.topbar-metrics div,
.control-strip,
.model-panel,
.events-panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.topbar-metrics div {
  min-height: 68px;
  padding: 14px 16px;
  border-radius: 8px;
}

.topbar-metrics span {
  display: block;
  font-size: 22px;
  font-weight: 800;
}

.topbar-metrics small {
  color: var(--muted);
}

.control-strip {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px;
  border-radius: 8px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: var(--surface-2);
}

.segment {
  min-height: 38px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.segment.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(20, 36, 45, 0.08);
}

.segment:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.search-box {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 44px;
  gap: 10px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

.search-box input {
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  color: var(--muted);
  white-space: nowrap;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.dashboard-grid {
  display: grid;
  gap: 14px;
}

.model-panel,
.events-panel {
  border-radius: 8px;
}

.model-panel {
  overflow: hidden;
}

.panel-section {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child {
  border-bottom: 0;
}

dl {
  display: grid;
  gap: 12px;
  margin: 0;
}

dt {
  color: var(--muted);
  font-size: 12px;
}

dd {
  margin: 2px 0 0;
  font-weight: 700;
}

.risk-scale {
  display: grid;
  gap: 8px;
}

.risk-scale span {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}

.pitch-map {
  position: relative;
  height: 140px;
  border: 1px solid rgba(20, 122, 82, 0.36);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(20, 122, 82, 0.08), rgba(31, 95, 153, 0.08)),
    repeating-linear-gradient(90deg, #eef7f2 0, #eef7f2 24px, #e7f1ef 24px, #e7f1ef 48px);
  overflow: hidden;
}

.pitch-line,
.signal-dot {
  position: absolute;
}

.pitch-line.center {
  top: 0;
  bottom: 0;
  left: 50%;
  border-left: 1px solid rgba(20, 122, 82, 0.36);
}

.pitch-line.box-left,
.pitch-line.box-right {
  top: 32px;
  width: 44px;
  height: 76px;
  border: 1px solid rgba(20, 122, 82, 0.36);
}

.pitch-line.box-left {
  left: -1px;
}

.pitch-line.box-right {
  right: -1px;
}

.signal-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 8px rgba(20, 122, 82, 0.16);
}

.dot-a {
  left: 68%;
  top: 42%;
}

.dot-b {
  left: 58%;
  top: 62%;
  background: var(--blue);
  box-shadow: 0 0 0 8px rgba(31, 95, 153, 0.16);
}

.dot-c {
  left: 77%;
  top: 28%;
  background: var(--amber);
  box-shadow: 0 0 0 8px rgba(181, 107, 22, 0.16);
}

.events-panel {
  min-height: 420px;
  padding: 10px;
}

.events-list {
  display: grid;
  gap: 10px;
}

.event-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.event-summary,
.best-signal {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.event-summary {
  min-height: 86px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
}

.event-summary:hover,
.event-summary:focus-visible,
.best-signal:hover,
.best-signal:focus-visible {
  background: #f9fbfc;
  outline: 0;
}

.event-main {
  min-width: 0;
}

.league-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}

.teams {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 17px;
  font-weight: 800;
}

.confidence {
  display: grid;
  min-width: 74px;
  gap: 6px;
}

.confidence-value {
  font-size: 22px;
  font-weight: 900;
  color: var(--green);
  text-align: right;
}

.confidence-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.confidence-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.chevron {
  display: none;
}

.best-signal {
  display: grid;
  gap: 6px;
  padding: 0 14px 14px;
}

.signal-label {
  color: var(--muted);
  font-size: 12px;
}

.signal-market {
  font-weight: 900;
}

.signal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.signal-meta span {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
}

.outcomes {
  display: none;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 0 14px 14px;
}

.event-card.open .outcomes {
  display: grid;
}

.outcome {
  position: relative;
  min-height: 118px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.outcome:hover,
.outcome:focus-within {
  border-color: #9fb6c7;
}

.outcome-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.market-name {
  min-width: 0;
  font-weight: 800;
}

.probability {
  color: var(--green);
  font-weight: 900;
  white-space: nowrap;
}

.outcome-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
}

.pill.value {
  background: var(--green-soft);
  color: var(--green);
}

.pill.risk {
  background: #f6e8d6;
  color: var(--amber);
}

.reason {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(45, 63, 75, 0.12);
  border-radius: 8px;
  background: #f0f4f7;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
}

.empty-state {
  margin: 40px 0;
  color: var(--muted);
  text-align: center;
}

.signal-drawer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
}

.signal-drawer.open {
  display: block;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(12, 22, 30, 0.42);
  cursor: pointer;
}

.drawer-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(88vh, 720px);
  overflow: auto;
  padding: 10px 16px 18px;
  border-radius: 16px 16px 0 0;
  background: var(--surface);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.18);
  transform: translateY(100%);
  transition: transform 180ms ease;
}

.signal-drawer.open .drawer-panel {
  transform: translateY(0);
}

.drawer-handle {
  width: 44px;
  height: 4px;
  margin: 0 auto 12px;
  border-radius: 999px;
  background: var(--line);
}

.drawer-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.drawer-kicker {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.drawer-content {
  display: grid;
  gap: 12px;
}

.drawer-match {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 18px;
  font-weight: 900;
}

.drawer-signal-card,
.drawer-reason {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.drawer-signal-card h3 {
  margin-bottom: 12px;
}

.drawer-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.drawer-stats div {
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-2);
}

.drawer-stats span,
.drawer-stats small {
  display: block;
}

.drawer-stats span {
  font-weight: 900;
}

.drawer-stats small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.drawer-reason h3 {
  margin-bottom: 8px;
  font-size: 15px;
}

.drawer-reason p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

@media (min-width: 640px) {
  .app-shell {
    padding: 20px;
  }

  h1 {
    font-size: 30px;
  }

  .topbar-metrics {
    grid-template-columns: repeat(3, 1fr);
  }

  .control-strip {
    grid-template-columns: 1fr 1.2fr auto;
    align-items: center;
  }

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

@media (min-width: 980px) {
  .app-shell {
    width: min(1440px, 100%);
    padding: 24px;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    align-items: end;
    gap: 24px;
    margin-bottom: 18px;
  }

  .topbar-metrics {
    min-width: 430px;
  }

  .dashboard-grid {
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 16px;
  }

  .model-panel {
    align-self: start;
  }

  .events-panel {
    min-height: 560px;
  }

  .event-summary {
    grid-template-columns: minmax(210px, 1fr) 140px 36px;
  }

  .chevron {
    width: 28px;
    height: 28px;
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--muted);
    font-weight: 800;
  }

  .event-card.open .chevron {
    color: var(--green);
  }

  .best-signal {
    grid-template-columns: 120px 1fr auto;
    align-items: center;
    padding: 0 14px 14px;
  }

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

  .reason {
    position: absolute;
    z-index: 5;
    left: 14px;
    right: 14px;
    bottom: calc(100% - 8px);
    margin-top: 0;
    pointer-events: none;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 140ms ease, transform 140ms ease;
    background: rgba(29, 37, 44, 0.9);
    color: #ffffff;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.16);
  }

  .outcome:hover .reason,
  .outcome:focus-within .reason {
    opacity: 1;
    transform: translateY(0);
  }

  .drawer-panel {
    top: 0;
    right: 0;
    left: auto;
    bottom: 0;
    width: min(440px, 92vw);
    max-height: none;
    padding: 22px;
    border-radius: 0;
    transform: translateX(100%);
  }

  .signal-drawer.open .drawer-panel {
    transform: translateX(0);
  }

  .drawer-handle {
    display: none;
  }
}
