/* The in-page sheet (assets/sheet.js): a spreadsheet window, not a table on
   a page. Everything lives under .xs and is drawn from the page's tokens; the
   fallbacks only matter when the component is shown on its own. No keyframes
   anywhere: the one transition is the hover reveal of the attempt bars. */

.xs {
  --xs-paper:      var(--paper,      #f7f4ee);
  --xs-paper-2:    var(--paper-2,    #fffdf9);
  --xs-paper-3:    var(--paper-3,    #efebe3);
  --xs-ink:        var(--ink,        #17150f);
  --xs-ink-2:      var(--ink-2,      #5a564d);
  --xs-ink-3:      var(--ink-3,      #8f8a7e);
  --xs-line:       var(--line,       #e2ddd2);
  --xs-line-2:     var(--line-2,     #c9c3b5);
  --xs-accent:     var(--accent,     #c8371d);
  --xs-accent-ink: var(--accent-ink, #fff8f2);
  --xs-band-a:     var(--band-a,     #f4d9d1);
  --xs-band-b:     var(--band-b,     #f1e6c8);
  --xs-band-c:     var(--band-c,     #e8e4da);
  --xs-chrome:     var(--chrome,     #17150f);
  --xs-chrome-ink: var(--chrome-ink, #f1ece2);
  --xs-sans:  var(--sans,  ui-sans-serif, system-ui, sans-serif);
  --xs-serif: var(--serif, 'Iowan Old Style', Georgia, serif);
  --xs-mono:  var(--mono,  ui-monospace, Menlo, Consolas, monospace);
  --xs-fs-1: var(--fs-1, 12px); --xs-fs-2: var(--fs-2, 13.5px); --xs-fs-3: var(--fs-3, 15px);
  --xs-s1: var(--s1, 4px); --xs-s2: var(--s2, 8px); --xs-s3: var(--s3, 12px);
  --xs-s4: var(--s4, 16px); --xs-s6: var(--s6, 32px);
  --xs-r-sm: var(--r-sm, 6px); --xs-r: var(--r, 12px);
  --xs-shadow: var(--shadow-3, 0 4px 10px rgba(0,0,0,.08), 0 40px 80px -32px rgba(0,0,0,.35));

  /* A little ink laid over whatever a cell already is, so hover keeps the
     band tints; the same idea in light on the dark chrome. */
  --xs-wash: rgba(127, 127, 127, .14);
  --xs-wash-chrome: rgba(255, 255, 255, .12);

  --xs-gutter: 44px;   /* row-number column; the frozen column sticks just past it */
  --xs-letters: 24px;  /* column-letter row; the header row sticks just below it */
  --xs-row: 30px;

  font-family: var(--xs-sans);
  font-size: var(--xs-fs-2);
  line-height: 1.4;
  color: var(--xs-ink);
}
@supports (color: color-mix(in srgb, red 50%, transparent)) {
  .xs {
    --xs-wash: color-mix(in srgb, var(--xs-ink) 8%, transparent);
    --xs-wash-chrome: color-mix(in srgb, var(--xs-chrome-ink) 14%, transparent);
  }
}

/* ---------- the window ---------- */

.xs-frame {
  display: flex; flex-direction: column;
  width: 100%; height: clamp(420px, 70vh, 640px);
  background: var(--xs-paper-2); color: var(--xs-ink);
  border: 1px solid var(--xs-line-2); border-radius: var(--xs-r);
  box-shadow: var(--xs-shadow); overflow: hidden;
}
.xs-frame.xs-expanded { height: 90vh; }

.xs-chrome {
  flex: none; display: flex; align-items: center; gap: var(--xs-s2);
  padding: var(--xs-s1) var(--xs-s2) var(--xs-s1) var(--xs-s4);
  background: var(--xs-chrome); color: var(--xs-chrome-ink);
}
.xs-titles { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; justify-content: center; line-height: 1.3; }
.xs-title, .xs-badge { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xs-title { font-weight: 500; }
.xs-badge { font-family: var(--xs-mono); font-size: var(--xs-fs-1); letter-spacing: .03em; opacity: .65; }

.xs-expand, .xs-open {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 var(--xs-s3); margin: 0;
  border: 1px solid transparent; border-radius: 999px;
  background: transparent; color: inherit; text-decoration: none;
  font: 500 var(--xs-fs-1)/1 var(--xs-sans); white-space: nowrap; cursor: pointer;
}
.xs-open { border-color: currentColor; opacity: .85; }
.xs-expand:hover, .xs-open:hover { background: var(--xs-wash-chrome); opacity: 1; }
.xs-expand svg, .xs-open svg { width: 12px; height: 12px; flex: none; }

.xs-note {
  flex: none; margin: 0; padding: var(--xs-s2) var(--xs-s4);
  font-size: var(--xs-fs-1); color: var(--xs-ink-2);
  background: var(--xs-paper-2); border-bottom: 1px solid var(--xs-line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.xs-note[hidden] { display: none; }

.xs-panel {
  flex: 1 1 auto; min-height: 0; position: relative;
  overflow: auto; overscroll-behavior-x: contain;
  background: var(--xs-paper-2); outline: none;
  scrollbar-width: thin; scrollbar-color: var(--xs-line-2) transparent;
}
.xs-panel:focus-visible { box-shadow: inset 0 0 0 2px var(--xs-accent); }

/* ---------- the grid ---------- */

.xs-grid { border-collapse: separate; border-spacing: 0; table-layout: auto; min-width: 100%; }
.xs-grid-text { width: 100%; }
.xs-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.xs-grid th, .xs-grid td {
  box-sizing: border-box; height: var(--xs-row); padding: 0 var(--xs-s2);
  border-right: 1px solid var(--xs-line); border-bottom: 1px solid var(--xs-line);
  background: var(--xs-paper-2); color: var(--xs-ink);
  font-weight: 400; text-align: left; vertical-align: middle; white-space: nowrap;
}
.xs-grid-text td { white-space: pre-wrap; vertical-align: top; padding-top: 6px; padding-bottom: 6px; line-height: 1.35; }
/* Column A of a text tab is a heading column: narrow, and headings run on
   across the empty cells beside them (colspan, set by sheet.js). */
.xs-grid-text td.xs-c0:not([colspan]) { width: 1%; min-width: 14ch; }

/* Furniture: column letters along the top, row numbers down the side. */
.xs-grid .xs-rn {
  position: sticky; left: 0; z-index: 2;
  width: var(--xs-gutter); min-width: var(--xs-gutter); max-width: var(--xs-gutter); padding: 0;
  background: var(--xs-paper-3); color: var(--xs-ink-3);
  font: 400 var(--xs-fs-1)/1 var(--xs-mono); text-align: center;
  border-right: 1px solid var(--xs-line-2);
}
.xs-grid .xs-letters > td {
  position: sticky; top: 0; z-index: 3; height: var(--xs-letters); padding: 0;
  background: var(--xs-paper-3); color: var(--xs-ink-3);
  font: 500 var(--xs-fs-1)/1 var(--xs-mono); text-align: center;
}
.xs-grid .xs-head > th, .xs-grid .xs-head > td {
  position: sticky; top: var(--xs-letters); z-index: 3; padding: 0;
  background: var(--xs-paper-3); font-weight: 600;
}
/* Frozen columns. The first sticks just past the gutter; a second sticks
   past the first's measured width, which sheet.js writes to --xs-fz2-left
   on the table (and, on a phone, caps its text with --xs-fz2-max). */
.xs-grid .xs-fz { position: sticky; left: var(--xs-gutter); z-index: 2; }
.xs-grid .xs-fz2 { left: var(--xs-fz2-left, var(--xs-gutter)); }
.xs-grid .xs-fz2 .xs-clip { max-width: var(--xs-fz2-max, 40ch); }
.xs-grid .xs-fz-end { border-right: 1px solid var(--xs-line-2); }
.xs-grid .xs-letters > .xs-rn, .xs-grid .xs-letters > .xs-fz,
.xs-grid .xs-head > .xs-rn, .xs-grid .xs-head > .xs-fz { z-index: 4; }

/* Headers are buttons: the whole cell sorts, and says which way. */
.xs-th {
  display: flex; align-items: center; gap: 4px; width: 100%; min-height: 40px;
  padding: 0 var(--xs-s2); margin: 0; border: 0; background: none;
  font: inherit; color: inherit; text-align: inherit; cursor: pointer;
}
.xs-num .xs-th { justify-content: flex-end; }
.xs-th:hover { background: var(--xs-wash); }
.xs-sort { display: inline-flex; flex: none; width: 10px; height: 10px; color: var(--xs-ink-3); opacity: 0; }
.xs-sort svg { width: 100%; height: 100%; }
.xs-th:hover .xs-sort { opacity: .6; }
[aria-sort] .xs-th { box-shadow: inset 0 -2px 0 var(--xs-accent); }
[aria-sort] .xs-sort { opacity: 1; color: var(--xs-accent); }
[aria-sort="descending"] .xs-sort { transform: rotate(180deg); }

.xs-grid .xs-num { font-family: var(--xs-mono); font-variant-numeric: tabular-nums; text-align: right; }
.xs-clip {
  display: inline-block; max-width: 40ch; vertical-align: middle;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.xs-th .xs-clip { max-width: 24ch; min-width: 0; }

.xs-grid td.xs-band-a { background-color: var(--xs-band-a); }
.xs-grid td.xs-band-b { background-color: var(--xs-band-b); }
.xs-grid td.xs-band-c { background-color: var(--xs-band-c); }
.xs-dot { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; vertical-align: middle; background: var(--xs-ink-3); }
.xs-band-a .xs-dot { background: var(--xs-accent); }
.xs-band-b .xs-dot { background: var(--xs-ink-2); }

/* Row highlight, and the attempt bars it reveals. Both are a wash or an
   opacity change over what is already drawn: nothing moves. */
.xs-grid tbody tr:hover td, .xs-grid tbody tr.xs-active td {
  background-image: linear-gradient(var(--xs-wash), var(--xs-wash));
}
.xs-bars {
  display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; margin-left: var(--xs-s2);
  vertical-align: middle; border-bottom: 1px solid var(--xs-line-2);
  opacity: 0; transition: opacity .12s ease;
}
.xs-bars > span { display: block; width: 3px; background: var(--xs-accent); }
.xs-grid tbody tr:hover .xs-bars, .xs-grid tbody tr.xs-active .xs-bars { opacity: 1; }

/* ---------- locked tabs ---------- */

.xs-locked {
  min-height: 100%; display: flex; align-items: center; justify-content: center;
  padding: var(--xs-s6) var(--xs-s4);
  /* Empty cells behind the message: the grid, with nothing in it. */
  background-image: linear-gradient(var(--xs-line) 1px, transparent 1px),
                    linear-gradient(90deg, var(--xs-line) 1px, transparent 1px);
  background-size: 100% var(--xs-row), 120px 100%;
  background-position: 0 -1px, var(--xs-gutter) 0;
}
.xs-locked-card {
  display: flex; flex-direction: column; align-items: center; gap: var(--xs-s2);
  max-width: 36ch; padding: var(--xs-s4) var(--xs-s6);
  background: var(--xs-paper-2); text-align: center;
}
.xs-locked-card > svg { width: 22px; height: 22px; color: var(--xs-ink-3); }
.xs-locked-name { margin: 0; font: 500 var(--xs-fs-1)/1 var(--xs-mono); letter-spacing: .06em; color: var(--xs-ink-3); }
.xs-locked-line { margin: 0; font-family: var(--xs-serif); font-size: var(--xs-fs-3); line-height: 1.45; color: var(--xs-ink); }
.xs-cta {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 var(--xs-s4); margin-top: var(--xs-s2);
  border-radius: 999px; background: var(--xs-ink); color: var(--xs-paper);
  font-weight: 500; font-size: var(--xs-fs-2); text-decoration: none;
}
.xs-cta:hover { background: var(--xs-accent); color: var(--xs-accent-ink); }

/* ---------- the tab strip ---------- */

.xs-tabs {
  flex: none; position: relative; display: flex; align-items: flex-end; gap: 2px;
  padding: var(--xs-s1) var(--xs-s2) 0;
  background: var(--xs-paper-3); border-top: 1px solid var(--xs-line-2);
  overflow-x: auto; overflow-y: hidden; scrollbar-width: thin;
}
.xs-tab {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 40px;
  padding: 0 var(--xs-s3); margin: 0;
  border: 1px solid transparent; border-bottom: 0; border-radius: var(--xs-r-sm) var(--xs-r-sm) 0 0;
  background: transparent; color: var(--xs-ink-2);
  font: 500 var(--xs-fs-1)/1 var(--xs-sans); white-space: nowrap; cursor: pointer;
}
.xs-tab:hover { background: var(--xs-wash); color: var(--xs-ink); }
.xs-tab[aria-selected="true"] {
  background: var(--xs-paper-2); color: var(--xs-ink); border-color: var(--xs-line-2);
  box-shadow: inset 0 -2px 0 var(--xs-accent);
}
.xs-tab-locked { color: var(--xs-ink-3); }
.xs-tab svg { width: 11px; height: 11px; flex: none; opacity: .8; }

/* ---------- focus, motion, small screens ---------- */

.xs :is(.xs-tab, .xs-th, .xs-expand, .xs-open, .xs-cta):focus-visible {
  outline: 2px solid var(--xs-accent); outline-offset: -2px;
}
@media (prefers-reduced-motion: reduce) {
  .xs-bars { transition: none; }
}
@media (max-width: 640px) {
  .xs-note { white-space: normal; }
}
@media (max-width: 480px) {
  .xs-chrome { padding-left: var(--xs-s3); }
  .xs-expand .xs-label { display: none; }
  .xs-expand { padding: 0 var(--xs-s3); }
}
