/* ==========================================================================
   KEY-REX — component layer
   Reads ONLY semantic tokens from theme-jchimp.css. No hex values here.
   Blueprint Bench grammar: radius 0, hairline separators, no shadows,
   heavy ink rule reserved for the table head and the footer.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

/* The one literal colour in this file. A modal scrim has to stay dark in both
   modes, so it can't be derived from --jc-ink or --jc-ground (both invert).
   The value is the icon tile #20232A, which is a brand constant. */
:root { --kr-scrim: rgb(32 35 42 / 0.62); }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-size: 15px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.shell {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 20px;
}

.sprite { display: none; }

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

.icon { width: 16px; height: 16px; display: block; }

.mono { font-family: var(--jc-font-mono); }

.mono-caps {
  font-family: var(--jc-font-mono);
  font-size: 0.68rem;
  letter-spacing: var(--jc-tracking-label);
  text-transform: uppercase;
  color: var(--jc-text-dim);
}

.ta-r { text-align: right; }

/* ── Title block ──────────────────────────────────────────────────────────
   Text column left, mark and mode toggle right. There is no masthead bar —
   at /tools/ this page is the whole document, so a second title above the
   title was just a bar for its own sake. */
.titleblock {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 40px 0 0;
}

.titleblock-text { min-width: 0; }

.titleblock h1 {
  margin: 6px 0 0;
  font-size: clamp(2.1rem, 8vw, 3.4rem);
  font-weight: 800;
  text-transform: uppercase;
  line-height: 0.95;
}

.tagline {
  margin: 8px 0 0;
  font-size: 1rem;
  color: var(--jc-text-dim);
}

.kicker { margin: 0; }

/* 64px accent stub — never full width (BRAND.md §5). */
hr.accent { margin: 20px 0 0; }

.titleblock-aside {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  flex-shrink: 0;
}

.titleblock-mark {
  width: clamp(96px, 20vw, 168px);
  height: auto;
}

/* Wide layouts only: lift the mark out of flow so it stops setting the
   header's height, then oversize it. It now hangs past the header into the
   white space beside the lede — the lede's 62ch cap keeps the text clear, and
   the title column gets matching padding so the headline never runs under it.
   A negative margin cannot do this job: the aside is the taller of the two
   header columns, so shrinking it only moves the mark, never the text. */
@media (min-width: 720px) {
  .titleblock { position: relative; }

  .titleblock-text { padding-right: clamp(180px, 26vw, 280px); }

  .titleblock-mark {
    position: absolute;
    top: 110px;                 /* clears the mode toggle above it */
    right: 0;
    /* width: clamp(170px, 25vw, 240px); */
    pointer-events: none;      /* decorative — never eat clicks on the lede */
  }
}

/* Mark swap — same three-state logic theme-jchimp.css uses for colour:
   bare :root is light, prefers-color-scheme covers the untouched "system"
   default, and an explicit [data-theme] wins over both. The explicit rules
   must come after the media query: specificity ties, so source order decides. */
.mark-light { display: block; }
.mark-dark  { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .mark-light { display: none; }
  :root:not([data-theme="light"]) .mark-dark  { display: block; }
}

:root[data-theme="light"] .mark-light { display: block; }
:root[data-theme="light"] .mark-dark  { display: none; }
:root[data-theme="dark"]  .mark-light { display: none; }
:root[data-theme="dark"]  .mark-dark  { display: block; }

.lede {
  margin: 26px 0 34px;
  max-width: 62ch;
  color: var(--jc-text-dim);
  font-size: 0.95rem;
}

/* ── Tabs ─────────────────────────────────────────────────────────────────
   Navigation, so Schibsted Grotesk 600 — mono is banned here (§4). */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border-bottom: 1px solid var(--jc-border);
}

.tab {
  font-family: var(--jc-font-body);
  font-weight: 600;
  font-size: 0.83rem;
  background: transparent;
  color: var(--jc-text-dim);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  margin-bottom: -1px;
  cursor: pointer;
}

.tab:hover { color: var(--jc-text); background: transparent; }

.tab[aria-selected="true"] {
  color: var(--jc-accent-ink);
  border-bottom-color: var(--jc-accent);
}

/* ── Panels ───────────────────────────────────────────────────────────── */
.panel {
  border: 1px solid var(--jc-border);
  border-top: none;
  background: var(--jc-surface);
  padding: 24px;
}

.panel[hidden] { display: none; }

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.panel-note {
  margin: 8px 0 0;
  max-width: 62ch;
  color: var(--jc-text-dim);
  font-size: 0.875rem;
}

/* ── Labeled rule — section transition (§5) ───────────────────────────── */
.label-rule {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 26px 0 12px;
}

.label-rule span {
  font-family: var(--jc-font-mono);
  font-size: 0.66rem;
  letter-spacing: var(--jc-tracking-label);
  color: var(--jc-text-dim);
  flex-shrink: 0;
}

.label-rule::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--jc-border);
}

/* ── Numbered section head (signature move, §4) ───────────────────────── */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.section-head .num {
  font-family: var(--jc-font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--jc-accent-ink);
}

