:root {
  color-scheme: dark;
  --bg: #07080c;
  --bg-elev: #0e131c;
  --ink: #e8eef8;
  --muted: #93a0b5;
  --line: #2a3548;
  --line-strong: #3c4d68;
  --cyan: #5ce1ff;
  --signal: #2ef2c5;
  --amber: #ffc14d;
  --green: #3dff8a;
  --danger: #ff6b7a;
  --sans: "Segoe UI", "WenQuanYi Micro Hei", "Droid Sans Fallback", "PingFang SC", "Hiragino Sans", "Noto Sans CJK SC", "Microsoft YaHei", "Malgun Gothic", sans-serif;
  --mono: "Cascadia Mono", "SFMono-Regular", ui-monospace, "WenQuanYi Micro Hei Mono", monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 78% -10%, rgba(92, 225, 255, 0.08), transparent 50%),
    var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
}

a { color: var(--cyan); text-underline-offset: 2px; }
a:hover { color: #d8f9ff; }

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

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.first-screen {
  align-content: start;
  display: grid;
  grid-template-rows: 48px minmax(0, calc(100vh - 78px)) 30px auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: rgba(8, 10, 14, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.01em;
}

.brand svg { display: block; }

h1 {
  margin: 0;
  min-width: 0;
  flex: 1;
  font-size: 16px;
  line-height: 1;
  font-weight: 650;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lang-menu { position: relative; margin-left: auto; flex: none; }

.lang-menu summary {
  list-style: none;
  height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: #141a24;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.lang-menu summary::-webkit-details-marker { display: none; }

.lang-menu summary::after {
  content: "";
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
}

.lang-list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 50;
  min-width: 148px;
  padding: 6px;
  display: grid;
  gap: 2px;
  background: #121822;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.lang-list a {
  display: flex;
  align-items: center;
  height: 32px;
  padding: 0 8px;
  border-radius: 7px;
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
}

.lang-list a:hover,
.lang-list a[aria-current="page"] { background: #1a2c31; color: #e7fff8; }

.workspace {
  width: min(1400px, calc(100% - 24px));
  height: calc(100% - 8px);
  margin: 8px auto 0;
  min-height: 0;
  display: grid;
  grid-template-columns: 156px minmax(0, 1fr) 260px;
  gap: 10px;
}

.toolbar,
.inspector,
.stage {
  min-width: 0;
  min-height: 0;
  border: 1px solid #263246;
  border-radius: 12px;
  background: var(--bg-elev);
}

.toolbar,
.inspector {
  overflow: auto;
  overscroll-behavior: contain;
  padding: 10px 8px;
}

.toolbar { display: flex; flex-direction: column; gap: 6px; }

.inspector {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
}

.toolbar h2,
.inspector h2 {
  margin: 6px 2px 0;
  font-size: 11px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.toolbar h2:first-child { margin-top: 0; }

.tool-btn,
.preset-btn,
.file-btn {
  height: 32px;
  min-height: 32px;
  max-height: 36px;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: #151b26;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
}

.tool-btn:hover,
.preset-btn:hover,
.file-btn:hover { border-color: #6f86a8; background: #1b2433; }

.tool-btn.is-active,
.preset-btn.is-active {
  background: #103238;
  border-color: var(--signal);
  color: #e9fff8;
}

#presets { display: flex; flex-direction: column; gap: 6px; flex: none; }

#file-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: none;
}

.file-btn { justify-content: center; padding: 0 8px; }

.stage {
  position: relative;
  background: #05070b;
  overflow: hidden;
}

.stage canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.stage-name {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 2;
  margin: 0;
  font-size: 12px;
  line-height: 1.2;
  color: var(--muted);
  pointer-events: none;
}

.noscript {
  position: absolute;
  z-index: 2;
  left: 16px;
  right: 16px;
  bottom: 16px;
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(12, 16, 24, 0.92);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 14px;
}

.truth {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #090c12;
}

.truth-fallback,
.truth-note {
  margin: 0;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
}

.truth table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.truth caption {
  caption-side: bottom;
  text-align: left;
  padding: 6px 8px 8px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 11px;
}

.truth th,
.truth td {
  padding: 4px 4px;
  text-align: center;
  border-bottom: 1px solid #1e2836;
  font-weight: 600;
}

.truth th { color: var(--muted); font-size: 11px; background: #101620; position: sticky; top: 0; }
.truth td.out,
.truth th.out { border-left: 2px solid #31445f; }
.truth tr.is-live td { background: rgba(46, 242, 197, 0.16); color: #f3fffb; }

.file-msg { min-height: 0; margin: 0; font-size: 12px; color: var(--signal); }
.file-msg.is-error { color: var(--danger); }

#extra { display: flex; flex-direction: column; gap: 6px; }
#extra[hidden] { display: none; }

.hz-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.hz-line input[type="range"] { grid-column: 1 / -1; width: 100%; height: 18px; accent-color: var(--signal); }
.hz-line .tool-btn { width: auto; padding: 0 12px; }

.edit-row { display: flex; flex-direction: column; gap: 6px; }
.edit-row label { display: grid; gap: 4px; font-size: 11px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }

.inspector input[type="text"],
dialog textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #090c12;
  border-radius: 8px;
  color: var(--ink);
}

.inspector input[type="text"] { height: 32px; padding: 0 8px; text-transform: none; letter-spacing: 0; font-size: 13px; }

.static-presets { margin: 0 0 8px; padding-left: 18px; font-size: 13px; }

.fineprint {
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  overflow: hidden;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
  line-height: 30px;
}

.fineprint p { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fineprint a { color: #b7ecff; }

.docs {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 72px;
}

.docs h2 { margin: 32px 0 10px; font-size: 22px; letter-spacing: -0.02em; }
.docs h3 { margin: 18px 0 6px; font-size: 16px; }
.docs p, .docs li { color: #d5deeb; }
.docs .eq {
  font-family: var(--mono);
  color: #d8fff4;
  background: #101820;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

.docs table {
  border-collapse: collapse;
  margin: 8px 0 14px;
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.docs th, .docs td {
  border: 1px solid var(--line);
  padding: 4px 10px;
  text-align: center;
}

.docs th { background: #121924; color: var(--muted); font-weight: 650; }
.docs td.out, .docs th.out { background: #102028; }

.docs pre {
  overflow: auto;
  padding: 12px;
  border-radius: 10px;
  background: #090c12;
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.faq h3 { font-size: 16px; }
.ftc-disclosure { color: #d5deeb; }

.drag-ghost {
  position: fixed;
  z-index: 80;
  height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 999px;
  background: #103238;
  border: 1px solid var(--signal);
  color: #e9fff8;
  font-size: 12.5px;
  font-weight: 700;
  pointer-events: none;
}

dialog {
  width: min(520px, calc(100vw - 28px));
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #10151e;
  color: var(--ink);
  padding: 16px;
}

dialog h3 { margin: 0 0 8px; font-size: 16px; }
dialog textarea { min-height: 180px; padding: 8px; resize: vertical; }
.dialog-actions { display: flex; gap: 8px; margin-top: 10px; }
.dialog-actions .file-btn { width: auto; padding: 0 14px; }
.dialog-error { min-height: 1.2em; margin: 8px 0 0; color: var(--danger); font-size: 13px; }

.missing {
  width: min(720px, calc(100% - 32px));
  margin: 48px auto 72px;
}

.missing h1 { white-space: normal; flex: none; font-size: 32px; margin: 12px 0; }
.missing ul { padding-left: 18px; }

@media (max-width: 960px) {
  .first-screen { grid-template-rows: 48px auto auto auto; }
  .workspace {
    width: calc(100% - 16px);
    height: auto;
    grid-template-columns: 1fr;
  }
  .stage { height: 68vh; min-height: 420px; }
  .toolbar { flex-direction: row; flex-wrap: wrap; }
  .toolbar h2 { width: 100%; }
  .tool-btn { width: auto; }
  h1 { font-size: 14px; }
  .fineprint { height: auto; white-space: normal; line-height: 1.4; padding: 6px 10px; }
  .fineprint p { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}
