:root {
    --bg: #1e1f27;
    --card: #2a2c38;
    --accent: #5865f2;
    --accent-hover: #4752c4;
    --text: #e7e8ee;
    --muted: #9a9cad;
    --error: #f26b6b;
    --ok: #57d38c;
    --warn: #e8b74b;
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

#login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card {
    background: var(--card);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.login-card { width: 340px; text-align: center; }

h1 { margin-top: 0; font-size: 20px; }
h2 { margin-top: 0; font-size: 16px; color: var(--muted); }

input, select, textarea, button {
    width: 100%;
    padding: 10px 12px;
    margin: 6px 0 14px;
    border-radius: 8px;
    border: 1px solid #3d3f4d;
    background: #1e1f27;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}

textarea { resize: vertical; }

label { font-size: 13px; color: var(--muted); }

button {
    background: var(--accent);
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.15s;
}

button:hover { background: var(--accent-hover); }

.error { color: var(--error); font-size: 13px; }
.result { font-size: 14px; margin-top: 4px; white-space: pre-wrap; }

/* --- Discord login button --- */
.discord-login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: 600;
    margin: 6px 0 14px;
}

.discord-login-btn:hover { background: var(--accent-hover); }

.invite-btn {
    display: inline-block;
    width: auto;
    text-align: center;
    text-decoration: none;
}

#login-screen .invite-btn { width: 100%; }

/* --- Header --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--card);
    flex-wrap: wrap;
    gap: 10px;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

header h1 { font-size: 17px; margin: 0; }
header select, header button { width: auto; margin: 0; }

.user-tag { font-size: 13px; color: var(--muted); white-space: nowrap; }

.status { font-size: 13px; color: var(--ok); }
.status.offline { color: var(--error); }

main {
    max-width: 1180px;
    margin: 24px auto;
    padding: 0 16px;
}

/* --- Tabs --- */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.tab-btn {
    width: auto;
    margin: 0;
    background: transparent;
    border: 1px solid #3d3f4d;
    color: var(--muted);
}

.tab-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.tab-panel.hidden { display: none; }

/* --- Two-column editor layout --- */
.layout {
    display: grid;
    grid-template-columns: 460px 1fr;
    gap: 20px;
    align-items: start;
}

.preview-col { position: sticky; top: 20px; }

@media (max-width: 1000px) {
    .layout { grid-template-columns: 1fr; }
    .preview-col { position: static; order: 2; }
    .form-col { order: 1; }
}

.card-head-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-head-row h2 { margin: 0; }

.secondary-btn {
    background: transparent;
    border: 1px dashed #4a4c5c;
    color: var(--muted);
}

.secondary-btn:hover { background: #262835; color: var(--text); }

.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

/* --- Drag & drop banner upload --- */
.dropzone {
    border: 2px dashed #4a4c5c;
    border-radius: 10px;
    padding: 18px 12px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
    margin: 6px 0 8px;
    transition: background 0.15s, border-color 0.15s;
}

.dropzone.small { padding: 10px 8px; font-size: 12px; }

.dropzone:hover, .dropzone.dragover {
    background: #262835;
    border-color: var(--accent);
    color: var(--text);
}

.row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

input[type="color"] { height: 40px; padding: 4px; cursor: pointer; }

.checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 4px 0 14px;
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 1px 0 0;
    flex: none;
    cursor: pointer;
}

.ai-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: start;
}

.ai-row input { margin: 6px 0; }
.ai-row button { width: auto; margin: 6px 0; white-space: nowrap; }

/* --- Discord-style message/embed preview --- */
.discord-preview {
    display: flex;
    gap: 12px;
    background: #313338;
    border-radius: 10px;
    padding: 14px;
    min-height: 80px;
}

.dp-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.dp-body { flex: 1; min-width: 0; }

.dp-header { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }

