/* ============ base.css ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  -moz-text-size-adjust: none; -webkit-text-size-adjust: none; text-size-adjust: none;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility; scroll-behavior: smooth;
}
body {
  min-height: 100dvh; line-height: 1.6;
  font-family: var(--font-body, sans-serif); font-size: var(--text-base);
  color: var(--color-text); background-color: var(--color-bg);
}
img, picture, video, canvas, svg { display: block; max-width: 100%; height: auto; }
input, button, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, h4, h5, h6 { text-wrap: balance; line-height: 1.15; }
p, li { text-wrap: pretty; }
::selection { background: color-mix(in oklab, var(--color-primary) 25%, transparent); color: var(--color-text); }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 3px; border-radius: var(--radius-sm); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
button { cursor: pointer; background: none; border: none; }
a, button, input, select { transition: color var(--transition-interactive), background var(--transition-interactive), border-color var(--transition-interactive), box-shadow var(--transition-interactive); }

/* ============ Design tokens ============ */
:root {
  --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, 2.25rem);
  --text-2xl: clamp(2rem, 1.2rem + 2.5vw, 3rem);

  --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; --space-20: 5rem; --space-24: 6rem;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', 'Helvetica Neue', sans-serif;

  --radius-sm: 0.375rem; --radius-md: 0.625rem; --radius-lg: 1rem; --radius-xl: 1.25rem; --radius-full: 9999px;
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* Light — warm cream + deep pine + gold + cranberry */
:root, [data-theme='light'] {
  --color-bg: #faf6ee;
  --color-surface: #ffffff;
  --color-surface-2: #fdfaf3;
  --color-surface-offset: #f3ecdc;
  --color-divider: #e6dcc6;
  --color-border: #ddd0ae;

  --color-text: #1c2b22;
  --color-text-muted: #5c6a5f;
  --color-text-faint: #9aa298;
  --color-text-inverse: #faf6ee;

  --color-primary: #0f3d2e;
  --color-primary-hover: #0a2d21;
  --color-primary-active: #071f17;
  --color-primary-highlight: #dbe6de;

  --color-accent: #b8862c;
  --color-accent-hover: #9a6f22;
  --color-accent-highlight: #f1e2bf;

  --color-cranberry: #8c2f39;
  --color-cranberry-highlight: #f0d9db;

  --shadow-sm: 0 1px 2px rgba(28, 43, 34, 0.06);
  --shadow-md: 0 8px 24px rgba(28, 43, 34, 0.10);
  --shadow-lg: 0 20px 48px rgba(28, 43, 34, 0.16);
}

[data-theme='dark'] {
  --color-bg: #10160f;
  --color-surface: #161d15;
  --color-surface-2: #1a2118;
  --color-surface-offset: #1e2a1e;
  --color-divider: #2a352a;
  --color-border: #354233;

  --color-text: #e8ece5;
  --color-text-muted: #a1ab9c;
  --color-text-faint: #6c766a;
  --color-text-inverse: #10160f;

  --color-primary: #6fae8e;
  --color-primary-hover: #8ec2a5;
  --color-primary-active: #a9d3ba;
  --color-primary-highlight: #223228;

  --color-accent: #e0b658;
  --color-accent-hover: #edc978;
  --color-accent-highlight: #3a301c;

  --color-cranberry: #d97e87;
  --color-cranberry-highlight: #3a2224;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
}

/* ============ Layout ============ */
.page {
  max-width: 1200px;
  margin-inline: auto;
  padding: var(--space-6) var(--space-6) var(--space-16);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  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: 34px; height: 34px; color: var(--color-accent); flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-title { font-family: var(--font-display); font-weight: 600; font-size: var(--text-lg); }
.brand-sub { font-size: var(--text-xs); color: var(--color-text-muted); }

.theme-toggle {
  width: 40px; height: 40px; border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  background: var(--color-surface); border: 1px solid var(--color-border);
  color: var(--color-text); box-shadow: var(--shadow-sm);
}
.theme-toggle:hover { background: var(--color-surface-offset); }

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: var(--space-8);
  align-items: start;
  flex: 1;
}

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

/* ============ Input card ============ */
.input-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-8) var(--space-6);
  box-shadow: var(--shadow-md);
  position: sticky;
  top: var(--space-6);
}

.input-card h1 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.input-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-6);
}

.stepper {
  display: flex;
  align-items: stretch;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--color-surface-2);
}

.stepper-btn {
  width: 52px;
  font-size: var(--text-xl);
  font-weight: 500;
  color: var(--color-primary);
  background: var(--color-surface-offset);
  flex-shrink: 0;
}
.stepper-btn:hover { background: var(--color-primary-highlight); }
.stepper-btn:active { transform: scale(0.96); }

#guestCount {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  text-align: center;
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 600;
  color: var(--color-text);
  -moz-appearance: textfield;
}
#guestCount::-webkit-outer-spin-button,
#guestCount::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.stepper-unit {
  display: block;
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: var(--space-2);
  margin-bottom: var(--space-6);
}

.quick-sizes {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.quick-btn {
  flex: 1;
  min-width: 52px;
  padding: var(--space-2) var(--space-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  background: var(--color-surface-2);
}
.quick-btn:hover { border-color: var(--color-primary); color: var(--color-primary); }
.quick-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-text-inverse);
}

.ratios-panel {
  margin-top: var(--space-6);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-divider);
}

.ratios-panel summary {
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.ratios-panel summary::-webkit-details-marker { display: none; }
.ratios-panel summary::before {
  content: '›';
  display: inline-block;
  font-size: 1.1em;
  transition: transform var(--transition-interactive);
}
.ratios-panel[open] summary::before { transform: rotate(90deg); }

.ratios-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-3);
  margin-bottom: var(--space-3);
}

.ratios-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.ratio-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-xs);
}

.ratio-row label {
  color: var(--color-text-muted);
  flex: 1;
}

.ratio-row .ratio-inputs {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
  white-space: nowrap;
}

.ratio-row input {
  width: 60px;
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  font-size: var(--text-xs);
  text-align: center;
}

.reset-btn {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.reset-btn:hover { color: var(--color-cranberry); }

/* ============ Results ============ */
.results-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-8);
  flex-wrap: wrap;
}

.results-header h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-xl);
}

#peopleEcho { color: var(--color-accent); }

.print-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}
.print-btn:hover { border-color: var(--color-primary); color: var(--color-primary); }

.group-block { margin-bottom: var(--space-10); }

.group-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 2px solid var(--color-divider);
}

.group-note {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--color-accent);
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-4);
}

.item-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-interactive), box-shadow var(--transition-interactive);
}
.item-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.item-qty {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1;
  margin-bottom: var(--space-2);
}

.item-card.addon .item-qty { color: var(--color-cranberry); }

.item-name {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: var(--space-1);
}

.item-unit {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.rounding-note {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: var(--space-2);
}

.page-footer {
  margin-top: var(--space-16);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-divider);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* ============ Print ============ */
@media print {
  .topbar, .input-card, .print-btn, .page-footer, .rounding-note { display: none; }
  .layout { grid-template-columns: 1fr; }
  body { background: white; color: black; }
  .item-card { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
}
