/* ══════════════════════════════════════════════════════════════
   DESIGN TOKENS
   All theming flows from here. Change values in :root to retheme.
   ══════════════════════════════════════════════════════════════ */

:root {
  /* ── COLORS ── */
  --bg: #ffffff;
  --surface: #fafafa;
  --surface-hover: #f7f7f7;

  /* Borders */
  --border: #f7f7f7;
  --border-strong: #edece9;

  /* Text */
  --text: #1a1a1a;
  --text-secondary: #6b6862;
  --text-tertiary: #9b9790;

  /* Interactive accent */
  --accent: #202020;
  --accent-text: #ffffff;

  /* ── SPACING SCALE (4px grid) ── */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* ── TYPOGRAPHY SCALE ── */
  --text-xs: 10px;
  --text-sm: 12px;
  --text-base: 14px;
  --text-lg: 16px;
  --text-xl: 24px;
  --text-2xl: 28px;

  --weight-medium: 500;
  --weight-semibold: 600;

  --line-height-body: 24px;

  /* ── RADII ── */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;

  /* ── TRANSITIONS ── */
  --transition-fast: 0.15s ease;
  --transition-slow: 0.25s ease;

  /* ── SHADOWS ── */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);

  /* ── LAYOUT ── */
  --max-width-content: 640px;
  --font-family: 'Inter', system-ui, -apple-system, sans-serif;

  --page-padding-top: 124px;
  --page-padding-bottom: 124px;
  --page-padding-x: var(--space-3);

  --header-height: 56px;
}

@media (max-width: 640px) {
  :root {
    --page-padding-top: 80px;
    --page-padding-bottom: 48px;
  }
}


/* ══════════════════════════════════════════════════════════════
   RESET
   ══════════════════════════════════════════════════════════════ */

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-family);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}


/* ══════════════════════════════════════════════════════════════
   UTILITIES
   ══════════════════════════════════════════════════════════════ */

.hidden { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

kbd {
  font-family: var(--font-family);
  font-size: 11px;
  padding: 1px 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}


/* ══════════════════════════════════════════════════════════════
   FIXED BRAND HEADER
   ══════════════════════════════════════════════════════════════ */

.brand-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  z-index: 100;
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.brand-logo svg {
  height: 24px;
  width: auto;
  display: block;
}

/* Mobile reset icon — visible only on small screens */
.header-reset-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.header-reset-btn:hover,
.header-reset-btn:active {
  background: var(--surface);
  color: var(--text);
}

@media (max-width: 640px) {
  .header-reset-btn {
    display: inline-flex;
  }
}


/* ══════════════════════════════════════════════════════════════
   LAYOUT
   ══════════════════════════════════════════════════════════════ */

.wrap {
  max-width: var(--max-width-content);
  margin: 0 auto;
  padding: var(--page-padding-top) var(--page-padding-x) var(--page-padding-bottom);
}


/* ══════════════════════════════════════════════════════════════
   PAGE HEADER
   ══════════════════════════════════════════════════════════════ */

.header {
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}

.header h1 {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
  line-height: 34px;
  color: var(--text);
}

.header p {
  font-size: var(--text-base);
  color: var(--text-secondary);
  line-height: var(--line-height-body);
  margin: var(--space-3) 0;
}


/* ══════════════════════════════════════════════════════════════
   TAB BAR (underline style)
   ══════════════════════════════════════════════════════════════ */

.tab-bar {
  position: relative;
  display: flex;
  gap: var(--space-6);
  border-bottom: 1px solid var(--border-strong);
  margin: 0 var(--space-3) var(--space-10);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.tab-bar::-webkit-scrollbar { display: none; }

.tab-btn {
  padding: var(--space-3) 0;
  border: none;
  background: transparent;
  font-family: var(--font-family);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--text-tertiary);
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition-fast);
}

.tab-btn.active { color: var(--text); }
.tab-btn:not(.active):hover { color: var(--text); }

.tab-indicator {
  position: absolute;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: var(--accent);
  width: 0;
  transition: left var(--transition-slow), width var(--transition-slow);
  pointer-events: none;
}


/* ══════════════════════════════════════════════════════════════
   BAND TOGGLE
   ══════════════════════════════════════════════════════════════ */

.band-toggle {
  display: flex;
  gap: var(--space-1);
  padding: 6px;
  background: var(--surface-hover);
  border-radius: var(--radius-pill);
  width: fit-content;
  margin: 0 auto var(--space-6);
}

.band-toggle-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  font-family: var(--font-family);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-tertiary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.band-toggle-btn.active {
  background: var(--accent);
  color: var(--accent-text);
}

.band-toggle-btn:not(.active):hover {
  color: var(--text);
}


/* ══════════════════════════════════════════════════════════════
   CARDS
   ══════════════════════════════════════════════════════════════ */

.card {
  background-color: var(--surface);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
}

.card-table {
  padding: var(--space-3);
  margin-bottom: var(--space-6);
}

.card-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-5);
}


/* ══════════════════════════════════════════════════════════════
   COLOR SWATCHES
   ══════════════════════════════════════════════════════════════ */

