/* Mobile-first, large tap targets */
:root {
  --bg: #f4f1ec;
  --surface: #fff;
  --text: #1a1a1a;
  --muted: #5c5c5c;
  --border: #d8d0c6;
  --accent: #2d6a4f;
  --accent-tint: #d8f3dc;
  --ring: 0 0 0 3px var(--accent-tint);
  font-synthesis: weight;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif;
  font-size: 1.05rem;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 28rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
}

.site-logo {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
  text-decoration: none;
  color: #a01010;
}

.site-logo:hover {
  color: #c41e1e;
}

.site-logo__icon {
  display: block;
  width: 18px;
  height: 18px;
}

.site-logo__text {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.header h1 {
  font-size: 1.35rem;
  font-weight: 650;
  margin: 0 0 0.35rem;
  letter-spacing: -0.02em;
}

.value-field {
  margin-bottom: 1rem;
  padding: 0.75rem 0.9rem 0.65rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
}

.value-field__label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.value-field__input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: 2.75rem;
  padding: 0.5rem 0.65rem;
  font: inherit;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.value-field__input::placeholder {
  color: #999;
  font-size: 0.95rem;
}

.value-field__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.value-field__hint {
  margin: 0.45rem 0 0;
  min-height: 1.2em;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.3;
}

.band-count {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 1.5rem 0 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
}

.band-count__label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.segmented {
  display: flex;
  border-radius: 0.5rem;
  padding: 0.2rem;
  background: var(--bg);
  border: 1px solid var(--border);
}

.segmented__btn {
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0 0.65rem;
  border: none;
  border-radius: 0.35rem;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.segmented__btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.segmented__btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.resistor-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.resistor {
  display: flex;
  align-items: center;
  gap: 0;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.12));
}

.resistor__lead {
  width: 1.1rem;
  height: 0.2rem;
  background: linear-gradient(180deg, #9a9a9a, #6a6a6a);
  border-radius: 1px;
}

.resistor__body {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  width: min(100%, 16rem);
  min-width: 10rem;
  height: 2.4rem;
  padding: 0 0.35rem;
  background: linear-gradient(180deg, #d4a574 0%, #b8895a 25%, #a67c52 50%, #8f6844 100%);
  border-radius: 0.2rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.resistor__band {
  width: 12%;
  max-width: 0.6rem;
  min-width: 0.4rem;
  height: 84%;
  border-radius: 1px;
  background: #333;
  transition: background 0.15s ease;
}

.resistor__band--hide {
  visibility: hidden;
  width: 0;
  min-width: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.result {
  text-align: center;
  padding: 1rem 0.75rem 1.5rem;
}

.result__value {
  margin: 0;
  font-size: clamp(1.5rem, 6vw, 1.85rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.result__detail {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.strip {
  margin-bottom: 1.25rem;
  padding: 0.9rem 0.75rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
}

.strip--active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  background: var(--accent-tint);
}

.strip__title {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  min-width: 2.6rem;
  padding: 0.3rem 0.25rem 0.4rem;
  border: 2px solid transparent;
  border-radius: 0.4rem;
  background: var(--bg);
  cursor: pointer;
  font: inherit;
  color: var(--text);
}

.swatch:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.swatch--selected {
  border-color: var(--accent);
  background: #fff;
}

.swatch__chip {
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 0.2rem;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.swatch__name {
  font-size: 0.65rem;
  font-weight: 600;
  line-height: 1.1;
  text-align: center;
  max-width: 3.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.swatch--black .swatch__name,
.swatch--brown .swatch__name,
.swatch--red .swatch__name,
.swatch--violet .swatch__name,
.swatch--blue .swatch__name {
  color: var(--text);
}

/* Match resistor body tone for "none" */
.swatch--bodytone .swatch__chip {
  background: linear-gradient(180deg, #d4a574, #8f6844);
}

@media (min-width: 400px) {
  .swatch {
    min-width: 2.75rem;
  }
}

.explain {
  margin-top: 2.25rem;
  padding: 0.5rem 0 0;
  border-top: 1px solid var(--border);
}

.explain__summary {
  list-style: none;
  padding: 0.65rem 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.explain__summary::-webkit-details-marker {
  display: none;
}

.explain__summary::before {
  content: "▶";
  display: inline-block;
  width: 1.1em;
  font-size: 0.7em;
  color: var(--accent);
  transform: translateY(-0.05em);
}

.explain[open] .explain__summary::before {
  transform: rotate(90deg) translate(0.05em, 0.05em);
}

.explain__summary:focus-visible {
  outline: none;
  color: var(--text);
  box-shadow: var(--ring);
  border-radius: 0.2rem;
}

.explain__body {
  margin: 0.5rem 0 0;
  padding: 0.65rem 0 0.25rem 0.15rem;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--muted);
}

.explain__body p {
  margin: 0 0 0.9rem;
}

.explain__body p:last-child {
  margin-bottom: 0;
}

.explain__form-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.explain__list {
  margin: 0 0 0.9rem;
  padding-left: 1.1rem;
}

.explain__list li {
  margin-bottom: 0.65rem;
}

.explain__list li:last-child {
  margin-bottom: 0;
}

.explain__math {
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
  font-size: 0.92em;
  color: var(--text);
  white-space: nowrap;
}

.explain__math .sup {
  position: relative;
  top: -0.35em;
  font-size: 0.8em;
  font-weight: 600;
}

.page-footer {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.footer-link {
  font-size: 0.82rem;
  color: var(--muted);
  text-decoration: none;
}

.footer-link:hover {
  color: var(--text);
  text-decoration: underline;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --surface: #1c2028;
    --text: #e8e6e3;
    --muted: #9a9a95;
    --border: #2f343d;
    --accent: #6bcf97;
    --accent-tint: #1a2e24;
  }

  .site-logo {
    color: #e05050;
  }

  .site-logo:hover {
    color: #ff7070;
  }

  .swatch--selected {
    background: #252a32;
  }

  .result__value {
    color: var(--text);
  }
}
