/* ============================================================
   permbits — rust-on-oatmeal. The 3×3 bit grid is the identity.
   Light: warm linen ground, ink text, deep rust for SET bits.
   Dark: roasted umber ground, linen text, ember rust.
   ============================================================ */

:root {
  --bg:        #F4EEE2;
  --bg2:       #FBF7EE;
  --ink:       #2B2420;
  --ink-soft:  #5C5148;
  --line:      #D9CDB9;
  --rust:      #A83E1C;
  --rust-deep: #8A3115;
  --clay:      #C97B5A;
  --cell-off:  #E8DFCC;
  --warn-bg:   #F6E3D8;
  --code-bg:   #EFE7D6;
  --focus:     #A83E1C;
  --on-rust:   #FFF6EE;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --wrap: 1040px;
}

[data-theme="dark"] {
  --bg:        #221B15;
  --bg2:       #2C231B;
  --ink:       #EFE6D6;
  --ink-soft:  #C4B5A0;
  --line:      #4A3B2D;
  --rust:      #E2653A;
  --rust-deep: #EE7B52;
  --clay:      #C97B5A;
  --cell-off:  #382D22;
  --warn-bg:   #46281B;
  --code-bg:   #322820;
  --focus:     #E2653A;
  --on-rust:   #221B15;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #221B15;
    --bg2:       #2C231B;
    --ink:       #EFE6D6;
    --ink-soft:  #C4B5A0;
    --line:      #4A3B2D;
    --rust:      #E2653A;
    --rust-deep: #EE7B52;
    --clay:      #C97B5A;
    --cell-off:  #382D22;
    --warn-bg:   #46281B;
    --code-bg:   #322820;
    --focus:     #E2653A;
    --on-rust:   #221B15;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 750; letter-spacing: -0.02em; line-height: 1.12; }
p { margin: 0; }
code { font-family: var(--mono); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
a { color: var(--rust); text-underline-offset: 2px; }
a:hover { color: var(--rust-deep); }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 20px; }

/* focus — always visible */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--rust); color: var(--on-rust);
  padding: 10px 18px; border-radius: 0 0 var(--radius-sm) 0;
  font-weight: 650; z-index: 10;
}
.skip-link:focus { left: 0; }

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

/* ---------------- hero ---------------- */
.hero { border-bottom: 2px solid var(--line); padding: 28px 0 40px; }
.hero__top { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 30px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand__mark { width: 44px; height: 44px; }
.bm-on  { fill: var(--rust); }
.bm-off { fill: var(--cell-off); stroke: var(--line); stroke-width: 1; }
.brand__name { font-weight: 800; font-size: 1.3rem; letter-spacing: -0.02em; }

.theme-toggle {
  font: inherit; font-size: 0.85rem; font-weight: 600;
  background: var(--bg2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 16px; cursor: pointer;
}
.theme-toggle:hover { border-color: var(--rust); }

.eyebrow {
  font-size: 0.8rem; font-weight: 700; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--rust); margin-bottom: 12px;
}
h1 { font-size: clamp(1.55rem, 3.6vw, 2.5rem); max-width: 22ch; }
h1, .lede { margin-bottom: 0; }
.lede { margin-top: 16px; max-width: 62ch; color: var(--ink-soft); font-size: 1.05rem; }
.lede code { background: var(--code-bg); padding: 1px 6px; border-radius: 5px; font-size: 0.92em; }

/* ---------------- cards ---------------- */
.card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 26px 30px;
  margin: 26px 0;
}
.card h2 { font-size: 1.35rem; margin-bottom: 14px; }
.section-lede { color: var(--ink-soft); max-width: 68ch; margin-bottom: 16px; }

/* ---------------- converter hub ---------------- */
.kind-switch { display: flex; gap: 10px; margin-bottom: 20px; }
.kind-opt {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 18px; cursor: pointer; font-weight: 600;
  background: var(--bg);
}
.kind-opt:has(input:checked) { border-color: var(--rust); background: var(--code-bg); }
.kind-opt input { accent-color: var(--rust); }

.hub { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(260px, 1fr); gap: 30px; }
@media (max-width: 760px) { .hub { grid-template-columns: 1fr; } }

