:root {
  color-scheme: light;
  --bg: #f4f8fb;
  --surface: #ffffff;
  --surface-soft: #eef5f8;
  --surface-muted: #e5eef3;
  --surface-overlay: rgba(255, 255, 255, 0.97);
  --border: rgba(18, 43, 58, 0.14);
  --control-border: rgba(18, 43, 58, 0.22);
  --ink: #172a36;
  --muted: #607786;
  --accent: #087b5d;
  --accent3: #087aa3;
  --accent-contrast: #ffffff;
  --warn: #b87800;
  --danger: #a72a2a;
  --danger-soft: rgba(167, 42, 42, 0.09);
  --button-bg: rgba(255, 255, 255, 0.78);
  --button-hover: rgba(8, 122, 163, 0.10);
  --button-text: #17313f;
  --selected-bg: rgba(8, 122, 163, 0.12);
  --selected-border: rgba(8, 122, 163, 0.52);
  --chip-text: #344d5b;
  --footer-surface: rgba(18, 43, 58, 0.04);
  --overlay: rgba(238, 246, 250, 0.96);
  --backdrop: rgba(20, 36, 46, 0.46);
  --shadow: 0 20px 40px rgba(21, 48, 63, 0.12);
  --shadow-heavy: 0 20px 60px rgba(21, 48, 63, 0.22);
  --page-glow-a: rgba(58, 240, 162, 0.10);
  --page-glow-b: rgba(91, 200, 255, 0.14);
  --page-glow-c: rgba(91, 200, 255, 0.08);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080c10;
  --surface: #0f1520;
  --surface-soft: rgba(255, 255, 255, 0.04);
  --surface-muted: #243041;
  --surface-overlay: rgba(8, 12, 16, 0.98);
  --border: rgba(255, 255, 255, 0.09);
  --control-border: rgba(255, 255, 255, 0.28);
  --ink: #dde8ff;
  --muted: #6d85ab;
  --accent: #3af0a2;
  --accent3: #5bc8ff;
  --accent-contrast: #07101a;
  --warn: #ffcd3a;
  --danger: #ffb2b2;
  --danger-soft: rgba(255, 80, 80, 0.12);
  --button-bg: rgba(255, 255, 255, 0.10);
  --button-hover: rgba(255, 255, 255, 0.20);
  --button-text: rgba(255, 255, 255, 0.92);
  --selected-bg: rgba(91, 200, 255, 0.14);
  --selected-border: rgba(91, 200, 255, 0.70);
  --chip-text: rgba(221, 232, 255, 0.72);
  --footer-surface: rgba(0, 0, 0, 0.15);
  --overlay: rgba(8, 12, 16, 0.96);
  --backdrop: rgba(0, 0, 0, 0.72);
  --shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  --shadow-heavy: 0 20px 60px rgba(0, 0, 0, 0.35);
  --page-glow-a: rgba(58, 240, 162, 0.10);
  --page-glow-b: rgba(91, 200, 255, 0.10);
  --page-glow-c: rgba(91, 200, 255, 0.08);
}

body {
  background: var(--bg);
}

body::before {
  background:
    radial-gradient(ellipse 800px 500px at 10% -10%, var(--page-glow-a) 0%, transparent 60%),
    radial-gradient(ellipse 700px 600px at 90% 5%, var(--page-glow-b) 0%, transparent 60%),
    radial-gradient(ellipse 900px 700px at 55% 95%, var(--page-glow-c) 0%, transparent 60%);
}

.hdr-badge,
.header-btn,
.step-tab,
.pg-btn,
.icon-btn,
.cup-size-option {
  border-color: var(--control-border);
  background: var(--button-bg);
  color: var(--button-text);
}

.header-btn:hover,
.step-tab:hover,
.pg-btn:not(:disabled):hover,
.icon-btn:hover,
.cup-size-option:hover,
.cup-size-btn:hover {
  background: var(--button-hover);
}

.cup-size-picker {
  border-color: var(--control-border);
  background: var(--surface-overlay);
  box-shadow: var(--shadow-heavy);
}

.cup-size-option.active {
  background: var(--selected-bg);
  border-color: var(--selected-border);
  color: var(--ink);
}

.field,
.syrup-panel,
.recipe-summary,
.dtag,
.drink-ingredient,
.drink-detail-recipe {
  background: var(--surface-soft);
  border-color: var(--control-border);
}

select {
  color: var(--ink);
}

