/* Rakugrid — raku.online/grid.
   One rule everything here follows: color carries exactly one meaning, the
   per-test status. Six statuses, six colors, used identically in the ribbon,
   the chips, the bars, the matrices and the drawer — learn them once on the
   home-page legend and every other page reads itself. */

.grid-page .content { --maxw: 74rem; }

/* The status palette. Strong values draw the ribbon, dots and bars; the -soft
   values tint matrix cells and table rows so text stays readable on them. */
:root {
  --st-a: #77b98a;   /* agree — calm, the ground the streaks sit on */
  --st-f: #4d94d8;   /* fixed — an older snapshot differed, the newest agrees */
  --st-d: #e2611c;   /* differs */
  --st-c: #a11a12;   /* crash */
  --st-r: #9a68e0;   /* ruled */
  --st-n: #c9ccd4;   /* no data */
  --st-a-soft: rgba(119, 185, 138, .16);
  --st-f-soft: rgba(77, 148, 216, .16);
  --st-d-soft: rgba(226, 97, 28, .17);
  --st-c-soft: rgba(161, 26, 18, .20);
  --st-r-soft: rgba(154, 104, 224, .16);
  --st-n-soft: rgba(140, 145, 155, .14);
}
html[data-theme-active="dark"] {
  --st-a: #3e7a52;
  --st-f: #5b9fdd;
  --st-d: #ef7734;
  --st-c: #e0554a;
  --st-r: #a983e4;
  --st-n: #4c5058;
  --st-a-soft: rgba(102, 178, 126, .14);
  --st-f-soft: rgba(91, 159, 221, .16);
  --st-d-soft: rgba(239, 119, 52, .18);
  --st-c-soft: rgba(224, 85, 74, .22);
  --st-r-soft: rgba(169, 131, 228, .17);
  --st-n-soft: rgba(140, 145, 155, .12);
}

/* ---- the grid-local nav ------------------------------------------------ */

.grid-nav {
  display: flex;
  gap: 1.1rem;
  font-size: .84rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 0 0 1.6rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: .55rem;
}
.grid-nav a { color: var(--muted); }
.grid-nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }

.grid-page h1 { margin: 0 0 .3rem; font-size: 2rem; letter-spacing: -0.02em; }
.grid-page h1.atom-title { font-size: 1.5rem; word-break: break-word; }
.grid-page .tagline { color: var(--muted); font-size: 1.06rem; margin: 0 0 1.2rem; }
.grid-page .crumb a { color: var(--muted); }
.grid-section { margin-top: 2.6rem; }
.grid-section h2 { font-size: 1.35rem; margin: 0 0 .6rem; }
.note-line { color: var(--muted); font-size: .92rem; }

/* ---- stat tiles -------------------------------------------------------- */

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: .7rem;
  margin: 1.6rem 0 .4rem;
}
.stat-tile {
  border: 1px solid var(--border);
  border-radius: .55rem;
  background: var(--card-bg);
  padding: .75rem .9rem .7rem;
}
.stat-tile b { display: block; font-size: 1.45rem; letter-spacing: -0.02em; }
.stat-tile span { display: block; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: .1rem; }
.stat-tile small { display: block; font-size: .78rem; color: var(--muted); margin-top: .3rem; line-height: 1.35; }

/* ---- status chips and bars --------------------------------------------- */

.st-chips { display: flex; flex-wrap: wrap; gap: .45rem; margin: .6rem 0 1rem; }
.st-chip {
  display: inline-flex;
  align-items: center;
  gap: .38rem;
  font-size: .82rem;
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: .12rem .6rem .12rem .45rem;
  background: var(--card-bg);
  color: var(--fg);
  white-space: nowrap;
}
.st-chip i { width: .62rem; height: .62rem; border-radius: .18rem; display: inline-block; }
.st-chip span { color: var(--muted); }
.st-chip.st-a i { background: var(--st-a); }
.st-chip.st-f i { background: var(--st-f); }
.st-chip.st-d i { background: var(--st-d); }
.st-chip.st-c i { background: var(--st-c); }
.st-chip.st-r i { background: var(--st-r); }
.st-chip.st-n i { background: var(--st-n); }

.st-bar {
  display: flex;
  height: .55rem;
  min-width: 8rem;
  border-radius: .3rem;
  overflow: hidden;
  background: var(--code-bg);
}
.st-bar i { display: block; height: 100%; }
.st-bar .st-a { background: var(--st-a); }
.st-bar .st-f { background: var(--st-f); }
.st-bar .st-d { background: var(--st-d); }
.st-bar .st-c { background: var(--st-c); }
.st-bar .st-r { background: var(--st-r); }
.st-bar .st-n { background: var(--st-n); }

