:root {
  --bg: #faf6ef;
  --ink: #2a2520;
  --ink-2: #3d362d;
  --muted: #8c7e5e;
  --tile-bg: #fff;
  --tile-border: #e3dcc9;
  --tile-border-hover: #bfa97a;
  --rule: #c9bfa8;
  --easy: #E25D26;
  --clarity: #C5183A;
  --shyft: #0F3D5C;
  --ref: #c5bda5;
  --ok: #5b8a3a;
  --warn: #c98a1a;
  --err: #b03a2e;
  --serif: ui-serif, Georgia, 'Iowan Old Style', serif;
  --sans: ui-sans-serif, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); }
body { min-height: 100vh; padding: 24px clamp(16px, 4vw, 48px); }

.masthead {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: baseline;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 18px;
}
.masthead-left { font-size: 11px; letter-spacing: 0.12em; color: var(--muted); }
.wordmark { text-transform: uppercase; }
.masthead-center { text-align: center; }
.snapshot-title { font-family: var(--serif); font-size: clamp(20px, 2.6vw, 28px); margin: 0; letter-spacing: 0; }
.masthead-right { font-size: 11px; letter-spacing: 0.1em; color: var(--muted); text-transform: uppercase; text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.live-status { display: inline-flex; align-items: center; gap: 6px; }
.live-status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); display: inline-block; }
.live-status .dot.stale { background: var(--warn); }
.live-status .dot.err { background: var(--err); }
/* Floating view toggle — sits above the masthead, switches snapshot ↔ long read */
.view-toggle {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: rgba(250, 246, 239, 0.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--rule);
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
}
.view-pill {
  text-decoration: none;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 6px 16px;
  border-radius: 999px;
  color: var(--muted);
  transition: color .15s ease, background .15s ease;
  font-family: var(--sans);
}
.view-pill:hover { color: var(--ink); }
.view-pill.active { background: var(--ink); color: var(--bg); }
.view-pill.active:hover { color: var(--bg); }

/* Push the masthead down a hair so the floating pill doesn't overlap on
   smaller viewports where vertical breathing room is tight. */
body { padding-top: 64px; }
@media (max-width: 767px) {
  .view-toggle { top: 10px; }
  .view-pill { padding: 5px 12px; letter-spacing: 0.1em; }
  body { padding-top: 56px; }
}

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

.tile {
  background: var(--tile-bg);
  border: 1px solid var(--tile-border);
  border-left: 3px solid var(--ref);
  border-radius: 6px;
  padding: 14px 16px;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: border-color .15s ease;
}
.tile:hover, .tile:focus { border-color: var(--tile-border-hover); outline: none; }
.tile.live { border-left-color: var(--easy); }
.tile.ref { border-left-color: var(--ref); }
.tile-head { display: flex; justify-content: space-between; align-items: center; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.tile-num { color: var(--ink-2); }
.tile-body { flex: 1; display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--ink-2); }
.tile-body .v { font-family: var(--serif); font-size: 20px; line-height: 1.1; color: var(--ink); }
.tile-body .vs { font-family: var(--serif); font-size: 15px; }
.tile-body .row { display: flex; justify-content: space-between; }
.tile-body .row b { font-weight: 600; color: var(--ink); }
.tile-body canvas { width: 100%; height: 32px; display: block; }
.tile-foot { font-size: 10px; color: var(--muted); align-self: flex-end; }
.tile.stale { opacity: .65; }

.pill { font-size: 8px; padding: 2px 6px; border-radius: 8px; letter-spacing: 0.1em; }
.pill.live { background: #fdebe2; color: var(--easy); }
.pill.ref { background: #eee7d4; color: var(--muted); }

.badge { display: inline-block; font-size: 10px; padding: 2px 6px; border-radius: 3px; background: #f4ede0; color: var(--ink); margin-right: 4px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--err); }

.scatter { position: relative; flex: 1; background: #f4ede0; border-radius: 4px; min-height: 70px; }
.scatter span { position: absolute; width: 12px; height: 12px; border-radius: 50%; transform: translate(-50%, -50%); }

/* Drill-down panel */
.panel-backdrop {
  position: fixed; inset: 0;
  background: rgba(40, 36, 30, 0.4);
  z-index: 10;
}
.panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 480px; max-width: 100vw;
  background: var(--bg);
  border-left: 1px solid var(--rule);
  z-index: 11;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.08);
  animation: slide-in .2s ease-out;
}
.panel[hidden] { display: none; }
@keyframes slide-in { from { transform: translateX(100%); } to { transform: translateX(0); } }
.panel-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 22px 24px 12px;
  border-bottom: 1px solid var(--rule);
}
.panel-head h2 { font-family: var(--serif); font-size: 22px; margin: 0; }
.panel-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--muted); padding: 4px 8px; }
.panel-close:hover { color: var(--ink); }
.panel-body { padding: 18px 24px; overflow-y: auto; flex: 1; font-size: 14px; line-height: 1.5; color: var(--ink-2); }
.panel-body h3 { font-family: var(--serif); font-size: 16px; color: var(--ink); margin: 18px 0 8px; }
.panel-body table { width: 100%; border-collapse: collapse; font-size: 12px; }
.panel-body th, .panel-body td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--tile-border); }

/* Market drill-down platform tabs */
.market-tabs { display: flex; gap: 0; margin-bottom: 14px; border-bottom: 1px solid var(--rule); }
.market-tab {
  text-decoration: none;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 6px 12px 8px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.market-tab:hover { color: var(--ink); }
.market-tab.active { color: var(--ink); border-bottom-color: var(--easy); }

/* Responsive */
@media (max-width: 1099px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 767px) {
  body { padding: 16px; }
  .masthead { grid-template-columns: 1fr; text-align: center; }
  .masthead-right { align-items: center; text-align: center; }
  .grid { grid-template-columns: 1fr; }
  .panel { top: auto; bottom: 0; width: 100vw; height: 88vh; border-left: none; border-top: 1px solid var(--rule); animation: slide-up .2s ease-out; }
  @keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
}
