/**
 * Two visual languages in one page, kept deliberately separate:
 *   .dc-*  reproduces Discord's dark theme as closely as possible, because the
 *          preview is only useful if it can be trusted before posting publicly.
 *   everything else is editor chrome, styled to sit back and not compete.
 */

:root {
    --bg: #1a1b1e;
    --panel: #232428;
    --panel-2: #2b2d31;
    --line: #35373c;
    --text: #dbdee1;
    --muted: #949ba4;
    --brand: #5865f2;
    --link: #00a8fc;
    --ok: #57f287;
    --error: #ed4245;
    --warn: #f1c40f;
    --radius: 8px;
    --font: 'gg sans', 'Noto Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial,
        sans-serif;
}

* {
    box-sizing: border-box;
}

/*
 * `display: flex` on .field outranks the UA stylesheet's [hidden] rule, so
 * hidden fields would otherwise stay visible.
 */
[hidden] {
    display: none !important;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.45;
}

/* ---------------------------------------------------------------- *
 * Layout
 * ---------------------------------------------------------------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.topbar h1 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.topbar h1 span {
    color: var(--brand);
}

.grow {
    flex: 1;
}

.layout {
    display: grid;
    grid-template-columns: minmax(340px, 420px) 1fr;
    gap: 0;
    align-items: start;
    min-height: calc(100vh - 57px);
}

@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
    }
}

.editor {
    padding: 20px;
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.viewer {
    padding: 20px;
    position: sticky;
    top: 0;
}

.group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.group > h2 {
    margin: 0;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 700;
}

/* ---------------------------------------------------------------- *
 * Form controls
 * ---------------------------------------------------------------- */

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field--inline {
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.field > span {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    font-weight: 600;
}

input[type='text'],
textarea,
select {
    width: 100%;
    background: #1e1f22;
    border: 1px solid var(--line);
    border-radius: 4px;
    color: var(--text);
    padding: 8px 10px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
}

input[type='text']:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--brand);
}

input[type='color'] {
    width: 48px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: none;
    cursor: pointer;
}

button {
    font-family: inherit;
    cursor: pointer;
}

.primary-btn {
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 9px 18px;
    font-weight: 700;
    font-size: 14px;
}

.primary-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ghost-btn {
    background: none;
    border: 1px dashed var(--line);
    color: var(--muted);
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 13px;
}

.ghost-btn:hover {
    color: var(--text);
    border-color: var(--muted);
}

.icon-btn {
    background: #1e1f22;
    border: 1px solid var(--line);
    color: var(--muted);
    border-radius: 4px;
    width: 26px;
    height: 26px;
    font-size: 12px;
    line-height: 1;
    padding: 0;
}

.icon-btn:hover:not(:disabled) {
    color: var(--text);
    border-color: var(--muted);
}

.icon-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.accent-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.swatch {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid var(--line);
    padding: 0;
}

.swatch:hover {
    border-color: #fff;
}

/* ---------------------------------------------------------------- *
 * Block editor
 * ---------------------------------------------------------------- */

#blocks {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.block {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
}

.block-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.block-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
    color: var(--brand);
}

.block-controls {
    display: flex;
    gap: 4px;
}

.block-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.list-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.note {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--muted);
}

/* ---------------------------------------------------------------- *
 * Viewer chrome
 * ---------------------------------------------------------------- */

.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}

.tab {
    background: none;
    border: none;
    color: var(--muted);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
}

.tab.is-active {
    background: var(--panel-2);
    color: #fff;
}

#json {
    background: #1e1f22;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.5;
    color: #c3c8ce;
    overflow: auto;
    max-height: 70vh;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.meta {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#counts {
    font-size: 12px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

#issues {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.issue {
    font-size: 13px;
    padding: 8px 10px;
    border-radius: 4px;
    border-left: 3px solid;
}

.issue--error {
    border-color: var(--error);
    background: rgba(237, 66, 69, 0.1);
    color: #f5a3a5;
}

.issue--warn {
    border-color: var(--warn);
    background: rgba(241, 196, 15, 0.08);
    color: #e8d18a;
}

.status {
    font-size: 13px;
    color: var(--muted);
    min-height: 18px;
}

