/* ===== Design tokens ===== */
:root,
[data-theme='light'] {
  /* Surfaces — warm parchment/apothecary paper */
  --color-bg: #f6f1e6;
  --color-surface: #fdfaf3;
  --color-surface-2: #efe7d5;
  --color-border: #ddd0b3;
  --color-divider: #e6dcc4;

  /* Text — deep bark */
  --color-text: #29261c;
  --color-text-muted: #6f6752;
  --color-text-faint: #a89c7d;
  --color-text-inverse: #fbf7ec;

  /* Primary accent — herbal green */
  --color-primary: #2f5233;
  --color-primary-hover: #23401f;
  --color-primary-active: #1a2f18;
  --color-primary-highlight: #dbe6d4;

  /* Secondary accent — tincture amber */
  --color-amber: #b3661e;
  --color-amber-highlight: #f2e0c4;

  --shadow-card: 0 1px 2px rgba(41, 38, 28, 0.05), 0 8px 24px rgba(41, 38, 28, 0.06);
}

[data-theme='dark'] {
  --color-bg: #171d15;
  --color-surface: #1f261b;
  --color-surface-2: #263021;
  --color-border: #37432f;
  --color-divider: #2c3626;

  --color-text: #ece9dd;
  --color-text-muted: #a6a289;
  --color-text-faint: #6c6a57;
  --color-text-inverse: #1a1f16;

  --color-primary: #7fb787;
  --color-primary-hover: #97c99e;
  --color-primary-active: #6aa373;
  --color-primary-highlight: #2c3a28;

  --color-amber: #e0a256;
  --color-amber-highlight: #3a2e1a;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

:root {
  --font-display: 'Zodiak', 'Iowan Old Style', Georgia, serif;
  --font-body: 'General Sans', 'Segoe UI', system-ui, sans-serif;

  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html { color-scheme: light dark; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-base);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-16);
}

a { color: var(--color-primary); }

/* ===== Header ===== */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: var(--space-4);
  margin-bottom: var(--space-8);
}

.brand { display: flex; align-items: center; gap: var(--space-3); }

.brand-mark { width: 40px; height: 40px; color: var(--color-primary); flex-shrink: 0; }

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }

.brand-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-lg);
  color: var(--color-text);
}

.brand-sub {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.theme-toggle:hover { background: var(--color-surface-2); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-moon { display: none; }
[data-theme='dark'] .theme-toggle .icon-sun { display: none; }
[data-theme='dark'] .theme-toggle .icon-moon { display: block; }

/* ===== Layout ===== */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: var(--space-6);
  align-items: start;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-8);
}

@media (max-width: 640px) {
  .panel { padding: var(--space-5); }
}

.page-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-xl);
  margin: 0 0 var(--space-2);
  color: var(--color-text);
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-6);
}

/* ===== Form fields ===== */
.field-group { margin-bottom: var(--space-6); }
.field-group:last-child { margin-bottom: 0; }

.field-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-2);
  color: var(--color-text);
}

.field-note {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin: var(--space-2) 0 0;
}

input[type='number'],
select {
  width: 100%;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type='number']:focus,
select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-highlight);
}

.input-with-unit {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-surface);
}
.input-with-unit input {
  border: none;
  border-radius: 0;
  flex: 1;
}
.input-with-unit input:focus { box-shadow: none; }
.input-with-unit:has(input:focus) {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-highlight);
}
.input-with-unit .unit {
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  border-left: 1px solid var(--color-border);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%236f6752' stroke-width='1.6'%3E%3Cpath d='M6 8l4 4 4-4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-10);
}

.custom-ratio-row {
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.custom-ratio-row:not([hidden]) { display: flex; }
.custom-ratio-prefix { font-size: var(--text-sm); color: var(--color-text-muted); font-weight: 600; }
.custom-ratio-row input { max-width: 120px; }

.field-hint-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-2);
}
.field-hint { font-size: var(--text-xs); color: var(--color-text-muted); }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--color-primary);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  white-space: nowrap;
}
.link-btn:hover { color: var(--color-primary-hover); }

