/* ==========================================================================
   Chapter Extras - Reusable components for chapters 2+
   Sliders, formulas, result cards, category grids
   ========================================================================== */

/* ---------- Category cards (3-up grid) ---------- */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--s-4);
  margin: var(--s-5) 0;
}

.cat-card {
  background: var(--c-card);
  border: 2px solid var(--c-ink);
  border-radius: var(--r-md);
  padding: var(--s-5);
  box-shadow: 3px 3px 0 var(--c-ink);
  transition: transform 0.15s;
}
.cat-card:hover {
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--c-ink);
}
.cat-card .cat-icon {
  width: 48px;
  height: 48px;
  border: 2px solid var(--c-ink);
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  margin-bottom: var(--s-3);
}
.cat-card h3 {
  margin: 0 0 var(--s-2);
  font-size: 1.2rem;
}
.cat-card p {
  margin: 0 0 var(--s-2);
  font-size: 0.95rem;
  color: var(--c-ink-soft);
}
.cat-card p:last-child { margin-bottom: 0; }

/* ---------- Formula blocks ---------- */
.formula-block {
  background: var(--c-bg-soft);
  border: 2px solid var(--c-ink);
  border-radius: var(--r-md);
  padding: var(--s-4) var(--s-5);
  margin: var(--s-4) 0;
  font-family: var(--f-mono);
}
.formula {
  padding: var(--s-2) 0;
  font-size: 1.05rem;
  border-bottom: 1px dashed var(--c-shadow);
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  flex-wrap: wrap;
}
.formula:last-child { border-bottom: none; }
.formula .f-label {
  font-family: var(--f-display);
  font-weight: 700;
  color: var(--c-ink-soft);
  font-size: 0.9rem;
  min-width: 130px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.formula--big {
  font-size: 1.6rem;
  text-align: center;
  justify-content: center;
  font-weight: 700;
  color: var(--c-primary);
  padding: var(--s-3) 0;
}

/* ---------- Sliders ---------- */
.sliders {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  margin: var(--s-4) 0;
  padding: var(--s-4);
  background: var(--c-bg-soft);
  border: 2px dashed var(--c-ink);
  border-radius: var(--r-md);
}

.slider-row {
  display: grid;
  grid-template-columns: 140px 1fr 100px;
  gap: var(--s-3);
  align-items: center;
}

.slider-row label {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1rem;
  color: var(--c-ink);
}
.slider-row label .muted {
  font-family: var(--f-body);
  font-weight: 500;
  font-size: 0.85rem;
}

.slider-row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 100px;
  background: var(--c-card);
  border: 2px solid var(--c-ink);
  outline: none;
  cursor: pointer;
}
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--c-primary);
  border: 2px solid var(--c-ink);
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--c-ink);
  transition: transform 0.1s;
}
.slider-row input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}
.slider-row input[type="range"]::-webkit-slider-thumb:active {
  transform: scale(1.25);
}
.slider-row input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--c-primary);
  border: 2px solid var(--c-ink);
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--c-ink);
}

.slider-row output {
  font-family: var(--f-mono);
  font-weight: 600;
  font-size: 0.95rem;
  text-align: right;
  background: var(--c-card);
  padding: 6px 10px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--c-ink);
}

@media (max-width: 600px) {
  .slider-row {
    grid-template-columns: 1fr;
    gap: var(--s-1);
  }
  .slider-row output { text-align: center; }
}

/* ---------- Results Grid ---------- */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--s-3);
  margin: var(--s-4) 0;
}

.result-card {
  background: var(--c-card);
  border: 2px solid var(--c-ink);
  border-radius: var(--r-sm);
  padding: var(--s-3) var(--s-4);
  text-align: center;
  box-shadow: 2px 2px 0 var(--c-ink);
}

.result-label {
  font-family: var(--f-mono);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-muted);
  margin-bottom: var(--s-2);
}

.result-value {
  font-family: var(--f-display);
  font-weight: 800;
  font-size: 1.4rem;
  color: var(--c-primary);
  line-height: 1.2;
  word-break: break-word;
}

/* When result-value contains a select, normalize it */
.result-value .select-input {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1rem;
  color: var(--c-ink);
  padding: 6px 12px;
  background: var(--c-bg-soft);
  border: 2px solid var(--c-ink);
  border-radius: var(--r-sm);
  cursor: pointer;
  width: 100%;
}

/* ---------- Pulse animation for output state ---------- */
.result-value.is-high {
  color: var(--c-high);
  animation: pulse-high 0.4s;
}
.result-value.is-low {
  color: var(--c-low);
}

@keyframes pulse-high {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* ---------- Comparison Bars (TTL vs CMOS) ---------- */
.cmp-bar-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: var(--s-3);
  align-items: center;
}

.cmp-bar-label {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1.1rem;
}

.cmp-bar-track {
  height: 36px;
  background: var(--c-bg-soft);
  border: 2px solid var(--c-ink);
  border-radius: var(--r-sm);
  overflow: hidden;
  position: relative;
}

.cmp-bar-fill {
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 var(--s-3);
  color: white;
  font-family: var(--f-mono);
  font-weight: 700;
  font-size: 0.95rem;
  transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  border-right: 2px solid var(--c-ink);
  white-space: nowrap;
  min-width: 60px;
  position: relative;
  overflow: hidden;
}

