:root {
  --bg: #eef1f8;
  --surface: #ffffff;
  --ink: #181b38;
  --muted: #666d8a;
  --line: #dde1ee;
  --primary: #3346f0;
  --primary-soft: #e8ebff;
  --ok: #0aa862;
  --ok-soft: #dff7ea;
  --warn: #a15c00;
  --warn-soft: #fff3dc;
  --bad: #d62f4b;
  --code-bg: #14173a;
  --code-ink: #cfd4ff;
  --code-dim: #7a80b5;
  --radius: 12px;
  --sans: "SF Pro Text", -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1024;
    --surface: #181b38;
    --ink: #eceeff;
    --muted: #9aa0c7;
    --line: #2c3058;
    --primary: #7f8cff;
    --primary-soft: #252a5c;
    --ok: #35d68e;
    --ok-soft: #123a2a;
    --warn: #ffc266;
    --warn-soft: #3a2c12;
    --bad: #ff7a90;
    --code-bg: #0a0c1e;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 var(--sans);
  overflow: hidden;
}
a { color: var(--primary); text-underline-offset: 2px; overflow-wrap: anywhere; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
button { font: inherit; color: inherit; cursor: pointer; }

/* Top bar */
#top {
  flex: none;
  display: flex;
  align-items: center;
  gap: 18px;
  height: 60px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 16px; font-weight: 650; white-space: nowrap; }
.brand small { margin-left: 8px; color: var(--muted); font-size: 13px; font-weight: 400; }
.meter { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 60px; max-width: 420px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.meter i { position: relative; flex: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.meter b { position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: var(--ok); transition: width 0.35s cubic-bezier(0.2, 0.8, 0.2, 1); }
.saved { color: var(--ok); font-size: 12px; white-space: nowrap; opacity: 0; transition: opacity 0.2s; }
.saved.on { opacity: 1; }
.spacer { flex: 1; }
.btn {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  font-weight: 550;
  white-space: nowrap;
  transition: transform 0.12s, background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: var(--primary); }
.btn:active { transform: translateY(1px); }
.btn.primary { border-color: var(--primary); background: var(--primary); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0e1024; } }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { border-color: var(--bad); color: var(--bad); }

/* Three panes fill the window; only a pane's own content ever scrolls. */
#shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr) minmax(360px, 36%);
}

