:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --line: #e2e2e8;
  --text: #1d1d23;
  --muted: #6b6b78;
  --primary: #5b3df5;
  --primary-text: #fff;
  --danger: #d33;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111116; --panel: #1b1b22; --line: #2d2d38; --text: #ececf1; --muted: #9a9aa8; --primary: #8b74ff; color-scheme: dark; }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: var(--primary); }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }
button.small { padding: 3px 9px; font-size: 12px; font-weight: 500; margin-left: 8px; }
button.icon { padding: 3px 8px; }
button.danger:hover { border-color: var(--danger); color: var(--danger); }
button:disabled { opacity: .5; cursor: progress; }
input, select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; }
textarea { resize: vertical; }
input[type=color] { padding: 2px; height: 34px; width: 44px; flex: none; cursor: pointer; }
input[type=radio], input[type=checkbox] { width: auto; accent-color: var(--primary); }
label { display: block; color: var(--muted); font-size: 12px; font-weight: 500; margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); font-size: 14px; }

.top { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.top select { width: auto; max-width: 220px; }
.top #admin-key { width: 190px; }
.brand { margin-right: 8px; }
.spacer { flex: 1; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 44%); gap: 16px; padding: 16px; }
.editor { min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.panel h2 { font-size: 15px; margin: 0 0 14px; display: flex; align-items: center; }
.panel.ai { border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); }
.hint { color: var(--muted); font-size: 12px; margin: -6px 0 12px; }
.badge { color: var(--muted); font-weight: 500; margin-left: 6px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > label { flex: 1 1 140px; }
.row.end { justify-content: flex-end; align-items: center; }
.status { color: var(--muted); margin-right: auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 12px; }

.color { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; color: var(--muted); font-size: 12px; }
.color input[type=text] { font-family: ui-monospace, monospace; font-size: 12px; }

.item { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.item-head { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; }
.item-head strong { margin-right: auto; }
.inline { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.inline input.emoji { width: 64px; flex: none; text-align: center; }
.inline input.num { width: 80px; flex: none; }
.opt { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.opt.is-correct input[type=text] { border-color: #22a35a; }

.preview { position: sticky; top: 70px; height: calc(100vh - 86px); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.preview-bar { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); font-weight: 600; }
.preview-bar select { width: auto; margin-left: auto; font-weight: 400; }
.preview-bar a { color: var(--primary); font-weight: 500; text-decoration: none; }
.preview iframe { flex: 1; border: 0; width: 100%; background: #000; }

dialog { width: min(900px, 94vw); max-height: 86vh; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); padding: 16px; }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-head { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.dialog-head h2 { margin: 0; font-size: 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.error { background: var(--danger); color: #fff; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .preview { position: static; height: 640px; }
}
