:root {
  --bg: #F5F3FA;
  --surface: #FFFFFF;
  --ink: #1E1A2B;
  --muted: #686279;
  --line: #E3DEEE;
  --accent: #6C4CF5;
  --accent-ink: #FFFFFF;
  --accent-soft: #EEE9FF;
  --bad: #C81E37;
  --bad-soft: #FDE8EB;
  --good: #117A53;
  --good-soft: #E3F5EC;
  --x-bg: #0F0F14;
  --x-ink: #FFFFFF;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(30, 26, 43, .06), 0 8px 24px rgba(30, 26, 43, .06);
  --font-round: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  --font-body: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --stage-a: #EEEAF3;
  --stage-b: #F6F1EC;
  --stage-ink: #1E1A2B;
  --stage-sub: rgba(30, 26, 43, .66);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #110E18;
    --surface: #1B1725;
    --ink: #F1EEF8;
    --muted: #A49EB7;
    --line: #2D283C;
    --accent: #9C87FF;
    --accent-ink: #120E1C;
    --accent-soft: #2A2342;
    --bad: #FF7A8B;
    --bad-soft: #3A1A22;
    --good: #5ADBA4;
    --good-soft: #15302A;
    --x-bg: #FFFFFF;
    --x-ink: #0F0F14;
    --shadow: none;
    color-scheme: dark;
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; }

/* ---------- header ---------- */
.site-header {
  max-width: 1040px;
  margin: 0 auto;
  padding: 28px 16px 4px;
}
.eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: var(--font-round);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .04em;
}
h1 {
  margin: 2px 0 6px;
  font-family: var(--font-round);
  font-weight: 800;
  font-size: clamp(28px, 6.5vw, 44px);
  line-height: 1.15;
  text-wrap: balance;
}
.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  text-wrap: pretty;
}

/* ---------- layout ---------- */
.layout {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px 16px 24px;
  display: grid;
  gap: 16px;
}
.controls { display: grid; gap: 16px; min-width: 0; }

/* ---------- stage (result) ---------- */
.stage {
  position: sticky;
  top: 8px;
  z-index: 5;
  display: grid;
  grid-template-columns: 124px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 22px;
  background: linear-gradient(160deg, var(--stage-a), var(--stage-b));
  color: var(--stage-ink);
  box-shadow: var(--shadow);
  transition: color .3s;
}
.face-col { display: grid; gap: 6px; justify-items: center; }
.face { width: 100%; aspect-ratio: 1; }
.face svg { display: block; width: 100%; height: 100%; }

.look-row { display: flex; gap: 4px; justify-content: center; }
.look-btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 3px 9px;
  min-height: 28px;
  background: rgba(255, 255, 255, .7);
  color: #1E1A2B;
  font-family: var(--font-round);
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.look-btn[aria-pressed="true"] { background: #1E1A2B; color: #FFFFFF; }
.look-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.look-lbl { display: none; }

.verdict { min-width: 0; }
.verdict-lead { margin: 0; font-size: 12px; font-weight: 700; color: var(--stage-sub); }
.rank {
  margin: 0 0 6px;
  font-family: var(--font-round);
  font-weight: 800;
  font-size: 32px;
  line-height: 1.15;
}
.meter { width: 100%; }
.meter-track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #FF8FB1, #FFD45C 22%, #D6D0E2 50%, #A9AE96 75%, #5E6650);
}
.meter-marker {
  position: absolute;
  top: 50%;
  left: 40%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  background: #FFFFFF;
  border: 3px solid #1E1A2B;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
  transition: left .4s cubic-bezier(.2, .8, .2, 1);
}
.meter-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--stage-sub);
}
.score { margin: 4px 0 0; font-weight: 700; font-size: 13px; }
.score strong {
  font-family: var(--font-round);
  font-size: 22px;
  font-weight: 800;
  margin: 0 2px;
  font-variant-numeric: tabular-nums;
}
.comment {
  margin: 2px 0 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--stage-sub);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.panel h2 {
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-round);
  font-size: 18px;
  font-weight: 800;
}
.step {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
}
.hint { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

.drop {
  border: 2px dashed var(--line);
  border-radius: 16px;
  padding: 18px 14px;
  text-align: center;
  transition: border-color .2s, background .2s;
}
.drop.is-over { border-color: var(--accent); background: var(--accent-soft); }

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 12px 20px;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-round);
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
  transition: transform .1s, opacity .2s, background .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
.btn.x { background: var(--x-bg); color: var(--x-ink); }
.btn.wide { width: 100%; }

.ocr {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
  padding: 10px;
  border-radius: 14px;
  background: var(--accent-soft);
}
.thumb {
  width: 52px;
  height: 52px;
  flex: none;
  object-fit: cover;
  border-radius: 10px;
  background: var(--line);
}
.ocr-body { flex: 1; min-width: 0; }
.ocr-label { margin: 0 0 6px; font-size: 13px; font-weight: 700; }
.ocr-track {
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(108, 76, 245, .18);
}
.ocr-track span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .2s;
}
.ocr.is-error .ocr-label { color: var(--bad); }
.ocr.is-error .ocr-track span { background: var(--bad); }

.field-label {
  display: block;
  margin: 16px 0 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
textarea {
  display: block;
  width: 100%;
  min-height: 120px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  resize: vertical;
}
textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.samples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
}
.chip-btn {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 12px;
  min-height: 34px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.chip-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

#words h3 { margin: 0 0 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.chips { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
}
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip-count { font-size: 12px; opacity: .8; }
.chip-arrow { opacity: .6; }
.chip-fix { color: var(--ink); }
.empty { margin: 0 0 14px; font-size: 14px; color: var(--muted); }

.share-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- footer / toast ---------- */
.site-footer {
  max-width: 1040px;
  margin: 0 auto;
  padding: 4px 16px 40px;
  font-size: 13px;
  color: var(--muted);
}
.site-footer p { margin: 4px 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 999px;
  background: #1E1A2B;
  color: #FFFFFF;
  font-weight: 700;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- wide screens ---------- */
@media (min-width: 860px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
  }
  .stage {
    top: 20px;
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    gap: 8px;
    padding: 24px;
    border-radius: 28px;
  }
  .face-col { width: min(100%, 340px); gap: 10px; }
  .look-btn { font-size: 13px; padding: 5px 12px; min-height: 34px; }
  .look-lbl { display: inline; }
  .verdict { width: min(100%, 340px); }
  .verdict-lead { font-size: 14px; }
  .rank { font-size: clamp(44px, 5vw, 60px); margin: 2px 0 12px; }
  .meter-ends { font-size: 12px; margin-top: 6px; }
  .score { font-size: 15px; margin-top: 8px; }
  .score strong { font-size: 28px; }
  .comment { font-size: 14px; margin-top: 4px; -webkit-line-clamp: unset; }
}

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