/* Animated stripes */
.cmp-bar-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    -45deg,
    rgba(255,255,255,0.08) 0,
    rgba(255,255,255,0.08) 8px,
    transparent 8px,
    transparent 16px
  );
}

.cmp-bar-fill span {
  position: relative;
  z-index: 1;
}

.cmp-hint {
  text-align: center;
  font-family: var(--f-mono);
  font-size: 0.85rem;
  color: var(--c-muted);
  margin-top: var(--s-2);
}

/* ---------- FF LED Row (counter visualization) ---------- */
.ff-led-row {
  display: flex;
  gap: var(--s-3);
  justify-content: center;
  flex-wrap: wrap;
  padding: var(--s-4);
  background: var(--c-bg-soft);
  border: 2px solid var(--c-ink);
  border-radius: var(--r-md);
  margin: var(--s-3) 0;
}

/* ---------- States Grid (Mod-N Counter) ---------- */
.states-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(85px, 1fr));
  gap: var(--s-2);
  padding: var(--s-3);
  background: var(--c-bg-soft);
  border: 2px solid var(--c-ink);
  border-radius: var(--r-md);
}

.state-cell {
  background: var(--c-card);
  border: 2px solid var(--c-ink);
  border-radius: var(--r-sm);
  padding: var(--s-2);
  text-align: center;
  transition: all 0.2s;
  position: relative;
}

.state-cell .state-num {
  font-family: var(--f-display);
  font-weight: 800;
  font-size: 1.4rem;
  color: var(--c-ink);
  line-height: 1;
}

.state-cell .state-bin {
  font-size: 0.78rem;
  color: var(--c-muted);
  margin-top: 2px;
  font-weight: 600;
}

.state-cell.is-active {
  background: var(--c-primary);
  box-shadow: 3px 3px 0 var(--c-ink);
  transform: translate(-1px, -1px);
}
.state-cell.is-active .state-num,
.state-cell.is-active .state-bin {
  color: white;
}

.state-cell.is-unused {
  background: repeating-linear-gradient(
    -45deg,
    var(--c-bg-soft),
    var(--c-bg-soft) 6px,
    var(--c-card) 6px,
    var(--c-card) 12px
  );
  opacity: 0.55;
}
.state-cell.is-unused::after {
  content: '✕';
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 0.8rem;
  color: var(--c-low);
  font-weight: 700;
}

/* ---------- Decoder Outputs (mini LEDs grid) ---------- */
.decoder-outputs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: var(--s-2);
  padding: var(--s-3);
  background: var(--c-bg-soft);
  border: 2px solid var(--c-ink);
  border-radius: var(--r-md);
  margin: var(--s-2) 0;
}

.output-led-mini {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.output-led-mini-label {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--c-ink-soft);
}

.led-mini {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--c-ink);
  background: var(--c-low);
  color: white;
  font-family: var(--f-mono);
  font-size: 0.95rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  transition: all 0.3s;
  box-shadow: 2px 2px 0 var(--c-ink);
}

.led-mini.is-high {
  background: var(--c-high);
  box-shadow: 0 0 12px rgba(22, 163, 74, 0.5), 2px 2px 0 var(--c-ink);
  transform: scale(1.05);
}

/* ---------- Parity Table (BCD 0-15) ---------- */
.parity-table {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: var(--s-2);
  padding: var(--s-3);
  background: var(--c-bg-soft);
  border: 2px solid var(--c-ink);
  border-radius: var(--r-md);
}

.parity-cell {
  background: var(--c-card);
  border: 2px solid var(--c-ink);
  border-radius: var(--r-sm);
  padding: var(--s-2);
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}
.parity-cell:hover {
  transform: translate(-2px, -2px);
  box-shadow: 3px 3px 0 var(--c-ink);
}
.parity-cell.is-active {
  background: var(--c-primary);
  color: white;
  box-shadow: 3px 3px 0 var(--c-ink);
  transform: translate(-2px, -2px);
}
.parity-cell.is-active .parity-num,
.parity-cell.is-active .parity-bin,
.parity-cell.is-active .parity-tag {
  color: white;
}

.parity-num {
  font-family: var(--f-display);
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--c-ink);
  line-height: 1;
}

.parity-bin {
  font-size: 0.78rem;
  color: var(--c-muted);
  margin-top: 2px;
  font-weight: 600;
}

.parity-pair {
  display: flex;
  gap: 4px;
  justify-content: center;
  align-items: center;
  margin-top: 4px;
  font-family: var(--f-mono);
  font-size: 0.78rem;
}

.parity-tag {
  color: var(--c-muted);
  font-weight: 600;
}

.parity-bit {
  display: inline-block;
  min-width: 16px;
  text-align: center;
  background: var(--c-bg-soft);
  border-radius: 4px;
  padding: 1px 4px;
  font-weight: 700;
  color: var(--c-low);
}
.parity-bit.is-one {
  background: var(--c-high);
  color: white;
}
.parity-cell.is-active .parity-bit {
  background: white;
  color: var(--c-ink);
}
.parity-cell.is-active .parity-bit.is-one {
  background: var(--c-tertiary);
  color: white;
}