option {
  color: var(--ink);
  background: var(--surface);
}

.chip {
  border-color: var(--control-border);
  background: var(--surface-soft);
  color: var(--chip-text);
}

.chip.active,
.step-tab.active {
  background: var(--selected-bg);
  border-color: var(--selected-border);
  color: var(--ink);
}

.col {
  box-shadow: var(--shadow);
}

.col-head,
.col-count {
  background: var(--surface-soft);
}

.icon-btn {
  color: var(--ink);
}

.section-divider {
  border-color: var(--control-border);
}

.col-foot {
  background: var(--footer-surface);
}

#toast {
  border-color: var(--control-border);
  box-shadow: var(--shadow-heavy);
}

.foot strong,
.lnk {
  color: var(--ink);
}

.drink-detail {
  background: var(--overlay);
}

.drink-detail-card {
  background: var(--surface);
  border-color: var(--border);
  color: var(--ink);
  box-shadow: var(--shadow-heavy);
}

.detail-back-btn,
.detail-fav-btn {
  background: var(--surface-muted);
  color: var(--ink);
}

.drink-detail-source {
  color: var(--muted);
}

.drink-detail-recipe {
  color: var(--ink);
}

.theme-toggle {
  min-width: 128px;
  justify-content: center;
}

/* Supabase bridge + guest auth share the main Drink Shoppe theme tokens. */
html body .dsb-hidden { display: none !important; }
html body .dsb-auth {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--overlay);
  color: var(--ink);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}
html body .dsb-auth-card,
html body dialog.dsb-dialog,
html body .dsb-menu {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--control-border);
  box-shadow: var(--shadow-heavy);
}
html body .dsb-auth-card {
  width: min(760px, 100%);
  border: 1px solid var(--control-border);
  border-radius: 22px;
  padding: 22px;
}
html body .dsb-auth-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
html body .dsb-stack,
html body .dsb-auth form { display: grid; gap: 10px; }
html body .dsb-auth input,
html body .dsb-settings input[type="number"],
html body .dsb-field input,
html body .dsb-field select,
html body .dsb-dialog input,
html body .dsb-dialog select,
html body .dsb-dialog textarea,
html body .dsb-inventory-row input[type="number"],
html body .dsb-order input,
html body .dsb-order select {
  background: var(--surface-soft);
  color: var(--ink);
  border-color: var(--control-border);
}
html body .dsb-auth input,
html body .dsb-dialog input,
html body .dsb-dialog select,
html body .dsb-dialog textarea {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid var(--control-border);
  border-radius: 9px;
}
html body .dsb-auth input::placeholder,
html body .dsb-dialog input::placeholder,
html body .dsb-dialog textarea::placeholder { color: var(--muted); opacity: .82; }
html body .dsb-btn {
  appearance: none;
  border: 1px solid var(--control-border);
  background: var(--button-bg);
  color: var(--button-text);
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}
html body .dsb-btn:hover:not(:disabled) { background: var(--button-hover); }
html body .dsb-btn.primary {
  background: var(--accent3);
  border-color: var(--accent3);
  color: var(--accent-contrast);
  text-shadow: none;
}
html body .dsb-btn.primary:hover:not(:disabled) { filter: brightness(.94); background: var(--accent3); }
html body .dsb-btn.compact { padding: 6px 9px; font-size: .78rem; }
html body .dsb-btn.danger,
html body .dsb-menu button[style*="ffb2b2"] { color: var(--danger) !important; }
html body .dsb-btn:disabled { opacity: .5; cursor: not-allowed; }
html body .dsb-note {
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--accent3) 28%, transparent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent3) 9%, transparent);
  color: var(--ink);
  margin: 10px 0;
}
html body .dsb-note.error {
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  background: var(--danger-soft);
  color: var(--danger);
}
html body .dsb-menu-wrap { position: relative; }
html body .dsb-menu {
  position: absolute;
  left: 0;
  right: auto;
  top: calc(100% + 6px);
  z-index: 2000;
  width: 220px;
  min-width: 200px;
  min-height: 0 !important;
  height: auto !important;
  max-height: min(60dvh, 360px);
  overflow-y: auto;
  border: 1px solid var(--control-border);
  border-radius: 14px;
  padding: 6px;
}
html body .dsb-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 9px;
  cursor: pointer;
  font: inherit;
}
html body .dsb-menu button:hover { background: var(--button-hover); }
html body dialog.dsb-dialog {
  width: min(1000px, calc(100vw - 24px));
  max-height: 88vh;
  border: 1px solid var(--control-border);
  border-radius: 18px;
  padding: 0;
}
html body dialog.dsb-dialog::backdrop { background: var(--backdrop); }
html body .dsb-dialog-inner { padding: 18px; }
html body .dsb-dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}
html body .dsb-dialog-head h2 { margin: 0; }
html body .dsb-dialog-subtitle { margin: 5px 0 0; color: var(--muted); line-height: 1.35; }
html body .dsb-close {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 1px solid var(--control-border);
  border-radius: 10px;
  background: var(--button-bg);
  color: var(--ink);
  cursor: pointer;
}
html body .dsb-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 14px; }
html body .dsb-tab {
  border: 1px solid var(--control-border);
  background: var(--button-bg);
  color: var(--muted);
  padding: 9px 13px;
  border-radius: 999px;
  cursor: pointer;
}
html body .dsb-tab.active { border-color: var(--selected-border); background: var(--selected-bg); color: var(--ink); }
html body .dsb-settings,
html body .dsb-inventory-row,
html body .dsb-order,
html body .dsb-random,
html body .dsb-random-card,
html body .dsb-compose-row {
  border-color: var(--border);
  background: var(--surface-soft);
}
html body .dsb-settings { border: 1px solid var(--border); }
html body .dsb-inventory-row,
html body .dsb-order,
html body .dsb-random-card,
html body .dsb-compose-row { border: 1px solid var(--border); }
html body .dsb-stepper button {
  border-color: var(--control-border);
  background: var(--button-bg);
  color: var(--ink);
}
html body .dsb-count { background: var(--accent3); color: var(--accent-contrast); }
html body .dsb-detail-order { border-top-color: var(--border); }
html body .dsb-order-list,
html body .dsb-inventory-list { color: var(--ink); }
html body .dsb-dialog [style*="border-bottom:1px solid rgba(255,255,255"] { border-bottom-color: var(--border) !important; }

