:root {
  --bg: #fafaf8;
  --text: #1d1d1b;
  --meta: #5f5f5a;
  --line: #e2e1dc;
  --card: #fff;
  --header-bg: #f8f5f0;
  --focus: #8a4b00;
  --link: #1f5fbf;
  --r1: #c0392b;
  --r2: #e67e5a;
  --r3: #e9d99a;
  --r4: #8fcf8f;
  --r5: #2e9e52;
  --r0: #d9d8d2;
  --fail-bg: #f1f0ec;
  --fail-text: #5f5e59;
  --ok-bg: #e5f4ea;
  --unk-bg: #fbf3dc;
  --bad-bg: #f6e5e2;
  --chip: #f4f3ef;
  --font:
    -apple-system, blinkmacsystemfont, "Segoe UI", roboto, "Helvetica Neue",
    arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --text: #e6e6e2;
    --meta: #a6a6a0;
    --line: #34342f;
    --card: #1b1b19;
    --header-bg: #1e1e1e;
    --focus: #ffeb3b;
    --link: #8ab4f8;
    --r0: #4a4a45;
    --fail-bg: #262624;
    --fail-text: #8f8f88;
    --ok-bg: #1f3a28;
    --unk-bg: #3a3320;
    --bad-bg: #3d2421;
    --chip: #262624;
  }
}

* {
  box-sizing: border-box;
}

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

button,
select,
input {
  font: inherit;
  color: inherit;
}

a {
  color: var(--link);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: 8px;
  transform: translateY(-150%);
  z-index: 80;
  padding: 8px 12px;
  background: var(--header-bg);
  color: var(--text);
}

.skip-link:focus {
  transform: none;
}

.tool-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
}

/* Same bar as the other tools (AGENTS.md "Tool Header Bar"). */
.tool-nav {
  width: 100%;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.tool-nav__link {
  text-decoration: none;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.tool-nav__link:hover {
  text-decoration: underline;
}

main {
  padding: 12px 20px 24px;
}

.intro h1 {
  margin: 0;
  font-size: 1.6rem;
}

.intro p {
  margin: 6px 0 0;
  color: var(--meta);
  max-width: 80ch;
}

.intro .attribution {
  font-size: 13px;
}

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

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
}

.panel-h {
  font-size: 14px;
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--meta);
  font-weight: 700;
}

h3 {
  font-size: 15px;
  margin: 16px 0 6px;
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 460px;
  gap: 16px;
  padding-top: 12px;
  align-items: start;
}

.needs,
.detail {
  position: sticky;
  top: 64px;
  max-height: calc(100vh - 76px);
  overflow: auto;
}

.needs summary {
  list-style: none;
  cursor: default;
}

.needs summary::-webkit-details-marker {
  display: none;
}

#needs-summary {
  display: none;
}

.need {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 14px;
}

.need.relrow {
  flex-wrap: wrap;
  border-bottom: 0;
}

.need.relrow select {
  width: 100%;
}

