:root {
  --bg: #f4f1ea;
  --card: #fff;
  --text: #1f2933;
  --muted: #5b6770;
  --line: #e4ddd2;
  --primary: #1f6f5b;
  --primary-press: #175544;
  --correct: #157347;
  --wrong: #b42318;
  --warn: #b54708;
  --error-bg: #fdecea;
  --ok-bg: #e8f6ee;
  --warn-bg: #fff6e5;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

body.camera-open {
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.hidden {
  display: none !important;
}

.topbar,
.page,
.footer {
  width: min(720px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
}

.topbar h1,
.login-card h1 {
  margin: 0;
  font-size: 1.25rem;
}

.page {
  padding: 0 16px 88px;
}

.lead,
.login-desc,
.footer {
  color: var(--muted);
  font-size: 0.95rem;
}

.error-box {
  background: var(--error-bg);
  color: var(--wrong);
  padding: 12px 14px;
  border-radius: 10px;
}

.preview-wrap {
  position: relative;
  background: #111;
  border-radius: 16px;
  overflow: hidden;
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-wrap.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 50;
  border-radius: 0;
  min-height: 100vh;
  background: #000;
}

#video {
  width: 100%;
  max-height: 70vh;
  display: none;
  background: #111;
  object-fit: contain;
}

.preview-wrap.fullscreen #video {
  max-height: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#video.active {
  display: block;
}

.preview-placeholder {
  color: #d0d0d0;
  margin: 48px 0;
}

.camera-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 10px;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
}

.camera-bar .btn {
  flex: 1;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0;
}

.btn,
button.btn,
label.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  min-height: 48px;
  padding: 12px 14px;
  font-size: 1rem;
  text-align: center;
  background: #e8e2d6;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-text {
  background: transparent;
  min-height: 36px;
  color: var(--muted);
}

.btn:disabled,
label.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

.tips,
.gallery,
.loading,
.result-card,
.summary,
.encourage {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  margin: 12px 0;
}

.tips ol {
  margin: 8px 0 0;
  padding-left: 1.2em;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.gallery:empty {
  display: none;
}

.thumb {
  position: relative;
  background: #faf7f1;
  border-radius: 12px;
  overflow: hidden;
}

.thumb img {
  display: block;
  width: 100%;
  height: 140px;
  object-fit: cover;
  cursor: zoom-in;
}

.thumb .meta {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 6px 8px 10px;
}

.thumb .remove {
  position: absolute;
  top: 6px;
  right: 6px;
  min-height: 32px;
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  z-index: 1;
}

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

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

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

.summary-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 8px 0 0;
}

.stat-correct { color: var(--correct); }
.stat-wrong { color: var(--wrong); }
.stat-warn { color: var(--warn); }

.result-card.correct { border-left: 6px solid var(--correct); background: var(--ok-bg); }
.result-card.wrong { border-left: 6px solid var(--wrong); background: var(--error-bg); }
.result-card.uncertain { border-left: 6px solid var(--warn); background: var(--warn-bg); }

.result-card h3,
.encourage h2,
.summary h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.result-card p {
  margin: 6px 0;
}

.crop-wrap {
  margin: 0 0 12px;
  border-radius: 12px;
  overflow: hidden;
  background: #111;
}

.crop-wrap img {
  display: block;
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  cursor: zoom-in;
  background: #111;
}

.reason-strong {
  font-weight: 600;
}

.result-tabs {
  position: sticky;
  bottom: 0;
  z-index: 25;
  display: flex;
  gap: 8px;
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(244, 241, 234, 0.96);
  border-top: 1px solid var(--line);
}

.result-tabs button {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  background: #e8e2d6;
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
}

.result-tabs button.active.correct {
  background: var(--correct);
  color: #fff;
}

.result-tabs button.active.wrong {
  background: var(--wrong);
  color: #fff;
}

.result-tabs button.active.uncertain {
  background: var(--warn);
  color: #fff;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 12px 12px;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: 12px;
  min-height: 40px;
  padding: 8px 14px;
  border: 0;
  border-radius: 10px;
  background: #fff;
  color: #111;
}

.footer {
  padding: 8px 16px 28px;
}

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: 18px;
  padding: 28px 20px;
  box-shadow: 0 8px 30px rgba(31, 41, 51, 0.06);
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.login-card input {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
}

@media (max-width: 420px) {
  .actions {
    grid-template-columns: 1fr;
  }
}