/* ---- the ribbon (home) ------------------------------------------------- */

.ribbon-legend { display: flex; flex-wrap: wrap; gap: .45rem; margin: .9rem 0 .5rem; }
.ribbon-legend .st-chip { cursor: pointer; }
.ribbon-legend .st-chip[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.fam-block { margin: 1.5rem 0 0; }
.fam-block h3 { margin: 0 0 .4rem; font-size: 1.02rem; display: flex; align-items: baseline; gap: .7rem; }
.fam-block .fam-n { font-size: .8rem; color: var(--muted); font-weight: 400; }
canvas.ribbon {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: .35rem;
  cursor: crosshair;
  background: var(--code-bg);
}

.ribbon-tipbox {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: .45rem;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .18);
  padding: .45rem .65rem;
  font-size: .82rem;
  max-width: 22rem;
}
.ribbon-tipbox b { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: .82rem; word-break: break-word; }
.ribbon-tipbox .tip-counts { color: var(--muted); margin-top: .15rem; }

/* ---- atom quick-find (home) -------------------------------------------- */

.fam-search { position: relative; margin: 1rem 0 0; }
.fam-search input {
  width: 100%;
  font: inherit;
  padding: .5rem .8rem;
  border: 1px solid var(--border);
  border-radius: .5rem;
  background: var(--card-bg);
  color: var(--fg);
}
.fam-search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.fam-search ul {
  position: absolute;
  z-index: 30;
  left: 0; right: 0;
  margin: .25rem 0 0;
  padding: .3rem;
  list-style: none;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: .5rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
  max-height: 20rem;
  overflow: auto;
}
.fam-search li a {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: .32rem .55rem;
  border-radius: .35rem;
  color: var(--fg);
  text-decoration: none;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: .86rem;
}
.fam-search li a:hover, .fam-search li a.sel { background: var(--code-bg); }
.fam-search li .hit-n { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.fam-search li .hit-n em { font-style: normal; color: var(--st-d); }

/* ---- atom pages -------------------------------------------------------- */

.atom-origin { color: var(--muted); font-size: .92rem; margin: .2rem 0 .6rem; }
.atom-meta { margin: .4rem 0 .8rem; }
.atom-meta div { display: flex; gap: .8rem; margin: .12rem 0; }
.atom-meta dt { min-width: 6.5rem; color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; padding-top: .12rem; }
.atom-meta dd { margin: 0; font-size: .9rem; word-break: break-word; }
.atom-count { font-size: 1.05rem; margin: .8rem 0 .2rem; font-weight: 600; }
.atom-steps { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2.2rem; font-size: .9rem; }
.atom-steps a { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; }
.grid-loading { color: var(--muted); }

/* the matrix */
.matrix-wrap {
  overflow: auto;
  max-height: 78vh;
  border: 1px solid var(--border);
  border-radius: .5rem;
  margin: 1rem 0;
}
table.matrix { border-collapse: separate; border-spacing: 0; font-size: .78rem; }
table.matrix th, table.matrix td { padding: .18rem .42rem; white-space: nowrap; }
table.matrix thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-weight: 500;
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}
table.matrix tbody th {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-weight: 500;
  text-align: left;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.matrix thead th:first-child { left: 0; z-index: 4; }
table.matrix td {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  cursor: pointer;
  max-width: 8.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 2px;
}
table.matrix td:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
table.matrix td.st-a { background: var(--st-a-soft); }
table.matrix td.st-f { background: var(--st-f-soft); }
table.matrix td.st-d { background: var(--st-d-soft); }
table.matrix td.st-c { background: var(--st-c-soft); color: var(--st-c); font-weight: 600; }
table.matrix td.st-r { background: var(--st-r-soft); }
table.matrix td.st-n { color: var(--muted); }
table.matrix td.hl { outline: 2px solid var(--accent); outline-offset: -2px; }

.matrix-legend { font-size: .82rem; color: var(--muted); margin: .4rem 0 1rem; }
.matrix-legend code { font-size: .8rem; }

/* the record list */
.rec-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 1rem 0 .6rem; }
.rec-toolbar input {
  flex: 1 1 14rem;
  font: inherit;
  font-size: .92rem;
  padding: .42rem .7rem;
  border: 1px solid var(--border);
  border-radius: .5rem;
  background: var(--card-bg);
  color: var(--fg);
}
.rec-toolbar .st-chip { cursor: pointer; }
.rec-toolbar .st-chip[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.rec-wrap { border: 1px solid var(--border); border-radius: .5rem; overflow: auto; max-height: 78vh; }
table.rec-list { border-collapse: collapse; width: 100%; font-size: .84rem; }
table.rec-list th {
  position: sticky; top: 0; z-index: 2;
  background: var(--sidebar);
  text-align: left;
  padding: .34rem .6rem;
  border-bottom: 1px solid var(--border);
  font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
}
table.rec-list td { padding: .3rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.rec-list tr:last-child td { border-bottom: 0; }
table.rec-list tbody tr { cursor: pointer; }
table.rec-list tbody tr:hover td { background: var(--code-bg); }
table.rec-list tbody tr.hl td { background: var(--st-f-soft); }
table.rec-list .mono, .mono { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; }
table.rec-list td.rc-code { max-width: 34rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.rec-list td.rc-obs { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-dot { display: inline-block; width: .62rem; height: .62rem; border-radius: .18rem; vertical-align: -1px; }
.st-dot.st-a { background: var(--st-a); }
.st-dot.st-f { background: var(--st-f); }
.st-dot.st-d { background: var(--st-d); }
.st-dot.st-c { background: var(--st-c); }
.st-dot.st-r { background: var(--st-r); }
.st-dot.st-n { background: var(--st-n); }
.rec-more { padding: .6rem; text-align: center; color: var(--muted); font-size: .84rem; }

/* ---- the drawer -------------------------------------------------------- */

.drawer-back {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .35);
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 51;
  width: min(34rem, 94vw);
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 40px rgba(0, 0, 0, .25);
  overflow-y: auto;
  padding: 1.1rem 1.3rem 2rem;
}
.drawer h2 { margin: 0 0 .2rem; font-size: 1.02rem; word-break: break-word; }
.drawer .d-close {
  position: absolute; top: .7rem; right: .8rem;
  font: inherit; font-size: 1.1rem; line-height: 1;
  background: none; border: 1px solid var(--border); border-radius: .4rem;
  color: var(--muted); padding: .25rem .55rem; cursor: pointer;
}
.drawer .d-close:hover { color: var(--fg); }
.drawer .d-status { margin: .3rem 0 .9rem; }
.drawer pre {
  background: var(--code-bg);
  padding: .7rem .8rem;
  border-radius: .5rem;
  overflow-x: auto;
  font-size: .86rem;
  margin: .4rem 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.drawer .d-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0 1rem; }
.drawer .d-actions button, .drawer .d-actions a {
  font: inherit; font-size: .84rem;
  border: 1px solid var(--border); border-radius: .45rem;
  background: var(--card-bg); color: var(--fg);
  padding: .3rem .7rem; cursor: pointer; text-decoration: none;
}
.drawer .d-actions button:hover, .drawer .d-actions a:hover { border-color: var(--accent); }
.drawer .d-actions .primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.drawer h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.2rem 0 .35rem; }
.drawer .d-expect { font-size: .92rem; }
table.d-engines { border-collapse: collapse; width: 100%; font-size: .84rem; }
table.d-engines td { padding: .3rem .45rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.d-engines tr:last-child td { border-bottom: 0; }
table.d-engines .d-eng { color: var(--muted); font-size: .78rem; white-space: nowrap; }
table.d-engines .d-obs { word-break: break-word; }
table.d-engines .d-tag {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .05em;
  border-radius: .3rem; padding: .05rem .35rem; white-space: nowrap;
  background: var(--code-bg); color: var(--muted);
}
table.d-engines tr.differ .d-obs { color: var(--st-d); }
table.d-engines tr.differ.crash .d-obs { color: var(--st-c); }
.d-ruling {
  border: 1px solid var(--st-r);
  border-radius: .5rem;
  padding: .6rem .8rem;
  margin: .4rem 0;
  background: var(--st-r-soft);
  font-size: .9rem;
}
.verdict-tag {
  display: inline-block;
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  background: var(--st-r); color: #fff;
  border-radius: .3rem; padding: .08rem .4rem;
  margin-right: .3rem;
}
.d-extra { font-size: .86rem; }
.d-extra div { display: flex; gap: .7rem; margin: .15rem 0; }
.d-extra dt { min-width: 5.5rem; color: var(--muted); }
.d-extra dd { margin: 0; word-break: break-word; }
.d-isolate { font-size: .8rem; }

/* ---- family pages ------------------------------------------------------ */

table.atom-table { border-collapse: collapse; width: 100%; font-size: .88rem; }
table.atom-table th {
  text-align: left; padding: .4rem .6rem;
  border-bottom: 2px solid var(--border);
  font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  white-space: nowrap;
}
table.atom-table th[data-sort] { cursor: pointer; }
table.atom-table th[data-sort]:hover { color: var(--fg); }
table.atom-table th .arrow { font-size: .7rem; }
table.atom-table td { padding: .4rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.atom-table td[data-n] { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.atom-table .atom-label { color: var(--muted); font-size: .78rem; }
table.atom-table .bar-cell { width: 22%; min-width: 9rem; vertical-align: middle; }

/* ---- clusters (divergences / rulings / crashes) ------------------------ */

details.cluster {
  border: 1px solid var(--border);
  border-radius: .5rem;
  margin: .45rem 0;
  background: var(--card-bg);
}
details.cluster summary {
  display: flex;
  align-items: baseline;
  gap: .7rem;
  padding: .5rem .8rem;
  cursor: pointer;
  list-style: none;
}
details.cluster summary::-webkit-details-marker { display: none; }
details.cluster .cluster-n {
  min-width: 3.4rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  flex: 0 0 auto;
}
details.cluster .cluster-shape { font-size: .88rem; min-width: 0; overflow-wrap: anywhere; }
details.cluster .cluster-shape .vs { color: var(--muted); font-size: .78rem; padding: 0 .15rem; }
details.cluster code.ref { color: inherit; }
details.cluster code.got { color: var(--st-d); }
details.cluster.crash .cluster-shape code:first-child { color: var(--st-c); }
details.cluster[open] { border-color: var(--accent); }
.cluster-detail { padding: 0 .8rem; font-size: .88rem; color: var(--muted); overflow-wrap: anywhere; }
.ruled-line { padding: 0 .8rem; font-size: .8rem; color: var(--muted); }
.member-list { margin: .3rem 0 .7rem; padding: 0 .8rem 0 2rem; font-size: .84rem; }
.member-list li { margin: .18rem 0; overflow-wrap: anywhere; }
.member-list li.more { color: var(--muted); list-style: none; }

/* ---- the ruling example card (home) ------------------------------------ */

.ruling-card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--st-r);
  border-radius: .5rem;
  padding: .8rem 1rem;
  margin: 1rem 0;
  background: var(--card-bg);
}
.ruling-card .rc-code { font-size: 1rem; margin: 0 0 .5rem; }
.ruling-card table.rc-table { border-collapse: collapse; font-size: .9rem; }
.ruling-card table.rc-table td { padding: .2rem .8rem .2rem 0; vertical-align: top; }
.ruling-card table.rc-table td:first-child { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; padding-top: .32rem; }
.ruling-card .rc-link { margin: .5rem 0 0; font-size: .9rem; }

/* ---- history charts ---------------------------------------------------- */

.hist-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 1rem; margin: 1rem 0; }
.hist-chart { margin: 0; border: 1px solid var(--border); border-radius: .5rem; padding: .6rem; background: var(--card-bg); }
.hist-chart svg { width: 100%; height: auto; display: block; cursor: crosshair; }
.hist-line { fill: none; stroke: var(--st-f); stroke-width: 2; }
.hist-line.fail { stroke: var(--st-d); }
.hist-chart circle { fill: var(--st-f); }
.hist-chart circle.fail { fill: var(--st-d); }
.hist-chart .grid { stroke: var(--border); stroke-width: 1; }
.hist-chart .axis { stroke: var(--muted); stroke-width: 1; opacity: .5; }
.hist-chart text { fill: var(--muted); font-size: 10px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.hist-chart .ylab { text-anchor: end; }
.hist-chart .xlab { text-anchor: middle; }
.hist-chart figcaption { font-size: .82rem; color: var(--muted); margin-top: .3rem; }
.hist-chart .hist-last { float: right; font-variant-numeric: tabular-nums; }
.hist-data summary { cursor: pointer; font-size: .88rem; color: var(--muted); }
.hist-data table { font-size: .84rem; border-collapse: collapse; }
.hist-data td, .hist-data th { padding: .25rem .6rem; border-bottom: 1px solid var(--border); text-align: left; }

/* ---- shared bits ------------------------------------------------------- */

.grid-page .tablewrap { overflow-x: auto; }
.grid-page pre.native-code {
  background: var(--code-bg);
  padding: .8rem 1rem;
  border-radius: .5rem;
  overflow-x: auto;
  font-size: .86rem;
}
.grid-page footer {
  margin-top: 3.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .84rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

@media (max-width: 640px) {
  .grid-nav { flex-wrap: wrap; gap: .6rem .9rem; }
  .stat-tile b { font-size: 1.2rem; }
  .drawer { width: 100vw; }
  table.atom-table .bar-cell { display: none; }
}