.seg {
  display: inline-flex;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.seg button {
  border: 0;
  background: var(--card);
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
  min-width: 38px;
}

.seg button[aria-pressed="true"] {
  background: var(--text);
  color: var(--bg);
}

.seg button[data-v="nice"][aria-pressed="true"] {
  background: #3f6299;
  color: #fff;
}

.btn {
  border: 1px solid var(--text);
  background: var(--card);
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 13px;
}

.btn.primary {
  background: var(--text);
  color: var(--bg);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.scoreset {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.scoreset summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}

.slider {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 8px;
  font-size: 13px;
  margin: 4px 0;
}

.slider input {
  grid-column: 1 / -1;
  width: 100%;
}

.slider output {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.check {
  display: block;
  font-size: 13px;
  margin: 8px 0;
}

.formula {
  font-size: 12px;
  color: var(--meta);
  background: var(--chip);
  border-radius: 6px;
  padding: 6px 8px;
  margin: 10px 0 0;
}

/* grid */
.summary {
  font-size: 15px;
  margin: 0 0 10px;
}

.mygrid {
  display: grid;
  grid-template-columns: 128px repeat(7, minmax(46px, 1fr));
  gap: 4px;
}

.yh {
  font-size: 12px;
  color: var(--meta);
  text-align: center;
  align-self: end;
}

.mh {
  font-weight: 600;
  font-size: 13px;
  align-self: center;
  line-height: 1.15;
}

.mh small {
  display: block;
  font-weight: 400;
  color: var(--meta);
  font-size: 11px;
}

.cell {
  position: relative;
  border: 2px solid transparent;
  border-radius: 8px;
  min-height: 68px;
  padding: 4px 2px;
  text-align: center;
  cursor: pointer;
  background: var(--r0);
  color: #1d1d1b;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1px;
  min-width: 0;
}

.cell .s {
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.cell .cr {
  font-size: 11px;
}

.cell .t {
  font-size: 10.5px;
  line-height: 1.1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell.r1,
.sw.r1 {
  background-color: var(--r1);
  color: #fff;
}

.cell.r2,
.sw.r2 {
  background-color: var(--r2);
}

.cell.r3,
.sw.r3 {
  background-color: var(--r3);
}

.cell.r4,
.sw.r4 {
  background-color: var(--r4);
}

.cell.r5,
.sw.r5 {
  background-color: var(--r5);
}

.sw.r0 {
  background-color: var(--r0);
}

.cell.unk,
.sw.unk {
  background-image: repeating-linear-gradient(
    135deg,
    rgb(255 255 255 / 45%) 0 4px,
    transparent 4px 11px
  );
}

.cell.fail,
.sw.fail {
  background: var(--fail-bg);
  color: var(--fail-text);
  border-color: var(--line);
}

.cell.fail .s {
  font-size: 15px;
  font-weight: 500;
}

.cell.na {
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--meta);
  cursor: default;
  font-size: 11px;
}

.cell.sel {
  border-color: var(--text);
  box-shadow: inset 0 0 0 2px #fff;
}

.cell.incmp {
  outline: 2px dashed var(--link);
  outline-offset: 1px;
}

.cell .q {
  position: absolute;
  top: 1px;
  left: 5px;
  font-size: 11px;
  font-weight: 700;
}

/* no CR reliability: scored neutral, so make the gap obvious */
.cell .q.big {
  top: -7px;
  left: -6px;
  min-width: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: #1d1d1b;
  color: #fff;
  font-size: 14px;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 1.5px var(--card);
}

.cell.norel {
  border-style: dashed;
  border-color: #1d1d1b;
}

.unrated {
  color: #7a5c00;
  font-weight: 600;
}

.cell .pen {
  position: absolute;
  top: 1px;
  right: 5px;
  font-size: 11px;
  font-weight: 700;
}

.groupsep {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--meta);
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12px;
  color: var(--meta);
  margin: 12px 0 6px;
  align-items: center;
}

.sw {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  vertical-align: -2px;
  margin-right: 3px;
  border: 1px solid transparent;
}

/* detail */
.detail .close {
  display: none;
}

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

.dtitle h2 {
  font-size: 20px;
  margin: 0;
}

.dbtns {
  display: flex;
  gap: 6px;
  flex: none;
}

.verdict {
  margin: 8px 0;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
}

.verdict.ok {
  background: var(--ok-bg);
}

.verdict.unk {
  background: var(--unk-bg);
}

.verdict.fail {
  background: var(--bad-bg);
}

.yearstrip {
  display: flex;
  gap: 3px;
  margin: 4px 0 10px;
}

.yearstrip .cell {
  min-height: 40px;
  flex: 1;
}

.yearstrip .cell .s {
  font-size: 14px;
}

.score-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.score-head .big {
  font-size: 30px;
  font-weight: 700;
}

.bd summary,
details summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}

details {
  margin-top: 8px;
}

table {
  border-collapse: collapse;
  width: 100%;
}

td,
th {
  padding: 4px 5px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  vertical-align: top;
}

thead th {
  font-weight: 600;
  color: var(--meta);
  font-size: 11px;
  text-transform: uppercase;
}

tbody th,
tfoot th {
  font-weight: 500;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.breakdown tfoot .total th,
.breakdown tfoot .total td {
  font-weight: 700;
  font-size: 15px;
}

.q-inline {
  display: inline-block;
  min-width: 15px;
  padding: 0 4px;
  border-radius: 8px;
  background: #b08a1e;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.scrollx {
  overflow-x: auto;
}

.ladder td,
.ladder th {
  font-size: 12px;
  padding: 3px;
}

.ladder .price {
  white-space: nowrap;
}

.ladder tr.q td,
.ladder tr.q th {
  background: var(--ok-bg);
}

.ladder tr.first th {
  font-weight: 700;
}

.tag {
  display: inline-block;
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 9px;
  background: var(--chip);
}

.tag.ok {
  background: #2e9e52;
  color: #fff;
}

button.v {
  border: 0;
  border-bottom: 1px solid #a9b8d6;
  background: none;
  padding: 0 1px;
  cursor: pointer;
  text-align: left;
}

button.v:hover {
  background: rgb(31 95 191 / 10%);
}

button.v.medium {
  border-bottom: 1px dotted #8a9a9a;
}

button.v.low {
  border-bottom: 1px dashed #d08a3a;
}

button.v.low::after {
  content: "?";
  font-size: 10px;
  color: #d08a3a;
  vertical-align: super;
}

button.v.null {
  color: var(--meta);
  font-style: italic;
  border-bottom: 1px dotted var(--line);
}

.st-std {
  color: #1d7a3e;
  font-weight: 700;
}

.st-opt {
  color: #3b6fb6;
  font-weight: 600;
}

.st-no {
  color: #b5463a;
}

.st-unk {
  color: #b08a1e;
  font-weight: 700;
}

.spots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 3px;
}

.spot {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 5px;
  color: #1d1d1b;
}

.spot.s1 {
  background: #f3c4bd;
}

.spot.s2 {
  background: #f7dccd;
}

.spot.s3 {
  background: #efefea;
}

.spot.s4 {
  background: #d5eed9;
}

.spot.s5 {
  background: #b6e2c1;
}

.kv {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 3px 8px;
  font-size: 13px;
}

.kv .k {
  color: var(--meta);
}

.recalls {
  font-size: 12px;
  padding-left: 18px;
}

.tree {
  font-size: 12px;
}

.tree .k {
  color: var(--meta);
}

.tree-n .tree-n {
  padding-left: 10px;
}

.tree ul {
  margin: 0;
  padding-left: 14px;
}

/* compare */
.tray {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 20px;
  background: var(--card);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgb(0 0 0 / 8%);
}

/* --tray-h is the tray's measured height (set by app.js) */
body.has-tray main {
  padding-bottom: calc(var(--tray-h, 88px) + 16px);
}

body.has-tray .needs,
body.has-tray .detail {
  max-height: calc(100vh - var(--panel-top, 76px) - 12px - var(--tray-h, 88px));
}

.tray-msg {
  flex-basis: 100%;
  color: #8a2a1b;
  font-size: 13px;
}

.tray-msg:empty {
  display: none;
}

.warn {
  margin: 0 0 8px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--bad-bg);
  font-size: 14px;
}

.flag {
  display: inline-block;
  min-width: 14px;
  border-radius: 7px;
  background: #b08a1e;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

/* Low-confidence price, shown as text so it reads without tapping. */
.conf-tag {
  padding: 0 4px;
  border: 1px solid currentcolor;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.ladder td.conflict {
  background: var(--unk-bg);
}

.ladder .cx {
  margin-left: 2px;
  color: #8a2a1b;
  font-weight: 700;
}

.q-inline.big {
  min-width: 18px;
  background: #1d1d1b;
  font-size: 13px;
}

.cmp tr.sub th {
  padding-left: 18px;
  font-weight: 400;
}

.intro .lead {
  color: var(--text);
}

.intro-more summary {
  cursor: pointer;
  color: var(--link);
  font-size: 14px;
  margin-top: 4px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 3px 4px 3px 10px;
  font-size: 13px;
  background: var(--chip);
}

.chip button {
  border: 0;
  background: none;
  cursor: pointer;
}

#compare {
  margin-top: 16px;
  scroll-margin-top: 64px;
}

.cmp th[scope="col"] {
  font-size: 14px;
  color: var(--text);
  text-transform: none;
}

.cmp tbody th {
  width: 210px;
}

.cmp td.best {
  background: var(--ok-bg);
  font-weight: 600;
}

.cmp tr.same {
  display: none;
}

.cmp.showall tr.same {
  display: table-row;
  opacity: 0.6;
}

.cmp tr.sec th {
  background: var(--chip);
  font-size: 11px;
  text-transform: uppercase;
  color: var(--meta);
  padding-top: 8px;
}

/* provenance */
dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  max-width: 540px;
  width: calc(100% - 24px);
  padding: 16px;
  background: var(--card);
  color: var(--text);
}

dialog::backdrop {
  background: rgb(0 0 0 / 30%);
}

.dialog-close {
  float: right;
}

.prov-label {
  color: var(--meta);
  font-size: 13px;
  margin: 0;
}

.prov-val {
  font-size: 18px;
  font-weight: 600;
  margin: 4px 0 8px;
  overflow-wrap: anywhere;
}

.prov .url {
  overflow-wrap: anywhere;
}

.prov pre {
  font-size: 11px;
  white-space: pre-wrap;
}

.path {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  background: var(--chip);
  padding: 4px 6px;
  border-radius: 5px;
  overflow-wrap: anywhere;
}

.conf {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 600;
  color: #1d1d1b;
  background: #eee;
}

.conf.high {
  background: #d5eed9;
}

.conf.medium {
  background: #e5ebf6;
}

.conf.low {
  background: #f7e1c6;
}

#methodology {
  max-width: 52rem;
  margin-top: 28px;
  border-top: 1px solid var(--line);
}

