:root {
  --bg: #12100e;
  --surface: #1c1917;
  --surface-2: #262220;
  --border: #35302c;
  --text: #f5f0ea;
  --muted: #a89f97;
  --accent: #ff8a3d;
  --accent-2: #ffb26b;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1100px 620px at 12% -8%, #2b211a 0%, transparent 58%),
    radial-gradient(900px 560px at 105% 8%, #241a15 0%, transparent 52%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.app {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 16px 0;
}

.screen[hidden] { display: none; }

h1 { font-size: 1.7rem; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 1.2rem; margin: 0; letter-spacing: -0.01em; }

.brand { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.brand-emoji { font-size: 3rem; line-height: 1; }

.tagline {
  margin: 0;
  color: var(--muted);
  max-width: 30ch;
}

.muted { color: var(--muted); margin: 0; }

/* Buttons */

.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 11px 22px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  min-height: 44px;
}

.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #2b1405;
  box-shadow: 0 4px 16px rgba(255, 138, 61, 0.28);
}

.btn-ghost {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover { background: #302a27; }

.btn-send {
  background: var(--accent);
  color: #2b1405;
  padding: 11px 18px;
}

/* Photo upload */

.upload {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.upload-empty {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 26px 18px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  text-align: center;
}

.upload.dragging .upload-empty {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface-2));
}

.upload-emoji { font-size: 2.6rem; line-height: 1; }
.upload-title { font-weight: 600; margin: 0; }
.upload-hint { margin: 0; font-size: 0.88rem; max-width: 34ch; }

.upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 8px;
}

.upload-preview {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.chosen {
  max-width: 100%;
  max-height: 220px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  object-fit: cover;
  box-shadow: var(--shadow);
}

.chosen-dish {
  margin: 0;
  font-weight: 600;
  color: var(--accent);
}

/* Turnstile mounts in the footer. It is invisible until Cloudflare decides a
   challenge is needed, so it must not take up space. */
#turnstile-widget {
  display: flex;
  justify-content: center;
  min-height: 0;
}

/* Privacy note */

.privacy {
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 34ch;
  margin: 4px 0 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.2);
}

/* Spinner */

.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}

.analyzing-text { color: var(--muted); margin: 0; }

/* Waiting */

.waiting-emoji, .reject-emoji { font-size: 3.4rem; line-height: 1; }

.scope-line { display: flex; align-items: center; gap: 10px; margin: 0; }

.scope-pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-2);
}

.preview-wrap { min-height: 0; }

.preview {
  max-width: 160px;
  max-height: 160px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  object-fit: cover;
  box-shadow: var(--shadow);
}

/* Chat */

.screen-chat { justify-content: flex-start; gap: 10px; padding: 0; }

.chat-header {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
}

.chat-banner {
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--accent-2);
}

.chat-who { display: flex; align-items: center; gap: 8px; }
.chat-nickname { color: var(--muted); font-size: 0.9rem; }

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

.conn-dot.off { background: var(--danger); box-shadow: 0 0 8px var(--danger); }

.messages {
  width: 100%;
  flex: 1;
  min-height: 180px;
  max-height: 46vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 2px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.96rem;
}

.msg-partner {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

/* The sender's own messages, right-aligned. */
.msg-self {
  align-self: flex-end;
  background: linear-gradient(180deg, #a8551f, #8a4218);
  border: 1px solid #c26a28;
  border-bottom-right-radius: 5px;
  color: #fff5ec;
}

/* Awaiting the server's echo — slightly dimmed. */
.msg-self.msg-pending {
  opacity: 0.6;
}

.msg-system {
  align-self: center;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  max-width: 90%;
}

.msg-error {
  align-self: center;
  border-color: var(--danger);
  color: #fca5a5;
  font-size: 0.85rem;
}

.typing-line {
  width: 100%;
  min-height: 18px;
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
  padding-left: 2px;
}

.composer {
  width: 100%;
  display: flex;
  gap: 8px;
}

.composer input {
  flex: 1;
  font: inherit;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  padding: 11px 16px;
  min-height: 44px;
}

.composer input:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }

.chat-actions {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chat-actions .btn { padding: 8px 15px; font-size: 0.86rem; min-height: 38px; }

/* Footer */

.footer {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 16px 18px;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.76rem;
}

/* Accessibility */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 400px) {
  .app { padding: 14px 12px 8px; }
  h1 { font-size: 1.45rem; }
  .chat-actions .btn { padding: 8px 12px; font-size: 0.82rem; }
  .msg { max-width: 86%; }
}
