:root {
  --bg: #08111b;
  --bg2: #0f1f2f;
  --panel: rgba(12, 24, 36, 0.82);
  --ink: #ecf2f8;
  --muted: #93a7ba;
  --line: rgba(236, 242, 248, 0.12);
  --accent: #ffc86b;
  --up: #51d289;
  --warn: #ff9f43;
  --down: #ff6b6b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Segoe UI", "Arial", sans-serif;
  overscroll-behavior-y: contain;
  background:
    radial-gradient(circle at 80% 10%, rgba(255, 200, 107, 0.2), transparent 35%),
    radial-gradient(circle at 10% 10%, rgba(81, 210, 137, 0.16), transparent 30%),
    linear-gradient(140deg, var(--bg), var(--bg2));
}

.pull-refresh-indicator {
  position: fixed;
  left: 50%;
  top: 8px;
  transform: translate(-50%, -56px);
  z-index: 60;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  color: #ffe3bb;
  background: rgba(8, 20, 32, 0.92);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.pull-refresh-indicator.visible {
  opacity: 1;
}

.pull-refresh-indicator.armed {
  color: #b8f0ce;
  border-color: rgba(81, 210, 137, 0.45);
}

.shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 20px 42px;
  display: grid;
  gap: 18px;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.kicker {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 44px);
}

.hero p { margin: 6px 0 0; color: var(--muted); }

.hero-metrics {
  display: grid;
  gap: 8px;
  min-width: 220px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--panel);
}
.metric span { color: var(--muted); font-size: 12px; display: block; }
.metric strong { font-size: 20px; }
.metric-actions { margin-top: 8px; }
.metric-actions button {
  width: 100%;
  border-radius: 10px;
  padding: 7px 10px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: var(--panel);
  backdrop-filter: blur(4px);
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.controls .control-label {
  margin: 0 0 6px;
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.row { display: flex; flex-wrap: wrap; gap: 8px; }
button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}
button.active, button:hover {
  border-color: rgba(255, 200, 107, 0.7);
  background: rgba(255, 200, 107, 0.18);
}

select {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 12px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.panel-head h2 { margin: 0; }
.panel-head p { margin: 0; color: var(--muted); font-size: 13px; }

.chart { height: 420px; margin-top: 12px; }
.chart {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(5, 14, 24, 0.72);
  padding: 12px;
  position: relative;
}

.chart.loading::after {
  content: attr(data-loading-label);
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 12px;
  color: #ffe3bb;
  background: rgba(255, 159, 67, 0.2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  z-index: 2;
}

.chart-headline {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.chart-headline strong {
  font-size: 16px;
}

.chart-svg {
  width: 100%;
  height: calc(100% - 28px);
  display: block;
}

.grid { display: grid; gap: 10px; }
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-top: 10px; }
.decision-grid { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: rgba(6, 14, 24, 0.66);
}
.card h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.card p { margin: 0; font-weight: 600; }

.ppce-card {
  margin-top: 10px;
}

.ppce-interpretation {
  margin-top: 8px;
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 400;
  color: var(--ink);
  line-height: 1.5;
}

.ppce-interpretation p {
  margin: 0 0 4px;
}

.ppce-credibility-line {
  margin-top: 8px;
  font-size: 18px;
  font-weight: 700;
}

.ppce-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.ppce-head p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.ppce-grid {
  margin-top: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.ppce-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  padding: 8px 10px;
  display: grid;
  gap: 5px;
}

.ppce-grid span {
  color: var(--muted);
  font-size: 12px;
}

.ppce-grid strong {
  font-size: 16px;
}

#ppce-paper-stress-temporal {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 24px;
}

#ppce-state {
  margin-top: 10px;
  font-size: 16px;
}

#ppce-note {
  margin-top: 4px;
  font-size: 13px;
}

.decision {
  margin: 0 0 8px;
  font-size: 22px;
  color: var(--accent);
}

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