.swatches {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.swatch-box {
  padding: var(--space-3);
  margin-bottom: var(--space-2);
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: transform var(--transition-fast), outline-offset var(--transition-fast);
  flex-shrink: 0;
}

.swatch:hover { transform: scale(1.08); }

.swatch.selected {
  outline: 2px solid currentColor;
  outline-offset: 4px;
}


/* ══════════════════════════════════════════════════════════════
   RESULT DISPLAY
   ══════════════════════════════════════════════════════════════ */

.result {
  text-align: center;
  padding: var(--space-5) var(--space-3);
  margin-bottom: var(--space-2);
  min-height: 104px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.result-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.result-value {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--text);
}

.result-value.empty {
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--text-tertiary);
}

.result-tol {
  font-size: var(--text-base);
  color: var(--text-secondary);
  margin-top: var(--space-1);
}

.copy-btn {
  position: relative;
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-fast), background var(--transition-fast);
}

.copy-btn:hover {
  color: var(--text);
  background: var(--surface);
}

.copy-feedback {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-text);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.copy-btn.copied .copy-feedback {
  opacity: 1;
}


/* ══════════════════════════════════════════════════════════════
   RESET BUTTON (in-page)
   ══════════════════════════════════════════════════════════════ */

.reset-btn {
  display: block;
  margin: var(--space-10) auto 0;
  padding: var(--space-2) var(--space-4);
  background: none;
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.reset-btn:hover {
  background-color: var(--surface-hover);
  color: var(--text);
}

.hint-text {
  text-align: center;
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}


/* ══════════════════════════════════════════════════════════════
   RESISTOR SVG
   ══════════════════════════════════════════════════════════════ */

.resistor-wrap {
  padding: var(--space-6) 0;
}

.resistor-wrap svg {
  width: 100%;
  max-width: 420px;
  display: block;
  margin: 0 auto;
}

.band-label {
  font-family: var(--font-family);
  font-size: 8px;
  font-weight: var(--weight-medium);
  fill: var(--text-tertiary);
}


/* ══════════════════════════════════════════════════════════════
   REVERSE LOOKUP
   ══════════════════════════════════════════════════════════════ */

.lookup-intro {
  font-size: var(--text-base);
  color: var(--text-secondary);
  line-height: var(--line-height-body);
  margin-bottom: var(--space-5);
}

.lookup-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.lookup-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.lookup-field label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}

.lookup-field input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-family);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--text);
  caret-color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  -webkit-appearance: none;
  appearance: none;
  -moz-appearance: textfield;
}

.lookup-field input[type="number"]::-webkit-outer-spin-button,
.lookup-field input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.lookup-field input:focus {
  outline: 2px solid var(--text);
  outline-offset: -1px;
}


/* ══════════════════════════════════════════════════════════════
   CUSTOM SELECT (radix-style)
   ══════════════════════════════════════════════════════════════ */

.select {
  position: relative;
  width: 100%;
}

.select-trigger {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-family);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.select-trigger:hover {
  border-color: var(--text-tertiary);
}

.select.open .select-trigger {
  border-color: var(--text);
  outline: 2px solid var(--text);
  outline-offset: -1px;
}

.select-value {
  flex: 1;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.select-chevron {
  color: var(--text-secondary);
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}

.select.open .select-chevron {
  transform: rotate(180deg);
}

.select-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-1);
  box-shadow: var(--shadow-md);
  z-index: 50;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  max-height: 240px;
  overflow-y: auto;
}

.select.open .select-menu {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.select-option {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.select-option:hover,
.select-option.focused {
  background: var(--surface);
  color: var(--text);
}

.select-option.selected {
  color: var(--text);
  font-weight: var(--weight-semibold);
}


/* ══════════════════════════════════════════════════════════════
   LOOKUP RESULT
   ══════════════════════════════════════════════════════════════ */

.lookup-result {
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  text-align: center;
}

.lookup-bands {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.lookup-band {
  width: 24px;
  height: 48px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
}

.lookup-readout {
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  line-height: var(--line-height-body);
}

.lookup-readout strong {
  color: var(--text);
  font-weight: var(--weight-semibold);
}

.lookup-empty {
  text-align: center;
  font-size: var(--text-base);
  color: var(--text-tertiary);
  padding: var(--space-5);
}


/* ══════════════════════════════════════════════════════════════
   REFERENCE TABLES
   ══════════════════════════════════════════════════════════════ */

.ref-table {
  width: 100%;
  font-size: var(--text-base);
}

.ref-table th {
  text-align: left;
  padding: var(--space-3) var(--space-2);
  border-bottom: 1px solid var(--border-strong);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.ref-table td {
  padding: var(--space-3) var(--space-2);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-secondary);
}

.color-dot {
  display: inline-block;
  width: var(--space-3);
  height: var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  vertical-align: middle;
  margin-right: var(--space-2);
  flex-shrink: 0;
}

.color-cell {
  display: inline-flex;
  align-items: center;
  color: var(--text);
}


/* ══════════════════════════════════════════════════════════════
   HOW-TO SECTION
   ══════════════════════════════════════════════════════════════ */

.howto p {
  font-size: var(--text-base);
  line-height: var(--line-height-body);
  color: var(--text-secondary);
  margin-bottom: var(--space-5);
}

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

.howto strong {
  color: var(--text);
  font-weight: var(--weight-semibold);
}
