:root {
  --bg: #0e0a14;
  --bg-2: #170f22;
  --card: rgba(255, 255, 255, 0.055);
  --card-strong: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f0fa;
  --muted: #b8aecb;
  --pink: #ff6fae;
  --pink-2: #ff9ccb;
  --green: #45d69a;
  --amber: #ffc14d;
  --blue: #7aa8ff;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

/* 避免下面的 display 规则覆盖 hidden 属性（否则该藏的藏不住） */
[hidden] { display: none !important; }

html { background-color: #0e0a14; }

body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background-color: #0e0a14;
  background-image:
    radial-gradient(1100px 700px at 12% -10%, rgba(255, 111, 174, 0.22), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(122, 168, 255, 0.16), transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 60%, #0b0710 100%);
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; justify-content: center; }

.app {
  width: 100%;
  max-width: 720px;
  padding: 18px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { font-size: 30px; line-height: 1; filter: drop-shadow(0 4px 10px rgba(255, 111, 174, 0.5)); }
.brand-text h1 { margin: 0; font-size: 19px; letter-spacing: 0.5px; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 6px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill-busy .dot { background: var(--amber); animation: pulse 1.1s infinite; }
.pill-ready { color: var(--green); border-color: rgba(69, 214, 154, 0.35); }
.pill-ready .dot { background: var(--green); }
.pill-error { color: #ff8f8f; border-color: rgba(255, 110, 110, 0.4); }
.pill-error .dot { background: #ff6e6e; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-size: 17px; line-height: 1;
}
.icon-btn:hover { background: var(--card-strong); }

/* ---------- stage ---------- */
.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 24px;
  overflow: hidden;
  background: #08050d;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.stage video, .stage img { width: 100%; height: 100%; object-fit: cover; display: block; }
.stage video { background: #08050d; }

.scan-frame {
  position: absolute; inset: 11% 13%;
  border-radius: 22px;
  pointer-events: none;
  transition: opacity 0.3s;
}
.corner { position: absolute; width: 34px; height: 34px; border: 3px solid var(--pink-2); opacity: 0.9; }
.corner.tl { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 16px 0 0 0; }
.corner.tr { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 16px 0 0; }
.corner.bl { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 16px; }
.corner.br { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 16px 0; }
.scanline {
  position: absolute; left: 4%; right: 4%; height: 2px; top: 6%;
  background: linear-gradient(90deg, transparent, var(--pink), transparent);
  box-shadow: 0 0 14px var(--pink);
  animation: scan 2.4s ease-in-out infinite;
}
@keyframes scan { 0%, 100% { top: 6%; opacity: 0.25; } 50% { top: 92%; opacity: 0.95; } }
.stage.busy .scanline { animation-duration: 1s; }
.stage.done .scan-frame { opacity: 0.15; }

.stage-msg {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  background: rgba(10, 6, 16, 0.66); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-size: 12px; color: var(--text); white-space: nowrap;
  max-width: 92%; overflow: hidden; text-overflow: ellipsis;
}

.boot {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; text-align: center;
  background: rgba(8, 5, 13, 0.9); padding: 26px; transition: opacity 0.4s;
}
.boot.hide { opacity: 0; pointer-events: none; }
.boot-title { font-size: 14px; }
.boot-bar { width: min(320px, 80%); height: 7px; border-radius: 99px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 2%; border-radius: 99px; background: linear-gradient(90deg, var(--pink), var(--blue)); transition: width 0.25s; }
.boot-file { font-size: 11px; color: var(--muted); max-width: 90%; word-break: break-all; }

/* ---------- controls ---------- */
.controls { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 2px; }
.round-btn {
  width: 62px; height: 62px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line); background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; color: var(--text); font-size: 11px; user-select: none;
}
.round-btn span { font-size: 20px; line-height: 1; }
.round-btn em { font-style: normal; color: var(--muted); font-size: 10px; }
.round-btn:hover { background: var(--card-strong); }

.shutter {
  position: relative; width: 84px; height: 84px; border-radius: 50%; cursor: pointer;
  border: 0; color: #2a0c1c; font-weight: 700; font-size: 15px;
  background: linear-gradient(145deg, #ffd0e6, var(--pink) 55%, #ff4f9a);
  box-shadow: 0 10px 26px rgba(255, 79, 154, 0.45), inset 0 0 0 4px rgba(255, 255, 255, 0.22);
  transition: transform 0.12s;
}
.shutter:active { transform: scale(0.95); }
.shutter[disabled] { filter: grayscale(0.75) brightness(0.8); cursor: progress; box-shadow: none; }
.shutter-ring { position: absolute; inset: -7px; border-radius: 50%; border: 2px dashed rgba(255, 156, 203, 0.5); animation: spin 9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.local-note { text-align: center; font-size: 11px; color: var(--muted); margin: 0; }

/* ---------- samples ---------- */
.samples { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.samples-label { font-size: 11.5px; color: var(--muted); }
.samples-list { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.sample {
  position: relative; width: 82px; height: 62px; padding: 0; cursor: pointer; overflow: hidden;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card);
}
.sample img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sample span {
  position: absolute; left: 0; right: 0; bottom: 0; font-size: 10px; padding: 2px 4px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75)); color: #fff; text-align: center;
}
.sample:hover { border-color: var(--pink-2); }
.sample[disabled] { opacity: 0.5; cursor: progress; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.sub { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: 0.4px; }
.tiny { font-size: 11px; color: var(--muted); margin: 10px 0 0; line-height: 1.6; }
code { background: rgba(255, 255, 255, 0.1); padding: 1px 5px; border-radius: 5px; font-size: 11px; }

.result-head { display: flex; gap: 14px; align-items: flex-start; }
#resultThumb {
  width: 92px; height: 92px; object-fit: cover; border-radius: 14px;
  border: 1px solid var(--line); flex: 0 0 auto; background: #0b0710;
}
.result-title { min-width: 0; flex: 1; }
.result-name-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.result-name-row h2 { margin: 0; font-size: 24px; }
.conf { font-size: 13px; color: var(--pink-2); font-weight: 700; }
.conf.tier-high { color: var(--green); }
.conf.tier-medium { color: #6ee7c8; }
.conf.tier-low { color: var(--amber); }
.conf.tier-vague { color: #ffb27a; }
.conf.tier-none { color: #ff8f8f; }
.sci { margin: 4px 0 8px; font-style: italic; color: var(--muted); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; }
.chip {
  font-size: 11px; padding: 4px 9px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); color: var(--text);
}
.chip-meaning { background: rgba(255, 111, 174, 0.16); border-color: rgba(255, 111, 174, 0.4); color: var(--pink-2); }
.desc { margin: 14px 0 0; font-size: 13.5px; line-height: 1.75; color: #e7e1f2; }

.warn {
  margin-top: 12px; padding: 10px 12px; border-radius: 12px; font-size: 12.5px; line-height: 1.6;
  background: rgba(255, 193, 77, 0.12); border: 1px solid rgba(255, 193, 77, 0.35); color: #ffdb9b;
}

.top5 { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.top5 li { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.top5 .name { font-size: 13px; }
.top5 .name small { color: var(--muted); font-style: italic; margin-left: 6px; font-size: 11px; }
.top5 .val { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.top5 .bar { grid-column: 1 / -1; height: 6px; border-radius: 99px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.top5 .bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--pink), var(--blue)); }
.top5 li.first .name { font-weight: 700; }
.top5 li.first .bar i { background: linear-gradient(90deg, #ffd0e6, var(--pink)); }

.result-actions, .settings-actions { display: flex; gap: 10px; margin-top: 16px; }
.btn {
  flex: 1; padding: 11px 14px; border-radius: 12px; cursor: pointer; font-size: 13.5px;
  border: 1px solid var(--line); background: var(--card-strong); color: var(--text);
}
.btn:hover { background: rgba(255, 255, 255, 0.14); }
.btn.primary { background: linear-gradient(145deg, #ffb3d6, var(--pink)); color: #2a0c1c; font-weight: 700; border: 0; }

.collapsed-toggle { cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.species-list { list-style: none; margin: 4px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.species-list li { background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; }
.species-list b { font-size: 13px; display: block; }
.species-list small { color: var(--muted); font-size: 11px; font-style: italic; }

.debug-card summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.debug-card pre { max-height: 220px; overflow: auto; font-size: 11px; line-height: 1.55; color: #b9f5d6; white-space: pre-wrap; word-break: break-all; }
.foot { text-align: center; font-size: 11px; color: rgba(184, 174, 203, 0.7); margin-top: 4px; }

/* ---------- settings dialog ---------- */
.settings {
  border: 1px solid var(--line); border-radius: 20px; padding: 0; width: min(420px, 92vw);
  background: #17101f; color: var(--text); box-shadow: var(--shadow);
}
.settings::backdrop { background: rgba(5, 3, 8, 0.7); backdrop-filter: blur(3px); }
.settings form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.settings h3 { margin: 0; font-size: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field.range span { display: flex; justify-content: space-between; }
.field.check { flex-direction: row; align-items: flex-start; gap: 8px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.field select, .field input[type="range"] { width: 100%; }
.field select {
  padding: 9px 10px; border-radius: 10px; background: #221730; color: var(--text);
  border: 1px solid var(--line); font-size: 13px;
}
.field input[type="range"] { accent-color: var(--pink); }

@media (max-width: 480px) {
  .app { padding: 14px 12px 32px; }
  .brand-text p { display: none; }
  .result-name-row h2 { font-size: 21px; }
  #resultThumb { width: 76px; height: 76px; }
}
