:root {
  --bg: #fdf6ec;
  --ink: #2e2620;
  --accent: #e8683c;
  --accent-dark: #c94f28;
  --card: #ffffff;
  --muted: #8a7f72;
  --green: #3c9a5f;
  --orange: #e0912c;
  --red: #d33f3f;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  position: relative;
  padding: 20px 68px 10px 68px;
  text-align: center;
}

.info-btn {
  position: absolute;
  top: 14px;
  left: 14px;
  background: var(--card);
  color: var(--accent-dark);
  border: 2px solid var(--accent);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 0.95rem;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.lang-switch {
  position: absolute;
  top: 14px;
  right: 14px;
}

.lang-current {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--card);
  color: var(--accent-dark);
  border: 2px solid var(--accent);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.lang-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--card);
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  z-index: 20;
  min-width: 90px;
}

.lang-dropdown.open {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.lang-option.active {
  background: rgba(232, 104, 60, 0.12);
  color: var(--accent-dark);
}

header h1 {
  margin: 0;
  font-size: 1.6rem;
  color: var(--accent-dark);
}

header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

main {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(16px + 76px + env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.tab-content {
  display: none;
  flex-direction: column;
  gap: 16px;
}

.tab-content.active {
  display: flex;
}

.active-profile-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  background: var(--card);
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent-dark);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  cursor: pointer;
}

.exit-toast {
  display: none;
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  z-index: 50;
}

.exit-toast.visible {
  display: block;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--card);
  box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0 8px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.75rem;
  cursor: pointer;
}

.nav-item .nav-icon {
  font-size: 1.3rem;
}

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

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
}

.btn {
  display: block;
  width: 100%;
  padding: 18px;
  font-size: 1.15rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active { background: var(--accent-dark); }

.btn.secondary {
  background: transparent;
  color: var(--accent-dark);
  border: 2px solid var(--accent);
}

#scanner-view {
  display: none;
  flex-direction: column;
  gap: 12px;
}

#scanner-view.active { display: flex; }

.video-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  aspect-ratio: 3 / 4;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-frame {
  position: absolute;
  inset: 18% 10%;
  border: 3px solid #fff;
  border-radius: 12px;
  box-shadow: 0 0 0 999px rgba(0,0,0,0.35);
}

.manual-entry {
  display: flex;
  gap: 8px;
}

.manual-entry input {
  flex: 1;
  padding: 14px;
  font-size: 1rem;
  border-radius: 12px;
  border: 1px solid #ddd;
}

#result {
  display: none;
}

#result.active { display: block; }

.result-code {
  font-size: 1.3rem;
  font-weight: 700;
  word-break: break-all;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 8px;
}

.status {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.status.error { color: var(--red); }

.allergen-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

.allergen-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
}

.allergen-item input {
  width: 18px;
  height: 18px;
}

.semaphore-banner {
  padding: 16px;
  border-radius: 14px;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  color: #fff;
}

.semaphore-banner.green { background: var(--green); }
.semaphore-banner.orange { background: var(--orange); }
.semaphore-banner.red { background: var(--red); }
.semaphore-banner.unknown { background: var(--muted); }

.result-name {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 14px 0 4px;
}

.profile-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid #eee;
}

.profile-row:last-child { border-bottom: none; }

.profile-select {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  background: none;
  border: none;
  padding: 6px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
}

.profile-row.active .profile-select {
  background: rgba(232, 104, 60, 0.12);
}

.profile-select strong {
  font-size: 1.05rem;
}

.profile-meta {
  font-size: 0.85rem;
  color: var(--muted);
}

.icon-btn {
  border: none;
  background: none;
  font-size: 1.2rem;
  padding: 8px;
  cursor: pointer;
}

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

.disclaimer-banner {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #fff3e0;
  border-left: 4px solid var(--orange);
  color: #6b4a1f;
  font-size: 0.88rem;
  line-height: 1.4;
}

.disclaimer-banner.emphasized {
  background: #fff0d6;
  border-left-width: 6px;
  font-weight: 700;
  font-size: 0.95rem;
}

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

.history-header .icon-btn {
  font-size: 0.85rem;
  color: var(--red);
}

.history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #eee;
}

.history-row:last-child { border-bottom: none; }

.history-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.history-dot.green { background: var(--green); }
.history-dot.orange { background: var(--orange); }
.history-dot.red { background: var(--red); }
.history-dot.unknown { background: var(--muted); }

.history-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.history-info strong {
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.history-top strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-profile-badge {
  flex-shrink: 0;
  background: rgba(232, 104, 60, 0.12);
  color: var(--accent-dark);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.history-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.field-input {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  border-radius: 12px;
  border: 1px solid #ddd;
  margin-top: 6px;
  margin-bottom: 4px;
}

#contribute-card input[type="file"] {
  width: 100%;
  font-size: 0.9rem;
}

footer {
  display: flex;
  justify-content: center;
  gap: 24px;
  padding: 18px 16px 28px;
}

.footer-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}

.footer-link:active {
  color: var(--accent-dark);
}

.intro-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(46, 38, 32, 0.55);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.intro-overlay.active {
  display: flex;
}

.intro-card {
  position: relative;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 32px 24px 24px;
  max-width: 440px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}

.intro-card h2 {
  margin: 0 0 14px;
  color: var(--accent-dark);
  font-size: 1.3rem;
}

.intro-card p {
  margin: 0 0 14px;
  line-height: 1.5;
  color: var(--ink);
}

.intro-card p:last-child {
  margin-bottom: 0;
}

.intro-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--card);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1rem;
  color: var(--muted);
  cursor: pointer;
}
