:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #16191d;
  --muted: #55606c;
  --line: #d5dbe1;
  --accent: #0a55c8;
  --accent-text: #ffffff;
  --good: #146c2e;
  --good-bg: #e3f4e8;
  --bad: #b3261e;
  --bad-bg: #fbe7e5;
  --warn: #8a4b00;
  --warn-bg: #fff1d6;
  --focus: #b45309;
  --bar-up: #2e8b57;
  --bar-down: #c8443b;
  --ch-mid: #0a55c8;
  --ch-band: rgba(10, 85, 200, 0.16);
  --ch-est: #b4510b;
  --ch-estband: rgba(217, 119, 6, 0.2);
  --ch-no: #7e22ce;
  --star: #a8620a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --card: #171b22;
    --text: #e8ecf1;
    --muted: #a2adba;
    --line: #2c333d;
    --accent: #7fadff;
    --accent-text: #0b1220;
    --good: #5ed08c;
    --good-bg: #12301f;
    --bad: #ff8f83;
    --bad-bg: #3a1a17;
    --warn: #f3bf6b;
    --warn-bg: #33270f;
    --focus: #ffb454;
    --bar-up: #4cc38a;
    --bar-down: #ff7d70;
    --ch-mid: #7fadff;
    --ch-band: rgba(127, 173, 255, 0.22);
    --ch-est: #ffb454;
    --ch-estband: rgba(255, 180, 84, 0.22);
    --ch-no: #d8a6ff;
    --star: #f3bf6b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  max-width: 60rem;
  padding: 0 1rem 3rem;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; margin: 1rem 0 .4rem; }
h3 { font-size: 1.02rem; line-height: 1.35; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip {
  position: absolute;
  left: -999px;
  padding: .5rem 1rem;
  background: var(--accent);
  color: var(--accent-text);
}
.skip:focus { left: 1rem; top: .5rem; z-index: 5; }

.top {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  justify-content: space-between;
  align-items: end;
  padding: 1rem 0 .5rem;
}
.mode, .fresh, .foot { color: var(--muted); font-size: .9rem; }

button, input {
  font: inherit;
  color: inherit;
}
button {
  min-height: 44px;
  padding: .4rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  cursor: pointer;
}
button.small { min-height: 44px; padding: .2rem .7rem; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { background: var(--bad); border-color: var(--bad); color: var(--card); font-weight: 600; }
button[disabled] { opacity: .55; cursor: default; }

.tabs {
  display: flex;
  gap: .25rem;
  overflow-x: auto;
  overflow-y: hidden;
  border-bottom: 2px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
}
.tabs a {
  display: block;
  padding: .7rem .9rem;
  min-height: 44px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 4px solid transparent;
  margin-bottom: -2px;
}
.tabs a:focus-visible { outline-offset: -4px; }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }

.banner { margin: .8rem 0 0; padding: .7rem .9rem; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.banner.bad { background: var(--bad-bg); color: var(--bad); }

.summary { font-size: 1.05rem; margin-bottom: .8rem; }
.empty { padding: 1.2rem; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); }
.error-note { color: var(--bad); }

.list { display: grid; gap: .7rem; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .8rem .9rem;
}
.card > * + * { margin-top: .35rem; }
.deal { font-size: .98rem; }
.deal strong { font-weight: 700; }
.meta { color: var(--muted); font-size: .9rem; }
.pos { color: var(--good); font-weight: 600; white-space: nowrap; }
.neg { color: var(--bad); font-weight: 600; white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 0 .55rem;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 600;
  background: var(--line);
}
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

details.why > summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  min-height: 44px;
  display: flex;
  align-items: center;
}
details.why[open] > summary { margin-bottom: .3rem; }
.why-body { border-left: 3px solid var(--line); padding-left: .8rem; }
.why-body p + p { margin-top: .5rem; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: .6rem; margin-bottom: .9rem; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; }
.tile .label { color: var(--muted); font-size: .85rem; }
.tile .value { font-size: 1.3rem; font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .8rem; }
.chips button, .starred-toggle { border-radius: 999px; min-height: 44px; padding: .2rem .85rem; }
.starred-toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.chips button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

.search { display: grid; gap: .25rem; margin-bottom: .7rem; }
.search label { font-weight: 600; font-size: .9rem; }
.search input {
  width: 100%;
  min-height: 44px;
  padding: .4rem .7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.pager { display: flex; gap: .6rem; align-items: center; justify-content: center; margin-top: 1rem; }

.block { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .8rem .9rem; margin-bottom: .9rem; }
.block h3 { margin-bottom: .3rem; }
.block p + p, .block p + table, .block table + p { margin-top: .5rem; }
.block h4 { margin: .7rem 0 .2rem; font-size: .95rem; }
.block details.why { margin-top: .4rem; }
.why-body table + h4, .why-body table + p { margin-top: .6rem; }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .35rem .4rem; text-align: right; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; }
.scroll { overflow-x: auto; }

