:root {
  color-scheme: dark;
  --bg: #0b0b0b;
  --surface: #151515;
  --surface-hover: #202020;
  --input: #101010;
  --text: #f4f4f4;
  --muted: #9a9a9a;
  --border: #292929;
  --accent: #75a7f7;
  --discord: #313338;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", sans-serif;
  padding: 32px 18px;
}

main {
  width: min(1280px, 100%);
  margin: 0 auto;
}

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
  margin-bottom: 18px;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1;
}

h2,
h3 {
  font-size: 1rem;
}

.label,
.muted,
label span,
small {
  color: var(--muted);
}

.label,
label span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.78rem;
  text-transform: uppercase;
}

.header-note,
.target-help,
.share-status {
  margin-top: 8px;
}

.target-help strong {
  color: var(--text);
  font-weight: 600;
}

.field-note {
  margin-top: 8px;
  font-size: 0.86rem;
  line-height: 1.45;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(360px, 1.05fr);
  gap: 12px;
  align-items: start;
}

.editor-panel,
.side-panel {
  display: grid;
  gap: 12px;
}

.editor-block,
.preview-panel,
.export-panel,
.variable-picker {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  padding: 16px;
}

.block-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.block-head.compact {
  align-items: center;
  margin: 14px 0 10px;
}

label {
  display: block;
  margin-top: 12px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--input);
  color: var(--text);
  font: inherit;
  outline: none;
}

input {
  height: 40px;
  padding: 0 11px;
}

textarea {
  min-height: 96px;
  padding: 10px 11px;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: #3d3d3d;
}

.color-input {
  padding: 3px;
}

.split {
  display: grid;
  grid-template-columns: 0.55fr 1fr;
  gap: 10px;
}

button,
.wide-button {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-hover);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

button:hover,
.wide-button:hover,
.back-link:hover {
  border-color: #3a3a3a;
  background: #242424;
}

.small-button {
  min-height: 36px;
  padding: 0 14px;
}

.muted-button {
  color: var(--muted);
}

.icon-button {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
}

.wide-button {
  width: 100%;
  min-height: 42px;
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--muted);
  white-space: nowrap;
}

.check-row input {
  width: 16px;
  height: 16px;
}

.button-builder {
  display: grid;
  grid-template-columns: minmax(0, 0.75fr) minmax(0, 1fr) auto;
  gap: 8px;
}

.button-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.button-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
}

.button-pill button {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  padding: 0;
}

.error-text {
  margin-top: 10px;
  color: #ef7777;
  font-size: 0.9rem;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 7px;
  padding: 14px 16px;
  text-align: center;
}

.discord-message {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  border-radius: 7px;
  background: var(--discord);
  padding: 18px;
}

.discord-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #1e1f22;
  font-weight: 700;
}

.discord-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
}

.discord-meta span {
  padding: 2px 5px;
  border-radius: 3px;
  background: #5865f2;
  font-size: 0.65rem;
}

.message-content,
.embed-description {
  color: #dbdee1;
  line-height: 1.5;
  white-space: pre-wrap;
}

.embed-preview {
  width: min(560px, 100%);
  margin-top: 10px;
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  background: #2b2d31;
  padding: 12px;
  overflow: hidden;
}

.embed-preview h3 {
  margin-top: 5px;
  font-size: 1rem;
}

.embed-author,
.embed-footer {
  color: #b5bac1;
  font-size: 0.8rem;
}

.mention-token,
.plain-token,
.template-token {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 5px;
  border-radius: 4px;
  line-height: 1.35;
  white-space: break-spaces;
}

.mention-token {
  background: rgba(88, 101, 242, 0.28);
  color: #c9d0ff;
  font-weight: 600;
}

.plain-token {
  background: rgba(255, 255, 255, 0.08);
  color: #f1f1f1;
}

.template-token {
  background: rgba(117, 167, 247, 0.16);
  color: #bcd6ff;
}

.title-fallback-token {
  border: 1px dashed rgba(255, 255, 255, 0.16);
}

.template-media {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  margin-bottom: 8px;
  padding: 5px 8px;
  border: 1px dashed #4d5f7f;
  border-radius: 5px;
  color: #bcd6ff;
  font-size: 0.85rem;
}

.template-media.wide {
  margin: 10px 0 0;
}

.embed-thumbnail {
  float: right;
  width: 72px;
  height: 72px;
  margin-left: 12px;
  border-radius: 4px;
  object-fit: cover;
}

.embed-image {
  display: block;
  width: 100%;
  max-height: 320px;
  margin-top: 10px;
  border-radius: 4px;
  object-fit: cover;
}

.embed-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.embed-field {
  grid-column: 1 / -1;
}

.embed-field.inline {
  grid-column: auto;
}

.embed-field strong,
.embed-field span {
  display: block;
  overflow-wrap: anywhere;
}

.embed-field span {
  color: #dbdee1;
  margin-top: 3px;
}

.preview-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.preview-buttons a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 4px;
  background: #5865f2;
  color: white;
  text-decoration: none;
}

.export-panel textarea {
  min-height: 280px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.88rem;
}

.variable-picker summary {
  cursor: pointer;
  font-weight: 600;
}

.alias-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.alias-button,
.variable-row {
  width: 100%;
  border-radius: 7px;
  text-align: left;
}

.alias-button {
  display: grid;
  gap: 3px;
  padding: 9px 10px;
}

.alias-button span {
  font-weight: 700;
}

.alias-button small {
  line-height: 1.35;
}

.variable-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.75fr);
  gap: 8px;
  margin-bottom: 12px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.legend-dot.mention {
  background: #5865f2;
}

.legend-dot.plain {
  background: #9a9a9a;
}

.legend-dot.url {
  background: #75a7f7;
}

.variable-groups {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.variable-groups details {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.variable-list {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.variable-row {
  display: grid;
  grid-template-columns: minmax(190px, 0.42fr) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 9px 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.variable-row.mention {
  border-color: rgba(88, 101, 242, 0.42);
}

.variable-row.plain {
  border-color: rgba(255, 255, 255, 0.12);
}

.variable-row.url,
.variable-row.time {
  border-color: rgba(117, 167, 247, 0.32);
}

code {
  color: var(--text);
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  body {
    padding: 22px 12px;
  }

  header,
  .workspace,
  .split,
  .button-builder,
  .variable-controls,
  .alias-grid {
    grid-template-columns: 1fr;
  }

  header {
    display: grid;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .check-row {
    justify-content: flex-start;
  }

  .embed-fields {
    grid-template-columns: 1fr;
  }

  .variable-row {
    grid-template-columns: 1fr;
  }
}