.list {
  margin: 10px 0 0;
  padding-left: 16px;
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.stress-meter {
  margin-top: 8px;
  width: 100%;
  height: 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  overflow: hidden;
  background: linear-gradient(90deg, #284968, #2a7053, #9f7332, #8f3535);
}
.stress-meter > div {
  height: 100%;
  width: 0%;
  background: rgba(255,255,255,0.35);
}

.markdown {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
}

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

.board-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 14px;
}

.table-scroll {
  width: 100%;
  overflow-x: visible;
}

.table-scroll .board-table {
  min-width: 0;
}

.board-table th,
.board-table td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.board-table th {
  color: var(--muted);
  font-weight: 600;
}

.chg-up {
  background: rgba(81, 210, 137, 0.25);
  color: #b8f0ce;
}

.chg-down {
  background: rgba(255, 107, 107, 0.25);
  color: #ffd0d0;
}

.chg-flat {
  background: rgba(236, 242, 248, 0.08);
  color: var(--ink);
}

.flash {
  animation: pulse 0.7s ease-in-out;
}

@keyframes pulse {
  from { filter: brightness(1.25); }
  to { filter: brightness(1); }
}

.news-stream {
  margin-top: 8px;
  display: grid;
  gap: 8px;
}

.news-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: rgba(6, 14, 24, 0.66);
}

.news-item h4 {
  margin: 0 0 4px;
  font-size: 21px;
}

.news-item a {
  color: var(--ink);
  text-decoration: none;
}

.news-item a:hover {
  text-decoration: underline;
}

.board-table a,
.board-table a:visited {
  color: #9fd3ff;
  text-decoration: none;
}

.board-table a:hover,
.board-table a:focus {
  color: #d7ebff;
  text-decoration: underline;
}

.news-item p {
  margin: 0;
  color: var(--muted);
}

.status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-aligned {
  color: #b8f0ce;
  background: rgba(81, 210, 137, 0.25);
}

.status-partial,
.status-context {
  color: #ffe3bb;
  background: rgba(255, 159, 67, 0.22);
}

.status-drifting,
.status-unknown {
  color: #ffd0d0;
  background: rgba(255, 107, 107, 0.2);
}

.status-demonstrated {
  color: #b8f0ce;
  background: rgba(81, 210, 137, 0.25);
}

.status-not_demonstrable,
.status-not-demonstrable {
  color: #ffd0d0;
  background: rgba(255, 107, 107, 0.2);
}

.price-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
}

.price-green {
  color: #b8f0ce;
  background: rgba(81, 210, 137, 0.2);
}

.price-orange {
  color: #ffe3bb;
  background: rgba(255, 159, 67, 0.2);
}

.price-red {
  color: #ffd0d0;
  background: rgba(255, 107, 107, 0.2);
}

.api-loading,
.api-idle {
  color: #ffe3bb;
  background: rgba(255, 159, 67, 0.2);
}

.api-ok {
  color: #b8f0ce;
  background: rgba(81, 210, 137, 0.2);
}

.api-error {
  color: #ffd0d0;
  background: rgba(255, 107, 107, 0.2);
}

.diagnostic-row {
  display: none;
}

@media (max-width: 980px) {
  .shell {
    padding: 20px 14px 30px;
    gap: 14px;
  }

  .hero {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-metrics {
    min-width: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric strong {
    font-size: 18px;
  }

  .panel {
    padding: 12px;
    border-radius: 12px;
  }

  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-scroll .board-table {
    min-width: 640px;
  }

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

@media (max-width: 680px) {
  h1 {
    font-size: clamp(28px, 9vw, 38px);
  }

  .hero-metrics {
    grid-template-columns: 1fr;
  }

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

  .pull-refresh-indicator {
    top: 6px;
  }

  .chart {
    height: 320px;
  }

  .chart-headline {
    font-size: 12px;
    gap: 8px;
  }

  .chart-headline strong {
    font-size: 14px;
  }

  .board-table th,
  .board-table td {
    padding: 7px 8px;
    font-size: 13px;
  }

  .news-item h4 {
    font-size: 18px;
  }
}

@media (max-width: 420px) {
  .shell {
    padding: 14px 10px 24px;
  }

  .chart {
    height: 280px;
    padding: 8px;
  }
}
