:root {
  color-scheme: light;
  --page: #f5f5f7;
  --surface-1: #ffffff;
  --surface-2: #f0f0f2;
  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-muted: #86868b;
  --gridline: #e5e5ea;
  --border: rgba(0, 0, 0, 0.06);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 12px 28px rgba(0, 0, 0, 0.06);
  --shadow-control: 0 1px 1px rgba(0, 0, 0, 0.03);
  --accent: #0071e3;
  --protein: #0071e3;
  --carbs: #ff9500;
  --fat: #34c759;
  --kcal: #ffcc00;
  --protein-track: #dcebfc;
  --carbs-track: #ffe9cc;
  --fat-track: #dbf5e4;
  --kcal-track: #fff3c2;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #000000;
    --surface-1: #1c1c1e;
    --surface-2: #2c2c2e;
    --text-primary: #f5f5f7;
    --text-secondary: #98989d;
    --text-muted: #8e8e93;
    --gridline: #38383a;
    --border: rgba(255, 255, 255, 0.08);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 28px rgba(0, 0, 0, 0.4);
    --shadow-control: none;
    --accent: #0a84ff;
    --protein: #0a84ff;
    --carbs: #ff9f0a;
    --fat: #30d158;
    --kcal: #ffd60a;
    --protein-track: #132743;
    --carbs-track: #3a2811;
    --fat-track: #0f2e1c;
    --kcal-track: #332b07;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #000000;
  --surface-1: #1c1c1e;
  --surface-2: #2c2c2e;
  --text-primary: #f5f5f7;
  --text-secondary: #98989d;
  --text-muted: #8e8e93;
  --gridline: #38383a;
  --border: rgba(255, 255, 255, 0.08);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 28px rgba(0, 0, 0, 0.4);
  --shadow-control: none;
  --accent: #0a84ff;
  --protein: #0a84ff;
  --carbs: #ff9f0a;
  --fat: #30d158;
  --kcal: #ffd60a;
  --protein-track: #132743;
  --carbs-track: #3a2811;
  --fat-track: #0f2e1c;
  --kcal-track: #332b07;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 20px 72px;
}

.page[hidden] {
  display: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: rgba(245, 245, 247, 0.78);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
}

:root[data-theme="dark"] .topbar {
  background: rgba(28, 28, 30, 0.72);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .topbar {
    background: rgba(28, 28, 30, 0.72);
  }
}

.topbar-title {
  flex: 1;
  min-width: 0;
}

.topbar h1 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0;
}

.icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: var(--surface-2);
  color: var(--text-primary);
  border-radius: 50%;
  cursor: pointer;
  transition: background-color 180ms ease, transform 120ms ease;
  flex: 0 0 auto;
}

.icon-button:active {
  transform: scale(0.94);
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0;
  visibility: hidden;
  transition: opacity 220ms ease;
  z-index: 60;
}

.drawer-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(320px, 86vw);
  background: var(--surface-1);
  z-index: 61;
  padding: 20px;
  transform: translateX(-100%);
  transition: transform 260ms cubic-bezier(0.25, 1, 0.5, 1);
  overflow-y: auto;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.15);
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.drawer-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 500;
  padding: 13px 10px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background-color 150ms ease;
}

.nav-item:hover {
  background: var(--surface-2);
}

.nav-item.active {
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 700;
}

.drawer-section {
  margin-bottom: 20px;
  margin-top: 20px;
}

.drawer-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.drawer-section .segmented {
  width: 100%;
}

.drawer-section .segmented button {
  flex: 1;
  text-align: center;
}

.drawer-footnote {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.6;
  border-top: 1px solid var(--gridline);
  padding-top: 16px;
  margin-top: 8px;
}

.day-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.day-tab {
  border: none;
  background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: 980px;
  padding: 11px 18px;
  font-size: 0.92rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-control);
  transition: background-color 180ms ease, color 180ms ease;
}

.day-tab.active {
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: stretch;
  margin-bottom: 20px;
  padding: 18px;
  background: var(--surface-1);
  border-radius: 18px;
  box-shadow: var(--shadow-card);
}

@media (min-width: 720px) {
  .toolbar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px 24px;
  }
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 100%;
}

select.metric-select {
  -webkit-appearance: none;
  appearance: none;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--text-primary);
  background-color: var(--surface-2);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2386868b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px 16px;
  border: none;
  border-radius: 10px;
  padding: 10px 34px 10px 12px;
  flex: 1 1 140px;
  min-width: 0;
  cursor: pointer;
}

:root[data-theme="dark"] select.metric-select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2398989d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) select.metric-select {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2398989d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  }
}

.dir-toggle {
  border: none;
  background: var(--surface-2);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.3;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  flex: 1 1 auto;
  min-width: 0;
  transition: background-color 150ms ease;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  border-radius: 980px;
  padding: 3px;
  background: var(--surface-2);
  max-width: 100%;
}

.segmented button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 980px;
  padding: 9px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  font-family: inherit;
  transition: background-color 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