.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 12px; }
.chart .axis, .chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .zero { stroke: var(--muted); stroke-width: 1.5; }
.chart .up { fill: var(--bar-up); }
.chart .down { fill: var(--bar-down); }
.chart .title { font-size: 12px; font-weight: 600; }
.chart.touch { touch-action: pan-y; }
.chart .mid, .swatch .mid { fill: none; stroke: var(--ch-mid); stroke-width: 2; }
.chart .band, .swatch .band { fill: var(--ch-band); stroke: none; }
.chart .bandline { stroke: var(--ch-mid); stroke-width: 6; stroke-opacity: 0.25; }
.chart .middot { fill: var(--ch-mid); }
.chart .est, .swatch .est { fill: none; stroke: var(--ch-est); stroke-width: 2; stroke-dasharray: 6 3; }
.chart .estband, .swatch .estband { fill: var(--ch-estband); stroke: none; }
.chart .mark.yes, .swatch .mark.yes { fill: var(--good); stroke: var(--card); stroke-width: 1; }
.chart .mark.no, .swatch .mark.no { fill: var(--ch-no); stroke: var(--card); stroke-width: 1; }
.chart .mark.sold { fill-opacity: 0.35; stroke: var(--text); }
.chart .close, .swatch .close { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart .nowline { stroke: var(--muted); stroke-width: 1; }
.chart .cursor { stroke: var(--text); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .eqline { fill: none; stroke: var(--ch-mid); stroke-width: 2.5; }
.chart .eqdot { fill: var(--ch-mid); }
.chart .eqnow { fill: var(--card); stroke: var(--ch-mid); stroke-width: 2.5; }
.chart .diag { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .whisker { stroke: var(--ch-mid); stroke-width: 1.5; }
.chart .calpt { fill: var(--ch-mid); fill-opacity: 0.75; stroke: var(--card); }
.chart .calpt.thin { fill: var(--card); fill-opacity: 1; stroke: var(--ch-mid); stroke-width: 1.5; }
.swatch { flex: none; }
.narrow { max-width: 440px; margin: .5rem auto; }

.legend { list-style: none; margin: .5rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: .3rem 1rem; color: var(--muted); font-size: .88rem; }
.legend li { display: flex; align-items: center; gap: .4rem; }
.readout { min-height: 3em; margin-top: .4rem; font-size: .92rem; }
.back { display: inline-block; min-height: 44px; padding: .6rem 0; color: var(--accent); font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0 1.4rem; }
.actions details { flex: 1 1 8rem; }
.detail-link { display: inline-block; padding: .55rem 0; min-height: 44px; color: var(--accent); font-weight: 600; text-decoration: none; }
.detail-link:hover { text-decoration: underline; }
.block a { color: var(--accent); }

.ladders { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: .6rem; }
.ladder table { table-layout: fixed; }
td.depth { white-space: nowrap; }
td.depth svg { width: 48px; height: 10px; vertical-align: middle; }
td.depth rect { fill: var(--ch-mid); fill-opacity: 0.35; }
tr.best td { font-weight: 700; }
.slider { margin: .4rem 0 .8rem; }
.slider label { display: block; font-weight: 600; }
input[type="range"] { width: 100%; min-height: 44px; accent-color: var(--accent); }
.whatif-out .tiles { margin: .6rem 0; }
.score { padding: .6rem 0; border-bottom: 1px solid var(--line); }
.score:last-child { border-bottom: 0; }
.score p { margin-top: .2rem; }

.svc { display: flex; gap: .6rem; align-items: baseline; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.svc:last-child { border-bottom: 0; }
.svc .mark { font-weight: 800; min-width: 4.5rem; }
.svc.ok .mark { color: var(--good); }
.svc.down .mark { color: var(--bad); }

.confirm { margin-top: .6rem; padding: .7rem; border: 2px solid var(--warn); border-radius: 8px; background: var(--warn-bg); }
.confirm .row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }

.glossary { margin-top: 2rem; padding: 0 .8rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.glossary > summary { color: var(--accent); font-weight: 600; }
.glossary dl { margin: 0 0 .8rem; }
.glossary dt { font-weight: 700; margin-top: .6rem; }
.glossary dd { margin: 0; color: var(--muted); }
.foot { margin-top: 1.5rem; }

/* the watchlist star, filters and alert controls (Gate 7.4) */
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .4rem; }
.card-head h2, .card-head h3 { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.card-head h2 { margin-top: .5rem; }
.card-head .star { margin: -.3rem -.45rem 0 0; }
.star {
  flex: none;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 1.7rem;
  line-height: 1;
  border-radius: 999px;
}
.star[aria-pressed="true"] { color: var(--star); }
.star:hover { background: var(--line); }

.filter-box { margin-bottom: .8rem; padding: 0 .8rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.filter-box > summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; color: var(--accent); font-weight: 600; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .6rem; align-items: end; padding-bottom: .8rem; }
.field { display: grid; gap: .2rem; }
.field label, .alert-row label { font-weight: 600; font-size: .9rem; }
select, .alert-row input {
  width: 100%;
  min-height: 44px;
  padding: .4rem .6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: inherit;
  font: inherit;
}
.alert-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; margin-top: .5rem; }
.alert-row .field { flex: 1 1 10rem; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  z-index: 10;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(36rem, calc(100vw - 1.5rem));
  padding: .7rem 1rem;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
}
.toast.bad { background: var(--bad); color: #fff; }
.deal.short { display: none; }
td a { display: inline-flex; align-items: center; min-width: 44px; min-height: 44px; }
summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; }

/* linked markets (Gate 7.5) */
.sumbar { height: auto; margin: .2rem 0; }
.sumbar .seg.s0 { fill: var(--ch-mid); fill-opacity: .7; }
.sumbar .seg.s1 { fill: var(--ch-mid); fill-opacity: .4; }
.sumbar .seg.fee { fill: var(--warn); }
.sumbar .payline { stroke: var(--text); stroke-width: 2.5; }
.sumbar .paytext { fill: var(--text); font-weight: 600; }

@media (max-width: 40rem) {
  .ladders { grid-template-columns: 1fr; }
}

/* phone: a compact Today (Gate 7.6) */
@media (max-width: 420px) {
  body { padding: 0 .6rem 2rem; }
  .top { padding-top: .6rem; }
  .mode, .fresh, .foot { font-size: .85rem; }
  h2 { font-size: 1.05rem; margin-top: .8rem; }
  .summary { font-size: 1rem; margin-bottom: .6rem; }
  .list { gap: .5rem; }
  .card { padding: .55rem .7rem; }
  .card > * + * { margin-top: .2rem; }
  .card h3 { font-size: .98rem; }
  .deal.long { display: none; }
  .deal.short { display: block; }
  .block { padding: .6rem .7rem; }
  .tile .value { font-size: 1.15rem; }
}

@media (max-width: 30rem) {
  body { padding: 0 .75rem 2rem; }
  h1 { font-size: 1.25rem; }
  .tabs a { padding: .6rem .45rem; font-size: .92rem; }
}

/* first paint: grey placeholder blocks until a panel has its first data */
.skel { display: grid; gap: .6rem; margin-bottom: .9rem; }
.skel span { display: block; height: 4.2rem; border-radius: 10px; background: var(--line); opacity: .55; animation: skel-pulse 1.4s ease-in-out infinite; }
.skel span:nth-child(2) { animation-delay: .15s; }
.skel span:nth-child(3) { animation-delay: .3s; height: 2.6rem; }
[data-panel]:not(.loading) .skel { display: none; }
@keyframes skel-pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) {
  .skel span { animation: none; }
}

/* phone: the tab bar scrolls sideways with a fade on the side that has more, and the header stays short */
@media (max-width: 480px) {
  .tabs { scrollbar-width: none; scroll-padding: 0 1.5rem; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { flex: none; min-height: 44px; }
  .tabs.more-r { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 1.8rem), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 1.8rem), transparent); }
  .tabs.more-l { -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 1.8rem), transparent); mask-image: linear-gradient(to left, #000 calc(100% - 1.8rem), transparent); }
  .tabs.more-l.more-r { -webkit-mask-image: linear-gradient(to right, transparent, #000 1.8rem, #000 calc(100% - 1.8rem), transparent); mask-image: linear-gradient(to right, transparent, #000 1.8rem, #000 calc(100% - 1.8rem), transparent); }
  .top { flex-wrap: nowrap; align-items: center; gap: .5rem; padding: .5rem 0 .3rem; }
  .mode .long { display: none; }
  .fresh { display: flex; flex-direction: column; align-items: flex-end; gap: .1rem; text-align: right; font-size: .8rem; }
  button.small { min-height: 40px; padding: .1rem .6rem; }
}

@media (forced-colors: active) {
  .badge, .tile, .card, .block { border: 1px solid CanvasText; }
}

/* sign-in (login mode) */
.login { max-width: 24rem; margin: 3rem auto; padding: 0 1rem; }
.login form { display: grid; gap: .8rem; }
#whoami { margin: 0; text-align: right; font-size: .85rem; color: var(--muted); }
button.link { background: none; border: 0; min-height: 44px; padding: 0 .3rem; color: var(--accent); text-decoration: underline; }
body.viewer .star, body.viewer .alert-row, body.viewer #system-kill { display: none; }

.account { max-width: 36rem; margin: 1rem auto; padding: 0 1rem; }
.account form { display: grid; gap: .6rem; }
.account select, .account input { width: 100%; min-height: 44px; box-sizing: border-box; }
ul.plain { list-style: none; margin: 0 0 .6rem; padding: 0; display: grid; gap: .4rem; overflow-wrap: anywhere; }
#account-note:empty { display: none; }

.hint { font-weight: normal; color: var(--muted, inherit); opacity: .75; }