.bitgrid { border-collapse: separate; border-spacing: 6px; }
.bitgrid th { font-size: 0.82rem; font-weight: 650; color: var(--ink-soft); text-align: left; padding: 2px 6px; }
.bitgrid th .mono { color: var(--rust); font-size: 0.78rem; }
.bitgrid tbody th { padding-right: 10px; }
.bitgrid td { padding: 0; }
.bitgrid tbody td input {
  appearance: none; -webkit-appearance: none;
  width: 54px; height: 54px; margin: 0; display: block;
  background: var(--cell-off);
  border: 2px solid var(--line);
  border-radius: 10px; cursor: pointer;
  position: relative;
}
.bitgrid tbody td input:checked { background: var(--rust); border-color: var(--rust-deep); }
.bitgrid tbody td input:checked::after {
  content: "✓";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--on-rust); font-weight: 800; font-size: 1.35rem;
}
.bitgrid tbody td input:hover { border-color: var(--rust); }

.specials { border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: 12px 16px 14px; margin-top: 16px; }
.specials legend { font-size: 0.82rem; font-weight: 700; color: var(--ink-soft); padding: 0 6px; }
.specials label { display: inline-flex; align-items: center; gap: 7px; margin-right: 18px; font-weight: 600; cursor: pointer; }
.specials .mono { color: var(--ink-soft); font-size: 0.8rem; }
.specials input { width: 20px; height: 20px; accent-color: var(--rust); }

.field { margin-bottom: 18px; }
.field label, .field-label { display: block; font-size: 0.82rem; font-weight: 700; color: var(--ink-soft); margin-bottom: 6px; }
input[type="text"], input[type="search"] {
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--ink);
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 100%;
}
input[type="search"] { font-family: var(--sans); }
input.big { font-size: 1.5rem; letter-spacing: 0.12em; padding: 10px 14px; }
input:focus { border-color: var(--rust); }
.field-err { color: var(--rust-deep); font-weight: 600; font-size: 0.88rem; min-height: 1.2em; margin-top: 5px; }

.cmdrow { margin-bottom: 10px; }
.cmd {
  display: block; background: var(--code-bg);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 1.02rem;
}
.copyrow { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.copy-note { font-size: 0.85rem; color: var(--ink-soft); font-family: var(--mono); }

.btn {
  font: inherit; font-size: 0.9rem; font-weight: 650;
  background: var(--bg); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 16px; cursor: pointer;
}
.btn:hover { border-color: var(--rust); color: var(--rust-deep); }
.btn--primary { background: var(--rust); border-color: var(--rust); color: var(--on-rust); }
.btn--primary:hover { background: var(--rust-deep); border-color: var(--rust-deep); color: var(--on-rust); }
.btn--chip { border-radius: 999px; font-size: 0.82rem; padding: 6px 13px; }

.explain { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }
.explain__head { font-weight: 700; font-size: 1.05rem; color: var(--rust); margin-bottom: 8px; }
.explain p { margin-bottom: 4px; }
.explain__special { color: var(--ink-soft); }
.explain__special::before { content: "◆ "; color: var(--clay); }

.warnings { margin-top: 12px; }
.warnbadge {
  background: var(--warn-bg);
  border: 1.5px solid var(--rust);
  border-radius: var(--radius-sm);
  padding: 10px 14px; margin-top: 8px;
  font-size: 0.95rem;
}
.warnbadge strong { color: var(--rust-deep); }

/* ---------------- ls parser / clauses ---------------- */
.lsrow { display: flex; gap: 10px; margin-bottom: 16px; }
.lsrow input { flex: 1; }
@media (max-width: 560px) { .lsrow { flex-direction: column; } }

.ls-result { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 16px 18px; background: var(--bg); }
.ls-result dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; margin: 0 0 14px; }
.ls-result dt { font-weight: 700; font-size: 0.85rem; color: var(--ink-soft); }
.ls-result dd { margin: 0; }

.clause-line { font-size: 1.3rem; font-family: var(--mono); margin-bottom: 10px; }
.diff .chg {
  color: var(--rust-deep); font-weight: 800;
  text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 3px;
  background: var(--warn-bg);
  border-radius: 3px;
}

