:root {
  --bg: #f3ecdf;
  --surface: #fffaf1;
  --surface-2: #f8f0e3;
  --surface-3: #efe4d1;
  --text: #19213a;
  --muted: #6d6b73;
  --line: #19213a;
  --primary: #ff6b35;
  --primary-dark: #d94c1d;
  --primary-soft: #ffe0d2;
  --accent: #23a997;
  --accent-soft: #d6f2ed;
  --danger: #b52e3d;
  --danger-soft: #ffe2e5;
  --navy: #19213a;
  --yellow: #ffd166;
  --shadow: 7px 7px 0 #19213a;
  --shadow-small: 4px 4px 0 #19213a;
  --radius: 24px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #11182b;
  --surface: #202942;
  --surface-2: #172038;
  --surface-3: #2a3552;
  --text: #fff7e8;
  --muted: #b8b4b1;
  --line: #fff7e8;
  --primary: #ff7c4d;
  --primary-dark: #ff986f;
  --primary-soft: #4b2d2c;
  --accent: #4fd8c5;
  --accent-soft: #173f43;
  --danger: #ff8290;
  --danger-soft: #4a2631;
  --navy: #0c1120;
  --yellow: #ffd166;
  --shadow: 7px 7px 0 #fff7e8;
  --shadow-small: 4px 4px 0 #fff7e8;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(rgba(25, 33, 58, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(25, 33, 58, .045) 1px, transparent 1px),
    var(--bg);
  background-size: 30px 30px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
  transition: background-color .2s ease, color .2s ease;
}
button, input { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.container { width: min(1180px, calc(100% - 32px)); margin-inline: auto; }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

.site-header { padding: 20px 0 0; }
.nav-shell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 13px 16px;
  border: 2px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-small);
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand > span:last-child { display: grid; }
.brand strong { font-size: 1.12rem; line-height: 1; letter-spacing: -.02em; }
.brand small { margin-top: 4px; color: var(--muted); font: 700 .65rem/1 var(--mono); letter-spacing: .12em; }
.brand-mark { display: grid; grid-template-columns: repeat(2, 10px); grid-template-rows: repeat(2, 10px); gap: 3px; padding: 8px; border: 2px solid var(--line); border-radius: 10px; background: var(--primary); }
.brand-mark i { display: block; border-radius: 2px; background: #fffaf1; }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { background: var(--navy); }
.nav-meta { display: flex; align-items: center; gap: 10px; }
.version-tag { padding: 8px 11px; border: 2px solid var(--line); border-radius: 999px; background: var(--yellow); color: #19213a; font: 900 .68rem/1 var(--mono); }
.theme-toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 7px 11px; border: 2px solid var(--line); border-radius: 12px; color: var(--text); background: var(--surface-2); font: 800 .68rem/1 var(--mono); }
.theme-toggle:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--line); }

