:root {
  --bg: #0e1117;
  --bg-soft: #161b24;
  --panel: #1b212c;
  --panel-2: #222a37;
  --line: #2c3645;
  --text: #e6edf6;
  --muted: #93a0b3;
  --accent: #4f8cff;
  --accent-2: #36d399;
  --warn: #f6c177;
  --danger: #ff6b6b;
  --code-bg: #0c1018;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(1100px 600px at 80% -10%, rgba(79, 140, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at 0% 0%, rgba(54, 211, 153, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* top bar */
.topbar {
  border-bottom: 1px solid var(--line);
  background: rgba(14, 17, 23, 0.82);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 30;
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 30px; line-height: 1; }
.brand h1 { font-size: 19px; margin: 0; letter-spacing: .2px; }
.tag { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); max-width: 640px; }

/* layout */
.layout {
  display: grid;
  grid-template-columns: minmax(340px, 430px) 1fr;
  gap: 22px;
  padding-top: 26px;
  padding-bottom: 30px;
  align-items: start;
}
.panel {
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.input-panel { position: sticky; top: 86px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.panel-head h2, .output-head h2 { font-size: 15px; margin: 0; color: var(--text); }
.hint { font-size: 11.5px; color: var(--muted); font-weight: 400; }
.hint.inline { margin-left: 8px; }

/* templates */
.templates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.tpl {
  text-align: left; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 9px; padding: 9px 10px;
  font-size: 12.5px; display: flex; align-items: center; gap: 8px;
  transition: border-color .15s, transform .1s, background .15s;
}
.tpl:hover { border-color: var(--accent); transform: translateY(-1px); }
.tpl.active { border-color: var(--accent); background: rgba(79,140,255,.12); }
.tpl .emoji { font-size: 16px; }

label.field-label {
  display: block; font-size: 12.5px; color: var(--muted);
  margin: 14px 0 6px; font-weight: 600;
}
textarea, select {
  width: 100%; background: var(--code-bg); border: 1px solid var(--line);
  color: var(--text); border-radius: 9px; padding: 10px 11px;
  font-size: 13.5px; font-family: inherit; resize: vertical;
}
textarea:focus, select:focus { outline: none; border-color: var(--accent); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* toggles */
.toggles { display: flex; flex-wrap: wrap; gap: 7px; }
.toggle {
  cursor: pointer; user-select: none;
  font-size: 12px; padding: 6px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--muted);
  transition: all .14s;
}
.toggle[aria-pressed="true"] { background: rgba(54,211,153,.15); border-color: var(--accent-2); color: #bdf3dc; }

.actions { display: flex; gap: 10px; margin-top: 20px; }
.primary-btn {
  flex: 1; cursor: pointer; border: none; border-radius: 9px;
  background: linear-gradient(180deg, #5b95ff, #3f7cf0); color: #fff;
  font-size: 14px; font-weight: 600; padding: 11px 16px;
  box-shadow: 0 6px 16px rgba(63,124,240,.3);
  transition: transform .1s, box-shadow .15s;
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(63,124,240,.4); }
.ghost-btn {
  cursor: pointer; border: 1px solid var(--line); background: transparent;
  color: var(--muted); border-radius: 9px; padding: 9px 14px;
  font-size: 13px; text-decoration: none; display: inline-flex; align-items: center;
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent); }

/* output */
.output-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.scene-line { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }
.scene-line code { font-family: var(--mono); color: var(--accent-2); }
.export-btns { display: flex; gap: 8px; flex-shrink: 0; }
.mini-btn, .copy-btn {
  cursor: pointer; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--muted); border-radius: 7px; padding: 6px 10px; font-size: 11.5px;
  transition: all .14s;
}
.mini-btn:hover, .copy-btn:hover { color: var(--text); border-color: var(--accent); }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab {
  cursor: pointer; background: transparent; border: none; color: var(--muted);
  padding: 9px 13px; font-size: 13px; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: all .14s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.tab-pane { display: none; animation: fade .2s ease; }
.tab-pane.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.empty { color: var(--muted); font-size: 13.5px; padding: 30px 6px; text-align: center; }

/* field cards */
.field-row {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  margin-bottom: 9px; background: var(--panel-2);
}
.field-row .fr-top { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.fname { font-family: var(--mono); font-size: 13.5px; color: var(--text); font-weight: 600; }
.ftype { font-family: var(--mono); font-size: 11px; color: var(--accent); background: rgba(79,140,255,.12); padding: 2px 7px; border-radius: 5px; }
.fbadge { font-size: 10.5px; padding: 2px 7px; border-radius: 5px; border: 1px solid var(--line); color: var(--muted); }
.fbadge.key { color: var(--warn); border-color: rgba(246,193,119,.4); background: rgba(246,193,119,.1); }
.fbadge.notnull { color: var(--danger); border-color: rgba(255,107,107,.35); }
.fdesc { font-size: 12.5px; color: var(--text); margin: 7px 0 4px; }
.fmeta { font-size: 11.5px; color: var(--muted); }
.fmeta .ex { font-family: var(--mono); color: #cdd8e6; }
.fgrouptag { font-size: 10px; color: var(--muted); opacity: .8; }

/* info blocks */
.info-block { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.info-block h3 { margin: 0 0 8px; font-size: 14px; }
.info-block p { margin: 4px 0; font-size: 13px; color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 8px 0; }
.chip { font-family: var(--mono); font-size: 12px; background: rgba(54,211,153,.14); color: #bdf3dc; border: 1px solid rgba(54,211,153,.35); padding: 4px 10px; border-radius: 7px; }
.muted-p { color: var(--muted); font-size: 12.5px; }

/* code */
.code-wrap { position: relative; margin-bottom: 14px; }
.code-wrap .copy-btn { position: absolute; top: 9px; right: 9px; }
.code-title { font-size: 12.5px; color: var(--text); font-weight: 600; margin: 0 0 3px; }
.code-purpose { font-size: 11.5px; color: var(--muted); margin: 0 0 6px; }
pre {
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 9px;
  padding: 14px 14px; overflow-x: auto; margin: 0;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55; color: #d6e2f0;
}
pre .kw { color: #79b8ff; }
pre .fn { color: #f6c177; }
pre .str { color: #36d399; }
pre .com { color: #5b6877; font-style: italic; }

/* explain */
.explain { padding-top: 18px; padding-bottom: 10px; border-top: 1px solid var(--line); }
.explain > h2 { font-size: 17px; margin: 6px 0 16px; }
.explain-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.explain-grid .card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 15px; }
.explain-grid h3 { margin: 0 0 8px; font-size: 14px; color: var(--accent); }
.explain-grid p { margin: 0; font-size: 12.5px; color: var(--muted); }
.loop-note { margin: 18px 0 6px; font-size: 12.5px; color: var(--muted); border-left: 2px solid var(--accent-2); padding-left: 12px; }

.foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 18px; padding-bottom: 28px; color: var(--muted); font-size: 11.5px; border-top: 1px solid var(--line); margin-top: 14px; }

/* toast */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--accent-2); color: #06231a; padding: 10px 18px; border-radius: 9px;
  font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none; transition: all .25s;
  z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* responsive */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .input-panel { position: static; }
  .explain-grid { grid-template-columns: 1fr 1fr; }
  .tag { display: none; }
}
@media (max-width: 540px) {
  .templates { grid-template-columns: 1fr; }
  .explain-grid { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .output-head { flex-direction: column; }
  .brand h1 { font-size: 17px; }
}
