:root {
  --bg: #fafbfc;
  --bg-elev: #ffffff;
  --ink: #0b1220;
  --ink-2: #243044;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #e8edf5;
  --line-2: #d7e0ee;
  --blue: #2f6bff;
  --blue-deep: #1f54e0;
  --blue-soft: #eef3ff;
  --blue-ring: rgba(47, 107, 255, 0.14);
  --teal: #0f8f7b;
  --teal-soft: #e8f8f4;
  --amber: #c27803;
  --amber-soft: #fff7e8;
  --red: #d92d20;
  --red-soft: #fef3f2;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.06);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 12px rgba(16, 24, 40, 0.04);
  --radius: 18px;
  --radius-sm: 12px;
  --font: "Noto Sans SC", "PingFang SC", "Segoe UI", sans-serif;
  --display: "Fraunces", "Noto Serif SC", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --safe: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.55;
  background:
    radial-gradient(circle at top left, rgba(47, 107, 255, 0.06), transparent 28%),
    radial-gradient(circle at top right, rgba(15, 143, 123, 0.05), transparent 24%),
    linear-gradient(180deg, #ffffff 0%, var(--bg) 180px);
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

/* ── Header ── */
.header {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(14px);
  background: rgba(255, 255, 255, 0.82);
  border-bottom: 1px solid rgba(232, 237, 245, 0.9);
}

.header-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo-box {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  background: linear-gradient(145deg, #3b82f6 0%, #2f6bff 45%, #0f8f7b 120%);
  box-shadow: 0 10px 20px rgba(47, 107, 255, 0.22);
}

.logo-text {
  font-weight: 700;
  font-size: 0.98rem;
  letter-spacing: -0.02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ai-tag {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber);
  border: 1px solid #f6e0b5;
}

.ai-tag.on {
  background: var(--teal-soft);
  color: var(--teal);
  border-color: #b7e8dc;
}

.hbtn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-2);
  transition: 0.15s ease;
}

.hbtn:hover {
  border-color: var(--line-2);
  background: #f8fafc;
  transform: translateY(-1px);
}

.hbtn.danger {
  color: var(--red);
  border-color: #f3c4c0;
  background: #fff;
}

.hbtn.danger:hover {
  background: var(--red-soft);
}

/* ── Layout ── */
.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 18px calc(36px + var(--safe));
}

