:root {
  --paper: #e7ecef;
  --panel: #f5f7f8;
  --ink: #0a1a26;
  --muted: #5b6870;
  --line: #a9b4ba;
  --navy: #0d2c40;
  --blue: #1d6688;
  --cyan: #28a995;
  --amber: #e6a727;
  --coral: #d94e43;
  --price-electric: #0067d8;
  --shadow: 0 18px 50px rgba(17, 39, 52, 0.12);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(13, 44, 64, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(13, 44, 64, 0.035) 1px, transparent 1px);
  background-size: 24px 24px;
}

button,
input {
  font: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 24px clamp(18px, 4vw, 56px) 18px;
  border-bottom: 1px solid var(--ink);
  background: rgba(231, 236, 239, 0.94);
}

.eyebrow,
.section-label,
.cell-label {
  margin: 0;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: "Avenir Next Condensed", "Arial Narrow", sans-serif;
  font-weight: 800;
  letter-spacing: -0.035em;
}

h1 {
  margin-top: 3px;
  font-size: clamp(1.65rem, 4vw, 2.7rem);
}

h2 {
  font-size: 1.55rem;
}

.connection {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 6px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.connection-dot {
  width: 9px;
  height: 9px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: var(--amber);
}

.connection.live .connection-dot {
  background: var(--cyan);
}

.connection.stale .connection-dot {
  background: var(--coral);
}

main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 3vw, 44px);
}

.price-board {
  display: grid;
  grid-template-columns: minmax(240px, 0.8fr) minmax(420px, 2fr);
  gap: clamp(32px, 6vw, 90px);
  padding: clamp(26px, 5vw, 64px);
  border: 1px solid var(--ink);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.price-lead {
  align-self: center;
}

.price-lockup {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 6px 0;
}

.price-value {
  color: var(--price-electric);
  font-family: "Avenir Next Condensed", "Arial Narrow", sans-serif;
  font-size: clamp(5rem, 11vw, 10rem);
  font-weight: 800;
  line-height: 0.82;
  letter-spacing: -0.075em;
}

.price-unit {
  padding-bottom: 8px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 700;
}

.price-caption,
.rail-note,
.cell-note,
.form-message {
  color: var(--muted);
  font-size: 0.8rem;
}

.rail-wrap {
  align-self: center;
}

.rail-labels {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.68rem;
}

.cost-rail {
  position: relative;
  height: 74px;
  margin: 48px 0 42px;
  border: 1px solid var(--ink);
  background: #fff;
}

.safe-zone,
.hysteresis-zone,
.danger-zone {
  position: absolute;
  inset-block: 0;
}

.safe-zone {
  left: 0;
  background: rgba(40, 169, 149, 0.24);
}

.hysteresis-zone {
  background: rgba(230, 167, 39, 0.28);
}

.danger-zone {
  right: 0;
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(217, 78, 67, 0.22),
      rgba(217, 78, 67, 0.22) 8px,
      rgba(217, 78, 67, 0.08) 8px,
      rgba(217, 78, 67, 0.08) 16px
    );
}

.rail-marker {
  position: absolute;
  top: -39px;
  transform: translateX(-50%);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.62rem;
  text-align: center;
  white-space: nowrap;
}

.rail-marker::after {
  position: absolute;
  top: 32px;
  left: 50%;
  width: 1px;
  height: 80px;
  background: var(--ink);
  content: "";
}

.rail-marker strong {
  display: block;
  margin-top: 2px;
  font-size: 0.72rem;
}

.restart-marker span,
.restart-marker strong {
  position: relative;
  left: -28px;
}

.shutdown-marker span,
.shutdown-marker strong {
  position: relative;
  left: 28px;
}

