:root {
  color-scheme: light;
  --paper: #f6f4ee;
  --surface: #ffffff;
  --ink: #1e2528;
  --muted: #687276;
  --line: #d9ded8;
  --green: #16866a;
  --red: #c34848;
  --amber: #bb7a19;
  --blue: #366d8c;
  --shadow: 0 18px 45px rgba(32, 40, 43, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

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

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 14px calc(28px + env(safe-area-inset-bottom));
}

.topbar,
.pick-top,
.section-head,
.ledger-card,
.signal-strip,
.button-row,
.toggle-row,
.section-actions {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  font-size: 2.05rem;
  line-height: 1;
}

h2 {
  font-size: 1.1rem;
}

h3 {
  margin-top: 8px;
  font-size: 1.02rem;
  line-height: 1.25;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 1.4rem;
}

.status-grid,
.performance-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

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

.metric,
.control-band,
.pick-card,
.empty-state,
.ledger-card,
.rule-list article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric {
  min-width: 0;
  padding: 12px;
}

.metric span,
.field-row label,
.field-hint,
.section-head span,
.ledger-meta,
.pick-meta,
.rule-list span,
.empty-state span {
  color: var(--muted);
  font-size: 0.82rem;
}

.field-hint {
  line-height: 1.35;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(0.95rem, 4vw, 1.15rem);
  white-space: nowrap;
}

.control-band {
  padding: 14px;
  box-shadow: var(--shadow);
}

.field-row {
  display: grid;
  gap: 6px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

input,
select {
  min-height: 44px;
  width: 100%;
  border: 1px solid #cbd3cd;
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  padding: 0 12px;
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(22, 134, 106, 0.22);
  outline-offset: 2px;
}

.toggle-row {
  flex-wrap: wrap;
  gap: 12px;
  margin: 14px 0;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch span {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #ccd5cf;
  transition: 0.2s ease;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  transition: 0.2s ease;
}

.switch input:checked + span {
  background: var(--green);
}

.switch input:checked + span::after {
  transform: translateX(18px);
}

.button-row {
  gap: 8px;
}

.primary-button,
.secondary-button,
.text-button,
.ledger-actions button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  font-weight: 800;
}

.primary-button {
  flex: 1;
  background: var(--green);
  color: #fff;
}

.secondary-button {
  background: #e9eee9;
  color: var(--ink);
  border-color: var(--line);
}

.small-button {
  min-height: 36px;
  padding: 0 11px;
  font-size: 0.85rem;
}

.text-button {
  background: transparent;
  color: var(--red);
  min-height: auto;
  padding: 4px 0;
  font-weight: 800;
}

.signal-strip {
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid #cfd8d2;
  border-radius: 8px;
  background: #eef7f2;
}

.signal-strip > div {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.signal-strip p {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.signal-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
}

.signal-strip.is-warning {
  background: #fff7e8;
  border-color: #ecd29c;
}

.signal-strip.is-warning .signal-dot {
  background: var(--amber);
}

.signal-strip.is-stop {
  background: #fff0f0;
  border-color: #edc4c4;
}

.signal-strip.is-stop .signal-dot {
  background: var(--red);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 14px 0;
}

.tab {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e7ece8;
  color: var(--muted);
  font-weight: 800;
}

.tab.is-active {
  background: var(--ink);
  color: #fff;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.section-head {
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.pick-list,
.ledger-list,
.rule-list {
  display: grid;
  gap: 10px;
}

.empty-state {
  display: grid;
  gap: 6px;
  padding: 18px;
  text-align: center;
}

.pick-card {
  padding: 14px;
  box-shadow: var(--shadow);
}

.pick-top {
  justify-content: space-between;
  gap: 10px;
}

.pick-top > div {
  min-width: 0;
}

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 2px 9px;
  background: #e9f5ef;
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 900;
}

.badge.consider {
  background: #fff3dd;
  color: var(--amber);
}

.badge.skip {
  background: #fff0f0;
  color: var(--red);
}

.stake {
  flex: 0 0 auto;
  min-width: 74px;
  text-align: right;
  font-size: 1.2rem;
}

.pick-meta {
  margin: 8px 0 10px;
}

.score-line {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7ece8;
}

.score-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), #70a848);
}

.pick-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.pick-stats div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fbfcfa;
}

.pick-stats dt {
  color: var(--muted);
  font-size: 0.74rem;
}

.pick-stats dd {
  margin: 4px 0 0;
  font-weight: 900;
  white-space: nowrap;
}

.reason {
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.42;
}

.compact {
  margin-top: 12px;
}

.compact .secondary-button,
.compact .primary-button {
  flex: 1;
}

.ledger-card {
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
}

.ledger-card > div:first-child {
  min-width: 0;
}

.ledger-title {
  display: block;
  line-height: 1.3;
}

.ledger-meta {
  display: block;
  margin-top: 4px;
}

.ledger-note {
  display: block;
  margin-top: 6px;
  color: var(--blue);
  font-size: 0.78rem;
  line-height: 1.3;
}

.ledger-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: flex-end;
}

.ledger-actions button {
  min-height: 34px;
  padding: 0 9px;
  background: #edf1ed;
  border-color: var(--line);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
}

.ledger-card.is-settled .ledger-actions {
  display: none;
}

.rule-list article {
  display: grid;
  gap: 5px;
  padding: 14px;
}

.toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 10;
  max-width: 720px;
  margin: 0 auto;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  padding: 12px 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

@media (max-width: 520px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .status-grid,
  .performance-grid,
  .pick-stats {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
  }

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

  .pick-stats {
    grid-template-columns: 1fr 1fr;
  }

  .metric,
  .pick-stats div {
    padding: 9px 7px;
  }

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

  .signal-strip,
  .ledger-card {
    display: grid;
  }

  .stake {
    min-width: 58px;
    font-size: 1.05rem;
  }
}