/* ---------------- umask ---------------- */
.umaskrow { display: flex; align-items: end; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.umaskrow label { font-size: 0.82rem; font-weight: 700; color: var(--ink-soft); }
.umaskrow input { width: 120px; }
.umask-presets { display: flex; gap: 8px; }
.umask-math__row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.umask-math .mono { font-size: 1.02rem; }

/* ---------------- recipes ---------------- */
.count-badge {
  font-size: 0.8rem; font-weight: 700; font-family: var(--mono);
  color: var(--rust); border: 1px solid var(--rust);
  border-radius: 999px; padding: 2px 10px; vertical-align: 3px;
}
.recent { margin-bottom: 14px; }
.recent__label { font-size: 0.85rem; font-weight: 700; color: var(--ink-soft); margin-right: 8px; }
#recent-list { display: inline-flex; gap: 8px; flex-wrap: wrap; }

.recipe-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.recipe {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); padding: 16px 18px;
  display: flex; flex-direction: column; gap: 9px;
}
.recipe h3 { font-size: 1rem; }
.recipe__cmd {
  display: block; background: var(--code-bg);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px; font-size: 0.88rem;
  overflow-x: auto; white-space: pre;
}
.recipe p { font-size: 0.9rem; color: var(--ink-soft); }
.recipe__caveat { border-left: 3px solid var(--clay); padding-left: 10px; }
.recipe__cite { font-size: 0.8rem; }
.beta-badge {
  align-self: flex-start;
  font-size: 0.74rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--rust-deep); background: var(--warn-bg);
  border: 1px solid var(--rust); border-radius: 5px; padding: 2px 8px;
}
.print-hint { margin-top: 16px; font-size: 0.85rem; color: var(--ink-soft); }

/* ---------------- concepts / faq ---------------- */
.concept-list details, #faq details {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); padding: 0 16px; margin-bottom: 10px;
}
.concept-list summary, #faq summary {
  font-weight: 700; padding: 12px 0; cursor: pointer;
}
.concept-list summary:hover, #faq summary:hover { color: var(--rust-deep); }
.concept-list details p, #faq details p { padding-bottom: 12px; color: var(--ink-soft); }
.concept-list blockquote {
  margin: 0 0 10px; padding: 8px 14px;
  border-left: 3px solid var(--rust);
  background: var(--code-bg); border-radius: 0 6px 6px 0;
  font-size: 0.9rem; color: var(--ink);
}

/* ---------------- limits / footer ---------------- */
.card--limits { border-style: dashed; }
.limits { margin: 0; padding-left: 20px; color: var(--ink-soft); }
.limits li { margin-bottom: 9px; }

.footer { border-top: 2px solid var(--line); margin-top: 40px; padding: 28px 0 40px; }
.footer p { color: var(--ink-soft); font-size: 0.88rem; max-width: 78ch; margin-bottom: 10px; }

/* ---------------- reduced motion ---------------- */
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

/* ---------------- print: the recipes cheat sheet ---------------- */
@media print {
  :root { --bg: #fff; --bg2: #fff; --ink: #000; --ink-soft: #333; --line: #999; }
  body { background: #fff; color: #000; font-size: 11px; }
  .hero .theme-toggle, .skip-link,
  #converter, #lsparse, #clauses, #umask, #concepts, #faq, #limits,
  #recipe-search, .recent, .print-hint, .recipe .copyrow, .lsrow { display: none !important; }
  .hero { padding: 0 0 8px; border-bottom: 1.5px solid #000; }
  .hero h1 { font-size: 15px; max-width: none; }
  .lede, .eyebrow { display: none; }
  .card { border: none; padding: 6px 0; margin: 6px 0; }
  #recipes h2 { font-size: 13px; }
  .recipe-list { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .recipe { border: 0.5pt solid #999; padding: 6px 8px; gap: 3px; break-inside: avoid; }
  .recipe h3 { font-size: 10.5px; }
  .recipe p { font-size: 9px; }
  .recipe__cmd { font-size: 9.5px; background: #fff; border: none; padding: 0; }
  .recipe__cite { font-size: 8px; }
  .recipe__cite a { color: #333; text-decoration: none; }
  .beta-badge { border-color: #000; color: #000; background: #fff; }
  .footer { font-size: 8.5px; padding: 8px 0 0; margin-top: 8px; }
  .footer p { font-size: 8.5px; }
}