.page-shell { display: grid; gap: 28px; padding: 28px 0 60px; }
.hero-grid { display: grid; grid-template-columns: 1.45fr .75fr; gap: 22px; }
.box-card, .card {
  position: relative;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.box-card--navy { color: #fff7e8; background: var(--navy); }
.hero-copy { min-height: 420px; padding: clamp(28px, 5vw, 54px); overflow: hidden; }
.hero-copy::after {
  content: "";
  position: absolute;
  right: -52px;
  bottom: -82px;
  width: 260px;
  height: 260px;
  border: 26px solid var(--primary);
  border-radius: 58px;
  transform: rotate(22deg);
  opacity: .9;
}
.box-label { display: inline-flex; padding: 7px 10px; border: 2px solid #fff7e8; border-radius: 999px; color: var(--yellow); font: 900 .72rem/1 var(--mono); letter-spacing: .08em; }
.hero-copy h1 { position: relative; z-index: 1; max-width: 760px; margin: 30px 0 18px; font-size: clamp(2.6rem, 6.4vw, 5.2rem); line-height: .94; letter-spacing: -.065em; }
.hero-copy h1 em { color: var(--primary); font-style: normal; }
.hero-copy p { position: relative; z-index: 1; max-width: 700px; margin: 0; color: rgba(255, 247, 232, .78); font-size: 1.02rem; }
.hero-actions { position: relative; z-index: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin-top: 32px; }
.jump-button { display: inline-flex; align-items: center; gap: 18px; padding: 12px 15px; border: 2px solid #fff7e8; border-radius: 13px; color: #19213a; background: var(--yellow); text-decoration: none; font: 900 .74rem/1 var(--mono); box-shadow: 4px 4px 0 #fff7e8; }
.hero-note { color: rgba(255,247,232,.65); font-size: .85rem; }

.hero-specs { display: grid; grid-template-rows: auto auto 1fr; gap: 18px; min-height: 420px; padding: 24px; overflow: hidden; background: var(--primary); color: #19213a; }
.spec-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; font: 900 .7rem/1 var(--mono); }
.spec-heading strong { padding: 6px 8px; border: 2px solid #19213a; border-radius: 999px; background: #fff7e8; }
.spec-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.spec-grid article { display: grid; align-content: center; min-height: 92px; padding: 14px; border: 2px solid #19213a; border-radius: 16px; background: #fff7e8; box-shadow: 4px 4px 0 #19213a; }
.spec-grid b { font-size: 1.75rem; line-height: 1; }
.spec-grid span { margin-top: 6px; font: 900 .65rem/1 var(--mono); }
.mini-lock { position: relative; display: grid; place-items: end center; min-height: 120px; }
.lock-loop { position: absolute; top: 4px; width: 94px; height: 74px; border: 16px solid #19213a; border-bottom: 0; border-radius: 50px 50px 0 0; }
.lock-body { position: relative; z-index: 1; display: grid; place-items: center; width: 148px; height: 92px; border: 2px solid #19213a; border-radius: 22px; background: var(--accent); box-shadow: 5px 5px 0 #19213a; }
.lock-body b { color: #fff7e8; font: 900 1.55rem/1 var(--mono); }

.workspace-layout { display: grid; grid-template-columns: 210px minmax(0,1fr); gap: 22px; align-items: start; }
.tool-index { position: sticky; top: 18px; padding: 18px; background: var(--yellow); color: #19213a; }
.tool-index > p { margin: 0 0 14px; font: 900 .72rem/1 var(--mono); letter-spacing: .1em; }
.tool-index ol { display: grid; gap: 9px; margin: 0; padding: 0; list-style: none; }
.tool-index li { display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 10px; min-height: 48px; padding: 8px; border: 2px solid transparent; border-radius: 12px; }
.tool-index li span { font: 900 .72rem/1 var(--mono); }
.tool-index li strong { font-size: .86rem; }
.tool-index li.active { border-color: #19213a; background: #fff7e8; box-shadow: 3px 3px 0 #19213a; }
.tool-note { display: grid; gap: 4px; margin-top: 24px; padding-top: 16px; border-top: 2px dashed #19213a; }
.tool-note span, .tool-note small { font: 800 .65rem/1.4 var(--mono); }
.tool-note strong { font-size: 1.2rem; }

.input-card, .result-card, .reference-card, .steps-toolbar { padding: clamp(22px, 4vw, 34px); }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 26px; }
.section-heading h2, .steps-toolbar h2 { margin: 0; font-size: clamp(1.55rem, 3vw, 2.25rem); line-height: 1.05; letter-spacing: -.045em; }
.section-kicker { margin: 0 0 7px; color: var(--primary-dark); font: 900 .7rem/1 var(--mono); letter-spacing: .11em; }
.section-stamp, .status-badge { display: inline-flex; padding: 8px 10px; border: 2px solid var(--line); border-radius: 999px; background: var(--primary-soft); color: var(--text); font: 900 .68rem/1 var(--mono); box-shadow: 3px 3px 0 var(--line); }
.section-stamp--teal { background: var(--accent-soft); }

.mode-selector { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 13px; margin: 0 0 24px; padding: 0; border: 0; }
.mode-selector legend { width: 100%; margin-bottom: 10px; font-weight: 850; }
.mode-option { position: relative; display: grid; grid-template-columns: 46px 1fr; align-items: center; gap: 13px; min-height: 80px; padding: 13px; border: 2px solid var(--line); border-radius: 17px; background: var(--surface-2); cursor: pointer; transition: .16s ease; }
.mode-option input { position: absolute; opacity: 0; }
.mode-letter { display: grid !important; place-items: center; width: 42px; height: 42px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); font: 900 .95rem/1 var(--mono); }
.mode-option > span:last-child { display: grid; }
.mode-option small { color: var(--muted); }
.mode-option:has(input:checked) { background: var(--primary-soft); transform: translate(-2px,-2px); box-shadow: var(--shadow-small); }
.mode-option:has(input:checked) .mode-letter { color: #fff7e8; background: var(--primary); }

.input-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 17px; }
.form-group { margin-bottom: 20px; }
.label-row { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
label, legend { font-weight: 850; }
.char-count { color: var(--primary-dark); font: 900 .72rem/1 var(--mono); }
.boxed-input { display: grid; grid-template-columns: 50px 1fr; align-items: stretch; border: 2px solid var(--line); border-radius: 15px; overflow: hidden; background: var(--surface-2); }
.boxed-input > span { display: grid; place-items: center; border-right: 2px solid var(--line); background: var(--primary); color: #fff7e8; font: 900 .72rem/1 var(--mono); }
.boxed-input--key > span { background: var(--accent); }
input[type="text"] { width: 100%; min-width: 0; padding: 15px 14px; border: 0; outline: none; color: var(--text); background: transparent; font: 800 .96rem/1 var(--mono); letter-spacing: .08em; }
.boxed-input:focus-within { outline: 4px solid color-mix(in srgb,var(--primary) 22%,transparent); }
.boxed-input:has(input.invalid) { background: var(--danger-soft); border-color: var(--danger); }
.form-group small { display: block; margin-top: 7px; color: var(--muted); }
.error-message { min-height: 1.35em; margin: 4px 0 0; color: var(--danger); font-size: .84rem; font-weight: 750; }

.example-panel { margin: 2px 0 24px; padding: 18px; border: 2px dashed var(--line); border-radius: 19px; background: var(--surface-3); }
.example-panel__header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.example-panel__header > div { display: grid; gap: 3px; }
.example-panel__eyebrow { color: var(--primary-dark); font: 900 .66rem/1 var(--mono); letter-spacing: .12em; }
.example-chip { padding: 6px 8px; border: 2px solid var(--line); border-radius: 999px; background: var(--yellow); color: #19213a; font: 900 .63rem/1 var(--mono); }
.example-control-row { display: grid; grid-template-columns: minmax(230px,1fr) auto auto; gap: 9px; }
.single-vector-label { display: grid; gap: 4px; min-height: 46px; padding: 10px 12px; border: 2px solid var(--line); border-radius: 13px; background: var(--surface); }
.single-vector-label span { color: var(--muted); font: 800 .63rem/1 var(--mono); }
.single-vector-label strong { font: 900 .9rem/1 var(--mono); }
.example-preview { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 9px; margin-top: 12px; }
.example-preview__item { min-width: 0; padding: 11px; border: 2px solid var(--line); border-radius: 13px; background: var(--surface); }
.example-preview__item span, .example-preview__item small { display: block; color: var(--muted); font-size: .7rem; }
.example-preview__item strong { display: block; margin: 4px 0 2px; overflow-wrap: anywhere; font-size: .76rem; }
.example-preview__active { background: var(--accent-soft); box-shadow: inset 5px 0 0 var(--accent); }
.example-panel > small { display: block; margin-top: 10px; color: var(--muted); }

.form-actions, .toolbar-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.button { min-height: 45px; padding: 10px 16px; border: 2px solid var(--line); border-radius: 13px; color: var(--text); background: var(--surface); font: 900 .7rem/1 var(--mono); letter-spacing: .05em; transition: .14s ease; }
.button:hover { transform: translate(-2px,-2px); box-shadow: var(--shadow-small); }
.button:active { transform: translate(0,0); box-shadow: none; }
.button--primary { display: inline-flex; align-items: center; gap: 24px; color: #fff7e8; background: var(--primary); }
.button--primary b { font-size: 1rem; }
.button--secondary { background: var(--surface-2); }
.button--example { background: var(--accent); color: #fff7e8; }
.button--small { min-height: 38px; padding: 7px 11px; font-size: .65rem; }

.result-card { overflow: hidden; background: var(--surface); }
.result-card::after { content: "02"; position: absolute; right: 22px; bottom: -38px; color: var(--primary-soft); font: 900 9rem/1 var(--mono); pointer-events: none; }
.result-grid { position: relative; z-index: 1; display: grid; grid-template-columns: 1.45fr .75fr; gap: 14px; }
.result-box { position: relative; display: grid; gap: 8px; min-width: 0; min-height: 130px; padding: 20px; border: 2px solid var(--line); border-radius: 18px; background: var(--surface-2); box-shadow: var(--shadow-small); }
.result-box--binary { background: var(--navy); color: #fff7e8; }
.result-box--hex { background: var(--yellow); color: #19213a; }
.result-box > span { font: 800 .72rem/1 var(--mono); text-transform: uppercase; opacity: .72; }
.result-value { align-self: center; overflow-wrap: anywhere; font-size: clamp(1.25rem,4vw,2rem); }
.copy-button { position: absolute; top: 13px; right: 13px; padding: 5px 8px; border: 2px solid currentColor; border-radius: 9px; color: inherit; background: transparent; font: 900 .62rem/1 var(--mono); }
.result-summary { position: relative; z-index: 1; margin-top: 16px; padding: 14px 16px; border: 2px solid var(--line); border-radius: 14px; background: var(--accent-soft); }

.steps-panel { display: grid; gap: 15px; }
.steps-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
#stepsContainer { display: grid; gap: 15px; }
details.step-card { overflow: clip; border: 2px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow-small); }
details.step-card[open] { background: var(--surface); }
.step-card summary { display: flex; align-items: center; gap: 13px; padding: 17px 20px; cursor: pointer; list-style: none; font-weight: 850; }
.step-card summary::-webkit-details-marker { display: none; }
.step-card summary::after { content: "+"; display: grid; place-items: center; width: 30px; height: 30px; margin-left: auto; border: 2px solid var(--line); border-radius: 9px; background: var(--yellow); color: #19213a; font-size: 1.2rem; }
.step-card[open] summary::after { content: "−"; background: var(--primary); color: #fff7e8; }
.step-number { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 auto; border: 2px solid var(--line); border-radius: 10px; background: var(--accent); color: #fff7e8; font: 900 .8rem/1 var(--mono); }
.step-content { padding: 0 20px 22px; border-top: 2px dashed var(--line); }
.step-description { margin: 17px 0; color: var(--muted); }
.subsection { margin-top: 19px; }
.subsection h4 { margin: 0 0 10px; }
.operation-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 13px; align-items: stretch; }
.operation-grid.two { grid-template-columns: repeat(2,minmax(0,1fr)); }
.matrix-panel { min-width: 0; padding: 13px; border: 2px solid var(--line); border-radius: 16px; background: var(--surface-2); }
.matrix-panel > span { display: block; margin-bottom: 9px; color: var(--muted); font-size: .82rem; font-weight: 800; }
.state-matrix { display: grid; grid-template-columns: repeat(2,minmax(55px,1fr)); gap: 7px; max-width: 270px; }
.nibble-cell { display: grid; place-items: center; min-height: 54px; padding: 7px; border: 2px solid var(--line); border-radius: 11px; background: var(--primary-soft); font: 900 1rem/1 var(--mono); box-shadow: 2px 2px 0 var(--line); }
.nibble-cell small { color: var(--muted); font-size: .64rem; font-weight: 700; }
.code-line, .formula-box, .gf-detail { overflow-x: auto; padding: 12px 13px; border: 2px solid var(--line); border-radius: 13px; background: var(--surface-2); }
.code-line, .formula-box { font-family: var(--mono); }
.formula-box { margin: 10px 0; }
.nibble-transform-list, .gf-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.nibble-transform { display: flex; justify-content: space-between; gap: 10px; padding: 11px 12px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface-2); font-family: var(--mono); }
.gf-detail summary { cursor: pointer; color: var(--primary-dark); font-weight: 850; }
.gf-detail pre { margin: 10px 0 0; white-space: pre-wrap; color: var(--muted); font: .77rem/1.55 var(--mono); }
.table-scroll { overflow-x: auto; }
.word-table, .reference-table, .comparison-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .88rem; }
.word-table th, .word-table td, .reference-table th, .reference-table td, .comparison-table th, .comparison-table td { padding: 9px 10px; border-right: 2px solid var(--line); border-bottom: 2px solid var(--line); text-align: center; }
.word-table tr > *:first-child, .reference-table tr > *:first-child, .comparison-table tr > *:first-child { border-left: 2px solid var(--line); }
.word-table thead tr:first-child > *, .reference-table thead tr:first-child > *, .comparison-table thead tr:first-child > * { border-top: 2px solid var(--line); }
.word-table th, .reference-table th, .comparison-table th { background: var(--yellow); color: #19213a; }

.reference-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px; }
.reference-block { padding: 16px; border: 2px solid var(--line); border-radius: 17px; background: var(--surface-2); }
.reference-title { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.reference-title span { display: grid; place-items: center; width: 32px; height: 32px; border: 2px solid var(--line); border-radius: 9px; background: var(--primary); color: #fff7e8; font: 900 .8rem/1 var(--mono); }
.reference-title h3 { margin: 0; font-size: 1rem; }
.constant-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; margin-top: 20px; }
.constant-card { position: relative; min-height: 175px; padding: 16px; border: 2px solid var(--line); border-radius: 17px; background: var(--surface-2); box-shadow: var(--shadow-small); }
.constant-card > span:first-child { display: inline-grid; place-items: center; width: 30px; height: 30px; border: 2px solid var(--line); border-radius: 9px; background: var(--surface); font: 900 .7rem/1 var(--mono); }
.constant-card h3 { margin: 16px 0 10px; font-size: 1rem; }
.constant-card p { margin: 5px 0; }
.constant-card--orange { background: var(--primary-soft); }
.constant-card--teal { background: var(--accent-soft); }
.constant-card--navy { background: var(--navy); color: #fff7e8; }
.math-matrix { display: grid; grid-template-columns: repeat(2,42px); gap: 6px; width: max-content; padding: 0 10px; border-left: 3px solid currentColor; border-right: 3px solid currentColor; font-family: var(--mono); }
.math-matrix span { text-align: center; }
.formula { font-family: Georgia, serif; font-style: italic; }

footer { padding: 0 0 30px; }
.footer-inner { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 17px 19px; border: 2px solid var(--line); border-radius: 18px; background: var(--navy); color: #fff7e8; box-shadow: var(--shadow-small); }
.footer-inner > div { display: grid; }
.footer-inner span { color: rgba(255,247,232,.65); font-size: .76rem; }
.footer-inner p { margin: 0; font: 800 .65rem/1 var(--mono); letter-spacing: .08em; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 30; transform: translate(-50%,20px); padding: 11px 15px; border: 2px solid #fff7e8; border-radius: 12px; color: #fff7e8; background: #19213a; box-shadow: 4px 4px 0 var(--primary); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { transform: translate(-50%,0); opacity: 1; }

@media (max-width: 980px) {
  .hero-grid, .workspace-layout { grid-template-columns: 1fr; }
  .tool-index { position: static; }
  .tool-index ol { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .tool-note { display: none; }
  .constant-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 760px) {
  .nav-meta .version-tag { display: none; }
  .hero-copy { min-height: 390px; }
  .hero-specs { min-height: auto; }
  .input-grid, .result-grid, .reference-grid, .operation-grid, .operation-grid.two, .example-preview, .nibble-transform-list, .gf-grid { grid-template-columns: 1fr; }
  .example-control-row { grid-template-columns: 1fr; }
  .steps-toolbar, .footer-inner { align-items: flex-start; flex-direction: column; }
  .tool-index ol { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 520px) {
  .container { width: min(100% - 20px, 1180px); }
  .nav-shell { padding: 11px 12px; }
  .theme-toggle b { display: none; }
  .hero-copy, .hero-specs, .input-card, .result-card, .reference-card, .steps-toolbar { padding: 20px; }
  .hero-copy h1 { font-size: 2.55rem; }
  .hero-actions { align-items: flex-start; flex-direction: column; }
  .mode-selector, .constant-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .tool-index ol { grid-template-columns: 1fr; }
  .step-card summary { padding: 15px; }
  .step-content { padding: 0 15px 18px; }
}
