/* ============================================================
   Interactive resistor color code decoder (rcd)
   ============================================================ */

.rcd-section {
  margin: 24px 0 40px;
}

.rcd-intro {
  color: var(--ink-soft);
  font-size: 15px;
  margin-bottom: 16px;
}

/* Mode tabs */
.rcd-mode-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  width: fit-content;
}
.rcd-tab {
  padding: 8px 18px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}
.rcd-tab:hover {
  color: var(--ink);
}
.rcd-tab.is-active {
  background: var(--surface-1);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* Resistor body */
.rcd-resistor {
  margin: 32px auto;
  max-width: 600px;
  display: flex;
  justify-content: center;
  padding: 20px 0;
}
.rcd-body {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 560px;
}
.rcd-leads {
  flex: 0 0 60px;
  height: 4px;
  background: linear-gradient(to bottom, #b8b8b8 0%, #e0e0e0 50%, #888 100%);
  border-radius: 1px;
}
.rcd-bands {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 100px;
  /* Beige resistor body */
  background: linear-gradient(to bottom, #d4b896 0%, #e8d4b0 30%, #c9a87f 100%);
  border-radius: 50px / 100%;
  padding: 0 16px;
  position: relative;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15), inset 0 -8px 16px rgba(0,0,0,0.1);
}

/* Individual band */
.rcd-band {
  width: 18px;
  height: 100%;
  border-radius: 0;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
  position: relative;
}
.rcd-band:hover {
  transform: scaleX(1.2);
  filter: brightness(1.15);
  z-index: 2;
}
.rcd-band:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  z-index: 3;
}

/* Color swatches */
.rcd-color-black    { background: #1a1a1a; }
.rcd-color-brown    { background: #8B4513; }
.rcd-color-red      { background: #d72d2d; }
.rcd-color-orange   { background: #ff8c1a; }
.rcd-color-yellow   { background: #ffd91a; }
.rcd-color-green    { background: #2d8a2d; }
.rcd-color-blue     { background: #2d4ada; }
.rcd-color-violet   { background: #8a2dd4; }
.rcd-color-gray     { background: #808080; }
.rcd-color-white    { background: #f5f5f5; border: 1px solid #ccc; }
.rcd-color-gold     { background: linear-gradient(135deg, #d4af37 0%, #ffd700 50%, #b8860b 100%); }
.rcd-color-silver   { background: linear-gradient(135deg, #b8b8b8 0%, #e8e8e8 50%, #999 100%); }
.rcd-color-pink     { background: #ff9eb5; }
.rcd-color-none     { background: transparent; }

/* Result display */
.rcd-result {
  text-align: center;
  margin: 24px auto 16px;
  padding: 24px;
  background: var(--surface-2);
  border-radius: var(--radius);
  max-width: 500px;
}
.rcd-value {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.02em;
}
.rcd-meta {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink-soft);
  margin-top: 8px;
}

/* Color picker popover */
.rcd-picker {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  max-width: 320px;
  width: 90vw;
  z-index: 1000;
}
.rcd-picker[hidden] { display: none; }
.rcd-picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 600;
  color: var(--ink);
  font-size: 15px;
}
.rcd-picker-close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 4px 8px;
}
.rcd-picker-close:hover {
  color: var(--ink);
}
.rcd-swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.rcd-swatch {
  aspect-ratio: 1;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s, border-color 0.15s;
  position: relative;
}
.rcd-swatch:hover {
  transform: scale(1.1);
  border-color: var(--ink);
}
.rcd-swatch.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.rcd-swatch-label {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--ink-soft);
  white-space: nowrap;
}

/* Backdrop for the picker */
.rcd-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 999;
}
.rcd-backdrop[hidden] { display: none; }

/* Mobile responsive */
@media (max-width: 600px) {
  .rcd-body {
    flex-direction: column;
  }
  .rcd-leads {
    width: 4px;
    height: 30px;
    background: linear-gradient(to right, #b8b8b8 0%, #e0e0e0 50%, #888 100%);
  }
  .rcd-bands {
    width: 100%;
    height: 80px;
  }
  .rcd-band {
    width: 14px;
  }
  .rcd-value {
    font-size: 22px;
  }
}

/* Hide in print */
@media print {
  .rcd-section { display: none !important; }
}