/* ── Form controls ────────────────────────────────────────────────────── */
.field { margin-top: 18px; }

.field-inline { margin-top: 0; display: flex; align-items: center; gap: 10px; }

.label {
  display: block;
  font-family: var(--jc-font-mono);
  font-size: 0.66rem;
  letter-spacing: var(--jc-tracking-label);
  text-transform: uppercase;
  color: var(--jc-text-dim);
  margin-bottom: 6px;
}

.field-inline .label { margin-bottom: 0; }

input[type="text"], input[type="password"], select {
  font-family: var(--jc-font-body);
  font-size: 0.9rem;
  color: var(--jc-text);
  background: var(--jc-bg);
  border: 1px solid var(--jc-border);
  border-radius: var(--jc-radius);
  padding: 8px 10px;
  width: 100%;
}

input.mono { font-family: var(--jc-font-mono); }

#comboSep { width: 72px; text-align: center; }

select {
  appearance: none;
  padding-right: 28px;
}

/* Chevron as a bordered triangle on the wrapper. The obvious CSS trick here is
   a pair of linear-gradients, but BRAND.md §6 bans gradients outright and a
   rule with an exception for "only a little gradient" is not a rule. */
.select-wrap { position: relative; }

.select-wrap::after {
  content: "";
  position: absolute;
  right: 11px;
  top: 50%;
  margin-top: -2px;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--jc-text-dim);
  pointer-events: none;
}

input:focus-visible, select:focus-visible {
  outline: 2px solid var(--jc-accent);
  outline-offset: 1px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.input-group { display: flex; }
.input-group input { flex: 1; }
.input-group .icon-btn { border-left: none; }

/* Checkboxes / radios */
.opt-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 18px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.875rem;
  cursor: pointer;
}

.check input {
  appearance: none;
  width: 15px; height: 15px;
  margin: 0;
  border: 1px solid var(--jc-border);
  background: var(--jc-bg);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
}

.check input:checked {
  background: var(--jc-accent);
  border-color: var(--jc-accent-hover);
}

.check input:checked::after {
  content: "";
  position: absolute;
  left: 4px; top: 1px;
  width: 4px; height: 8px;
  border: solid var(--jc-on-accent);
  border-width: 0 2px 2px 0;
  transform: rotate(42deg);
}

.check input:focus-visible { outline: 2px solid var(--jc-accent); outline-offset: 2px; }

/* Range */
input[type="range"] {
  width: 100%;
  appearance: none;
  background: transparent;
  height: 18px;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px; background: var(--jc-border);
}
input[type="range"]::-moz-range-track { height: 3px; background: var(--jc-border); }

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 14px; height: 14px;
  margin-top: -5.5px;
  background: var(--jc-accent);
  border: 1px solid var(--jc-accent-hover);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 0;
  background: var(--jc-accent);
  border: 1px solid var(--jc-accent-hover);
}

.slider-val {
  font-family: var(--jc-font-mono);
  font-size: 0.8rem;
  color: var(--jc-accent-ink);
  letter-spacing: 0;
}

.range-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--jc-text-dim);
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.btn-row-tight { margin-top: 0; }

.btn-sm { font-size: 0.78rem; padding: 6px 12px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  padding: 0;
  background: transparent;
  color: var(--jc-text-dim);
  border: 1px solid var(--jc-border);
  cursor: pointer;
}

.icon-btn:hover { color: var(--jc-text); background: transparent; border-color: var(--jc-accent); }

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-ghost:disabled:hover { border-color: var(--jc-border); }

/* ── Result display ───────────────────────────────────────────────────── */
.result {
  display: block;
  font-family: var(--jc-font-mono);
  font-size: 1rem;
  background: var(--jc-bg);
  border: 1px solid var(--jc-border);
  border-left: 3px solid var(--jc-border);
  padding: 14px 16px;
  margin-top: 20px;
  min-height: 52px;
  word-break: break-all;
  color: var(--jc-text);
  user-select: all;
}

.result.has-value { border-left-color: var(--jc-accent); }
.result-sm { font-size: 0.84rem; }

/* ── Strength meter ───────────────────────────────────────────────────── */
.strength { margin-top: 16px; }
.strength[hidden] { display: none; }

.strength-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.strength-label {
  font-family: var(--jc-font-mono);
  font-size: 0.68rem;
  letter-spacing: var(--jc-tracking-label);
  text-transform: uppercase;
}

.strength-bits {
  font-family: var(--jc-font-mono);
  font-size: 0.72rem;
  color: var(--jc-text-dim);
}

.strength-track { height: 3px; background: var(--jc-border); }
.strength-fill { height: 100%; transition: width .3s ease; }

/* Status hues only — fern OK, brass warn, red danger (§1). */
.s-bad  .strength-label { color: var(--jc-error); }
.s-bad  .strength-fill  { background: var(--jc-error); }
.s-mid  .strength-label { color: var(--jc-warn); }
.s-mid  .strength-fill  { background: var(--jc-warn); }
.s-good .strength-label { color: var(--jc-ok); }
.s-good .strength-fill  { background: var(--jc-ok); }

