:root {
  --bg: #0e2f24;
  --panel: #0b261d;
  --accent: #d4af37;
  --accent-2: #ffffff;
  --text: #ffffff;
  --muted: #d4e4da;
  --border: #174634;
  --card: linear-gradient(145deg, #11372a, #0b261d);
  --die-fill: rgba(212, 175, 55, 0.7);
  --kerf-waste: rgba(248, 113, 113, 0.22);
  --edge-waste: rgba(180, 190, 200, 0.22);
  --metal-tone: linear-gradient(145deg, rgba(212, 175, 55, 0.22), rgba(212, 175, 55, 0.12));
  --via-tone: linear-gradient(145deg, rgba(248, 171, 69, 0.25), rgba(248, 171, 69, 0.15));
  --substrate-tone: linear-gradient(140deg, rgba(16, 185, 129, 0.35), rgba(15, 118, 110, 0.2));
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  font-family: 'Space Grotesk', 'Segoe UI', 'Helvetica Neue', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(circle at 20% 20%, rgba(212, 175, 55, 0.08), transparent 30%),
              radial-gradient(circle at 80% 10%, rgba(255, 255, 255, 0.06), transparent 20%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--text); text-decoration: none; }

a:hover { color: var(--accent); }

.page-shell { max-width: 1100px; margin: 0 auto; padding: 32px 24px 64px; }

.topbar { display: flex; align-items: center; gap: 18px; justify-content: space-between; margin-bottom: 24px; }
.dev-banner { width: 100%; padding: 8px 12px; background: linear-gradient(90deg, #f59e0b, #f97316); color: #0b0f18; border-radius: 10px; font-weight: 700; text-align: center; margin-bottom: 10px; }
.nav-links { display: flex; gap: 14px; align-items: center; }
.nav-links a { padding: 8px 10px; border-radius: 10px; transition: background 0.2s; }
.nav-links a:hover { background: rgba(255,255,255,0.05); }

.nav-user { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.theme-picker select { background: #0b1220; color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.theme-picker button[disabled], .theme-picker select:disabled { opacity: 0.6; cursor: not-allowed; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-name { font-weight: 700; letter-spacing: -0.02em; }
.brand-sub { color: var(--muted); font-size: 13px; }
.logo-img img { height: 44px; width: 44px; }
.logo-img.footer img { height: 38px; width: 38px; }

.content { display: flex; flex-direction: column; gap: 32px; }
.section-head { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.section-title-block { width: 100%; min-width: 0; }

.hero { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 18px; align-items: stretch; padding: 20px; border-radius: 20px; background: linear-gradient(120deg, rgba(34,211,238,0.12), rgba(168,85,247,0.12)); border: 1px solid var(--border); }

h1, h2, h3 { margin: 8px 0; letter-spacing: -0.02em; }
.lede { color: var(--text); font-size: 17px; max-width: 720px; }
.muted { color: var(--muted); }
.eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: 0.08em; font-size: 12px; margin: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.grid.two-col { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); }
.card.highlight { border-color: rgba(125, 211, 252, 0.4); box-shadow: 0 0 0 1px rgba(125,211,252,0.2), var(--shadow); }
.card h3 { margin-top: 0; }

.tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; margin-bottom: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,0.06); color: var(--text); border-radius: 12px; padding: 6px 10px; font-size: 13px; border: 1px solid var(--border); }
.pill.small { font-size: 12px; padding: 5px 8px; }

.actions { display: flex; gap: 10px; margin-top: 14px; }
button, .primary, .ghost { cursor: pointer; border: none; }
.primary { background: linear-gradient(135deg, #d4af37, #b68d22); color: #0e2f24; padding: 10px 16px; border-radius: 12px; font-weight: 700; border: 1px solid #d4af37; }
.ghost { border: 1px solid var(--border); color: var(--text); background: transparent; padding: 10px 14px; border-radius: 12px; }
.ghost:hover { border-color: var(--accent); }

.footer { margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; color: var(--muted); }
.footer-left { display: flex; align-items: center; gap: 10px; }

.bullets { list-style: disc; padding-left: 20px; color: var(--muted); }
.bullets li { margin-bottom: 6px; }

.small { font-size: 12px; }
.form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; color: var(--text); }
.form input, .form textarea, .form select { background: #0b1220; color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 12px; font-size: 15px; }
input[type="number"] { padding-right: 34px; color-scheme: dark; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { background: linear-gradient(180deg, rgba(212,175,55,0.14), rgba(212,175,55,0.05)); border-left: 1px solid var(--border); border-radius: 0 12px 12px 0; width: 22px; height: calc(100% - 6px); margin: 3px 3px 3px 0; opacity: 1; }
input[type="number"]:hover::-webkit-inner-spin-button,
input[type="number"]:hover::-webkit-outer-spin-button { background: linear-gradient(180deg, rgba(212,175,55,0.25), rgba(212,175,55,0.12)); border-color: var(--accent); }
input[type="number"]::-moz-focus-outer { border: 0; }

.inline-form { display: flex; align-items: center; gap: 10px; }

.filter-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; align-items: end; background: rgba(255,255,255,0.04); padding: 12px; border-radius: 12px; border: 1px solid var(--border); }
.filter-group { display: flex; flex-direction: column; gap: 6px; }
.filter-group input[type="text"],
.filter-group select { background: #0b1220; border: 1px solid var(--border); border-radius: 10px; color: var(--text); padding: 10px; }
.filter-group.wide { grid-column: span 2; min-width: 300px; }
.filter-group.full { grid-column: 1 / -1; }
.tag-scroll { max-height: 160px; overflow-y: auto; display: flex; flex-wrap: wrap; gap: 8px; padding: 6px; border: 1px solid var(--border); border-radius: 10px; background: #0b1220; }
.tag-scroll input { display: none; }
.tag-scroll .tag-toggle { cursor: pointer; transition: all 0.15s ease; }
.tag-scroll .tag-toggle .pill { padding: 6px 10px; border-radius: 12px; border: 1px solid var(--border); display: inline-flex; align-items: center; background: rgba(255,255,255,0.04); }
.tag-scroll .tag-toggle input { display: none; }
.tag-scroll .tag-toggle input:checked + .pill { border-color: #d4af37; background: #f7d66b; color: #0e2f24; }
.tag-scroll .tag-toggle:hover .pill { border-color: #d4af37; }
.tag-scroll::-webkit-scrollbar { width: 8px; }
.tag-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
.tag-scroll::-webkit-scrollbar-track { background: rgba(255,255,255,0.03); }
.filter-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-checkbox { display: inline-flex; align-items: center; }
.tag-checkbox input { display: none; }
.tag-checkbox .pill { cursor: pointer; }
.tag-checkbox input:checked + .pill { border-color: var(--accent); background: rgba(212, 175, 55, 0.15); }
.selected-tags { display: flex; gap: 6px; flex-wrap: wrap; }

.row { display: flex; gap: 10px; align-items: center; }
.card .row { margin-top: 12px; }
.card .row + .row { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.card-head h3 { margin: 0; }

.alert { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); }
.alert.success { background: rgba(34,197,94,0.1); border-color: rgba(34,197,94,0.4); }

.narrow { max-width: 680px; }
.center { text-align: center; align-items: center; }

.calculator-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.calc-panel { display: flex; flex-direction: column; gap: 12px; }
.calc-illustration { position: sticky; top: 20px; }
.stat-grid .card { min-height: 140px; }
.live-note { font-size: 13px; color: var(--muted); }
.wafer-card { display: flex; flex-direction: column; gap: 12px; }
.wafer-visual { position: relative; border: 1px solid var(--border); border-radius: 16px; padding: 28px 16px; background: radial-gradient(circle at 20% 20%, rgba(212,175,55,0.08), rgba(212,175,55,0.02)); overflow: hidden; display: grid; place-items: center; }
.wafer-canvas { width: 100%; height: auto; display: block; border-radius: 12px; background: linear-gradient(135deg, rgba(255,255,255,0.03), rgba(255,255,255,0.05)); max-width: 640px; }
.wafer-meta { display: none; }
.wafer-legend { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.stack-section { display: flex; flex-direction: column; gap: 12px; }
.stack-grid { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 16px; align-items: start; }
.metal-card { display: flex; flex-direction: column; gap: 12px; }
.metal-stack { display: flex; flex-direction: column-reverse; align-items: center; gap: 10px; min-height: 280px; padding: 12px; background: radial-gradient(circle at 40% 20%, rgba(212,175,55,0.08), rgba(212,175,55,0.02)); border: 1px solid var(--border); border-radius: 12px; }
.stack-layer { width: calc(100% - var(--shrink, 0px)); max-width: 320px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: rgba(255,255,255,0.05); box-shadow: var(--shadow); text-align: center; position: relative; }
.stack-layer span { font-weight: 700; letter-spacing: -0.01em; color: var(--text); display: block; margin-bottom: 6px; }
.stack-layer.metal { background: var(--metal-tone); border-color: rgba(212,175,55,0.35); }
.stack-layer.metal .metal-bar { width: 100%; border-radius: 8px; background: linear-gradient(145deg, rgba(241, 196, 83, 0.55), rgba(212, 175, 55, 0.45)); box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2); }
.stack-layer.substrate { background: var(--substrate-tone); border-color: rgba(16,185,129,0.6); }
.stack-layer.oxide { background: linear-gradient(140deg, rgba(125, 211, 252, 0.25), rgba(59, 130, 246, 0.18)); border-color: rgba(125,211,252,0.6); }
.stack-layer.poly { background: linear-gradient(145deg, rgba(248, 180, 0, 0.25), rgba(249, 115, 22, 0.2)); border-color: rgba(248, 180, 0, 0.55); }
.layer-body { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.stack-via { width: calc(100% - 20px); max-width: 300px; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px; border-radius: 10px; border: 1px dashed rgba(255,255,255,0.15); background: var(--via-tone); box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25); }
.stack-via .via-bar { width: 18px; border-radius: 8px; background: linear-gradient(180deg, rgba(248, 171, 69, 0.6), rgba(212, 175, 55, 0.35)); box-shadow: 0 0 0 1px rgba(0,0,0,0.3); }
.stack-via span { font-size: 13px; color: var(--text); }

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .nav-links { flex-wrap: wrap; }
  .calculator-grid { grid-template-columns: 1fr; }
  .calc-illustration { position: relative; }
  .stack-grid { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: 1fr; }
  .filter-group.wide { grid-column: 1 / -1; min-width: 0; }
}

@media (max-width: 1000px) {
  .section-head { flex-direction: column; align-items: flex-start; }
  .section-title-block { width: 100%; min-width: 0; }
  .filter-bar { width: 100%; }
}