.current-needle {
  position: absolute;
  top: -12px;
  bottom: -12px;
  width: 4px;
  transform: translateX(-50%);
  background: var(--ink);
  transition: left 500ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.current-needle::after {
  position: absolute;
  top: -7px;
  left: 50%;
  width: 12px;
  height: 12px;
  transform: translateX(-50%) rotate(45deg);
  border: 2px solid var(--panel);
  background: var(--ink);
  content: "";
}

.current-needle span {
  position: absolute;
  bottom: -27px;
  left: 50%;
  transform: translateX(-50%);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.62rem;
  font-weight: 700;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  margin-top: 16px;
  border: solid var(--ink);
  border-width: 1px 0 0 1px;
}

.status-cell {
  min-height: 150px;
  padding: 20px;
  border: solid var(--ink);
  border-width: 0 1px 1px 0;
  background: rgba(245, 247, 248, 0.88);
}

.state-cell {
  background: var(--navy);
  color: #f8fbfc;
}

.state-cell .cell-note {
  color: #bfccd2;
}

.cell-value {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 22px 0 5px;
  font-family: "Avenir Next Condensed", "Arial Narrow", sans-serif;
  font-size: clamp(2rem, 3.2vw, 3.2rem);
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: -0.04em;
}

.cell-value small {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.7rem;
  letter-spacing: 0;
}

.state-value,
.decision-value,
.time-value {
  font-size: clamp(1.55rem, 2.2vw, 2.25rem);
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(340px, 0.65fr) minmax(0, 1.35fr);
  gap: 16px;
  margin-top: 16px;
}

.panel {
  border: 1px solid var(--ink);
  background: var(--panel);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px;
  border-bottom: 1px solid var(--ink);
}

.text-button {
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
}

.event-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.event-list li {
  display: grid;
  grid-template-columns: 150px 150px minmax(0, 1fr);
  gap: 18px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  font-size: 0.82rem;
}

.event-list li:last-child {
  border-bottom: 0;
}

.event-time,
.event-type {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.69rem;
}

.event-type {
  font-weight: 700;
}

.empty-event {
  display: block !important;
  color: var(--muted);
}

.guard-badge {
  padding: 5px 8px;
  border: 1px solid var(--ink);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.62rem;
  font-weight: 700;
}

.notice {
  margin: 20px 22px 0;
  padding: 12px;
  border-left: 4px solid var(--amber);
  background: rgba(230, 167, 39, 0.14);
  font-size: 0.78rem;
  line-height: 1.45;
}

form {
  padding: 22px;
}

form label {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
  font-size: 0.78rem;
  font-weight: 700;
}

.input-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border: 1px solid var(--ink);
  background: #fff;
}

.input-shell input {
  width: 100%;
  min-width: 0;
  padding: 13px;
  border: 0;
  background: transparent;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 1rem;
}

.input-shell span {
  padding-right: 12px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.68rem;
}

.auth-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 18px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  background: #f7f9fa;
  font-size: 0.72rem;
  font-weight: 700;
}

.auth-note a {
  color: var(--price-electric);
  text-underline-offset: 3px;
}

.review-box {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--amber);
  background: rgba(230, 167, 39, 0.1);
}

.review-box p,
.review-box strong,
.review-box span {
  display: block;
}

.review-box p {
  margin: 0 0 6px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.review-box span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.73rem;
}

.primary-button {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--ink);
  background: var(--navy);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.primary-button:hover {
  background: var(--blue);
}

.form-message {
  min-height: 1.2em;
  margin-bottom: 0;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 18px clamp(18px, 4vw, 56px) 30px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.65rem;
  text-transform: uppercase;
}

@media (max-width: 1000px) {
  .price-board {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 640px) {
  .masthead {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .connection {
    padding: 0;
  }

  h1 {
    font-size: 2rem;
  }

  main {
    padding: 12px;
  }

  .price-board {
    gap: 30px;
    padding: 24px 18px 28px;
  }

  .price-value {
    font-size: 6rem;
  }

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

  .status-cell {
    min-height: 132px;
    padding: 16px;
  }

  .event-list li {
    grid-template-columns: 1fr auto;
    gap: 8px 12px;
  }

  .event-list li:nth-child(n + 6) {
    display: none;
  }

  .event-message {
    grid-column: 1 / -1;
  }

  footer {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  .current-needle {
    transition: none;
  }
}