/* ── Chips, badges, washes ────────────────────────────────────────────── */
.chip { flex-shrink: 0; }

.badge-row { display: flex; flex-wrap: wrap; gap: 6px; }

.badge-off {
  background: transparent;
  color: var(--jc-text-dim);
  border-color: var(--jc-border);
  opacity: 0.65;
}

.callout { margin: 18px 0 0; }
.callout p { margin: 0; font-size: 0.86rem; }
.callout-tight { padding: 9px 12px; font-size: 0.8rem; }

.callout-label {
  font-family: var(--jc-font-mono);
  font-size: 0.66rem;
  letter-spacing: var(--jc-tracking-label);
  margin: 0 0 4px !important;
}

.wash-danger .callout-label { color: var(--jc-error); }
.wash-brass  .callout-label { color: var(--jc-warn); }

/* ── Combination builder ──────────────────────────────────────────────── */
.combo-area {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px dashed var(--jc-border);
}

.combo-empty { font-size: 0.82rem; color: var(--jc-text-dim); }

/* Parts are named concepts, so plum — plum names, never acts (§1). */
.combo-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--jc-font-mono);
  font-size: 0.7rem;
  padding: 3px 4px 3px 9px;
  background: var(--jc-term-bg);
  color: var(--jc-term);
  border: 1px solid var(--jc-border);
}

.combo-chip button {
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  opacity: 0.6;
}
.combo-chip button:hover { opacity: 1; background: none; }

.combo-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
}

.combo-controls .btn { margin-left: auto; }

/* ── Crack table ──────────────────────────────────────────────────────── */
.crack-table { margin-top: 0; }
.crack-table tbody td { font-size: 0.83rem; }
.crack-table .assumes { color: var(--jc-text-dim); font-size: 0.78rem; }

.crack-time {
  font-family: var(--jc-font-mono);
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
}

.t-bad  { color: var(--jc-error); }
.t-mid  { color: var(--jc-warn); }
.t-good { color: var(--jc-ok); }

.footnote {
  margin: 10px 0 0;
  font-size: 0.74rem;
  color: var(--jc-text-dim);
  max-width: 62ch;
}

/* ── Observations ─────────────────────────────────────────────────────── */
.stack { display: flex; flex-direction: column; gap: 6px; }

.note {
  font-size: 0.83rem;
  padding: 8px 12px;
  border: 1px solid var(--jc-border);
  border-left-width: 3px;
}

.note-bad  { background: var(--jc-error-bg); border-left-color: var(--jc-error); }
.note-warn { background: var(--jc-warn-bg);  border-left-color: var(--jc-warn); }
.note-info { background: var(--jc-link-bg);  border-left-color: var(--jc-link-color); }

/* ── History ──────────────────────────────────────────────────────────── */
.history {
  margin: 40px 0;
  border-top: 1px solid var(--jc-border);
  padding-top: 22px;
}

.history-empty {
  font-size: 0.85rem;
  color: var(--jc-text-dim);
  margin: 16px 0 0;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--jc-border);
  margin-top: 6px;
  background: var(--jc-surface);
}

.history-type {
  font-family: var(--jc-font-mono);
  font-size: 0.64rem;
  letter-spacing: var(--jc-tracking-label);
  text-transform: uppercase;
  color: var(--jc-text-dim);
  flex-shrink: 0;
  min-width: 68px;
}

.history-value {
  font-family: var(--jc-font-mono);
  font-size: 0.8rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item .btn { flex-shrink: 0; }

/* ── Footer ───────────────────────────────────────────────────────────────
   Third and last sanctioned use of the heavy ink rule. */
.footer {
  margin-top: auto;
  border-top: var(--jc-rule-heavy);
  padding: 14px 0;
  background: var(--jc-surface);
}

.footer p { margin: 0; }

/* ── QR dialog ────────────────────────────────────────────────────────── */
.modal {
  border: 1px solid var(--jc-border);
  border-radius: var(--jc-radius);
  background: var(--jc-surface);
  color: var(--jc-text);
  padding: 0;
  width: min(340px, calc(100vw - 32px));
}

.modal::backdrop { background: var(--kr-scrim); }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--jc-border);
}

.modal-head h2 { margin: 0; font-size: 0.95rem; font-weight: 700; }

.modal-body { padding: 16px; }

#qrCanvas { display: flex; justify-content: center; }
#qrCanvas img, #qrCanvas canvas { display: block; }

.qr-value {
  font-size: 0.72rem;
  word-break: break-all;
  color: var(--jc-text-dim);
  margin: 12px 0 0;
}

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 560px) {
  .titleblock { gap: 14px; padding-top: 28px; }
  .lede { margin: 20px 0 26px; }
  .panel { padding: 18px 16px; }
  .tab { padding: 9px 10px; font-size: 0.78rem; }
  .history-type { min-width: 0; }
  .crack-table .assumes { display: none; }
  .combo-controls .btn { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .strength-fill { transition: none; }
}