/* Invitation history */
html body .dsb-invite-history { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
html body .dsb-invite-history h3 { margin: 0 0 10px; }
html body .dsb-invite-list { display: grid; gap: 8px; }
html body .dsb-invite-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
}
html body .dsb-invite-main { min-width: 0; display: grid; gap: 3px; }
html body .dsb-invite-main strong { overflow-wrap: anywhere; }
html body .dsb-invite-main span { color: var(--muted); font-size: .78rem; text-transform: capitalize; }
html body .dsb-invite-meta { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: .78rem; }
html body .dsb-status { padding: 4px 8px; border-radius: 999px; border: 1px solid var(--border); font-weight: 800; }
html body .dsb-status.pending { color: var(--accent3); border-color: color-mix(in srgb, var(--accent3) 48%, transparent); }
html body .dsb-status.accepted { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 48%, transparent); }
html body .dsb-status.expired { color: var(--muted); }

/* Guest browsing/auth */
html[data-auth-mode="guest"] body .dsb-guest-note { color: var(--accent3); font-weight: 700; }
html body .dsb-guest-auth-dialog { width: min(760px, calc(100vw - 24px)); }
html body .dsb-guest-help { margin: 16px 0 0; color: var(--muted); text-align: center; font-size: .9rem; }
html body .dsb-gateway-notice {
  position: fixed;
  z-index: 12000;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(620px, calc(100vw - 24px));
  box-shadow: var(--shadow-heavy);
}
html body .dsb-startup-error { max-width: 760px; margin: 40px auto; padding: 20px; color: var(--ink); font-family: system-ui; }
html body .dsb-startup-error pre { white-space: pre-wrap; }

@media (max-width: 760px) {
  .theme-toggle { min-width: 0; }
  html body .dsb-auth-grid,
  html body .dsb-settings,
  html body .dsb-two,
  html body .dsb-compose-grid { grid-template-columns: 1fr; }
  html body .dsb-inventory-row { grid-template-columns: 1fr 1fr; }
  html body .dsb-order-grid,
  html body .dsb-compose-row { grid-template-columns: 1fr; }

  /* Open the mobile menu into the viewport instead of off the left edge. */
  html body .dsb-menu-wrap .dsb-menu {
    left: 0;
    right: auto;
    width: min(240px, calc(100vw - 24px));
    min-width: min(200px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
  }

  html body .dsb-invite-row { align-items: flex-start; flex-direction: column; }
  html body .dsb-invite-meta { justify-content: flex-start; }
}