/* Segmented control */
.segmented {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: 100%;
}
.segmented-btn {
  flex: 1;
  border: none;
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.segmented-btn + .segmented-btn { border-left: 1px solid var(--color-border); }
.segmented-btn.is-active {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}
.segmented-btn:not(.is-active):hover { background: var(--color-surface-2); }

/* ===== Results ===== */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}
@media (max-width: 480px) { .stat-grid { grid-template-columns: 1fr; } }

.stat-card {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.stat-card-accent {
  background: var(--color-primary-highlight);
  border-color: var(--color-primary);
}

.stat-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}
.stat-value {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.1;
}
.stat-sub { font-size: var(--text-xs); color: var(--color-text-muted); }

.result-block { margin-bottom: var(--space-8); }
.result-block:last-of-type { margin-bottom: var(--space-6); }

.block-heading {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: var(--text-base);
  margin: 0 0 var(--space-3);
  color: var(--color-text);
}
.block-note {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-4);
}

.bottle-recommend {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  background: var(--color-amber-highlight);
  border: 1px solid var(--color-amber);
  border-radius: var(--radius-md);
  padding: var(--space-5);
}
.bottle-recommend .bottle-icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  color: var(--color-amber);
}
.bottle-recommend-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-lg);
  color: var(--color-text);
  margin: 0 0 2px;
}
.bottle-recommend-sub {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0;
}

.table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius-md); }

.breakdown-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
  min-width: 420px;
}
.breakdown-table th,
.breakdown-table td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-divider);
  white-space: nowrap;
}
.breakdown-table thead th {
  background: var(--color-surface-2);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  font-weight: 600;
}
.breakdown-table tbody tr:last-child td { border-bottom: none; }
.breakdown-table tbody tr.is-best { background: var(--color-primary-highlight); }
.breakdown-table td.cell-strong { font-weight: 700; color: var(--color-text); }

/* Methodology */
.methodology {
  border-top: 1px solid var(--color-divider);
  padding-top: var(--space-5);
}
.methodology summary {
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
}
.methodology ul {
  margin: var(--space-4) 0 0;
  padding-left: var(--space-5);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.methodology a { color: var(--color-primary); }

/* ===== Spirit Blend Calculator (independent panel) ===== */
.blend-panel {
  margin-top: var(--space-8);
}

.blend-header { margin-bottom: var(--space-6); }
.blend-header .page-title { margin-bottom: var(--space-2); }
.blend-header .page-subtitle { margin-bottom: 0; }

.blend-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: var(--space-8);
  align-items: start;
}
@media (max-width: 860px) {
  .blend-grid { grid-template-columns: 1fr; gap: var(--space-6); }
}

.strength-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
@media (max-width: 480px) {
  .strength-fields { grid-template-columns: 1fr; }
}

.strength-input-row {
  display: flex;
  gap: var(--space-2);
}
.strength-input-row input { flex: 1.2; min-width: 0; }
.strength-input-row select { flex: 1; min-width: 0; padding-right: var(--space-6); }

.target-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.target-row .field-label { margin-bottom: 0; }
.target-value-input { max-width: 190px; flex-shrink: 0; }
.target-value-input input {
  text-align: right;
  font-weight: 700;
  padding: var(--space-3) var(--space-2);
  min-width: 0;
}
.target-value-input .unit { padding: 0 var(--space-3); white-space: nowrap; }

.blend-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--color-primary-highlight), var(--color-amber-highlight));
  outline: none;
  margin: var(--space-3) 0;
  cursor: pointer;
}
.blend-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 3px solid var(--color-surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: transform 0.15s ease;
}
.blend-slider::-webkit-slider-thumb:hover { transform: scale(1.1); }
.blend-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 3px solid var(--color-surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}
.blend-slider:disabled { opacity: 0.4; cursor: not-allowed; }

.slider-scale {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  gap: var(--space-3);
}

.stat-grid-blend { margin-bottom: var(--space-4); }

.blend-check {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  margin: 0 0 var(--space-6);
}

#blendError {
  color: var(--color-amber);
  font-weight: 600;
}

/* Footer */
.site-footer {
  text-align: center;
  margin-top: var(--space-10);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}
