/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-card: #212433;
  --bg-input: #161921;
  --border: #2a2d3a;
  --text-primary: #e4e6f0;
  --text-secondary: #8b8fa3;
  --text-muted: #5c6072;
  --accent: #4a9eff;
  --accent-hover: #3d8ae6;
  --accent-glow: rgba(74, 158, 255, 0.15);
  --green: #34d399;
  --orange: #fb923c;
  --red: #f87171;
  --purple: #a78bfa;
  --yellow: #fbbf24;
  --resistor-body: #e8d5b7;
  --resistor-lead: #c0c0c0;
}

[data-theme="light"] {
  --bg-primary: #f4f5f7;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #eeeff2;
  --border: #d4d6dc;
  --text-primary: #1a1b2e;
  --text-secondary: #5a5d6e;
  --text-muted: #9498a8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-glow: rgba(37, 99, 235, 0.12);
  --green: #059669;
  --orange: #ea580c;
  --red: #dc2626;
  --purple: #7c3aed;
  --yellow: #d97706;
  --resistor-body: #e8d5b7;
  --resistor-lead: #c0c0c0;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  min-height: 100vh;
}

/* ===== Header ===== */
.header {
  grid-area: header;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 18px 28px;
}
.header-inner { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.logo { font-size: 1.4rem; font-weight: 700; color: var(--text-primary); }
.subtitle { font-size: 0.875rem; color: var(--text-secondary); }

/* ===== Sidebar ===== */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sidebar-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 4px 20px 12px;
}
.tool-nav { list-style: none; flex: 1; }
.tool-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.9rem;
  cursor: pointer;
  transition: var(--transition);
  border-left: 3px solid transparent;
  font-family: inherit;
}
.tool-btn:hover { background: var(--bg-card); color: var(--text-primary); }
.tool-btn.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.github-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: var(--transition);
}
.github-link:hover { color: var(--text-primary); }

/* Theme toggle */
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  line-height: 1;
  transition: var(--transition);
}
.theme-toggle:hover {
  border-color: var(--text-muted);
  color: var(--text-primary);
}

/* ===== Main Content ===== */
.main-content {
  grid-area: main;
  padding: 28px 32px;
  overflow-y: auto;
}

/* ===== Tool Panel ===== */
.tool-panel { display: none; }
.tool-panel.active { display: block; }

.tool-header { margin-bottom: 24px; }
.tool-header h2 { font-size: 1.5rem; margin-bottom: 6px; }
.tool-header p { color: var(--text-secondary); font-size: 0.9rem; }
.result-actions { display: flex; align-items: center; gap: 10px; margin: -8px 0 16px; }
.result-copy-btn { white-space: nowrap; }
.result-copy-status { color: var(--green); font-size: 0.82rem; min-height: 1.2em; }

.tool-body {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

/* ===== Form Elements ===== */
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }
.form-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}
.form-row {
  display: flex;
  gap: 12px;
  align-items: center;
}
.form-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  transition: var(--transition);
  min-width: 0;
}
.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-input::placeholder { color: var(--text-muted); }
.form-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 32px 10px 12px;
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b8fa3' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  font-family: inherit;
}
.form-select:focus { outline: none; border-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-secondary:hover { border-color: var(--text-muted); color: var(--text-primary); }

/* ===== Results ===== */
.result-box {
  margin-top: 20px;
  padding: 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.result-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.result-value {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 1.1rem;
  color: var(--accent);
  word-break: break-all;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 16px;
}
.result-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}
.result-item .unit { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; }
.result-item .value {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 1.05rem;
  color: var(--text-primary);
  word-break: break-all;
}
.result-item.highlight {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.result-item.highlight .value { color: var(--accent); font-weight: 700; }

/* ===== Color Code ===== */
.color-bands { display: flex; gap: 12px; flex-wrap: wrap; margin: 16px 0; align-items: flex-end; }
.band-group { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.band-label { font-size: 0.75rem; color: var(--text-muted); }
.band-color {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
  transition: var(--transition);
}
.band-color:hover { border-color: var(--accent); transform: scale(1.1); }
.band-color.band-active {
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
  transform: scale(1.15);
}
.band-color:focus-visible, .color-swatch:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
.band-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 4px 8px;
  font-size: 0.8rem;
  cursor: pointer;
  max-width: 100px;
  font-family: inherit;
}

.color-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px;
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: var(--transition);
}
.color-swatch:hover { border-color: #fff; transform: scale(1.2); }
.color-swatch.swatch-selected {
  border-color: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  transform: scale(1.15);
}

/* ===== Ohm's Law ===== */
.ohms-diagram-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.ohms-circuit {
  width: 100%;
  max-width: 360px;
  height: auto;
}
.ohms-wire {
  stroke: var(--text-secondary);
}
.ohms-resistor {
  stroke: var(--text-secondary);
}
.ohms-accent-wire {
  stroke: var(--accent);
}
.ohms-accent-fill {
  fill: var(--accent);
}
.ohms-accent-text {
  fill: var(--accent);
}
.ohms-label {
  fill: var(--text-primary);
}
.ohms-dash {
  stroke: var(--text-muted);
  fill: var(--text-muted);
}

.ohms-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 12px;
}
.ohms-unit-select {
  width: 75px;
  flex-shrink: 0;
}

.ohms-result-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Formula reference cards */
.ohms-formula-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  margin-top: 16px;
}
.ohms-formula-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
}
.ohms-formula-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}
.ohms-formula-card-eq {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

@media (max-width: 768px) {
  .ohms-form {
    grid-template-columns: 1fr;
  }
}

/* ===== Formula Box ===== */
.formula-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 12px;
  text-align: center;
}

