:root {
  --bg: #0d0e12;
  --surface: #15161c;
  --surface-2: #1b1c24;
  --input: #101116;
  --border: #262833;
  --border-strong: #343746;
  --text: #e8e9f0;
  --muted: #8b8fa3;
  --brand: #7c5cff;
  --brand-hover: #8f74ff;
  --brand-soft: rgba(124, 92, 255, 0.14);
  --danger: #f2545b;
  --warning: #f5b544;
  --success: #3fbf7f;
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(124, 92, 255, 0.12), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  min-height: 100vh;
  padding-bottom: 88px;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* ── Topbar ─────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 14, 18, 0.8);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #7c5cff, #b26bff);
  font-weight: 700; font-size: 13px; letter-spacing: 0.5px;
  box-shadow: 0 4px 18px rgba(124, 92, 255, 0.35);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text span { color: var(--muted); font-size: 12px; }

a.brand { color: inherit; text-decoration: none; }
.auth { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-chip {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  padding: 4px 6px 4px 4px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); font-size: 13px; font-weight: 500;
}
.user-chip img { width: 26px; height: 26px; border-radius: 50%; flex: none; }
.user-chip .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.user-chip a { color: var(--muted); text-decoration: none; font-size: 12px; padding: 4px 8px; border-radius: 999px; white-space: nowrap; }
.user-chip a:hover { color: var(--text); background: var(--border); }
.skeleton { width: 140px; height: 34px; border-radius: 999px; background: var(--surface); }

.banner {
  margin: 16px auto 0; max-width: 1400px; width: calc(100% - 48px);
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--brand-soft); border: 1px solid rgba(124, 92, 255, 0.35);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.banner.error { background: rgba(242, 84, 91, 0.1); border-color: rgba(242, 84, 91, 0.4); }
.banner.warning { background: rgba(245, 181, 68, 0.08); border-color: rgba(245, 181, 68, 0.35); }
.banner p { margin: 0; flex: 1 1 320px; }

