:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #5c6b7c;
  --line: #e2e7ee;
  --green: #1b7a34;
  --up: #146c36;
  --up-bg: #d9f3e3;
  --down: #a61b1b;
  --down-bg: #f7d4d4;
  --flat-bg: #eceff3;
  --shadow: 0 1px 2px rgba(28, 36, 48, 0.04);
  --sans: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
}

button, input { font-family: inherit; }

.wrap {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: env(safe-area-inset-top) 0 calc(36px + env(safe-area-inset-bottom));
}

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: white;
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 5;
}

.skip:focus { top: 12px; }

.app-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.app-title-row {
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-title {
  margin: 0;
  font-family: "Michroma", "DM Sans", system-ui, sans-serif;
  font-weight: 400;
  font-size: clamp(16.8px, 3.2vmin, 21.6px);
  letter-spacing: 0.1em;
  line-height: 1.15;
  color: var(--ink);
  text-align: center;
  text-transform: none;
}

.gap-switch {
  display: inline-flex;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: white;
}

.gap-switch button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.02em;
  padding: 5px 16px;
  cursor: pointer;
}

.gap-switch button[aria-pressed="true"] {
  background: var(--ink);
  color: white;
}

.purpose {
  margin: 10px 0 0;
  max-width: 28rem;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.banner {
  margin: 12px 0 0;
  width: min(100%, 40rem);
  background: #fff6e8;
  color: #7a4b00;
  border: 1px solid #f0ddb8;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  text-align: left;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.about-link,
.reload {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: white;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}

.about-link { color: var(--ink); }

.reload:hover { color: var(--ink); }

/* The label changes to report what a press found, so the pill is sized for
   the longest of those words and does not jump the header around. */
.reload {
  min-width: 114px;
  justify-content: center;
}

.reload:disabled {
  opacity: 0.6;
}

.section { margin-top: 28px; }

.section-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px 12px;
  margin-bottom: 10px;
}

.section-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #667585;
}

.section-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.sort-ctl {
  margin-left: auto;
}

.sort-ctl select {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  padding: 4px 22px 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23667585' d='M1 1l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 8px center;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
}

