:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #1c2033;
  --muted: #5d6478;
  --border: #e2e5ee;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --cell: #ffffff;
  --cell-one: #1c2033;
  --cell-zero: #a3a9ba;
  --cell-x: #b45309;
  --wire: #1c2033;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 25, 50, .05), 0 4px 16px rgba(20, 25, 50, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1220;
    --panel: #171b2d;
    --text: #e8eaf3;
    --muted: #9aa1b9;
    --border: #2a3048;
    --accent: #8b85ff;
    --accent-soft: #23264a;
    --cell: #1d2236;
    --cell-one: #ffffff;
    --cell-zero: #5b6280;
    --cell-x: #fbbf24;
    --wire: #d6d9e6;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; background: var(--accent-soft); padding: .1em .35em; border-radius: 5px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }

/* Cabecera */
.site-header { background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 58px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand span { color: var(--text); }
.brand small { color: var(--muted); font-weight: 500; }
.header-nav { display: flex; gap: 18px; }
.header-nav a { color: var(--muted); text-decoration: none; font-size: .95rem; }
.header-nav a:hover { color: var(--text); }
@media (max-width: 640px) { .header-nav { display: none; } }

.hero { padding: 32px 16px 8px; }
.hero h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); line-height: 1.2; margin: 0 0 10px; letter-spacing: -.01em; }
.lead { color: var(--muted); font-size: 1.08rem; max-width: 760px; margin: 0; }