/* Steps */
#rail { padding: 14px 10px; overflow-y: auto; border-right: 1px solid var(--line); }
.stepbtn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 9px;
  background: none;
  text-align: left;
  transition: background 0.15s;
}
.stepbtn:hover { background: var(--line); }
.stepbtn.on { background: var(--primary-soft); color: var(--primary); font-weight: 650; }
.dot {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--line);
  color: var(--muted);
  font-size: 12px;
}
.stepbtn.on .dot { background: var(--primary); color: #fff; }
.stepbtn.done .dot { background: var(--ok); color: #fff; }
.stepbtn small { margin-left: auto; color: var(--muted); font: 11px var(--mono); }

.local { margin: 14px 10px 0; color: var(--muted); font-size: 12px; }

/* Stage */
#stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.stagehead { flex: none; padding: 20px 28px 0; }
.stagehead h1 { margin: 0; font-size: 24px; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
.stagehead p { margin: 3px 0 0; color: var(--muted); }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 12px; }
.tab {
  padding: 5px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-weight: 550;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { background: var(--bg); }
.tab.on { background: var(--ink); color: var(--surface); }
.tab .tick { color: var(--ok); margin-left: 4px; }
.stagebody { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 28px 16px; }
.panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
  align-items: start;
  max-width: 980px;
  animation: enter 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.panel.back { animation-name: enter-back; }
@keyframes enter { from { opacity: 0; transform: translateX(14px); } }
@keyframes enter-back { from { opacity: 0; transform: translateX(-14px); } }
.full { grid-column: 1 / -1; }
.stagefoot {
  flex: none;
  display: flex;
  justify-content: space-between;
  padding: 10px 28px;
  border-top: 1px solid var(--line);
}

/* Fields */
.field label { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 600; }
.control { position: relative; display: flex; align-items: center; }
input.text, textarea {
  width: 100%;
  padding: 9px 40px 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  transition: border-color 0.15s, background 0.15s;
}
input.text.mono { font-family: var(--mono); font-size: 13px; }
input.text:focus, textarea:focus { outline: 0; border-color: var(--primary); background: var(--surface); }
textarea { min-height: 170px; resize: vertical; }
.field.bad input.text { border-color: var(--bad); }
.mark { position: absolute; right: 11px; top: 10px; font-size: 16px; line-height: 1; color: var(--ok); pointer-events: none; }
.mark.pop { animation: pop 0.28s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes pop { from { transform: scale(0.3); opacity: 0; } }
.control:has(.eye) .mark { right: 40px; }
.control:has(.eye) input.text { padding-right: 68px; }
.eye { position: absolute; right: 6px; padding: 3px 6px; border: 0; border-radius: 6px; background: none; color: var(--muted); font-size: 12px; }
.eye:hover { color: var(--ink); }
.hint { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
.err { margin: 4px 0 0; color: var(--bad); font-size: 12.5px; }

/* Derived values read as finished, not as inputs. */
.derived { padding: 8px 12px; border-radius: 9px; background: var(--ok-soft); }
.derived span { display: block; font-size: 12px; color: var(--muted); }
.derived .chip { margin: 1px 0 0; background: none; padding: 0; font-size: 13.5px; color: var(--ink); text-align: left; }

/* Instructions */
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { position: relative; padding: 5px 0 5px 30px; counter-increment: s; }
.steps li::before {
  content: counter(s);
  position: absolute;
  left: 0;
  top: 7px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
}
.chip {
  display: inline;
  padding: 1px 6px;
  border: 0;
  border-radius: 5px;
  background: var(--primary-soft);
  color: var(--primary);
  font: 12.5px/1.6 var(--mono);
  overflow-wrap: anywhere;
  cursor: copy;
  transition: filter 0.12s;
}
.chip:hover { filter: brightness(0.94); }
.chip.got { background: var(--ok-soft); color: var(--ok); }
.note { padding: 9px 12px; border-radius: 9px; background: var(--bg); }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.copyblock { display: flex; gap: 8px; align-items: flex-start; }
.copyblock div { flex: 1; padding: 8px 12px; border-radius: 9px; background: var(--bg); }
.label { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 600; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 4px 8px; color: var(--muted); font-size: 12px; font-weight: 500; text-align: left; }
td { padding: 3px 8px; border-top: 1px solid var(--line); }
td:nth-child(2) { font-weight: 600; white-space: nowrap; }

/* Checks */
.check {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 2px 8px;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.15s;
}
.check:hover { background: var(--bg); }
.check input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--ok); cursor: pointer; }
.check.done .text { color: var(--muted); }
.check.danger .text { color: var(--bad); font-weight: 650; }
.check .hint { grid-column: 2; margin: 0; }

/* The files, writing themselves */
#preview { display: flex; flex-direction: column; min-height: 0; background: var(--code-bg); color: var(--code-ink); }
.pvtabs { flex: none; display: flex; gap: 2px; padding: 10px 10px 0; }
.pvtab { white-space: nowrap; padding: 7px 12px; border: 0; border-radius: 8px 8px 0 0; background: none; color: var(--code-dim); font: 12.5px var(--mono); transition: color 0.15s; }
.pvtab:hover { color: var(--code-ink); }
.pvtab.on { background: rgba(255, 255, 255, 0.07); color: #fff; }
.pvcopy { white-space: nowrap; margin-left: auto; padding: 5px 10px; border: 0; border-radius: 7px; background: rgba(255, 255, 255, 0.09); color: var(--code-ink); font-size: 12px; }
.pvcopy:hover { background: rgba(255, 255, 255, 0.16); }
.pvbody { flex: 1; min-height: 0; overflow: auto; padding: 12px 0 20px; background: rgba(255, 255, 255, 0.07); font: 12.5px/1.65 var(--mono); }
.line { display: block; min-height: 1.65em; padding: 0 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.line.head { color: #fff; font-weight: 700; }
.line.comment { color: var(--code-dim); }
.line.flash { animation: flash 1.1s ease-out; }
@keyframes flash { from { background: rgba(120, 140, 255, 0.45); color: #fff; } }

/* Dialog */
#dialog { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 20px; background: rgba(15, 17, 45, 0.45); animation: fade 0.15s; }
#dialog[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.sheet { width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 24px; border-radius: 16px; background: var(--surface); animation: rise 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }
.sheet h2 { margin: 0 0 6px; font-size: 19px; }
.sheet p { margin: 6px 0; }
.sheet .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.sheet .steps { margin-top: 8px; }
.gaps { margin: 8px 0; padding: 9px 12px; border-radius: 9px; background: var(--warn-soft); color: var(--warn); }

#toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 20;
  padding: 7px 14px;
  border-radius: 9px;
  background: var(--ink);
  color: var(--surface);
  font-size: 13px;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1180px) {
  #shell { grid-template-columns: 56px minmax(0, 1fr) minmax(300px, 34%); }
  .pvtabs { overflow-x: auto; }
  .stepbtn span:not(.dot), .stepbtn small, .local { display: none; }
  .stepbtn { justify-content: center; padding: 8px 0; }
}
@media (max-width: 820px) {
  body { overflow: auto; height: auto; }
  #top { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 10px; }
  .meter, .spacer { display: none; }
  #shell { display: block; }
  #rail { display: flex; gap: 4px; overflow-x: auto; border: 0; padding: 8px; position: sticky; top: 0; background: var(--bg); z-index: 2; }
  .stepbtn { width: auto; flex: none; }
  .panel { grid-template-columns: minmax(0, 1fr); }
  .stagehead, .stagebody, .stagefoot { padding-left: 16px; padding-right: 16px; }
  #preview { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
