:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --accent: #2563eb;
  --accent2: #16a34a;
  --danger: #dc2626;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 18px;
  --ring: 0 0 0 4px rgba(37, 99, 235, 0.22);
}

* {
  box-sizing: border-box;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, Segoe UI,
    Roboto, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(1000px 420px at 50% -120px, #e0e7ff 0%, var(--bg) 60%)
    fixed;
  -webkit-tap-highlight-color: transparent;
}

.safe {
  padding: max(14px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1360px;
  margin: 0 auto 14px;
}

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

.logo {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.22);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.logo svg {
  width: 26px;
  height: 26px;
  fill: #fff;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.icon-btn {
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 14px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
}

.icon-btn:focus-visible,
.btn:focus-visible,
.tile:focus-visible,
.check:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: var(--text);
}

.wrap {
  max-width: 1360px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.maincol,
.sidecol {
  display: grid;
  gap: 14px;
  align-content: start;
}

.card {
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.stage {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.stage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stage-title {
  margin: 0;
  font-size: clamp(1.45rem, 2.8vw, 2rem);
  letter-spacing: -0.02em;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-weight: 800;
  font-size: 0.95rem;
}

.badge small {
  font-weight: 700;
  opacity: 0.85;
}

.lead {
  margin: 0;
  color: var(--muted);
  font-size: 1.12rem;
  line-height: 1.55;
}

.hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.hero img {
  width: 100%;
  height: auto;
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  display: block;
}

.btnrow {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 14px 16px;
  font-weight: 900;
  font-size: 1.02rem;
  cursor: pointer;
  touch-action: manipulation;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.secondary {
  background: #e2e8f0;
  color: var(--text);
}

.btn.good {
  background: var(--accent2);
  color: #fff;
}

.btn.danger {
  background: #fee2e2;
  color: #7f1d1d;
}

.btn:active {
  transform: translateY(1px);
}

.progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.dots {
  display: flex;
  gap: 8px;
  align-items: center;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.18);
}

.dot.active {
  width: 22px;
  background: var(--accent);
}

.hintbox {
  background: #f1f5f9;
  border: 1px dashed rgba(15, 23, 42, 0.22);
  border-radius: 16px;
  padding: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.kicker {
  font-weight: 900;
  color: var(--text);
}

.imggrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.imgcard {
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 16px;
  overflow: hidden;
}

.imgcard img {
  width: 100%;
  height: auto;
  display: block;
  cursor: zoom-in;
}

.imgcap {
  padding: 12px 14px;
  font-weight: 900;
  font-size: 1.04rem;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.tile {
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 16px;
  background: #fff;
  padding: 14px;
  display: grid;
  gap: 10px;
  cursor: pointer;
  touch-action: manipulation;
}

.tile svg {
  width: 42px;
  height: 42px;
}

.tile h4 {
  margin: 0;
  font-size: 1.05rem;
}

.tile p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.tile.good {
  border-color: rgba(22, 163, 74, 0.32);
  background: rgba(220, 252, 231, 0.55);
}

.tile.bad {
  border-color: rgba(220, 38, 38, 0.32);
  background: rgba(254, 226, 226, 0.55);
}

.tile.selected {
  box-shadow: var(--ring);
}

.feedback {
  display: none;
  border-radius: 16px;
  padding: 12px;
  font-weight: 900;
}

.feedback.show {
  display: block;
}

.feedback.ok {
  background: rgba(220, 252, 231, 0.75);
  border: 1px solid rgba(22, 163, 74, 0.22);
  color: #14532d;
}

.feedback.no {
  background: rgba(254, 226, 226, 0.75);
  border: 1px solid rgba(220, 38, 38, 0.22);
  color: #7f1d1d;
}

.checks {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.sequence {
  display: grid;
  gap: 10px;
}

.sequence-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.sequence-card {
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.sequence-card.selected {
  box-shadow: var(--ring);
}

.sequence-card img {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
}

.sequence-cap {
  padding: 10px 12px;
  font-weight: 900;
  color: var(--muted);
}

.sequence-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.counter {
  display: grid;
  gap: 10px;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 16px;
  padding: 12px;
}

.counter-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.counter-big {
  font-size: clamp(3rem, 5vw, 4rem);
  font-weight: 1000;
  letter-spacing: -0.03em;
}

.counter-small {
  color: var(--muted);
  font-weight: 900;
}

.counter-bar {
  height: 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.08);
  overflow: hidden;
}

.counter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2563eb 0%, #16a34a 100%);
  border-radius: 999px;
}

.counter-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.check {
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 16px;
  background: #fff;
  padding: 12px;
  cursor: pointer;
  touch-action: manipulation;
  display: grid;
  gap: 8px;
  align-content: start;
}

.check.on {
  border-color: rgba(22, 163, 74, 0.35);
  background: rgba(220, 252, 231, 0.65);
}

.check .t {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 900;
}

.check .mark {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 2px solid rgba(15, 23, 42, 0.25);
  display: grid;
  place-items: center;
  font-weight: 1000;
}

.check.on .mark {
  border-color: rgba(22, 163, 74, 0.7);
  background: #16a34a;
  color: #fff;
}

.small {
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.55;
}

.footer {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.6;
}

.ai {
  display: grid;
  gap: 14px;
}

.ai-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.ai-title {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: -0.01em;
}

.ai-lock {
  display: grid;
  gap: 12px;
}

.ai-lock-title {
  font-size: 1rem;
  font-weight: 900;
  color: var(--text);
}

.ai-password {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: 16px;
  font-size: 1.04rem;
  font-family: inherit;
  background: #fff;
}

.ai-sub {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.55;
  display: none;
}

.ai-badge {
  background: #f1f5f9;
  border: 1px solid rgba(15, 23, 42, 0.1);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 900;
  font-size: 0.95rem;
}

.chips {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

body[data-ai-open="false"] .sidecol {
  display: none;
}

.chip {
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 999px;
  padding: 10px 12px;
  background: #fff;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.chip:active {
  transform: translateY(1px);
}

.ai-input {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  padding: 14px 14px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: 16px;
  font-size: 1.08rem;
  line-height: 1.55;
  font-family: inherit;
  background: #fff;
}

.ai-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.ai-busy {
  color: var(--muted);
  font-weight: 900;
}

.ai-error {
  background: rgba(254, 226, 226, 0.8);
  border: 1px solid rgba(220, 38, 38, 0.22);
  color: #7f1d1d;
  border-radius: 16px;
  padding: 12px;
  line-height: 1.55;
  font-weight: 800;
  white-space: pre-wrap;
}

.ai-answer {
  background: rgba(219, 234, 254, 0.6);
  border: 1px solid rgba(37, 99, 235, 0.18);
  color: var(--text);
  border-radius: 16px;
  padding: 12px;
  line-height: 1.7;
  font-weight: 650;
  white-space: pre-wrap;
}

.viewer {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(15, 23, 42, 0.88);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
}

.viewer[hidden] {
  display: none !important;
}

.viewer-close {
  justify-self: end;
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  background: #fff;
  font-weight: 900;
}

.viewer-img {
  width: 100%;
  max-width: 1100px;
  max-height: 72vh;
  object-fit: contain;
  justify-self: center;
  align-self: center;
  border-radius: 18px;
  background: #fff;
}

.viewer-cap {
  color: #fff;
  text-align: center;
  font-weight: 900;
}

@media (min-width: 860px) {
  .hero {
    grid-template-columns: 1.15fr 0.85fr;
    align-items: start;
  }
}

@media (min-width: 980px) {
  .wrap {
    grid-template-columns: minmax(0, 1.7fr) minmax(360px, 0.95fr);
    align-items: start;
  }

  body[data-ai-side="left"] .wrap {
    grid-template-columns: minmax(360px, 0.95fr) minmax(0, 1.7fr);
  }

  .maincol {
    order: 0;
  }

  .sidecol {
    position: sticky;
    top: max(12px, env(safe-area-inset-top));
    align-self: start;
  }

  body[data-ai-side="left"] .maincol {
    order: 1;
  }

  body[data-ai-side="left"] .sidecol {
    order: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn:active {
    transform: none;
  }
}