.btn.discord { background: #5865f2; border-color: #5865f2; color: #fff; text-decoration: none; white-space: nowrap; }
.btn.discord:hover { background: #4752c4; }
.btn.discord svg { width: 18px; height: 18px; }
.btn.small { padding: 6px 12px; font-size: 13px; }

.edit-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: rgba(245, 181, 68, 0.08); border: 1px solid rgba(245, 181, 68, 0.35); font-size: 13px;
}
.edit-banner strong { color: #f7cf86; }
.edit-banner .spacer { flex: 1; }
.edit-banner a { color: var(--brand-hover); font-weight: 600; text-decoration: none; }
.forum-box {
  display: flex; flex-direction: column; gap: 12px; padding: 12px;
  border: 1px solid rgba(124, 92, 255, 0.35); border-radius: var(--radius-sm); background: var(--brand-soft);
}
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-size: 13px; font-weight: 500; cursor: pointer;
}
.tag-chip:hover:not(:disabled) { border-color: var(--brand); }
.tag-chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.tag-chip:disabled { opacity: 0.4; cursor: default; }
.tag-chip img { width: 16px; height: 16px; }
.load-row { display: flex; gap: 8px; }
.load-row input { flex: 1; min-width: 0; }

/* ── Layout ─────────────────────────────── */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px; max-width: 1400px; margin: 0 auto; padding: 24px;
}
.editor { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.preview-sticky { position: sticky; top: 88px; }
.preview-label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-weight: 600; margin-bottom: 10px; font-size: 13px;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.view-switch { display: none; }

/* ── Cards ─────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.embed-card { border-left: 4px solid var(--accent, var(--border-strong)); }
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px 12px 16px; user-select: none;
}
.card-head.clickable { cursor: pointer; }
.card-head.clickable:hover { background: var(--surface-2); }
.card-head h2 { font-size: 15px; margin: 0; font-weight: 600; white-space: nowrap; }
.card-head .head-sub { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.card-head .spacer { flex: 1; }
.chev { transition: transform 0.15s; color: var(--muted); display: inline-flex; }
.collapsed .chev { transform: rotate(-90deg); }
.card-body { padding: 4px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.collapsed .card-body { display: none; }

.head-actions { display: flex; gap: 2px; flex: none; }
.icon-btn {
  width: 30px; height: 30px; display: inline-grid; place-items: center;
  border-radius: 7px; border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--border); color: var(--text); }
.icon-btn.danger:hover:not(:disabled) { background: rgba(242, 84, 91, 0.15); color: var(--danger); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn svg { width: 16px; height: 16px; }

/* ── Form fields ─────────────────────────────── */
.fld { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fld-label { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; color: var(--muted); }
.count { font-weight: 500; font-variant-numeric: tabular-nums; }
.count.warn { color: var(--warning); }
.count.over { color: var(--danger); }
input[type="text"], input[type="url"], textarea, select {
  width: 100%; background: var(--input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 11px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { resize: vertical; min-height: 42px; }
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input.invalid { border-color: var(--danger); }
select { cursor: pointer; }
select:disabled { opacity: 0.7; cursor: default; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }

.color-input { display: flex; gap: 8px; align-items: center; }
.color-input input[type="color"] {
  width: 42px; height: 40px; padding: 3px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--input); cursor: pointer; flex: none;
}
.color-input input[type="text"] { font-family: ui-monospace, Consolas, monospace; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch {
  width: 22px; height: 22px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; padding: 0;
}
.swatch:hover { border-color: #fff; }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }

.sec { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.sec summary {
  list-style: none; cursor: pointer; padding: 10px 12px; font-weight: 600; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.sec summary::-webkit-details-marker { display: none; }
.sec summary::before { content: "›"; color: var(--muted); font-size: 16px; line-height: 1; transition: transform 0.15s; }
.sec[open] summary::before { transform: rotate(90deg); }
.sec summary .badge { margin-left: auto; }
.sec-body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 10px; }
.badge {
  font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  background: var(--border); color: var(--muted);
}

.list-item {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px; display: flex; flex-direction: column; gap: 8px; background: var(--surface);
}
.list-row { display: flex; gap: 8px; align-items: center; }
.list-row > input { flex: 1; min-width: 0; }
.list-row .mini-actions { display: flex; gap: 2px; flex: none; }
.btn-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) minmax(0, 1.4fr) auto; gap: 8px; align-items: center; }

.add-btn {
  border: 1px dashed var(--border-strong); background: transparent; color: var(--muted);
  border-radius: var(--radius-sm); padding: 9px; cursor: pointer; font-weight: 500;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.add-btn:hover:not(:disabled) { border-color: var(--brand); color: var(--text); background: var(--brand-soft); }
.add-btn:disabled { opacity: 0.4; cursor: default; }
.add-btn.big { padding: 14px; border-radius: var(--radius); }

/* ── Buttons ─────────────────────────────── */
.btn {
  border: 1px solid var(--border-strong); background: var(--surface-2);
  padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600;
  display: inline-flex; align-items: center; gap: 8px; transition: background 0.15s, opacity 0.15s;
}
.btn:hover:not(:disabled) { background: var(--border); }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35); border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  border-top: 1px solid var(--border); background: rgba(13, 14, 18, 0.88); backdrop-filter: blur(10px);
}
.actionbar-inner {
  max-width: 1400px; margin: 0 auto; padding: 12px 24px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.actions-left { display: flex; gap: 8px; }

/* ── Issues ─────────────────────────────── */
.issues { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.issue { display: flex; gap: 8px; font-size: 13px; padding: 8px 12px; border-radius: var(--radius-sm); }
.issue.error { background: rgba(242, 84, 91, 0.1); color: #ff9ea2; }
.issue.warning { background: rgba(245, 181, 68, 0.1); color: #f7cf86; }
.issue.ok { background: rgba(63, 191, 127, 0.1); color: #8be0b4; }

/* ── Dialog & Toasts ─────────────────────────────── */
dialog {
  border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--text); width: min(720px, calc(100% - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(2px); }
.dialog { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog p { margin: 0; }
#json-text { font: 12.5px/1.5 ui-monospace, Consolas, monospace; min-height: 280px; }
#templates-body { display: flex; flex-direction: column; gap: 14px; }
.tpl-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.tpl-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
.tpl-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.tpl-info strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-info span { font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toasts { position: fixed; right: 20px; bottom: 84px; z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: calc(100% - 40px); }
.toast {
  background: var(--surface-2); border: 1px solid var(--border-strong); border-left: 4px solid var(--brand);
  padding: 12px 16px; border-radius: var(--radius-sm); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.2s ease-out; max-width: 380px;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast a { color: var(--brand-hover); font-weight: 600; margin-left: 6px; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ── Discord-Vorschau ─────────────────────────────── */
.discord {
  background: #313338; border-radius: var(--radius); padding: 16px 16px 20px 0;
  font-family: "gg sans", "Noto Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #dbdee1; font-size: 16px; line-height: 1.375rem;
  border: 1px solid #1f2023; overflow: hidden;
}
.d-post { margin: 0 0 14px 16px; padding-bottom: 12px; border-bottom: 1px solid #3f4147; }
.d-post-forum { font-size: 12px; color: #949ba4; font-weight: 600; margin-bottom: 4px; }
.d-post-title { font-size: 20px; font-weight: 600; color: #f2f3f5; line-height: 1.3; overflow-wrap: anywhere; }
.d-post-title .d-empty { font-size: 20px; }
.d-post-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.d-post-tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  background: #3f4147; color: #dbdee1; font-size: 12px; font-weight: 500;
}
.d-post-tag img { width: 14px; height: 14px; }
.d-msg { display: flex; gap: 16px; padding-left: 16px; }
.d-avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; object-fit: cover; margin-top: 2px; background: #5865f2; }
.d-body { min-width: 0; flex: 1; }
.d-head { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.d-name { color: #f2f3f5; font-weight: 500; }
.d-tag {
  background: #5865f2; color: #fff; font-size: 10px; font-weight: 600; line-height: 15px;
  padding: 0 4px; border-radius: 3px; text-transform: uppercase; margin-left: 2px;
}
.d-time { color: #949ba4; font-size: 12px; margin-left: 4px; }
.d-content { overflow-wrap: anywhere; }
.d-empty { color: #949ba4; font-style: italic; font-size: 14px; }

.d-embed {
  max-width: 516px; margin-top: 8px; background: #2b2d31;
  border-left: 4px solid #1e1f22; border-radius: 4px; padding: 8px 16px 16px 12px;
}
.e-top { display: flex; gap: 16px; }
.e-main { min-width: 0; flex: 1; }
.e-author { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 14px; font-weight: 600; color: #f2f3f5; }
.e-author img { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }
.e-author a { color: #f2f3f5; text-decoration: none; }
.e-author a:hover { text-decoration: underline; }
.e-title { margin-top: 8px; font-size: 16px; font-weight: 600; color: #f2f3f5; overflow-wrap: anywhere; }
.e-title a { color: #00a8fc; text-decoration: none; }
.e-desc { margin-top: 8px; font-size: 14px; line-height: 1.125rem; overflow-wrap: anywhere; }
.e-fields { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
.e-field { font-size: 14px; line-height: 1.125rem; min-width: 0; overflow-wrap: anywhere; }
.e-field-name { color: #f2f3f5; font-weight: 600; margin-bottom: 2px; }
.e-thumb { width: 80px; height: 80px; object-fit: contain; border-radius: 4px; margin-top: 8px; flex: none; }
.e-image { display: block; margin-top: 16px; max-width: 100%; max-height: 300px; border-radius: 4px; object-fit: contain; }
.e-footer { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; line-height: 1rem; color: #dbdee1; }
.e-footer img { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; }
.broken { display: none !important; }

.d-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.d-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 16px;
  background: #4e5058; color: #fff; border-radius: 8px; font-size: 14px; font-weight: 500; text-decoration: none;
}
.d-btn:hover { background: #6d6f78; }
.d-btn img { width: 18px; height: 18px; }
.d-btn svg { width: 14px; height: 14px; opacity: 0.85; }

/* Markdown */
.md a { color: #00a8fc; text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md strong { font-weight: 700; }
.md h1, .md h2, .md h3 { color: #f2f3f5; margin: 8px 0 4px; line-height: 1.375; }
.md h1 { font-size: 1.5em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1em; }
.md .subtext { font-size: 0.8em; color: #949ba4; }
.md code { background: #1e1f22; border-radius: 4px; padding: 0.1em 0.3em; font: 0.85em/1.125rem Consolas, "Andale Mono", monospace; }
.md pre { margin: 6px 0 0; background: #1e1f22; border: 1px solid #1a1b1e; border-radius: 4px; padding: 8px; overflow-x: auto; white-space: pre-wrap; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0; padding: 0 8px 0 12px; border-left: 4px solid #4e5058; border-radius: 2px; }
.md ul, .md ol { margin: 4px 0; padding-left: 22px; }
.md .mention { background: rgba(88, 101, 242, 0.3); color: #c9cdfb; border-radius: 3px; padding: 0 2px; font-weight: 500; }
.md .spoiler { background: #1e1f22; color: transparent; border-radius: 3px; cursor: pointer; }
.md .spoiler:hover { color: inherit; background: rgba(255, 255, 255, 0.1); }
.md .ts { background: rgba(255, 255, 255, 0.06); border-radius: 3px; padding: 0 2px; }
.md .emoji { width: 1.375em; height: 1.375em; vertical-align: bottom; object-fit: contain; }

/* ── Responsive ─────────────────────────────── */
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .topbar { padding: 12px 16px; }
  .banner { width: calc(100% - 32px); }
  .view-switch {
    display: flex; gap: 4px; margin: 16px 16px 0; padding: 4px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  }
  .view-switch button {
    flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--muted);
  }
  .view-switch button.active { background: var(--brand); color: #fff; }
  body:not(.show-preview) .preview-col { display: none; }
  body.show-preview .editor { display: none; }
  .preview-sticky { position: static; }
  .actionbar-inner { padding: 12px 16px; }
}
@media (max-width: 560px) {
  .brand-text span, .user-chip .name { display: none; }
  .brand-text strong { font-size: 14px; }
  .btn.discord .label-long { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .btn-row { grid-template-columns: 52px minmax(0, 1fr) auto; }
  .btn-row .btn-url { grid-column: 1 / -1; grid-row: 2; }
  .discord { padding-right: 8px; }
  .d-msg { gap: 10px; padding-left: 10px; }
}
