:root {
  --bg: #0e1016;
  --panel: #161922;
  --panel-2: #1c202b;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef0f6;
  --muted: #8e95a8;
  --faint: #5f6678;
  --accent: #5865f2;
  --accent-2: #4752c4;
  --ok: #3ecf8e;
  --bad: #ff5c6c;
  --dc-bg: #313338;
  --dc-embed: #2b2d31;
  --dc-text: #dbdee1;
  --dc-muted: #949ba4;
  --dc-link: #00a8fc;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

code { background: rgba(255, 255, 255, 0.08); padding: 1px 5px; border-radius: 5px; font-size: 0.92em; }
small { color: var(--muted); display: block; margin-top: 4px; }
h2 { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0; font-weight: 600; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px;
  background: rgba(14, 16, 22, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.guild-icon { width: 38px; height: 38px; border-radius: 12px; background: var(--panel-2); object-fit: cover; }
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.me { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.me img { width: 26px; height: 26px; border-radius: 50%; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
  max-width: 1500px;
  margin: 0 auto;
}
.editor { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.preview-wrap { position: sticky; top: 82px; align-self: start; max-height: calc(100vh - 100px); overflow: auto; }
.preview-title { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; font-weight: 600; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .preview-wrap { position: static; max-height: none; order: -1; }
  .me span { display: none; }
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.head-actions { display: flex; gap: 4px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 600px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.inline { display: flex; gap: 8px; align-items: center; }
.inline > input, .inline > select { flex: 1; min-width: 0; }
.inline.wrap { flex-wrap: wrap; }
.inline.end { justify-content: flex-end; }

fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 12px; margin: 0; }
legend { color: var(--muted); font-size: 12px; padding: 0 6px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { color: var(--muted); font-size: 12px; font-weight: 600; display: flex; justify-content: space-between; }
.field em { font-style: normal; font-weight: 400; }
.check { display: flex; flex-direction: row; align-items: center; gap: 8px; color: var(--muted); cursor: pointer; }
.field.check { align-self: end; padding-bottom: 10px; }
.check.small { font-size: 12px; white-space: nowrap; }

input, select, textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  font: inherit;
  outline: none;
  transition: border-color 0.15s;
}
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }
input[type="color"] { width: 44px; height: 38px; padding: 3px; flex: none; cursor: pointer; }
textarea { resize: vertical; min-height: 40px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input.invalid { border-color: var(--bad); }

.segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.segmented label {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 9px; border: 1px solid var(--line); cursor: pointer;
}
.segmented label:has(input:checked) { border-color: var(--accent); background: rgba(88, 101, 242, 0.12); }

.counter { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.counter.over { color: var(--bad); }

button {
  font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid transparent;
  padding: 9px 14px; color: var(--text); background: var(--panel-2);
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-2); }
button.secondary { border-color: var(--line); }
button.secondary:hover { border-color: var(--accent); }
button.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
button.ghost:hover { color: var(--text); }
button.danger { color: #ff9aa4; }
button.icon { background: transparent; padding: 4px 8px; color: var(--muted); }
button.icon:hover { color: var(--text); background: var(--panel-2); }
button.icon.danger:hover { color: var(--bad); }
button.add { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
button.add:hover { border-color: var(--accent); color: var(--text); }
button.add.small { align-self: flex-start; padding: 6px 12px; font-size: 13px; }
button.collapse { background: transparent; padding: 0; display: flex; align-items: center; gap: 8px; min-width: 0; }
button.collapse h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--muted); transition: transform 0.15s; display: inline-block; }
.embed-card.closed .chev { transform: rotate(-90deg); }
.embed-card.closed .embed-body { display: none; }
.embed-body { display: flex; flex-direction: column; gap: 12px; }
.embed-card { border-left: 4px solid var(--embed-color, var(--accent)); }

.tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 10px; padding: 4px; }
.tab { flex: 1; background: transparent; padding: 8px; color: var(--muted); }
.tab.active { background: var(--panel-2); color: var(--text); }

.send-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.mentions { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.mentions label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
#send { min-width: 120px; }

.status { font-size: 13px; min-height: 0; }
.status:empty { display: none; }
.status.ok { color: var(--ok); }
.status.err { color: #ff9aa4; }
.status a { color: inherit; }

.field-row {
  display: grid; grid-template-columns: 1fr 1.6fr auto auto; gap: 8px; align-items: start;
  padding: 10px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line);
}
.field-row .check { padding-top: 10px; }
.fields { display: flex; flex-direction: column; gap: 8px; }
.button-row { display: grid; grid-template-columns: 64px 1fr 1.4fr auto auto; gap: 8px; align-items: center; margin-bottom: 8px; }
@media (max-width: 600px) {
  .field-row { grid-template-columns: 1fr auto; }
  .field-row .f-value { grid-column: 1 / -1; }
  .button-row { grid-template-columns: 56px 1fr auto; }
  .button-row .b-url { grid-column: 1 / -1; }
}

.drop {
  display: block; text-align: center; padding: 18px; border-radius: 10px;
  border: 1px dashed var(--line); color: var(--muted); cursor: pointer;
}
.drop.over { border-color: var(--accent); background: rgba(88, 101, 242, 0.08); }
.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 6px 10px; background: var(--bg); border-radius: 9px; }
.file-list img { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; }
.file-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list code { cursor: pointer; }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  width: min(720px, calc(100vw - 32px)); padding: 18px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog textarea { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }

.preview {
  background: var(--dc-bg); color: var(--dc-text); border-radius: var(--radius);
  padding: 18px 16px; font-family: "gg sans", "Noto Sans", "Segoe UI", system-ui, sans-serif; font-size: 15px; line-height: 1.375;
}
.msg { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 0 16px; }
.msg-avatar { width: 40px; height: 40px; border-radius: 50%; background: #5865f2; object-fit: cover; }
.msg-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.msg-name { font-weight: 600; color: #f2f3f5; }
.msg-tag { background: #5865f2; color: #fff; font-size: 10px; font-weight: 600; padding: 1px 5px; border-radius: 4px; text-transform: uppercase; }
.msg-time { color: var(--dc-muted); font-size: 12px; }
.msg-body { min-width: 0; }
.msg-content { white-space: pre-wrap; word-wrap: break-word; }
.msg-content:empty { display: none; }
.md a, .embed a { color: var(--dc-link); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md h1 { font-size: 24px; margin: 8px 0 4px; line-height: 1.2; }
.md h2 { font-size: 20px; margin: 8px 0 4px; color: inherit; text-transform: none; letter-spacing: 0; font-weight: 700; }
.md h3 { font-size: 16px; margin: 8px 0 4px; }
.md .sub { color: var(--dc-muted); font-size: 13px; }
.md ul { margin: 2px 0; padding-left: 22px; white-space: normal; }
.md blockquote { margin: 2px 0; padding-left: 12px; border-left: 4px solid #4e5058; }
.md code { background: #1e1f22; padding: 0 4px; border-radius: 4px; font-size: 0.85em; font-family: Consolas, monospace; }
.md pre { background: #1e1f22; border: 1px solid #1e1f22; border-radius: 6px; padding: 8px; margin: 4px 0; white-space: pre-wrap; font-size: 13px; font-family: Consolas, monospace; }
.md .spoiler { background: #1e1f22; color: transparent; border-radius: 3px; cursor: pointer; }
.md .spoiler.open { background: rgba(255, 255, 255, 0.1); color: inherit; }
.md .mention { background: rgba(88, 101, 242, 0.3); color: #c9cdfb; border-radius: 3px; padding: 0 2px; font-weight: 500; }

.embed {
  margin-top: 6px; max-width: 520px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px;
  background: var(--dc-embed); border-left: 4px solid #1e1f22; border-radius: 4px; padding: 10px 16px 14px 12px;
}
.embed > * { grid-column: 1; min-width: 0; }
.embed-thumb { grid-column: 2; grid-row: 1 / span 4; width: 80px; height: 80px; border-radius: 4px; object-fit: cover; }
.embed-author { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: #f2f3f5; }
.embed-author img { width: 24px; height: 24px; border-radius: 50%; }
.embed-title { font-weight: 600; color: #f2f3f5; font-size: 16px; }
.embed-desc { font-size: 14px; white-space: pre-wrap; }
.embed-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.embed-field { grid-column: 1 / -1; font-size: 14px; min-width: 0; }
.embed-field.is-inline { grid-column: auto; }
.embed-field-name { font-weight: 600; color: #f2f3f5; margin-bottom: 2px; }
.embed-field-value { white-space: pre-wrap; }
.embed-image { grid-column: 1 / -1; max-width: 100%; border-radius: 4px; margin-top: 6px; }
.embed-footer { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--dc-muted); }
.embed-footer img { width: 20px; height: 20px; border-radius: 50%; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.attachments img, .attachments video { max-width: 400px; max-height: 300px; border-radius: 8px; }
.attachments .file { background: var(--dc-embed); border-radius: 8px; padding: 10px 14px; font-size: 14px; }
.dc-buttons { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.dc-row { display: flex; gap: 8px; flex-wrap: wrap; }
.dc-btn { background: #4e5058; color: #fff; border-radius: 4px; padding: 6px 14px; font-size: 14px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.dc-btn::after { content: "↗"; font-size: 12px; opacity: 0.8; }
.preview-empty { color: var(--dc-muted); font-style: italic; }

.center-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.notice { max-width: 440px; text-align: center; align-items: center; padding: 32px; }
.notice h1 { font-size: 20px; margin: 0; }
.notice p { margin: 0; }
.notice-icon { font-size: 40px; }
.muted { color: var(--muted); }