.page {
  animation: rise 0.28s ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ── Top steps ── */
.steps {
  list-style: none;
  margin: 0 0 18px;
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

.steps li {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 8px;
  border-radius: 999px;
  color: var(--faint);
  font-size: 0.86rem;
  font-weight: 700;
  transition: 0.18s ease;
}

.steps li span {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #eef2f7;
  font-size: 0.72rem;
  font-family: var(--mono);
}

.steps li.on {
  color: var(--blue-deep);
  background: var(--blue-soft);
}

.steps li.on span {
  background: var(--blue);
  color: #fff;
}

.steps li.done {
  color: var(--teal);
}

.steps li.done span {
  background: var(--teal-soft);
  color: var(--teal);
  border: 1px solid #b7e8dc;
}

/* ── Cards ── */
.card {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px;
  margin-bottom: 16px;
  overflow: hidden;
}

.card.light {
  background: linear-gradient(180deg, #ffffff, #fbfcfe);
}

.card.current {
  border-color: #c9d9ff;
  box-shadow: 0 14px 36px rgba(47, 107, 255, 0.08);
}

.card.current::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, var(--blue), #78a0ff 55%, #0f8f7b);
}

.card h1 {
  margin: 0 0 8px;
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(1.55rem, 3.5vw, 2rem);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.card-h {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card-h h2 {
  margin: 0;
}

.desc,
.help,
.muted,
.hint {
  color: var(--muted);
  font-size: 0.92rem;
}

.desc {
  margin: 0 0 18px;
  max-width: 36ch;
}

.help {
  margin: 0 0 14px;
}

.hint {
  margin: 8px 0 16px;
}

.hint b {
  color: var(--blue-deep);
  font-weight: 700;
}

.label {
  display: block;
  font-weight: 700;
  font-size: 0.88rem;
  margin: 0 0 8px;
  color: var(--ink-2);
}

.label em {
  color: var(--red);
  font-style: normal;
}

.label small {
  color: var(--faint);
  font-weight: 500;
}

textarea,
input[type="text"],
.full {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 13px 14px;
  outline: none;
  margin-bottom: 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

textarea:focus,
input[type="text"]:focus,
.full:focus {
  border-color: #9db7ff;
  box-shadow: 0 0 0 4px var(--blue-ring);
}

.btns {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 11px 15px;
  font-weight: 700;
  font-size: 0.92rem;
  transition: 0.15s ease;
}

.btn:hover {
  background: #f8fafc;
  transform: translateY(-1px);
}

.btn.primary {
  background: linear-gradient(180deg, #3b82f6, var(--blue));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 10px 18px rgba(47, 107, 255, 0.22);
}

.btn.primary:hover {
  background: linear-gradient(180deg, #3676f2, var(--blue-deep));
}

.link {
  border: 0;
  background: none;
  color: var(--blue);
  font-weight: 700;
  font-size: 0.86rem;
  padding: 4px 0;
}

.link:hover {
  text-decoration: underline;
}

.tip {
  margin: 10px 0 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--blue-soft);
  border: 1px solid #d8e4ff;
  color: var(--ink-2);
  font-size: 0.9rem;
}

.tip.bad {
  background: var(--red-soft);
  border-color: #f3c4c0;
  color: #912018;
}

.tip.good {
  background: var(--teal-soft);
  border-color: #b7e8dc;
  color: #0b6b5c;
}

.case-grid {
  display: grid;
  gap: 10px;
}

.case-item {
  text-align: left;
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 16px;
  padding: 14px;
  transition: 0.15s ease;
}

.case-item:hover {
  border-color: #b8ccff;
  background: linear-gradient(180deg, #fff, var(--blue-soft));
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.case-item .tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--blue-deep);
  background: var(--blue-soft);
  border-radius: 999px;
  padding: 3px 8px;
  margin-bottom: 8px;
}

.case-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.95rem;
}

.case-item span {
  color: var(--muted);
  font-size: 0.82rem;
}

/* ── Page 2 ── */
.problem-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.problem-text {
  font-weight: 700;
  margin-top: 2px;
  font-size: 1rem;
}

.bar-actions {
  display: flex;
  gap: 14px;
  flex-shrink: 0;
}

.layer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 8px;
}

.layer-no {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--blue-deep);
}

.badge {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--muted);
  background: #f5f7fb;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
}

.why-box {
  position: relative;
  background:
    radial-gradient(circle at top right, rgba(47, 107, 255, 0.1), transparent 40%),
    linear-gradient(180deg, #f8faff, #eef3ff);
  border: 1px solid #d5e1ff;
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 16px;
}

.why-label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--blue);
  margin-bottom: 8px;
}

.why-q {
  font-family: var(--display);
  font-size: clamp(1.35rem, 3.5vw, 1.75rem);
  font-weight: 500;
  line-height: 1.28;
  letter-spacing: -0.02em;
}

.why-from {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.subnav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.sub {
  text-align: center;
  padding: 10px 8px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--faint);
  font-size: 0.84rem;
  font-weight: 700;
  transition: 0.15s ease;
}

.sub.on {
  color: var(--blue-deep);
  border-color: #c3d5ff;
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 1px rgba(47, 107, 255, 0.05);
}

.sub.done {
  color: var(--teal);
  border-color: #b7e8dc;
  background: var(--teal-soft);
}

.because {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.because span {
  font-weight: 800;
  color: var(--blue-deep);
  background: var(--blue-soft);
  border: 1px solid #d5e1ff;
  border-radius: 14px;
  padding: 13px 14px;
}

.because input {
  margin: 0;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.checks i {
  font-style: normal;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--faint);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: #fff;
  transition: 0.15s ease;
}

.checks i.on {
  color: var(--teal);
  border-color: #b7e8dc;
  background: var(--teal-soft);
}

.echo,
.summary {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.echo,
.summary > div {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}

.echo small,
.summary small {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.judge {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.jbtn {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 112px;
  transition: 0.15s ease;
}

.jbtn strong {
  font-size: 1.02rem;
}

.jbtn span {
  color: var(--muted);
  font-size: 0.86rem;
}

.jbtn.no:hover {
  border-color: #f0d29a;
  background: var(--amber-soft);
  transform: translateY(-1px);
}

.jbtn.yes:hover {
  border-color: #b7e8dc;
  background: var(--teal-soft);
  transform: translateY(-1px);
}

.done-list {
  display: grid;
  gap: 10px;
}

.done-item {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #f9fafb);
  border-radius: 14px;
  padding: 14px;
  border-left: 4px solid var(--blue);
}

.done-item.root {
  background: linear-gradient(180deg, #fff, var(--teal-soft));
  border-color: #b7e8dc;
  border-left-color: var(--teal);
}

.done-item .lv {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--blue);
  margin-bottom: 6px;
  letter-spacing: 0.04em;
}

.done-item.root .lv {
  color: var(--teal);
}

.done-item .q {
  font-weight: 700;
  margin-bottom: 6px;
}

.done-item .a,
.done-item .m {
  color: var(--ink-2);
  font-size: 0.9rem;
}

/* ── Result ── */
.success-card {
  border-color: #b7e8dc;
  background:
    radial-gradient(circle at top right, rgba(15, 143, 123, 0.08), transparent 36%),
    #fff;
}

.ok {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--teal);
  background: var(--teal-soft);
  border: 1px solid #b7e8dc;
  border-radius: 999px;
  padding: 5px 10px;
  margin-bottom: 12px;
  letter-spacing: 0.04em;
}

.success-card h1 {
  font-family: var(--display);
  font-weight: 500;
}

.result {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.r {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.r.root {
  background: var(--blue-soft);
  border-color: #d5e1ff;
}

.r.fix {
  background: var(--teal-soft);
  border-color: #b7e8dc;
}

.r small {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.r p {
  margin: 0;
  font-weight: 700;
  font-size: 1.02rem;
}

/* ── Dialogs ── */
.dlg {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: calc(100vw - 24px);
}

.dlg::backdrop {
  background: rgba(11, 18, 32, 0.34);
  backdrop-filter: blur(3px);
}

.dlg-box {
  width: min(500px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(16, 24, 40, 0.16);
  overflow: hidden;
}

.dlg-box.wide {
  width: min(580px, 100%);
}

.dlg-box header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.dlg-box header h3 {
  margin: 0;
  font-size: 1rem;
}

.dlg-body {
  padding: 16px;
}

.dlg-body ol {
  margin: 0;
  padding-left: 1.2em;
}

.dlg-body li {
  margin-bottom: 8px;
  color: var(--ink-2);
}

.x {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 1.2rem;
  color: var(--muted);
}

.preview {
  padding: 12px 14px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 14px;
  font-weight: 700;
}

.choice {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
  transition: 0.15s ease;
}

.choice:hover {
  border-color: #b8ccff;
  background: var(--blue-soft);
  transform: translateY(-1px);
}

.choice strong {
  font-size: 1rem;
}

.choice span {
  color: var(--muted);
  font-size: 0.86rem;
}

#exportText {
  width: 100%;
  min-height: 230px;
  margin-bottom: 10px;
  font-family: var(--mono);
  font-size: 0.84rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 12px;
}

.suggest {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px solid #d8e4ff;
}

.suggest:last-child {
  border-bottom: 0;
}

/* ── Toast / loading ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe));
  transform: translateX(-50%);
  z-index: 50;
  background: var(--ink);
  color: #fff;
  padding: 11px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  max-width: min(92vw, 400px);
  text-align: center;
  box-shadow: 0 12px 28px rgba(11, 18, 32, 0.2);
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(255, 255, 255, 0.58);
  display: none;
  place-content: center;
  gap: 10px;
  justify-items: center;
  backdrop-filter: blur(2px);
}

.loading.on {
  display: grid !important;
}

.spin {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid #dbe6ff;
  border-top-color: var(--blue);
  animation: spin 0.75s linear infinite;
}

.loading p {
  margin: 0;
  color: var(--blue-deep);
  font-weight: 700;
}

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

/* ── Responsive ── */
@media (max-width: 640px) {
  .header-inner,
  .wrap {
    padding-left: 14px;
    padding-right: 14px;
  }

  .steps {
    border-radius: 18px;
  }

  .steps li {
    font-size: 0.78rem;
    gap: 6px;
    padding: 9px 4px;
  }

  .judge {
    grid-template-columns: 1fr;
  }

  .problem-bar {
    flex-direction: column;
  }

  .card {
    padding: 18px;
  }

  .card h1 {
    font-size: 1.4rem;
  }

  .why-q {
    font-size: 1.25rem;
  }

  .logo-text {
    font-size: 0.92rem;
  }
}

@media (min-width: 860px) {
  .wrap,
  .header-inner {
    max-width: 800px;
  }
}
