/* ============================================================
   菜品识别 · 暖调极简 UI
   ============================================================ */

:root {
  --canvas: #FBFBFA;
  --canvas-2: #F7F6F3;
  --surface: #FFFFFF;
  --ink: #111111;
  --ink-2: #2F2F2C;
  --muted: #787774;
  --border: #EAEAEA;
  --border-strong: #E3E1DC;

  --amber: #FBF3DB;   --amber-ink: #8A6100;
  --red: #FDEBEC;     --red-ink: #9F2F2D;
  --green: #EDF3EC;   --green-ink: #346538;
  --blue: #E1F3FE;    --blue-ink: #1F6C9F;

  --radius: 12px;
  --radius-sm: 8px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong", Georgia, serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background:
    radial-gradient(680px 340px at 50% -46px, rgba(184, 128, 74, 0.07), transparent 72%),
    var(--canvas);
  background-attachment: fixed;
}

img { max-width: 100%; display: block; }

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

.shell {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 0 14px;
  background: rgba(251, 251, 250, 0.82);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand__mark {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--amber);
  color: var(--amber-ink);
}
.brand__mark svg { width: 21px; height: 21px; }

.brand__text { display: flex; flex-direction: column; min-width: 0; }
.brand__name {
  color: var(--ink);
  font-size: 1.02rem;
  font-weight: 620;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.brand__sub {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------- 布局 ---------------- */
.main {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-top: 26px;
  padding-bottom: 72px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* ---------------- 上传区 ---------------- */
.uploader { padding: 16px; }

.dropzone {
  position: relative;
  min-height: 220px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 30px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: calc(var(--radius) - 2px);
  background: var(--canvas-2);
  cursor: pointer;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.dropzone:hover,
.dropzone:focus-visible { border-color: #D6D2C9; background: #FFFFFF; }
.dropzone.dragover { border-color: var(--ink); background: #FFFFFF; }
.dropzone.has-image {
  padding: 0;
  min-height: 0;
  border-style: solid;
  border-color: var(--border);
  background: var(--canvas-2);
  overflow: hidden;
}

.dropzone__hint { pointer-events: none; }

.dropzone__icon {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}
.dropzone__icon svg { width: 24px; height: 24px; }

.dropzone__title {
  margin: 14px 0 0;
  color: var(--ink);
  font-size: 0.98rem;
  font-weight: 560;
  letter-spacing: -0.005em;
}
.dropzone__meta {
  margin: 8px 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
}

.preview {
  width: 100%;
  max-height: 52vh;
  object-fit: contain;
  background: var(--canvas-2);
}

/* ---------------- 按钮 ---------------- */
.actions { display: flex; gap: 10px; margin-top: 16px; }

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.94rem;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease),
    transform 0.12s var(--ease), opacity 0.18s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: scale(0.985); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; }

.btn--primary { flex: 1; background: var(--ink); color: #FFFFFF; }
.btn--primary:not(:disabled):hover { background: #2A2A2A; }
.btn--primary:disabled {
  background: var(--canvas-2);
  color: #A9A7A1;
  border-color: var(--border);
  opacity: 1;
}

.btn--quiet {
  flex: 0 0 auto;
  background: transparent;
  border-color: var(--border-strong);
  color: var(--ink-2);
}
.btn--quiet:not(:disabled):hover { background: var(--canvas-2); }

/* ---------------- 选项（手风琴） ---------------- */
.options { margin-top: 18px; border-top: 1px solid var(--border); }

.options > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  list-style: none;
  cursor: pointer;
  color: var(--ink-2);
  font-size: 0.88rem;
  user-select: none;
}
.options > summary::-webkit-details-marker { display: none; }
.options__chev { display: inline-flex; color: var(--muted); }
.options__chev svg { width: 16px; height: 16px; transition: transform 0.22s var(--ease); }
.options[open] .options__chev svg { transform: rotate(180deg); }

.options__body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 0 8px;
}

.field { display: flex; align-items: center; gap: 14px; font-size: 0.9rem; }
.field__label { flex: 1; color: var(--ink-2); }
.field input[type="range"] { flex: 0 0 42%; accent-color: var(--ink); }
.field output {
  width: 22px;
  text-align: right;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
}
.field--switch input { width: 18px; height: 18px; accent-color: var(--ink); }

/* ---------------- 状态提示 ---------------- */
.status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 0.88rem;
  animation: rise 0.5s var(--ease) both;
}
.status svg { width: 16px; height: 16px; flex: none; }
.status.loading { background: var(--blue); border-color: #CFE8F8; color: var(--blue-ink); }
.status.error   { background: var(--red);  border-color: #F6D7D8; color: var(--red-ink); }
.status.warn    { background: var(--amber); border-color: #F0E5C4; color: var(--amber-ink); }

.spinner {
  flex: none;
  width: 15px;
  height: 15px;
  border: 1.8px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  opacity: 0.7;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- 结果 ---------------- */
.results { display: flex; flex-direction: column; gap: 18px; }
.results > * { animation: rise 0.55s var(--ease) both; }
.results > *:nth-child(2) { animation-delay: 0.06s; }
.results > *:nth-child(3) { animation-delay: 0.12s; }
.results > *:nth-child(4) { animation-delay: 0.18s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.16em;
}
.eyebrow__icon { display: inline-flex; color: var(--ink); }
.eyebrow__icon svg { width: 15px; height: 15px; }

.lead__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.lead__top .eyebrow { margin: 0; }

.badge {
  flex: none;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--amber);
  color: var(--amber-ink);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.dish-name {
  margin: 12px 0 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(1.62rem, 5.4vw, 2.1rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.conf-bar {
  height: 5px;
  margin: 16px 0 0;
  border-radius: 999px;
  background: var(--canvas-2);
  overflow: hidden;
}
.conf-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--ink);
  transition: width 0.8s var(--ease);
}

.nutrition {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--canvas-2);
  color: var(--ink-2);
  font-size: 0.86rem;
}
.nutrition__icon { display: inline-flex; color: var(--amber-ink); }
.nutrition__icon svg { width: 15px; height: 15px; }
.nutrition b { color: var(--ink); font-weight: 660; }

.desc {
  margin: 16px 0 0;
  color: var(--ink-2);
  font-size: 0.9rem;
  line-height: 1.75;
}

.baike-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  padding-bottom: 1px;
  border-bottom: 1px solid var(--border-strong);
  color: var(--ink);
  font-size: 0.84rem;
  text-decoration: none;
  transition: border-color 0.18s var(--ease);
}
.baike-link:hover { border-color: var(--ink); }
.baike-link svg { width: 13px; height: 13px; }

/* 候选列表 */
.candidates { margin: 4px 0 0; padding: 0; list-style: none; }
.candidates li {
  display: grid;
  grid-template-columns: 1.4em 1fr;
  align-items: baseline;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.candidates li:last-child { border-bottom: none; }
.candidates .rank { color: var(--muted); font-family: var(--mono); font-size: 0.72rem; }
.candidates .c-name { color: var(--ink); font-weight: 500; }

/* 解读正文 */
.prose { color: var(--ink-2); font-size: 0.92rem; line-height: 1.78; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  margin: 20px 0 7px;
  color: var(--ink);
  font-size: 0.98rem;
  font-weight: 640;
  letter-spacing: -0.005em;
}
.prose p { margin: 10px 0; }
.prose ul, .prose ol { margin: 10px 0; padding-left: 20px; }
.prose li { margin: 4px 0; }
.prose strong { color: var(--ink); font-weight: 640; }
.prose a { color: var(--ink); text-underline-offset: 2px; }
.prose code {
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--canvas-2);
  font-family: var(--mono);
  font-size: 0.84em;
}
.prose hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ---------------- 响应式 ---------------- */
@media (min-width: 640px) {
  .shell { padding: 0 24px; }
  .card { padding: 24px; }
  .uploader { padding: 18px; }
  .dropzone { min-height: 280px; }
  .preview { max-height: 58vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