#methodology li {
  margin: 4px 0;
  font-size: 14px;
}

/* mid widths: grid with the side panel; needs move above the grid */
@media (min-width: 901px) and (max-width: 1180px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 380px;
  }

  .needs {
    position: static;
    max-height: none;
    grid-column: 1;
  }

  .needlist {
    columns: 2;
    column-gap: 20px;
  }

  .needlist .need {
    break-inside: avoid;
  }

  .gridwrap {
    grid-column: 1;
  }

  .detail {
    grid-column: 2;
    grid-row: 1 / span 2;
  }
}

/* below the three-column layout: needs collapse to a summary chip */
@media (max-width: 1180px) {
  .needs summary {
    cursor: pointer;
  }

  .needs summary .panel-h {
    margin: 0;
  }

  .needs summary .panel-h::after {
    content: " ▾ change";
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
  }

  .needs details[open] summary .panel-h::after {
    content: " ▴ done";
  }

  #needs-summary {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .needs details[open] #needs-summary {
    display: none;
  }
}

/* tablet and phone: details become a bottom sheet */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 250px minmax(0, 1fr);
  }

  .detail {
    position: fixed;
    inset: auto 0 0;
    top: auto;
    z-index: 60;
    max-height: 85vh;
    border-radius: 14px 14px 0 0;
    padding-bottom: 24px;
    box-shadow: 0 -6px 30px rgb(0 0 0 / 25%);
    display: none;
  }

  .detail.open {
    display: block;
  }

  /* sit the sheet above the compare tray instead of under it */
  body.has-tray .detail {
    bottom: var(--tray-h, 88px);
    max-height: calc(85vh - var(--tray-h, 88px));
  }

  .detail .close {
    display: inline-block;
  }

  .detail::before {
    content: "";
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--line);
    margin: -4px auto 8px;
  }
}