.stamp {
  margin-left: auto;
  color: #000;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.totals-grid,
.near-grid {
  display: grid;
  gap: 12px;
}

.totals-grid { gap: 8px; }

/* Short strip above the three cards. The plot is the height; the key under
   it is one tight pair of lines, not a second card. */
.trend {
  margin: 0 0 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px 8px 5px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.trend * {
  -webkit-user-select: none;
  user-select: none;
}

.trend-plot {
  position: relative;
  height: 64px;
  cursor: crosshair;
  touch-action: pan-y;
}

.trend svg {
  display: block;
  width: 100%;
  height: 64px;
}

.trend svg .series,
.trend svg .rule,
.trend svg .base {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.trend svg .series { stroke-width: 1.75; }
.trend svg .base { stroke: #d5dbe3; stroke-width: 1; stroke-dasharray: 3 3; }
.trend svg .rule { stroke: #9aa6b2; stroke-width: 1; }

.trend-start {
  position: absolute;
  right: 0;
  transform: translateY(-50%);
  color: #8b98a5;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  pointer-events: none;
}

.trend-scale {
  margin-top: 1px;
  color: #8b98a5;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.trend-key {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-top: 3px;
}

.trend-key div {
  min-width: 0;
  border-top: 2px solid currentColor;
  padding-top: 2px;
}

.trend-n { color: #2f4d6f; }
.trend-l { color: #1b7a34; }
.trend-h { color: #b06a12; }

.trend-key .name {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.15;
  text-transform: uppercase;
}

.trend-key .val {
  display: block;
  margin-top: 0;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  white-space: nowrap;
}

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

@media (min-width: 800px) {
  .totals-grid { grid-template-columns: 1fr 1fr 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 14px 12px;
  min-width: 0;
}

.card-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.k {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.eq,
.delta-main {
  font-family: var(--mono);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.start-num {
  font-family: var(--mono);
  font-size: 13px;
  color: #3d4a57;
  margin-top: 2px;
  white-space: nowrap;
}

.delta {
  margin-top: 8px;
  margin-left: auto;
  width: fit-content;
  max-width: 100%;
  min-width: 9.2rem;
  border-radius: 12px;
  padding: 8px 10px;
  text-align: right;
}

.delta + .delta { margin-top: 6px; }

.delta-main { font-size: 15px; }
.delta-sub { font-size: 12px; margin-top: 2px; }

.delta.down { background: var(--down-bg); color: var(--down); }
.delta.up { background: var(--up-bg); color: var(--up); }
.delta.flat { background: var(--flat-bg); color: #3e4b59; }

.mini {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.mini.down { color: var(--down); }
.mini.up { color: var(--up); }
.mini.flat { color: var(--muted); }

.hot-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.hot-item + .hot-item { margin-top: 12px; }

.hot-item .mini {
  margin: 0;
  text-align: right;
}

.sym-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

/* The row can wrap because the trade time beside the name is already long
   at phone width. */
.hot-item { flex-wrap: wrap; }

.empty {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.totals-grid .card {
  position: relative;
  padding: 6px 9.2rem 5px 8px;
}

.totals-grid .delta-corner {
  position: absolute;
  top: 6px;
  right: 6px;
  margin: 0;
}

.totals-grid .card-title {
  margin-bottom: 1px;
  line-height: 1.2;
}

.totals-grid .money-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  line-height: 1.2;
}

.totals-grid .money-row .k {
  width: 4.6rem;
}

.totals-grid .money-row .start-num {
  margin-top: 0;
}

.totals-grid .money-row + .money-row {
  margin-top: 0;
}

.totals-grid .money-row-note {
  margin-top: 3px;
}

.totals-grid .money-row-note .k,
.totals-grid .money-row-note .start-num {
  font-size: 11px;
  color: #6b7784;
}

.totals-grid .delta {
  min-width: 0;
  margin-top: 0;
  margin-left: 0;
  padding: 3px 7px;
  border-radius: 8px;
}

.totals-grid .delta-sub { margin-top: 0; }

.totals-grid .mini {
  margin-top: 4px;
}

#books-table {
  width: 100%;
  min-width: 0;
  table-layout: auto;
}

#books-table td.sym,
#books-table th.sym {
  width: 1%;
  padding-left: 2px;
  padding-right: 5px;
}

#books-table th,
#books-table td {
  padding: 2px 2px;
}

#books-table th,
#books-table .trades-col {
  letter-spacing: 0;
  font-size: 10px;
}

#books-table .eq { font-size: 12px; }
#books-table .mini { margin-top: 1px; font-size: 10px; }
#books-table .sym-name { font-size: 13px; }
#books-table .trades-col,
#books-table td.trades {
  width: 14%;
  padding-right: 6px;
}

#books-table .trades {
  white-space: nowrap;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 12px;
}

#books-table .buy-n { color: var(--up); }
#books-table .sell-n { color: var(--down); }
#books-table .trade-dot {
  color: var(--muted);
  padding: 0 2px;
}

#books-table .trades-col {
  line-height: 1.05;
}
#books-table .th-buy,
#books-table .th-sell {
  display: block;
}

th, td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  background: #f6f8fb;
  z-index: 1;
  font: 700 11px var(--sans);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

th.num, td.num { text-align: right; }

td.sym, th.sym {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 1%;
  white-space: nowrap;
  background: white;
  box-shadow: 1px 0 0 var(--line);
  padding-left: 10px;
  padding-right: 8px;
}

th.sym { z-index: 2; background: #f6f8fb; }

.eq { font-size: 13.5px; }

@media (max-width: 800px) {
  .wrap { width: calc(100% - 8px); }
  #books-table th,
  #books-table td { padding: 2px 1px; }
}

tbody tr.is-hot td { background: #fbf8f2; }
tbody tr.is-gap .eq { color: #6a7785; }
tbody tr:hover td { background: #f3f6fa; }
tbody tr:last-child td { border-bottom: 0; }

.about-page {
  width: min(720px, calc(100% - 28px));
}

.about-block {
  margin-top: 14px;
  padding: 16px 16px 14px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  scroll-margin-top: 16px;
}

.about-block h2 {
  margin: 0 0 10px;
  font-family: "Michroma", "DM Sans", system-ui, sans-serif;
  font-weight: 400;
  font-size: 13px;
  letter-spacing: 0.04em;
  line-height: 1.35;
}

.about-block p,
.about-block li {
  margin: 0 0 10px;
  font-size: 15px;
  line-height: 1.55;
}

.about-block ul {
  margin: 0 0 10px;
  padding-left: 1.15rem;
}

.about-block li:last-child,
.about-block p:last-child { margin-bottom: 0; }

.about-block a { color: #1d4f8c; }

.about-note {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f6f8fb;
  color: #3d4a57;
  font-size: 14px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid #314e86;
  outline-offset: 2px;
}