/* ===== Quantity Tabs ===== */
.quantity-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.quantity-tab {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  white-space: nowrap;
}
.quantity-tab:hover {
  border-color: var(--text-muted);
  color: var(--text-primary);
}
.quantity-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ===== Footer ===== */
.footer {
  grid-area: footer;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 12px 28px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas:
      "header"
      "sidebar"
      "main"
      "footer";
  }
  .sidebar {
    flex-direction: row;
    overflow-x: auto;
    padding: 8px 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-title { display: none; }
  .tool-nav { display: flex; gap: 4px; flex: none; }
  .tool-btn {
    white-space: nowrap;
    font-size: 0.8rem;
    padding: 6px 14px;
    border-left: none;
    border-radius: 20px;
  }
  .tool-btn.active { border-left: none; }
  .sidebar-footer { display: none; }
  .main-content { padding: 16px; }
  .result-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* ===== Color Code Resistor Visual ===== */
.resistor-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 20px 0;
  gap: 0;
}
.resistor-body {
  width: 200px;
  height: 48px;
  background: var(--resistor-body);
  border-radius: 6px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.resistor-lead {
  width: 40px;
  height: 3px;
  background: var(--resistor-lead);
}
.band {
  width: 12px;
  height: 40px;
  border-radius: 2px;
}

/* Swatch hint */
.swatch-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Voltage Divider ===== */
.vd-diagram-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.vd-circuit {
  width: 100%;
  max-width: 320px;
  height: auto;
}
.vd-wire {
  stroke: var(--text-secondary);
}
.vd-resistor {
  stroke: var(--text-secondary);
}
.vd-label {
  fill: var(--text-muted);
}
.vd-param {
  fill: var(--text-primary);
}
.vd-accent-text {
  fill: var(--accent);
}
.vd-junction {
  fill: var(--accent);
  stroke: none;
}

.vd-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.vd-input-group { }
.vd-unit-static {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.vd-unit-select {
  width: 80px;
  flex-shrink: 0;
}

.vd-results {
  margin-bottom: 12px;
}

.vd-result-primary {
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px 24px;
  text-align: center;
  margin-bottom: 16px;
}
.vd-vout-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}
.vd-vout-value {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}
.vd-vout-unit {
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--text-secondary);
}
.vd-vout-eq {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  word-break: break-all;
}

.vd-formula-highlight {
  color: var(--accent);
  font-weight: 600;
}