/* phone */
@media (max-width: 720px) {
  main {
    padding: 10px 10px 24px;
  }

  .intro h1 {
    font-size: 1.3rem;
  }

  .intro p {
    font-size: 13px;
  }

  .intro .attribution {
    font-size: 11.5px;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .needs {
    position: sticky;
    top: 52px;
    z-index: 30;
    max-height: 75vh;
  }

  .needs .card {
    padding: 8px 10px;
  }

  .gridwrap {
    padding: 10px 8px;
  }

  .mygrid {
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 3px;
  }

  .mh {
    grid-column: 1 / -1;
    margin-top: 6px;
  }

  .mh small {
    display: inline;
    margin-left: 6px;
  }

  .mygrid .yh:first-child {
    display: none;
  }

  .cell {
    min-height: 54px;
    border-radius: 6px;
  }

  .cell .s {
    font-size: 16px;
  }

  .cell .cr {
    font-size: 10px;
  }

  .cell .t {
    font-size: 9.5px;
  }

  /* corner badge, so it doesn't sit on the score */
  .cell .q.big {
    top: -6px;
    left: -5px;
    font-size: 11px;
    line-height: 14px;
    min-width: 14px;
    padding: 0 2px;
    box-shadow: 0 0 0 1.5px var(--card);
  }

  .kv {
    grid-template-columns: 105px 1fr;
  }

  .tray {
    padding: 8px 10px;
  }

  .cmp tbody th {
    width: 120px;
  }
}

.ladder thead th {
  font-size: 11px;
  text-transform: none;
  padding: 3px 2px;
}

.ladder .f {
  text-align: center;
  padding: 3px 2px;
}

@media (prefers-color-scheme: dark) {
  .unrated {
    color: #e0b84a;
  }

  .tray-msg,
  .ladder .cx {
    color: #f0a08f;
  }

  .cell .q.big,
  .q-inline.big {
    background: #e6e6e2;
    color: #121212;
  }
}
