:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --surface: #ffffff;
  --surface-2: #eef2ef;
  --ink: #172126;
  --muted: #647178;
  --line: #d8ded9;
  --teal: #0e7c7b;
  --teal-dark: #0a5d5c;
  --amber: #b36b00;
  --rose: #9a4261;
  --blue: #2b5c8a;
  --red: #b23831;
  --green: #26734d;
  --shadow: 0 18px 50px rgba(20, 31, 36, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
select,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 14px;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

select {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 26px clamp(18px, 4vw, 44px) 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.74);
}

.topbar h1,
.panel h2 {
  margin: 0;
  line-height: 1.05;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(1.55rem, 3vw, 2.25rem);
}

.panel h2 {
  font-size: 1.15rem;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 0.95fr) minmax(340px, 1.25fr);
  gap: 18px;
  padding: 20px clamp(18px, 4vw, 44px) 44px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.action-panel,
.challenge-panel,
.metrics-panel {
  padding: 18px;
}

.metrics-panel {
  grid-column: 1 / -1;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.badge,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 11px;
  border: 1px solid rgba(14, 124, 123, 0.28);
  background: rgba(14, 124, 123, 0.1);
  color: var(--teal-dark);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge.neutral {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--muted);
}

.badge.warn {
  border-color: rgba(179, 107, 0, 0.28);
  background: rgba(179, 107, 0, 0.1);
  color: #734700;
}

.badge.danger {
  border-color: rgba(178, 56, 49, 0.25);
  background: rgba(178, 56, 49, 0.1);
  color: var(--red);
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
}

.control-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

.toggle-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  background: #fbfcfa;
}

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

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0;
}

.primary {
  background: var(--teal);
  color: #fff;
}

.primary:hover {
  background: var(--teal-dark);
}

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

.status-stack {
  display: grid;
  gap: 8px;
}

.status-line {
  border-left: 3px solid var(--teal);
  background: #f8fbfa;
  padding: 9px 11px;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.35;
}

.status-line.muted {
  border-left-color: var(--line);
  color: var(--muted);
}

.status-line.warn {
  border-left-color: var(--amber);
}

.status-line.error {
  border-left-color: var(--red);
}

.challenge-stage {
  min-height: 330px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(14, 124, 123, 0.05), transparent 38%),
    linear-gradient(180deg, #fbfcfa, #f0f4f1);
  overflow: hidden;
}

.empty-state {
  display: grid;
  gap: 16px;
  justify-items: center;
  max-width: 380px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.signal-preview {
  display: flex;
  gap: 10px;
  align-items: end;
  height: 78px;
}

.signal-preview span {
  display: block;
  width: 34px;
  border-radius: 7px 7px 3px 3px;
  background: var(--teal);
}

.signal-preview span:nth-child(1) {
  height: 42px;
  background: var(--teal);
}

.signal-preview span:nth-child(2) {
  height: 72px;
  background: var(--amber);
}

.signal-preview span:nth-child(3) {
  height: 54px;
  background: var(--rose);
}

.gate-shell {
  width: min(100%, 720px);
  padding: 22px;
}

.gate-prompt {
  margin: 0 0 18px;
  color: var(--ink);
  font-weight: 720;
}

.gate-track {
  position: relative;
  height: 96px;
  border: 1px solid #c9d5d1;
  border-radius: 8px;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(23, 33, 38, 0.06) 0,
      rgba(23, 33, 38, 0.06) 1px,
      transparent 1px,
      transparent 9%
    ),
    #ffffff;
  overflow: hidden;
}

.gate {
  position: absolute;
  top: 15px;
  bottom: 15px;
  width: 46px;
  transform: translateX(-50%);
  border-radius: 7px;
  border: 2px solid currentColor;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.82);
}

.gate[data-color="teal"] {
  color: var(--teal);
}

.gate[data-color="amber"] {
  color: var(--amber);
}

.gate[data-color="rose"] {
  color: var(--rose);
}

.gate.hit {
  color: var(--green);
  background: rgba(38, 115, 77, 0.13);
}

.pulse {
  position: absolute;
  top: 8px;
  bottom: 8px;
  width: 12px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: var(--blue);
  box-shadow: 0 0 0 7px rgba(43, 92, 138, 0.13);
}

.gate-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.gate-progress {
  min-height: 24px;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfa;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 1.55rem;
  letter-spacing: 0;
}

.event-log {
  display: grid;
  gap: 8px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.event-log li {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 9px;
  color: var(--muted);
  font-size: 0.88rem;
}

.event-log strong {
  color: var(--ink);
}

@media (max-width: 920px) {
  .workspace {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .control-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .event-log li {
    grid-template-columns: 1fr;
  }

  .gate-shell {
    padding: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
