:root {
  --bg: #0f0f11;
  --surface: #1a1a1f;
  --surface-alt: #22222a;
  --border: #2e2e38;
  --text: #e8e6e1;
  --text-dim: #9a9890;
  --text-muted: #6b6860;
  --accent: #E8A838;
  --accent-dim: #c48a2a;
  --accent-glow: rgba(232, 168, 56, 0.15);
  --green: #5cb85c;
  --red: #e05555;
  --yellow: #f0c040;
  --radius: 8px;
  --radius-lg: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
}

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

html { scroll-behavior: smooth; }

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

a { color: var(--accent); text-decoration: none; }
a:hover, a:focus { color: #f0c060; text-decoration: underline; }

.container { max-width: 1120px; margin: 0 auto; padding: 0 20px; }

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--text);
  font-size: 1.1rem;
  white-space: nowrap;
}
.logo:hover, .logo:focus { text-decoration: none; color: var(--accent); }
.logo svg { flex-shrink: 0; }

.site-header nav {
  display: flex;
  gap: 20px;
}

.site-header nav a {
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 500;
}

.site-header nav a:hover, .site-header nav a:focus {
  color: var(--accent);
}

/* Hero */
.hero {
  padding: 64px 0 48px;
  text-align: center;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
}

.hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--text) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-sub {
  font-size: 1.15rem;
  color: var(--text-dim);
  max-width: 560px;
  margin: 0 auto 32px;
}

.hero-stats {
  display: flex;
  justify-content: center;
  gap: 40px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat strong {
  font-size: 1.6rem;
  color: var(--accent);
  font-weight: 800;
}

.stat span {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Section styles */
section { padding: 48px 0; }
section:nth-child(even) { background: var(--surface); }

h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.section-lead {
  color: var(--text-dim);
  margin-bottom: 28px;
  max-width: 640px;
}

/* Controls */
.controls-section { padding-bottom: 0; }

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.preset-btn {
  padding: 8px 18px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}

.preset-btn:hover, .preset-btn:focus {
  border-color: var(--accent);
  color: var(--accent);
}

.preset-btn.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

.sort-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* Table */
.table-section { padding-top: 24px; }
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead {
  background: var(--surface-alt);
}

th {
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  border-bottom: 2px solid var(--border);
  position: relative;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

th:hover { color: var(--accent); }
th[data-dir="asc"]::after { content: " ↑"; color: var(--accent); }
th[data-dir="desc"]::after { content: " ↓"; color: var(--accent); }

th:last-child, td:last-child { text-align: center; }
td:first-child { font-weight: 700; text-align: center; }

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--accent-glow); }

.soap-name {
  font-weight: 600;
  white-space: nowrap;
}

.score-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.score-bar .bar {
  width: 48px;
  height: 6px;
  background: var(--surface-alt);
  border-radius: 3px;
  overflow: hidden;
}

.score-bar .fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.score-bar .num {
  font-weight: 600;
  min-width: 18px;
  text-align: right;
}

.score-bar .fill.s-9, .score-bar .fill.s-10 { background: var(--green); }
.score-bar .fill.s-7, .score-bar .fill.s-8 { background: var(--yellow); }
.score-bar .fill.s-5, .score-bar .fill.s-6 { background: var(--accent); }
.score-bar .fill.s-1, .score-bar .fill.s-2, .score-bar .fill.s-3, .score-bar .fill.s-4 { background: var(--red); }

.total-score {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--accent);
}

/* Calculator */
.calc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.calc-field label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.calc-field input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font);
}

.calc-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.calc-result {
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.calc-output {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.calc-number {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent);
}

.calc-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.calc-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Matrix */
.matrix-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.matrix-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.matrix-card h3 {
  font-size: 1rem;
  margin-bottom: 8px;
  color: var(--accent);
}

.matrix-card p {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.matrix-tag {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 0.78rem;
  font-weight: 600;
}

.matrix-tag.good { background: rgba(92, 184, 92, 0.15); color: var(--green); }
.matrix-tag.mid { background: rgba(240, 192, 64, 0.15); color: var(--yellow); }
.matrix-tag.warn { background: rgba(224, 85, 85, 0.15); color: var(--red); }

.chemistry-note {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.chemistry-note h4 {
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.chemistry-note p {
  font-size: 0.9rem;
  color: var(--text-dim);
  line-height: 1.7;
}

/* Mistakes */
.mistakes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.mistake-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
}

.mistake-num {
  font-size: 2.4rem;
  font-weight: 900;
  color: var(--accent-glow);
  line-height: 1;
  margin-bottom: 8px;
}

.mistake-card h3 {
  font-size: 1rem;
  margin-bottom: 8px;
}

.mistake-card p {
  font-size: 0.88rem;
  color: var(--text-dim);
  line-height: 1.65;
}

/* Edge cases */
.edge-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

details {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

summary {
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

summary::-webkit-details-marker { display: none; }
summary::before { content: "+"; color: var(--accent); font-weight: 700; font-size: 1.1rem; }
details[open] summary::before { content: "−"; }

summary:hover { background: var(--accent-glow); }

details p {
  padding: 0 18px 16px;
  font-size: 0.88rem;
  color: var(--text-dim);
  line-height: 1.7;
}

/* Methodology */
.method-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.method-item {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.method-item h4 {
  font-size: 0.9rem;
  color: var(--accent);
  margin-bottom: 6px;
}

.method-item p {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.6;
}

.method-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Footer */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 40px 0 20px;
}

.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 24px;
  margin-bottom: 28px;
}

.footer-grid strong {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: var(--text);
}

.footer-grid p, .footer-grid a {
  font-size: 0.85rem;
  color: var(--text-dim);
  display: block;
  margin-bottom: 4px;
}

.footer-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  gap: 8px;
}

/* Responsive */
@media (max-width: 768px) {
  .header-inner { height: 52px; }
  .logo-text { font-size: 0.95rem; }
  .site-header nav { gap: 12px; }
  .site-header nav a { font-size: 0.82rem; }
  .hero { padding: 40px 0 32px; }
  .hero-stats { gap: 24px; }
  section { padding: 36px 0; }
  .calc-result { gap: 20px; }
  .calc-number { font-size: 1.4rem; }
  .presets { gap: 6px; }
  .preset-btn { padding: 6px 14px; font-size: 0.8rem; }
}

@media (max-width: 480px) {
  .hero h1 { font-size: 1.5rem; }
  .hero-sub { font-size: 1rem; }
  .stat strong { font-size: 1.3rem; }
  th, td { padding: 8px 10px; font-size: 0.82rem; }
  .score-bar .bar { width: 32px; }
}

/* Focus styles */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Print */
@media print {
  .site-header, .controls-section, .calculator-section, .site-footer { display: none; }
  body { background: #fff; color: #000; }
  .table-wrapper { border: 1px solid #ccc; }
  th { background: #eee; }
}


/* Factory-injected deployment helpers. The AI owns the site design above this block. */
.ad-unit {
  width: min(100%, 720px);
  min-height: 120px;
  margin: 24px auto;
  display: block;
}

.legal-page {
  width: min(900px, calc(100% - 32px));
  margin: 40px auto;
}

.factory-fallback-nav {
  width: min(900px, calc(100% - 32px));
  margin: 24px auto 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  font-size: 0.95rem;
}

.factory-fallback-nav a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}
