:root {
  --mango-red: #e8571f;
  --mango-gold: #f2a516;
  --ink: #2b241c;
  --paper: #fff8f0;
  --card: #ffffff;
  --line: #ecdfce;
  --grade-a: linear-gradient(135deg, #e8571f, #f2a516);
  --grade-b: linear-gradient(135deg, #2b3440, #4b5a6b);
  --grade-c: linear-gradient(135deg, #cfcfcf, #ececec);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header h1 { font-size: 1.1rem; margin: 0; }
.badge-experimental {
  font-size: 0.7rem;
  background: var(--mango-gold);
  color: #3a2a06;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
}

main { flex: 1; padding: 16px; max-width: 480px; margin: 0 auto; width: 100%; }

.screen.hidden { display: none; }

.caveat-box {
  background: #fff3e0;
  border: 1px solid #ffd699;
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 0.85rem;
  line-height: 1.5;
}
.caveat-box summary { font-weight: 700; cursor: pointer; }
.caveat-box ul { margin: 8px 0 0; padding-left: 1.2em; }
.caveat-box li { margin-bottom: 4px; }

.lead { font-size: 0.95rem; color: #5a5044; margin: 8px 0 20px; }

.capture-buttons { display: flex; flex-direction: column; gap: 12px; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  border-radius: 14px;
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--mango-red); color: white; }
.btn-secondary { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.settings-box { margin-top: 24px; }
.switch-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.85rem;
  color: #5a5044;
}
.switch-row input { margin-top: 3px; }

.spinner {
  width: 42px;
  height: 42px;
  margin: 60px auto 16px;
  border: 4px solid var(--line);
  border-top-color: var(--mango-red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
#screen-loading { text-align: center; color: #5a5044; }
@keyframes spin { to { transform: rotate(360deg); } }

.preview-img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: 14px;
  background: #000;
  margin-bottom: 16px;
}

.result-card {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  border: 1px solid var(--line);
}

.grade-badge {
  width: 88px;
  height: 88px;
  line-height: 88px;
  margin: 0 auto 10px;
  border-radius: 50%;
  font-size: 2.4rem;
  font-weight: 800;
  color: white;
}
.grade-a { background: var(--grade-a); }
.grade-b { background: var(--grade-b); }
.grade-c { background: var(--grade-c); color: #444; }
.grade-unknown { background: #ccc; color: #444; }

.grade-label { font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.confidence-row { color: #5a5044; margin: 4px 0 12px; }

.needs-review {
  background: #fff0f0;
  border: 1px solid #ffb3b3;
  color: #a11;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.result-note {
  background: #eef6ff;
  border: 1px solid #bcdcff;
  color: #245;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.8rem;
  margin-bottom: 10px;
}

.feature-box { text-align: left; margin-top: 12px; font-size: 0.85rem; }
.feature-box summary { cursor: pointer; color: #5a5044; }
.feature-box dl { margin: 10px 0 0; }
.feature-box dt { font-weight: 700; margin-top: 8px; }
.feature-box dd { margin: 2px 0 0; color: #5a5044; }

.action-row { display: flex; gap: 10px; margin-top: 16px; }
.action-row .btn { flex: 1; }

h2 { font-size: 1.1rem; }
.radio-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
  font-size: 1rem;
}
.radio-row label { display: flex; align-items: center; gap: 10px; }

.app-footer {
  text-align: center;
  font-size: 0.75rem;
  color: #9a8c78;
  padding: 14px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--mango-red);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 0;
  cursor: pointer;
  text-align: left;
}

.threshold-status {
  font-size: 0.8rem;
  color: #5a5044;
  margin: 14px 0 4px;
}

.calibrate-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.calibrate-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
}
.calibrate-item img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.calibrate-item select {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 0.95rem;
}
.calibrate-item .remove-btn {
  background: none;
  border: none;
  color: #a11;
  font-size: 1.1rem;
  padding: 4px 8px;
  cursor: pointer;
}
.calibrate-empty {
  color: #9a8c78;
  font-size: 0.85rem;
  text-align: center;
  padding: 20px 0;
}

.calibrate-progress { text-align: center; margin: 16px 0; }
.calibrate-progress .spinner { margin: 0 auto 10px; width: 32px; height: 32px; }

.calibrate-result {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  line-height: 1.6;
}
.calibrate-result .improved { color: #0a7a2f; font-weight: 700; }
.calibrate-result .not-improved { color: #a11; font-weight: 700; }