.dp-username { color: #fff; font-weight: 600; font-size: 15px; }

.dp-botTag {
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
}

.dp-time { color: #949ba4; font-size: 11px; }

.dp-content {
    color: #dbdee1;
    font-size: 14px;
    margin-top: 4px;
    white-space: pre-wrap;
}

.dp-embed {
    margin-top: 8px;
    background: #2b2d31;
    border-left: 4px solid var(--accent);
    border-radius: 4px;
    padding: 10px 12px;
    max-width: 432px;
    overflow: hidden;
}

.dp-embed-author {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: #f2f3f5;
}

.dp-author-icon { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; }

.dp-embed-top { overflow: hidden; }

.dp-embed-thumbnail {
    float: right;
    width: 70px;
    height: 70px;
    object-fit: cover;
    border-radius: 4px;
    margin: 0 0 6px 12px;
}

.dp-embed-title { color: #f2f3f5; font-weight: 700; font-size: 15px; }

.dp-embed-desc {
    color: #dbdee1;
    font-size: 13px;
    line-height: 1.4;
    margin-top: 4px;
    white-space: pre-wrap;
    word-break: break-word;
}

.dp-embed-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
}

.dp-field { font-size: 12px; }
.dp-field-name { color: #f2f3f5; font-weight: 700; }
.dp-field-value { color: #dbdee1; }

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

.dp-embed-footer { color: #949ba4; font-size: 11px; margin-top: 8px; }

.dp-buttons { display: flex; gap: 8px; margin-top: 10px; }

.dp-btn {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    color: #fff;
}

.dp-btn-success { background: #248046; }
.dp-btn-danger { background: #da373c; }

/* --- Dashboard tournament list --- */
.tournament-row {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    gap: 12px;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #3d3f4d;
}

.tournament-row:last-child { border-bottom: none; }

.tournament-name { font-weight: 600; }
.tournament-meta { font-size: 12px; color: var(--muted); }

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    white-space: nowrap;
}

.badge-draft { background: #3d3f4d; color: var(--muted); }
.badge-published { background: rgba(87, 211, 140, 0.15); color: var(--ok); }
.badge-closed { background: rgba(242, 107, 107, 0.15); color: var(--error); }

.row-actions { display: flex; gap: 6px; }
.row-actions button {
    width: auto;
    margin: 0;
    padding: 6px 10px;
    font-size: 12px;
}

/* --- Participants table --- */
.participants-table { width: 100%; border-collapse: collapse; margin: 6px 0 0; }
.participants-table th, .participants-table td {
    text-align: left;
    padding: 8px 6px;
    border-bottom: 1px solid #3d3f4d;
    font-size: 13px;
}
.participants-table th { color: var(--muted); font-weight: 600; }

.csv-btn { width: auto; margin: 0; text-decoration: none; display: inline-block; text-align: center; }

.site-footer {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #3d3f4d;
}

.site-footer a { color: var(--muted); font-size: 12px; text-decoration: none; }
.site-footer a:hover { color: var(--text); }

#app-screen .site-footer { max-width: 1180px; margin: 24px auto 0; padding: 16px; }

/* --- Legal pages (terms.html / privacy.html) --- */
.legal-page {
    max-width: 720px;
    margin: 0 auto;
    padding: 40px 20px 64px;
}

.legal-back {
    display: inline-block;
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    margin-bottom: 20px;
}

.legal-back:hover { color: var(--text); }

.legal-page h1 { font-size: 26px; margin: 0 0 4px; }

.legal-updated { color: var(--muted); font-size: 13px; margin: 0 0 32px; }

.legal-page h2 {
    color: var(--text);
    font-size: 18px;
    margin: 32px 0 10px;
    padding-top: 12px;
    border-top: 1px solid #3d3f4d;
}

.legal-page h2:first-of-type { border-top: none; padding-top: 0; }

.legal-page p, .legal-page li {
    font-size: 14px;
    line-height: 1.65;
    color: #d3d4de;
}

.legal-page ul { padding-left: 22px; margin: 8px 0; }
.legal-page li { margin: 4px 0; }

.legal-page a { color: var(--accent); }

.legal-note {
    margin-top: 40px;
    padding: 14px 16px;
    background: var(--card);
    border-radius: 8px;
    border-left: 3px solid var(--warn);
    font-size: 13px;
    color: var(--muted);
}

/* --- Description formatting toolbar --- */
.format-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    margin: 6px 0;
}

.format-toolbar button {
    width: auto;
    margin: 0;
    padding: 5px 9px;
    font-size: 12px;
    background: #1e1f27;
    border: 1px solid #3d3f4d;
    color: var(--text);
    font-weight: 600;
}

.format-toolbar button:hover { background: #262835; border-color: var(--accent); }

.toolbar-sep {
    width: 1px;
    align-self: stretch;
    background: #3d3f4d;
    margin: 2px 4px;
}

/* --- Popover used by the mention/emoji pickers --- */
.dropdown-menu {
    position: relative;
    background: var(--card);
    border: 1px solid #3d3f4d;
    border-radius: 8px;
    padding: 10px;
    margin: -2px 0 10px;
    max-height: 220px;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.dropdown-menu.hidden { display: none; }

.dropdown-menu .dd-item {
    width: auto;
    margin: 0;
    padding: 5px 10px;
    font-size: 12px;
    background: #1e1f27;
    border: 1px solid #3d3f4d;
    color: var(--text);
    white-space: nowrap;
}

.dropdown-menu .dd-item:hover { background: #262835; border-color: var(--accent); }

.dropdown-menu .dd-empty {
    font-size: 12px;
    color: var(--muted);
    padding: 4px;
}

.dropdown-menu .dd-emoji-item {
    width: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1e1f27;
    border: 1px solid #3d3f4d;
    font-size: 18px;
}

.dropdown-menu .dd-emoji-item img { width: 22px; height: 22px; }
.dropdown-menu .dd-emoji-item:hover { border-color: var(--accent); }

.dropdown-menu .dd-form {
    display: flex;
    gap: 6px;
    width: 100%;
}

.dropdown-menu .dd-form input {
    margin: 0;
    flex: 1;
}

.dropdown-menu .dd-form button {
    width: auto;
    margin: 0;
    white-space: nowrap;
}

.matcherino-status { color: var(--ok); }
.matcherino-status.stale { color: var(--warn); }

/* --- Auto-react emoji picker --- */
.reaction-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0;
}

.reaction-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    width: auto;
    margin: 0;
    padding: 6px 12px;
    background: #1e1f27;
    border: 1px solid #3d3f4d;
    color: var(--muted);
    font-size: 13px;
    min-width: 90px;
}

.reaction-chip:hover { border-color: var(--accent); color: var(--text); }
.reaction-chip.has-value { color: var(--text); }
.reaction-chip img { width: 18px; height: 18px; vertical-align: -4px; }

.reaction-row input {
    width: auto;
    flex: 1;
    margin: 0;
    min-width: 0;
}

.reaction-row .secondary-btn { width: auto; margin: 0; white-space: nowrap; }

/* --- Custom date/time picker (replaces the native datetime-local popup) --- */
.dt-field { position: relative; }

.dt-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin: 6px 0 14px;
    text-align: left;
    background: #1e1f27;
    border: 1px solid #3d3f4d;
    color: var(--muted);
    font-weight: 400;
}

.dt-toggle.has-value { color: var(--text); }
.dt-toggle:hover { background: #262835; border-color: var(--accent); }

.dt-panel {
    position: absolute;
    z-index: 20;
    top: calc(100% - 8px);
    left: 0;
    width: 280px;
    background: var(--card);
    border: 1px solid #3d3f4d;
    border-radius: 10px;
    padding: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.dt-panel.hidden { display: none; }

.dt-cal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-weight: 600;
}

.dt-cal-header button {
    width: 28px;
    height: 28px;
    margin: 0;
    padding: 0;
    background: transparent;
    border: 1px solid #3d3f4d;
    color: var(--text);
}

.dt-cal-header button:hover { background: #262835; border-color: var(--accent); }

.dt-cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 10px;
}

.dt-cal-dow {
    text-align: center;
    font-size: 11px;
    color: var(--muted);
    padding: 4px 0;
}

.dt-cal-day {
    width: auto;
    margin: 0;
    padding: 6px 0;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text);
    font-size: 12px;
    font-weight: 400;
    border-radius: 6px;
}

.dt-cal-day:hover { background: #262835; border-color: #4a4c5c; }
.dt-cal-day.today { border-color: var(--muted); }
.dt-cal-day.selected { background: var(--accent); color: #fff; }
.dt-cal-day.empty { visibility: hidden; cursor: default; }

.dt-time-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
}

.dt-time-row select {
    width: auto;
    margin: 0;
    padding: 6px 8px;
    font-size: 13px;
}

.dt-ampm {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.dt-ampm button {
    width: auto;
    margin: 0;
    padding: 6px 10px;
    font-size: 12px;
    background: #1e1f27;
    border: 1px solid #3d3f4d;
    color: var(--muted);
}

.dt-ampm button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.dt-actions {
    display: flex;
    gap: 8px;
    justify-content: space-between;
}

.dt-actions button { width: auto; margin: 0; padding: 6px 10px; font-size: 12px; }

/* --- Discord-markup rendering in the live preview --- */
.dp-emoji { width: 18px; height: 18px; vertical-align: -4px; margin: 0 1px; }

.dp-mention {
    background: rgba(88, 101, 242, 0.3);
    color: #c9cdfb;
    border-radius: 3px;
    padding: 0 2px;
    font-weight: 500;
}

.dp-spoiler {
    background: #1a1b1f;
    color: transparent;
    border-radius: 3px;
    cursor: pointer;
    padding: 0 2px;
}

.dp-spoiler.revealed { background: #3d3f4d; color: inherit; }

.dp-code {
    background: #1e1f27;
    border-radius: 3px;
    padding: 0 4px;
    font-family: "Courier New", monospace;
    font-size: 0.9em;
}

.dp-code-block {
    background: #1e1f27;
    border-radius: 4px;
    padding: 8px 10px;
    margin: 4px 0;
    font-family: "Courier New", monospace;
    font-size: 0.85em;
    white-space: pre-wrap;
    overflow-x: auto;
}

.dp-quote {
    border-left: 3px solid #4a4c5c;
    padding-left: 8px;
    margin: 2px 0;
    color: #c2c4cc;
}

.dp-bullet { margin: 2px 0; }

.dp-h1, .dp-h2, .dp-h3 { font-weight: 700; margin: 6px 0 2px; }
.dp-h1 { font-size: 1.3em; }
.dp-h2 { font-size: 1.15em; }
.dp-h3 { font-size: 1.05em; }