.status.ok {
    color: var(--ok);
}

.status.error {
    color: var(--error);
}

/* ---------------------------------------------------------------- *
 * Discord preview
 * ---------------------------------------------------------------- */

.dc-stage {
    background: #313338;
    border-radius: var(--radius);
    padding: 20px 16px;
    overflow: auto;
    max-height: 78vh;
}

.dc-message {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.dc-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: #1e1f22;
}

.dc-content {
    min-width: 0;
    flex: 1;
}

.dc-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.dc-username {
    font-weight: 600;
    color: #fff;
    font-size: 15px;
}

.dc-badge {
    background: #5865f2;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 4px;
    border-radius: 3px;
    line-height: 1.3;
}

.dc-timestamp {
    font-size: 12px;
    color: var(--muted);
}

/*
 * The container. Discord caps message width, so an image wider than this box
 * saturates it and every sibling stretches to match — that is the whole
 * mechanism behind the wide cards.
 */
.dc-container {
    background: var(--panel-2);
    border-left: 4px solid var(--accent, var(--brand));
    border-radius: 4px;
    padding: 16px;
    max-width: 600px;
}

.dc-text {
    color: var(--text);
    font-size: 16px;
    line-height: 1.375;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.dc-text + .dc-text {
    margin-top: 8px;
}

.dc-separator {
    height: 1px;
    background: #3f4147;
    margin: 8px 0;
}

.dc-separator--large {
    margin: 16px 0;
}

.dc-separator--invisible {
    background: none;
}

.dc-gallery {
    display: grid;
    gap: 4px;
    grid-template-columns: 1fr;
    margin: 4px 0;
}

.dc-gallery[data-count='2'],
.dc-gallery[data-count='4'] {
    grid-template-columns: 1fr 1fr;
}

.dc-gallery[data-count='3'] {
    grid-template-columns: repeat(3, 1fr);
}

.dc-gallery-item img {
    width: 100%;
    display: block;
    border-radius: var(--radius);
}

.dc-gallery-item.is-broken {
    border: 1px dashed var(--error);
    border-radius: var(--radius);
    min-height: 80px;
    display: grid;
    place-items: center;
}

.dc-gallery-item.is-broken::after {
    content: 'Image failed to load';
    color: var(--error);
    font-size: 13px;
}

.dc-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.dc-button {
    background: #4e5058;
    color: #fff;
    border-radius: 3px;
    padding: 7px 16px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    line-height: 1.15;
}

.dc-button:hover {
    background: #6d6f78;
}

.dc-button--invalid {
    background: rgba(237, 66, 69, 0.2);
    border: 1px solid var(--error);
    color: #f5a3a5;
}

.dc-button-icon {
    font-size: 11px;
    opacity: 0.7;
}

.dc-section {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.dc-section-body {
    flex: 1;
    min-width: 0;
}

.dc-thumb {
    width: 86px;
    height: 86px;
    object-fit: cover;
    border-radius: var(--radius);
    flex-shrink: 0;
}

.dc-empty,
.dc-unknown {
    color: var(--muted);
    font-size: 14px;
    font-style: italic;
}

/* Discord markdown inside text displays */
.md-h1,
.md-h2,
.md-h3 {
    margin: 8px 0 4px;
    color: #fff;
    font-weight: 700;
    line-height: 1.25;
}

.md-h1 {
    font-size: 24px;
}

.md-h2 {
    font-size: 20px;
}

.md-h3 {
    font-size: 16px;
}

.md-small {
    font-size: 12px;
    color: var(--muted);
}

.md-quote {
    border-left: 4px solid #4e5058;
    margin: 4px 0;
    padding: 0 0 0 12px;
    color: var(--text);
}

.md-list {
    margin: 2px 0;
    padding-left: 22px;
}

.md-list li {
    margin: 1px 0;
}

.md-gap {
    height: 10px;
}

.dc-text code {
    background: #1e1f22;
    border: 1px solid #1e1f22;
    border-radius: 4px;
    padding: 1px 4px;
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: 85%;
}

.dc-text a {
    color: var(--link);
    text-decoration: none;
}

.dc-text a:hover {
    text-decoration: underline;
}
