:root {
  --ink: #241a4a;
  --ink-soft: #5a5178;
  --purple: #7c4dff;
  --purple-deep: #5a2ee6;
  --pink: #ff5da2;
  --yellow: #ffd23f;
  --mint: #2ee6a6;
  --card: #ffffff;
  --ring: rgba(124, 77, 255, 0.35);
  --shadow: 0 18px 40px rgba(60, 30, 120, 0.16);
}

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

body {
  margin: 0;
  font-family: "Nunito", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #f3ecff 0%, #eaf2ff 55%, #fff0f7 100%);
  min-height: 100vh;
  overflow-x: hidden;
}

/* floating background blobs */
.bg-blobs { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; filter: blur(40px); opacity: 0.5; }
.b1 { width: 340px; height: 340px; background: #c9b3ff; top: -80px; left: -60px; }
.b2 { width: 300px; height: 300px; background: #ffc6e0; bottom: -80px; right: -50px; }
.b3 { width: 260px; height: 260px; background: #b8e8ff; top: 40%; right: 20%; }

/* header */
.site-header {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 18px 22px; max-width: 760px; margin: 0 auto;
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-mark { font-size: 30px; }
.logo-text {
  font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 26px;
  letter-spacing: 1px;
  background: linear-gradient(90deg, var(--purple), var(--pink));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.pill {
  background: rgba(255,255,255,0.7); color: var(--purple-deep);
  border: 1px solid var(--ring); padding: 6px 14px; border-radius: 999px;
  font-weight: 700; font-size: 13px;
}

.wrap { position: relative; z-index: 1; max-width: 680px; margin: 0 auto; padding: 10px 20px 40px; }

/* hero */
.hero { text-align: center; padding: 18px 0 26px; }
.hero h1 {
  font-family: "Fredoka", sans-serif; font-weight: 700;
  font-size: clamp(28px, 6vw, 40px); line-height: 1.12; margin: 0 0 12px;
}
.hero .hl {
  background: linear-gradient(90deg, var(--purple), var(--pink));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero .sub { font-size: 17px; color: var(--ink-soft); margin: 0 auto; max-width: 520px; }

/* card */
.card {
  background: var(--card); border-radius: 24px; box-shadow: var(--shadow);
  padding: 22px; border: 1px solid rgba(124,77,255,0.08);
}
.field-label { display: block; font-weight: 800; font-size: 14px; margin: 4px 2px 8px; color: var(--ink); }

textarea {
  width: 100%; border: 2px solid #ece6ff; border-radius: 16px; padding: 14px;
  font-family: inherit; font-size: 16px; color: var(--ink); resize: vertical;
  background: #faf8ff; transition: border-color .15s, box-shadow .15s;
}
textarea:focus { outline: none; border-color: var(--purple); box-shadow: 0 0 0 4px var(--ring); }

/* photo input */
.photo-btn {
  margin-top: 12px; width: 100%; cursor: pointer; font-family: inherit; font-weight: 700;
  font-size: 15px; color: var(--purple-deep); background: #f6f2ff;
  border: 2px dashed var(--purple); border-radius: 16px; padding: 14px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .15s;
}
.photo-btn:hover { background: #efe8ff; }
.photo-btn span { font-size: 20px; }
.photo-preview { position: relative; margin-top: 12px; display: inline-block; }
.photo-preview img {
  max-width: 100%; max-height: 240px; border-radius: 14px; border: 2px solid #ece6ff; display: block;
}
.photo-remove {
  position: absolute; top: -10px; right: -10px; width: 30px; height: 30px; border-radius: 50%;
  border: none; background: var(--pink); color: #fff; font-size: 15px; font-weight: 700;
  cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

/* method match toggle */
.method-toggle {
  margin-top: 12px; background: none; border: none; cursor: pointer;
  font-family: inherit; font-weight: 700; font-size: 15px; color: var(--purple-deep);
  display: flex; align-items: center; gap: 8px; padding: 6px 2px;
}
.method-toggle .opt { color: var(--ink-soft); font-weight: 600; font-size: 13px; }
.method-toggle .chev { transition: transform .2s; display: inline-block; }
.method-toggle.open .chev { transform: rotate(90deg); }
.method-wrap { max-height: 0; overflow: hidden; transition: max-height .28s ease; }
.method-wrap.open { max-height: 340px; margin-top: 8px; }

/* controls */
.controls {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-top: 18px; flex-wrap: wrap;
}
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.slider {
  width: 46px; height: 26px; background: #ddd5f2; border-radius: 999px;
  position: relative; transition: background .2s; flex: none;
}
.slider::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + .slider { background: var(--mint); }
.switch input:checked + .slider::after { transform: translateX(20px); }
.switch-label { font-weight: 700; font-size: 14px; }
.switch-label small { color: var(--ink-soft); font-weight: 600; }

.solve-btn {
  border: none; cursor: pointer; font-family: "Fredoka", sans-serif; font-weight: 600;
  font-size: 18px; color: #fff; padding: 14px 24px; border-radius: 16px;
  background: linear-gradient(90deg, var(--purple), var(--purple-deep));
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 10px 22px rgba(90,46,230,0.35); transition: transform .12s, box-shadow .12s;
}
.solve-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 26px rgba(90,46,230,0.42); }
.solve-btn:active { transform: translateY(0); }
.solve-btn:disabled { opacity: .7; cursor: default; transform: none; }

/* result */
.result { margin-top: 20px; }
.result:empty { margin-top: 0; }
.answer-box {
  background: linear-gradient(135deg, #f2ecff, #ffeef6); border-radius: 18px;
  padding: 16px 18px; border: 2px solid #eadfff; margin-bottom: 14px;
}
.answer-box .label { font-weight: 800; font-size: 13px; color: var(--purple-deep); text-transform: uppercase; letter-spacing: .5px; }
.answer-box .answer { font-family: "Fredoka", sans-serif; font-size: 26px; margin-top: 4px; }
.reveal-btn {
  border: none; cursor: pointer; font-family: "Fredoka", sans-serif; font-size: 16px;
  color: var(--purple-deep); background: #fff; border: 2px dashed var(--purple);
  padding: 10px 18px; border-radius: 14px; margin-top: 6px;
}
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.steps li {
  position: relative; background: #faf8ff; border: 1px solid #efeaff; border-radius: 14px;
  padding: 14px 16px 14px 52px; margin-bottom: 10px; font-size: 16px; line-height: 1.5;
  animation: pop .3s ease both;
}
.steps li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 12px; top: 12px; width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--purple), var(--pink)); color: #fff;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 15px;
}
.tip { margin-top: 6px; background: #fffbe8; border: 1px solid #ffe9a8; border-radius: 14px; padding: 12px 14px; font-weight: 600; }
.tip b { color: #b8860b; }
.error-box { background: #fff0f0; border: 1px solid #ffd0d0; color: #b00030; border-radius: 14px; padding: 14px 16px; font-weight: 600; }

/* loading */
.thinking { display: flex; align-items: center; gap: 10px; color: var(--purple-deep); font-weight: 700; padding: 8px 2px; }
.dots span { display: inline-block; width: 8px; height: 8px; margin: 0 2px; background: var(--purple); border-radius: 50%; animation: bounce 1s infinite; }
.dots span:nth-child(2) { animation-delay: .15s; }
.dots span:nth-child(3) { animation-delay: .3s; }

/* how row */
.how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 22px; }
.how-item { background: rgba(255,255,255,0.65); border: 1px solid rgba(124,77,255,0.12); border-radius: 16px; padding: 14px; text-align: center; }
.how-item span { font-size: 26px; }
.how-item p { font-size: 13px; color: var(--ink-soft); margin: 8px 0 0; }
.how-item b { color: var(--ink); }

.site-footer { position: relative; z-index: 1; text-align: center; color: var(--ink-soft); padding: 10px 20px 30px; font-size: 14px; }

.shake { animation: shake .35s; }

@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-8px); } }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%,60%{transform:translateX(-6px)} 40%,80%{transform:translateX(6px)} }

@media (max-width: 520px) {
  .how { grid-template-columns: 1fr; }
  .controls { flex-direction: column-reverse; align-items: stretch; }
  .solve-btn { justify-content: center; width: 100%; }
}