/* Ratio bar */
.vd-ratio-bar-wrap {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.vd-ratio-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.vd-ratio-labels-bottom {
  margin-bottom: 0;
  margin-top: 6px;
}
.vd-ratio-bar {
  height: 10px;
  background: var(--bg-primary);
  border-radius: 5px;
  overflow: hidden;
}
.vd-ratio-r2 {
  height: 100%;
  background: var(--accent);
  border-radius: 5px;
  transition: width 0.3s ease;
  min-width: 0;
}

@media (max-width: 768px) {
  .vd-form {
    grid-template-columns: 1fr;
  }
  .vd-vout-value {
    font-size: 1.5rem;
  }
}

/* ===== Buck Inductor Calculator ===== */
.buck-diagram-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}
.buck-circuit {
  width: 100%;
  max-width: 520px;
  height: auto;
}
.buck-wire {
  stroke: var(--text-secondary);
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.buck-switch-fill {
  fill: var(--text-secondary);
}
.buck-accent-fill {
  fill: var(--accent);
}
.buck-label {
  fill: var(--text-muted);
}
.buck-label-text {
  fill: var(--text-primary);
}
.buck-junction {
  fill: var(--accent);
  stroke: none;
}
.buck-dash {
  stroke: var(--text-muted);
  stroke-width: 1.2;
  stroke-dasharray: 4 3;
  fill: none;
}
.buck-dash-fill {
  fill: var(--text-muted);
}
.buck-accent-text {
  fill: var(--accent);
}

.buck-section {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.buck-section:last-of-type {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
.buck-section--tip {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.buck-section-header {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
}

.buck-form {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.buck-unit-static {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  width: 85px;
  text-align: center;
  flex-shrink: 0;
}
.buck-unit-static--dim {
  color: var(--text-muted);
}

.buck-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 4px;
}
.buck-unit-select {
  width: 85px;
  flex-shrink: 0;
}

.buck-results {
  margin-bottom: 8px;
}

/* Result cards */
.buck-result-card {
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 14px;
}
.buck-result-card--primary {
  background: var(--accent-glow);
  border: 1px solid var(--accent);
}
.buck-result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.buck-result-main { }
.buck-result-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}
.buck-result-value {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
}
.buck-result-unit {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-secondary);
}
.buck-result-meta {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  word-break: break-all;
}
.buck-result-meta strong {
  color: var(--accent);
}

.buck-result-badge {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  white-space: nowrap;
}
.buck-badge--ok {
  background: rgba(52, 211, 153, 0.15);
  color: var(--green);
  border: 1px solid var(--green);
}
.buck-badge--warn {
  background: rgba(251, 146, 60, 0.15);
  color: var(--orange);
  border: 1px solid var(--orange);
}

/* Select & custom input */
.buck-select-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.buck-select-group {
  margin-bottom: 0;
}
.buck-l-select {
  flex: 1;
  min-width: 140px;
}
.buck-l-custom {
  width: 120px;
  flex-shrink: 0;
}

/* Sub line in result items */
.buck-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Warning */
.buck-warn {
  background: rgba(251, 146, 60, 0.12);
  border: 1px solid var(--orange);
  color: var(--orange);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 14px;
  text-align: center;
}

/* Tip text */
.buck-tip-text {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 12px;
}
.buck-checklist {
  list-style: none;
  padding: 0;
}
.buck-checklist li {
  font-size: 0.85rem;
  color: var(--text-primary);
  padding: 6px 0;
  line-height: 1.5;
}

/* Formula separator */
.buck-formula-sep {
  color: var(--border);
  margin: 0 6px;
}

@media (max-width: 768px) {
  .buck-form {
    grid-template-columns: 1fr;
  }
  .buck-select-wrap {
    grid-template-columns: 1fr;
  }
  .buck-unit-static {
    width: 65px;
  }
  .buck-unit-select {
    width: 65px;
  }
  .buck-result-value {
    font-size: 1.3rem;
  }
  .buck-diagram-wrap {
    display: none;
  }
}

/* ===== Crystal Load Capacitance ===== */
.crystal-diagram-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.crystal-ref-img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
}

.crystal-mode-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.crystal-mode-btn {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.88rem;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  text-align: center;
}
.crystal-mode-btn:hover {
  border-color: var(--text-muted);
  color: var(--text-primary);
}
.crystal-mode-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.crystal-panel {
  display: none;
}
.crystal-panel.active {
  display: block;
}

.crystal-form {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.crystal-unit-static {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  width: 85px;
  text-align: center;
  flex-shrink: 0;
}

.crystal-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 4px;
}

.crystal-result {
  margin-bottom: 8px;
}

.crystal-result-card {
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 14px;
}
.crystal-result-card--primary {
  background: var(--accent-glow);
  border: 1px solid var(--accent);
}

.crystal-badge {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  white-space: nowrap;
  background: rgba(52, 211, 153, 0.15);
  color: var(--green);
  border: 1px solid var(--green);
}

.crystal-section--tip {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  margin-top: 20px;
}
.crystal-section-header {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

@media (max-width: 768px) {
  .crystal-form {
    grid-template-columns: 1fr;
  }
  .crystal-unit-static {
    width: 65px;
  }
}

/* ===== Orbitvo Tools application shell ===== */
body { display: block; background: var(--bg-primary); min-height: 100vh; }
.app-shell { min-height: 100vh; display: flex; }
.sidebar { width: 260px; position: fixed; inset: 0 auto 0 0; z-index: 10; padding: 0; border-right: 1px solid var(--border); background: var(--bg-secondary); box-shadow: 1px 0 0 rgba(15,23,42,.02); }
.brand { display: flex; align-items: center; gap: 11px; min-height: 82px; padding: 18px 20px; border-bottom: 1px solid var(--border); color: var(--text-primary); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 24px; font-weight: 700; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: -.01em; }
.brand small { margin-top: 2px; color: var(--text-muted); font-size: 11px; }
.sidebar-title { padding: 18px 20px 8px; letter-spacing: .08em; font-weight: 700; }
.tool-nav { padding: 0 8px; }
.tool-btn { border-left: 0; border-radius: 8px; margin: 1px 0; padding: 11px 12px; font-size: 14px; }
.tool-btn.active { border-left: 0; background: var(--accent-glow); }
.sidebar-footer { padding: 15px 20px; align-items: flex-start; flex-direction: column; gap: 7px; font-size: 12px; }
.sidebar-footer span { color: var(--text-muted); }
.sidebar-footer i { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--green); }
.github-link { color: var(--text-secondary); }
.main { flex: 1; min-width: 0; margin-left: 260px; padding: 38px 48px; }
.main-shell { width: 100%; max-width: 1040px; margin: 0 auto; }
.family-bar { display: flex; align-items: center; gap: 9px; min-height: 38px; margin-bottom: 24px; color: var(--text-muted); font-size: 13px; }
.family-name { color: var(--text-primary); font-weight: 700; }
.family-bar .theme-toggle { margin-left: auto; width: 36px; height: 36px; border-radius: 9px; font-size: 17px; }
.main-content { padding: 0; overflow: visible; }
.tool-panel.active { display: block; }
.tool-header { margin: 0 0 16px; }
.tool-header h2 { font-size: clamp(1.6rem, 3vw, 2rem); letter-spacing: -.035em; margin-bottom: 7px; }
.tool-header p { max-width: 680px; font-size: 15px; line-height: 1.6; }
.tool-body { padding: 28px; border-radius: 14px; box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.result-actions { margin: 0 0 14px; }
.result-copy-btn { min-height: 38px; padding: 8px 13px; }
.tool-guide { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 0 0 24px; padding: 11px 13px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg-input); color: var(--text-secondary); font-size: 12px; }
.tool-guide span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.tool-guide b { display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; background: var(--accent-glow); color: var(--accent); font-size: 11px; }
.form-label { margin-bottom: 7px; color: var(--text-secondary); font-size: 13px; }
.form-input, .form-select { min-height: 42px; padding-top: 9px; padding-bottom: 9px; }
.result-grid { margin-top: 18px; gap: 12px; }
.result-item { padding: 14px 12px; }
.formula-box { line-height: 1.55; text-align: left; }
.footer { display: flex; justify-content: space-between; gap: 16px; margin-top: 54px; padding: 20px 0 4px; background: transparent; border-top: 1px solid var(--border); font-size: 12px; text-align: left; }
@media (max-width: 768px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; max-height: none; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { min-height: 62px; padding: 12px 16px; }
  .sidebar-title { display: none; }
  .tool-nav { padding: 7px 12px; overflow-x: auto; }
  .tool-btn { padding: 7px 12px; }
  .sidebar-footer { display: none; }
  .main { margin-left: 0; padding: 20px 16px; }
  .family-bar { margin-bottom: 18px; }
  .tool-body { padding: 18px; }
  .tool-guide { gap: 7px 12px; margin-bottom: 18px; }
  .footer { display: grid; margin-top: 36px; }
}
