:root {
  --color-bg: #faf8f5;
  --color-surface: #ffffff;
  --color-text: #1f1b16;
  --color-text-muted: #6b6258;
  --color-primary: #c1440e;
  --color-primary-contrast: #ffffff;
  --color-border: #e7e0d6;
  --color-specialty: #b8860b;
  --color-error: #b3261e;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font-heading: 'Belgrano', Georgia, 'Times New Roman', serif;
  --font-body: 'Karla', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --shadow-sm: 0 1px 2px rgba(31, 27, 22, 0.06), 0 1px 3px rgba(31, 27, 22, 0.08);
  --shadow-md: 0 4px 10px rgba(31, 27, 22, 0.1), 0 2px 4px rgba(31, 27, 22, 0.06);
  --transition-fast: 150ms ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #17140f;
    --color-surface: #221e18;
    --color-text: #f2ede4;
    --color-text-muted: #b3a999;
    --color-border: #362f26;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  line-height: 1.4;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
}

h1 {
  font-family: var(--font-heading);
  font-weight: 400;
  font-size: 1.75rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}

h2 {
  font-family: var(--font-heading);
  font-weight: 400;
  font-size: 1.25rem;
  line-height: 1.3;
  margin: 0 0 8px;
}

.subtitle {
  color: var(--color-text-muted);
  margin: 0 0 16px;
}

.hint {
  color: var(--color-text-muted);
  text-align: center;
  padding: 24px 0;
}

.hint a {
  color: var(--color-primary);
  font-weight: 600;
}

.error {
  color: var(--color-error);
  background: color-mix(in srgb, var(--color-error) 10%, transparent);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-top: 12px;
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

button, .btn-primary, .btn-secondary {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  min-height: 44px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: transform 100ms ease, box-shadow var(--transition-fast), background-color var(--transition-fast),
    border-color var(--transition-fast), opacity var(--transition-fast);
}

button:focus-visible, .btn-primary:focus-visible, .btn-secondary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 35%, transparent);
}

button[type="submit"], .btn-primary {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

button[type="submit"]:hover:not(:disabled), .btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-primary) 88%, black);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-bg);
  border-color: color-mix(in srgb, var(--color-primary) 40%, var(--color-border));
}

button[type="submit"]:active:not(:disabled), .btn-primary:active:not(:disabled),
.btn-secondary:active:not(:disabled) {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Landing ---------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}

.card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.card input {
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  transition: border-color var(--transition-fast);
}

.card input:focus-visible {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 20%, transparent);
}

.join-form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.join-form-actions button {
  flex: 1;
}

/* ---------- QR scanner overlay ---------- */

.qr-scanner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px;
}

.qr-scanner-video {
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: var(--radius);
  background: #000;
}

.qr-scanner-error {
  max-width: 420px;
  text-align: center;
}

/* ---------- Screen header ---------- */

.screen-header {
  margin-bottom: 16px;
}

.header-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.table-qr {
  margin-top: 10px;
}

.table-qr-toggle {
  padding: 8px 14px;
  min-height: unset;
  font-size: 0.9rem;
}

.table-qr-box {
  max-width: 220px;
  margin-top: 12px;
  padding: 12px;
  /* Always white, not a theme token: the QR needs firm light/dark module
     contrast to stay scannable, regardless of the app's own dark mode. */
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.table-qr-box svg {
  display: block;
  width: 100%;
  height: auto;
}

.table-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.table-actions-delete {
  color: var(--color-error);
  border-color: var(--color-error);
}

.table-actions-delete:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-error) 10%, var(--color-surface));
  border-color: var(--color-error);
}

/* ---------- Scan ---------- */

.thumb-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.thumb {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  min-height: unset;
  padding: 0;
  width: 22px;
  height: 22px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 16px;
  line-height: 1;
}

.thumb-remove:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.8);
}

.scan-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.file-label {
  position: relative;
}

.scan-progress:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
  color: var(--color-text-muted);
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Menu / dish cards ---------- */

.menu-category-heading {
  font-family: var(--font-heading);
  font-weight: 400;
  margin-top: 24px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: var(--color-bg);
}

.dish-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast);
}

.dish-card:has(.dish-summary:hover) {
  box-shadow: var(--shadow-md);
}

.dish-summary {
  width: 100%;
  display: block;
  text-align: left;
  background: none;
  border-radius: 0;
  padding: 14px 16px;
  min-height: unset;
  transition: background-color var(--transition-fast);
}

.dish-summary:hover {
  background: var(--color-bg);
}

.dish-name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.specialty-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-specialty);
  border: 1px solid var(--color-specialty);
  border-radius: 999px;
  padding: 1px 8px;
}

.dish-description {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.dish-price {
  margin-top: 6px;
  font-weight: 600;
}

.dish-detail {
  padding: 0 16px 16px;
  border-top: 1px solid var(--color-border);
}

.specialty-explanation {
  background: color-mix(in srgb, var(--color-specialty) 12%, transparent);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
  margin: 12px 0;
}

.dish-detail-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 0;
}

.btn-add {
  width: 100%;
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.btn-add:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-primary) 88%, black);
}

.btn-add:active:not(:disabled) {
  transform: scale(0.97);
}

/* ---------- Diner picker ---------- */

.diner-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.diner-chip {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 6px 14px;
  min-height: unset;
  font-size: 0.9rem;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), transform 100ms ease;
}

.diner-chip:hover:not(.selected) {
  border-color: color-mix(in srgb, var(--color-primary) 50%, var(--color-border));
}

.diner-chip:active {
  transform: scale(0.96);
}

.diner-chip.selected {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  border-color: var(--color-primary);
}

.diner-chip-add {
  border-style: dashed;
}

/* ---------- Qty stepper ---------- */

.qty-stepper {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 4px 8px;
  width: fit-content;
}

.qty-btn {
  min-height: unset;
  width: 28px;
  height: 28px;
  padding: 0;
  background: var(--color-bg);
  font-size: 1.1rem;
}

.qty-btn:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-primary) 14%, var(--color-bg));
}

.qty-btn:active:not(:disabled) {
  transform: scale(0.92);
}

.qty-value {
  min-width: 1.5em;
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- Basket ---------- */

.basket-group {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.basket-group h2 {
  font-size: 1.1rem;
}

.basket-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--color-border);
}

.basket-line:first-of-type {
  border-top: none;
}

.basket-line-name {
  font-weight: 500;
}

.basket-line-price {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.basket-line-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.basket-line-remove {
  background: none;
  color: var(--color-error);
  min-height: unset;
  padding: 4px 8px;
}

.basket-line-remove:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-error) 10%, transparent);
}

.basket-subtotal {
  text-align: right;
  font-weight: 600;
  margin-top: 8px;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.basket-total {
  text-align: right;
  font-size: 1.2rem;
  font-weight: 700;
  padding: 12px 4px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Reduced motion ---------- */

@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;
  }
}
