/* ---------- Design tokens ---------- */
:root {
  --ink: #12304a;
  --muted: #5d7385;
  --bg: #eef7f6;
  --card: #ffffff;
  --teal: #0f8b82;
  --teal-dark: #0b6b64;
  --line: #cfe3e1;
  --star: #f5b301;
  --star-off: #d7e3e2;
  --bad: #d64545;
  --warn: #e08a1e;
  --good: #1f9d6b;
}

* { box-sizing: border-box; }
.hidden { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

/* ---------- Layout ---------- */
.header { display: flex; justify-content: center; padding: 20px 16px 4px; }
.logo { width: 120px; height: 40px; color: var(--teal); }
.container { max-width: 520px; margin: 0 auto; padding: 8px 16px 40px; text-align: center; }

h1 { font-size: 1.75rem; margin: 16px 0 6px; }
.subtitle { color: var(--muted); margin: 0 0 20px; }
.disclaimer { color: var(--muted); font-size: 0.8rem; margin-top: 14px; }

/* ---------- Upload ---------- */
.drop-zone {
  display: flex; align-items: center; justify-content: center;
  min-height: 260px;
  background: var(--card);
  border: 2px dashed var(--teal);
  border-radius: 20px;
  cursor: pointer;
  padding: 16px;
  transition: background 0.2s;
}
.drop-zone:hover, .drop-zone:focus-visible, .drop-zone.dragover { background: #e3f4f2; outline: none; }
.drop-zone.has-image { border-style: solid; cursor: default; }
.drop-zone.locked { pointer-events: none; opacity: 0.6; }

.drop-icon {
  width: 56px; height: 56px; margin: 0 auto 10px;
  border-radius: 50%; background: var(--teal); color: #fff;
  font-size: 2rem; line-height: 56px;
}
.drop-zone p { margin: 2px 0; }
.hint { color: var(--muted); font-size: 0.85rem; }

.preview-wrap { position: relative; max-width: 100%; }
.preview-wrap img { display: block; max-width: 100%; max-height: 320px; border-radius: 14px; }
.remove-btn {
  position: absolute; top: -10px; right: -10px;
  width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: var(--bad); color: #fff; font-size: 1.4rem; line-height: 1;
  cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

.error-box {
  margin: 14px 0 0; padding: 12px 14px;
  background: #fdecec; color: #9b2222;
  border: 1px solid #f3bcbc; border-radius: 12px; font-weight: 600;
}

.primary-btn {
  width: 100%; margin-top: 18px; padding: 16px;
  border: 0; border-radius: 14px;
  background: var(--teal); color: #fff;
  font-size: 1.05rem; font-weight: 700; cursor: pointer;
  transition: background 0.2s;
}
.primary-btn:hover:not(:disabled) { background: var(--teal-dark); }
.primary-btn:disabled { background: #a9c9c6; cursor: not-allowed; }

/* ---------- Result ---------- */
.score-card {
  background: var(--card); border-radius: 20px; padding: 24px 16px;
  border: 1px solid var(--line);
}
.stars { font-size: 2.6rem; letter-spacing: 4px; line-height: 1; }
.star { position: relative; display: inline-block; color: var(--star-off); }
.star .fill { position: absolute; left: 0; top: 0; overflow: hidden; color: var(--star); white-space: nowrap; }
.score-number { font-size: 1.2rem; font-weight: 700; margin: 10px 0 2px; }
.score-summary { margin: 0; color: var(--muted); }

.class-card {
  text-align: left; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px;
  padding: 16px; margin-top: 14px;
}
.class-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.class-title { margin: 0; font-size: 1.1rem; }
.class-level { font-weight: 700; font-size: 0.9rem; }
.bar { height: 10px; background: #e3eeed; border-radius: 99px; margin: 10px 0; overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 99px; transition: width 0.8s ease; }
.class-comment { margin: 0; }
.level-low { color: var(--good); }   .bar-fill.level-low { background: var(--good); }
.level-mid { color: var(--warn); }   .bar-fill.level-mid { background: var(--warn); }
.level-high { color: var(--bad); }   .bar-fill.level-high { background: var(--bad); }

/* ---------- Processing overlay ---------- */
.loader {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgba(18, 48, 74, 0.82);
  backdrop-filter: blur(4px);
}
.loader-card { text-align: center; color: #fff; padding: 24px; }
.scan-box {
  position: relative; width: 220px; height: 220px; margin: 0 auto 20px;
  border-radius: 20px; overflow: hidden;
  border: 2px solid #5fe0d3; box-shadow: 0 0 30px rgba(95, 224, 211, 0.5);
}
.scan-box img { width: 100%; height: 100%; object-fit: cover; opacity: 0.7; }
.scan-line {
  position: absolute; left: 0; right: 0; height: 4px;
  background: #5fe0d3; box-shadow: 0 0 18px 6px rgba(95, 224, 211, 0.8);
  animation: scan 1.6s ease-in-out infinite alternate;
}
@keyframes scan { from { top: 0; } to { top: calc(100% - 4px); } }
.loader-text { font-size: 1.1rem; font-weight: 600; margin: 0; }
.dots::after { content: ""; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

@media (prefers-reduced-motion: reduce) {
  .scan-line, .dots::after { animation: none; }
  .bar-fill { transition: none; }
}