.segmented button.active {
  background: var(--surface-1);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.result-count {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 4px 4px 12px;
}

.meal-list {
  background: var(--surface-1);
  border-radius: 18px;
  padding: 4px 20px;
  box-shadow: var(--shadow-card);
}

.meal-row {
  padding: 16px 0;
  border-top: 1px solid var(--gridline);
}

.meal-row:first-of-type {
  border-top: none;
}

.offer-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.offer-counter {
  background: var(--surface-1);
  border-radius: 18px;
  padding: 6px 20px 4px;
  box-shadow: var(--shadow-card);
}

.offer-counter-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.006em;
  margin: 14px 0 4px;
}

.offer-item {
  padding: 12px 0;
  border-top: 1px solid var(--gridline);
}

.offer-item:first-of-type {
  border-top: none;
}

.offer-item.has-photo {
  cursor: pointer;
  margin: 0 -20px;
  padding: 12px 20px;
  border-radius: 10px;
  transition: background-color 150ms ease;
}

.offer-item.has-photo:hover {
  background: var(--surface-2);
}

.offer-item-name {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}

.offer-item-camera {
  width: 14px;
  height: 14px;
  margin-left: 5px;
  vertical-align: -2px;
  color: var(--text-muted);
}

.offer-item-subtitle {
  display: block;
  font-size: 0.82rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-top: 2px;
}

.offer-item-meta {
  margin-top: 6px;
  font-size: 0.76rem;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.meal-head {
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.rank {
  font-size: 0.82rem;
  color: var(--text-muted);
  min-width: 1.4em;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.meal-name {
  font-size: 0.96rem;
  font-weight: 600;
  letter-spacing: -0.006em;
  line-height: 1.35;
  flex: 1;
}

.meal-meta {
  margin: 4px 0 10px 1.9em;
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.tag {
  background: var(--surface-2);
  border-radius: 980px;
  padding: 2px 9px;
}

.bar-row {
  margin-left: 1.9em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar-track {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  min-width: 3px;
}

.bar-value {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 4.5em;
  text-align: right;
  flex: 0 0 auto;
}

.macro-line {
  margin: 10px 0 0 1.9em;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 12px 0;
}

#poll-body {
  background: var(--surface-1);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow-card);
  max-width: 420px;
  margin: 0 auto;
}

.poll-login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.poll-login-form input {
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--text-primary);
  background: var(--surface-2);
  border: none;
  border-radius: 10px;
  padding: 11px 12px;
}

.poll-submit {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.poll-error {
  color: #e5484d;
  font-size: 0.82rem;
  margin: 8px 0 0;
}

.poll-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 24px 0;
}

.poll-identity {
  font-size: 0.82rem;
  color: var(--text-secondary);
  text-align: center;
  margin: 10px 0 0;
}

.poll-identity strong {
  color: var(--text-primary);
}

.poll-admin-link {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-family: inherit;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  margin-top: 14px;
  text-align: center;
}

.poll-admin-form-wrap {
  margin-top: 14px;
}

.poll-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  text-decoration: underline;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}

.poll-result {
  text-align: center;
  padding: 16px;
  background: var(--protein-track);
  border-radius: 14px;
  margin-bottom: 16px;
}

.poll-result-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.poll-result-winner {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-top: 4px;
}

.poll-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.poll-option {
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  font-family: inherit;
  transition: box-shadow 150ms ease, transform 150ms ease;
}

.poll-option.selected {
  box-shadow: 0 0 0 2px var(--accent) inset;
}

.poll-option:disabled {
  cursor: default;
  opacity: 0.8;
}

.poll-option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.poll-option-name {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
}

.poll-option-count {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

.poll-bar-track {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}

.poll-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 300ms ease;
}

.poll-draw-button {
  width: 100%;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  margin-top: 4px;
}

.poll-draw-button:disabled {
  opacity: 0.5;
  cursor: default;
}

.poll-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
  margin: 8px 0 0;
}

.wheel-stage {
  position: relative;
  width: 240px;
  height: 240px;
  margin: 8px auto 18px;
}

.wheel-svg {
  display: block;
  border-radius: 50%;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25), 0 0 0 4px var(--surface-2);
}

.wheel-pointer {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-top: 18px solid var(--text-primary);
  z-index: 2;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3));
}

.wheel-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.wheel-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.wheel-legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex: 0 0 auto;
}

.wheel-legend-name {
  font-weight: 500;
  color: var(--text-primary);
}

.poll-reset-button {
  width: 100%;
  background: var(--surface-2);
  color: var(--text-secondary);
  border: none;
  border-radius: 12px;
  padding: 13px;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  margin-top: 4px;
}

.photo-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease;
  z-index: 80;
}

.photo-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.photo-viewer {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  width: min(480px, 92vw);
  z-index: 81;
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, transform 200ms ease, visibility 200ms;
  text-align: center;
}

.photo-viewer.open {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

.photo-viewer img {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 16px;
  background: #000;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.photo-close {
  position: absolute;
  top: -52px;
  right: 0;
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

.photo-nav-button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.photo-nav-button svg {
  width: 20px;
  height: 20px;
}

.photo-prev {
  left: 8px;
}

.photo-next {
  right: 8px;
}

.photo-credit {
  margin: 12px 0 0;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.75);
}

.photo-credit a {
  color: #ffffff;
}