/* Paneles */
.tool { display: flex; flex-direction: column; gap: 16px; padding-top: 16px; padding-bottom: 16px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.panel-title { font-size: 1.1rem; margin: 0 0 4px; }
.hint { color: var(--muted); font-size: .9rem; margin: 0 0 12px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 16px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

/* Controles */
.controls { display: flex; flex-direction: column; gap: 14px; }
.control-row { display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.grow { flex: 1 1 220px; }
.label { font-size: .82rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
input[type=text] {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; width: 100%;
}
input[type=text]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 3px; flex-wrap: wrap; }
.seg button {
  font: inherit; font-size: .93rem; border: 0; background: transparent; color: var(--muted);
  padding: 6px 14px; border-radius: 7px; cursor: pointer;
}
.seg button[aria-checked=true] { background: var(--accent); color: #fff; font-weight: 600; }
.buttons { gap: 10px; align-items: center; }
.btn {
  font: inherit; font-size: .93rem; padding: 8px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.input-error { color: #dc2626; margin: 0; font-size: .92rem; }

/* Tabla de verdad */
.table-scroll { max-height: 560px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.truth { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; text-align: center; }
.truth th, .truth td { padding: 5px 8px; border-bottom: 1px solid var(--border); }
.truth thead th { position: sticky; top: 0; background: var(--panel); font-size: .88rem; color: var(--muted); z-index: 1; }
.truth td.m { color: var(--muted); font-size: .82rem; }
.truth td.sep, .truth th.sep { border-left: 2px solid var(--border); }
.truth button.out {
  font: inherit; font-weight: 700; width: 40px; padding: 2px 0; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg); color: var(--cell-zero);
}
.truth button.out.v1 { color: #fff; background: var(--accent); border-color: var(--accent); }
.truth button.out.vx { color: var(--cell-x); border-color: var(--cell-x); }
.truth tr:hover td { background: var(--accent-soft); }

/* Mapa K (SVG) */
.kmap svg { width: 100%; max-width: 440px; height: auto; display: block; margin: 0 auto; user-select: none; }
.kmap .cell rect.bg { fill: var(--cell); stroke: var(--border); stroke-width: 1; }
.kmap .cell { cursor: pointer; }
.kmap .cell:hover rect.bg { fill: var(--accent-soft); }
.kmap .val { font-size: 22px; font-weight: 700; text-anchor: middle; dominant-baseline: central; fill: var(--cell-zero); pointer-events: none; }
.kmap .val.v1 { fill: var(--cell-one); }
.kmap .val.vx { fill: var(--cell-x); }
.kmap .idx { font-size: 10px; fill: var(--muted); pointer-events: none; }
.kmap .axis { font-size: 14px; fill: var(--muted); text-anchor: middle; dominant-baseline: central; font-family: ui-monospace, Menlo, Consolas, monospace; }
.kmap .axis-name { font-size: 15px; fill: var(--text); font-weight: 700; }
.kmap .grp { transition: opacity .15s; pointer-events: none; }
.kmap.hl .grp { opacity: .12; }
.kmap.hl .grp.on { opacity: 1; }
.kmap .frame { fill: none; stroke: var(--muted); stroke-width: 1.5; }

/* Resultado */
.result { margin-top: 16px; text-align: center; }
.expr { font-size: clamp(1.3rem, 3.5vw, 1.75rem); font-weight: 700; font-family: Georgia, "Times New Roman", serif; word-break: break-word; }
.expr .term { padding: 1px 4px; border-radius: 6px; border-bottom: 3px solid; cursor: default; }
.ov { display: inline-block; line-height: 1.05; border-top: .09em solid currentColor; padding-top: .04em; margin: 0 .07em; }
.result .meta { color: var(--muted); font-size: .92rem; margin-top: 6px; }
.result .btn { margin-top: 10px; }

/* Pasos */
.steps { display: flex; flex-direction: column; gap: 18px; }
.step h3 { font-size: 1rem; margin: 0 0 6px; }
.step p { margin: 0 0 8px; }
.step .mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.groups { display: flex; flex-direction: column; gap: 10px; padding: 0; margin: 0; list-style: none; }
.groups li { border: 1px solid var(--border); border-left: 6px solid; border-radius: 10px; padding: 10px 14px; }
.groups li .t { font-family: Georgia, serif; font-weight: 700; font-size: 1.1rem; }
.groups li .d { color: var(--muted); font-size: .93rem; }
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; vertical-align: middle; }
.chart-scroll { overflow-x: auto; }
.chart { border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.chart th, .chart td { border: 1px solid var(--border); padding: 4px 8px; text-align: center; }
.chart th:first-child, .chart td:first-child { text-align: left; font-family: Georgia, serif; font-weight: 700; white-space: nowrap; }
.chart td.x { font-weight: 700; }
.chart tr.ess td:first-child::after { content: " ★"; color: #d97706; }

/* Circuito */
.circuit { overflow-x: auto; }
.circuit svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.circuit .w { stroke: var(--wire); stroke-width: 2; fill: none; }
.circuit .g { stroke: var(--wire); stroke-width: 2; fill: var(--panel); }
.circuit .dot { fill: var(--wire); }
.circuit text { fill: var(--text); font: 600 15px Georgia, serif; }
.circuit .gl { font: 600 10px system-ui, sans-serif; fill: var(--muted); text-anchor: middle; dominant-baseline: central; }
.circuit-const { text-align: center; font-size: 1.2rem; color: var(--muted); padding: 20px; }

/* Contenido SEO */
.content { padding-top: 24px; padding-bottom: 40px; max-width: 820px; }
.content h2 { font-size: 1.4rem; margin: 32px 0 10px; }
.content ol { padding-left: 22px; }
.content li { margin-bottom: 6px; }
details { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; margin-bottom: 10px; }
summary { cursor: pointer; font-weight: 600; }
details p { margin: 10px 0 0; }

/* Espacios para anuncios: ocultos hasta activar la publicidad (quita display:none) */
.ad-slot { display: none; min-height: 100px; }

.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: .9rem; padding: 20px 0 32px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: .95rem;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20;
}
.toast.show { opacity: 1; }

/* Conversor de bases y códigos */
[hidden] { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.seg-modes button { padding: 8px 14px; }
.base-other { width: 76px !important; padding: 6px 8px !important; margin-left: 6px; }
input[type=number] { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.input-num { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.15rem !important; }
.outs { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.out-card {
  display: flex; flex-direction: column; gap: 4px; text-align: left; font: inherit; color: var(--text); cursor: pointer;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; min-width: 0;
}
.out-card:hover { border-color: var(--accent); }
.out-card.main { border-color: var(--accent); background: var(--accent-soft); }
.out-card.main .out-val { font-size: 1.25rem; }
.out-val { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; font-size: 1.08rem; word-break: break-all; }
.step .chart-scroll { margin: 4px 0 10px; }
.step .chart-scroll.tall { max-height: 420px; overflow: auto; border-radius: 6px; }
.conv-table td, .conv-table th { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.conv-table td:first-child, .conv-table th:first-child { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 400; text-align: center; }
.conv-table thead th { position: sticky; top: 0; background: var(--panel); }
.conv-table tr.dim td { color: var(--muted); }
.bitgrid th { text-align: left !important; font-family: system-ui, sans-serif !important; font-size: .82rem; color: var(--muted); font-weight: 600 !important; white-space: nowrap; }
.bitgrid td { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; min-width: 26px; padding: 3px 5px !important; }
.bitgrid small { color: var(--cell-x); font-weight: 700; }
.step p.mono { word-break: break-all; }
.hl-inv { color: #e11d48; font-weight: 700; }
.hl-copy { color: #16a34a; font-weight: 700; }
.f-s { color: #e11d48; }
.f-e { color: #2563eb; }
.f-m { color: #16a34a; }
@media (prefers-color-scheme: dark) {
  .f-s, .hl-inv { color: #fb7185; }
  .f-e { color: #60a5fa; }
  .f-m, .hl-copy { color: #4ade80; }
}
.ieee-bits { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; font-size: 1.05rem; word-break: break-all; display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 6px 0; }
.ieee-bits span { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; }
.ieee-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .85rem; font-weight: 600; margin-bottom: 8px; }

/* Código de colores de resistencias */
.content ul { padding-left: 22px; }
.rc-draw { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 10px 10px 0; }
.rc-draw .hint { text-align: center; margin: 2px 0 10px; }
.rc-svg svg { display: block; width: 100%; max-width: 620px; height: auto; margin: 0 auto; user-select: none; -webkit-tap-highlight-color: transparent; }
.rc-lead { stroke: #9aa0a8; stroke-width: 6; stroke-linecap: round; }
.rc-outline { fill: none; stroke: rgba(0, 0, 0, .35); stroke-width: 1.5; }
.rc-band { cursor: pointer; outline: none; }
.rc-hit { fill: transparent; stroke: transparent; stroke-width: 2.5; }
.rc-band:hover .rc-hit, .rc-band:focus-visible .rc-hit { stroke: var(--muted); stroke-dasharray: 4 3; }
.rc-band.on .rc-hit { stroke: var(--accent); stroke-dasharray: none; stroke-width: 3; }
.rc-empty { fill: none; stroke: rgba(0, 0, 0, .4); stroke-dasharray: 3 3; }
.rc-lbl { font: 600 13px system-ui, sans-serif; fill: var(--muted); text-anchor: middle; }
.rc-band.on .rc-lbl { fill: var(--accent); }
.rc-smd { font: 700 44px ui-monospace, Menlo, Consolas, monospace; fill: #f2f2f2; text-anchor: middle; dominant-baseline: central; letter-spacing: 4px; }
#palette-box { display: flex; flex-direction: column; gap: 8px; }
.rc-palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.rc-sw {
  display: flex; align-items: center; gap: 8px; font: inherit; font-size: .9rem; color: var(--text); text-align: left;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px; cursor: pointer; min-width: 0;
}
.rc-sw:hover { border-color: var(--accent); }
.rc-sw.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.rc-sw i, .rc-chip i { flex: none; width: 20px; height: 20px; border-radius: 5px; border: 1px solid rgba(0, 0, 0, .25); display: inline-block; }
.rc-sw i.none { border-style: dashed; border-color: var(--muted); }
.rc-sw i.gold, .rc-chip i[style*="#c9a227"] { background: linear-gradient(#f3dc84, #c9a227 50%, #8a6d12) !important; }
.rc-sw i.silver, .rc-chip i[style*="#b9bec4"] { background: linear-gradient(#f4f6f8, #b9bec4 50%, #7d838a) !important; }
.rc-sw span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-sw b { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; color: var(--muted); }
.rc-sw.on b { color: var(--accent); }
.rc-chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; white-space: nowrap; }
.rc-chip i { width: 16px; height: 16px; border-radius: 4px; vertical-align: -3px; }
.rc-list { list-style: none; padding: 0 !important; margin: 0 0 8px; display: flex; flex-direction: column; gap: 4px; }
.seg small { opacity: .75; font-size: .78em; }
.rc-table td, .rc-table th { text-align: center; }
.rc-table td:first-child { font-family: inherit !important; font-weight: 400 !important; }
