:root {
  --bg: #1e1f22;
  --panel: #2b2d31;
  --panel-2: #313338;
  --input: #1e1f22;
  --border: #3f4147;
  --text: #f2f3f5;
  --muted: #b5bac1;
  --faint: #80848e;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --success: #23a55a;
  --danger: #da373c;
  --warning: #f0b232;
  --link: #00a8fc;
  --embed-bg: #2b2d31;
  --radius: 10px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f3f5;
    --panel: #ffffff;
    --panel-2: #f7f7f8;
    --input: #ebedef;
    --border: #d9dbe0;
    --text: #1f2124;
    --muted: #4e5058;
    --faint: #6d6f78;
    --link: #006ce7;
    --embed-bg: #f2f3f5;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 "gg sans", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: .25rem 0 .75rem; }
.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: .85rem; }
.boot { padding: 3rem; text-align: center; color: var(--muted); }
.hidden { display: none !important; }

/* buttons and inputs */
button, .button {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
  border: 0; border-radius: 6px; padding: .55rem 1rem; font: inherit; font-weight: 600;
  background: var(--accent); color: #fff; cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .button:hover { background: var(--accent-hover); text-decoration: none; }
button:disabled { opacity: .55; cursor: not-allowed; }
button.secondary, .button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
button.secondary:hover, .button.secondary:hover { background: var(--border); }
button.danger { background: var(--danger); }
button.danger:hover { background: #a12828; }
button.success { background: var(--success); }
button.small { padding: .3rem .65rem; font-size: .85rem; }
button.link { background: none; color: var(--link); padding: 0; font-weight: 500; }

input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--input);
  border: 1px solid var(--border); border-radius: 6px; padding: .55rem .65rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=color] { padding: 2px; height: 2.4rem; width: 3.2rem; }
textarea { min-height: 6rem; resize: vertical; }
textarea.code { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; min-height: 14rem; }
label.field { display: block; margin-bottom: .9rem; }
label.field > span.label { display: block; font-size: .78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .02em; color: var(--muted); margin-bottom: .3rem; }
label.check { display: flex; gap: .5rem; align-items: center; margin-bottom: .6rem; cursor: pointer; }
.hint { font-size: .82rem; color: var(--faint); margin-top: .25rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 12rem; }
.row > .shrink { flex: 0 0 auto; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .5rem; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented button { border-radius: 0; background: var(--panel-2); color: var(--text); font-weight: 500; }
.segmented button.on { background: var(--accent); color: #fff; }

/* landing */
.landing { max-width: 640px; margin: 10vh auto; padding: 0 16px; text-align: center; }
.landing .logo { width: 88px; height: 88px; border-radius: 24px; margin-bottom: 1rem; }
.landing .features { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .75rem;
  margin: 2rem 0; text-align: left; }
.landing .features div { background: var(--panel); border-radius: var(--radius); padding: .8rem; }
.landing .features b { display: block; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1.25rem; background: var(--panel);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar .brand { font-weight: 800; display: flex; align-items: center; gap: .5rem; color: var(--text); }
.topbar .brand img { width: 30px; height: 30px; border-radius: 8px; }
.topbar .spacer { flex: 1; }
.user { display: flex; align-items: center; gap: .5rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); display: inline-grid;
  place-items: center; color: #fff; font-weight: 700; overflow: hidden; flex: 0 0 auto; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.menu-toggle { display: none; }

/* server picker */
.page { max-width: 1100px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
.server-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin-top: 1rem; }
.server-card { background: var(--panel); border-radius: var(--radius); padding: 1.25rem; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: .6rem; border: 1px solid var(--border); }
.server-card .icon { width: 72px; height: 72px; border-radius: 50%; font-size: 1.6rem; }
.server-card .name { font-weight: 700; overflow-wrap: anywhere; }

/* server layout */
.layout { display: grid; grid-template-columns: 250px 1fr; min-height: calc(100vh - 53px); }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 1rem .75rem; }
.sidebar .guild { display: flex; align-items: center; gap: .6rem; padding: .25rem .5rem 1rem; font-weight: 700; }
.sidebar .guild .avatar { width: 40px; height: 40px; }
.sidebar nav a { display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem; border-radius: 6px;
  color: var(--muted); font-weight: 500; }
.sidebar nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.sidebar nav a.on { background: var(--accent); color: #fff; }
.sidebar nav .sep { height: 1px; background: var(--border); margin: .6rem .5rem; }
.main { padding: 1.5rem; min-width: 0; }
.main > header { margin-bottom: 1.25rem; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem;
  margin-bottom: 1rem; }
.card > h2 { display: flex; align-items: center; gap: .5rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.stat { display: block; color: var(--text); }
.stat:hover { text-decoration: none; border-color: var(--accent); }
.stat .big { font-size: 1.5rem; font-weight: 800; }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.open { background: rgba(35,165,90,.18); border-color: var(--success); }
.badge.closed { background: rgba(240,178,50,.18); border-color: var(--warning); }
.badge.voting { background: rgba(88,101,242,.2); border-color: var(--accent); }
.notice { border-left: 4px solid var(--warning); background: rgba(240,178,50,.1); padding: .6rem .8rem;
  border-radius: 4px; margin: .5rem 0; }
.notice.ok { border-color: var(--success); background: rgba(35,165,90,.1); }
.notice.error { border-color: var(--danger); background: rgba(218,55,60,.1); }

.list { display: flex; flex-direction: column; gap: .75rem; }
.contest { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; }
.contest .top { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.contest .top h3 { margin: 0; flex: 1 1 auto; overflow-wrap: anywhere; }
.meta { display: flex; gap: 1.25rem; flex-wrap: wrap; color: var(--muted); font-size: .88rem; margin: .5rem 0; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { display: inline-flex; align-items: center; gap: .4rem; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; padding: .2rem .3rem .2rem .75rem; }

/* embed editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.editor .preview-col { position: sticky; top: 70px; }
details.section { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; margin-bottom: .6rem; }
details.section > summary { cursor: pointer; padding: .7rem .9rem; font-weight: 700; list-style: none; }
details.section > summary::before { content: "▸ "; color: var(--faint); }
details.section[open] > summary::before { content: "▾ "; }
details.section > .body { padding: 0 .9rem .6rem; }
.field-row { border: 1px dashed var(--border); border-radius: 6px; padding: .6rem; margin-bottom: .6rem; }

/* Discord message preview */
.discord { background: var(--panel-2); border-radius: 8px; padding: 1rem; display: flex; gap: .9rem; }
.discord .msg { min-width: 0; flex: 1; }
.discord .author-line { font-weight: 600; margin-bottom: .15rem; }
.discord .author-line .tag { background: var(--accent); color: #fff; font-size: .65rem; padding: .05rem .3rem;
  border-radius: 3px; margin-left: .3rem; vertical-align: 2px; }
.discord .author-line .time { color: var(--faint); font-weight: 400; font-size: .75rem; margin-left: .4rem; }
.discord .content { white-space: pre-wrap; overflow-wrap: anywhere; }
.embed { display: grid; max-width: 520px; background: var(--embed-bg); border-radius: 4px; border-left: 4px solid #1e1f22;
  padding: .6rem 1rem .9rem .75rem; margin-top: .4rem; gap: .35rem; grid-template-columns: 1fr auto; }
@media (prefers-color-scheme: light) { .embed { border-left-color: #e3e5e8; } }
.embed > * { grid-column: 1; min-width: 0; }
.embed .e-thumb { grid-column: 2; grid-row: 1 / span 3; max-width: 80px; max-height: 80px; border-radius: 4px; margin-left: .75rem; }
.embed .e-author { display: flex; align-items: center; gap: .4rem; font-size: .85rem; font-weight: 600; }
.embed .e-author img, .embed .e-footer img { width: 22px; height: 22px; border-radius: 50%; }
.embed .e-title { font-weight: 700; }
.embed .e-desc, .embed .e-field-value { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .9rem; }
.embed .e-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem .75rem; }
.embed .e-field { grid-column: 1 / -1; }
.embed .e-field.inline { grid-column: auto; }
.embed .e-field-name { font-weight: 700; font-size: .85rem; }
.embed .e-image { grid-column: 1 / -1; max-width: 100%; border-radius: 4px; margin-top: .3rem; }
.embed .e-footer { display: flex; align-items: center; gap: .4rem; font-size: .75rem; color: var(--muted); }
.discord-button { display: inline-block; margin-top: .5rem; background: var(--success); color: #fff; border-radius: 4px;
  padding: .3rem 1rem; font-size: .9rem; font-weight: 500; }
.md-code { font-family: ui-monospace, Consolas, monospace; background: var(--input); padding: 0 .25rem; border-radius: 3px; font-size: .85em; }
.md-mention { background: rgba(88,101,242,.3); color: #c9cdfb; border-radius: 3px; padding: 0 .15rem; font-weight: 500; }
@media (prefers-color-scheme: light) { .md-mention { color: #3c45a5; background: rgba(88,101,242,.15); } }
.md-time { background: var(--input); border-radius: 3px; padding: 0 .2rem; }
.md-quote { border-left: 4px solid var(--border); padding-left: .6rem; display: block; }
.md-h1 { font-size: 1.4rem; font-weight: 800; display: block; }
.md-h2 { font-size: 1.2rem; font-weight: 800; display: block; }
.md-h3 { font-size: 1.05rem; font-weight: 800; display: block; }

/* toasts and dialogs */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: .5rem; z-index: 50;
  max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--success);
  border-radius: 6px; padding: .7rem .9rem; box-shadow: 0 6px 24px rgba(0,0,0,.35); overflow-wrap: anywhere; }
.toast.error { border-left-color: var(--danger); }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0; width: min(640px, calc(100vw - 32px)); max-height: 85vh; }
dialog::backdrop { background: rgba(0,0,0,.6); }
#dialog-body { padding: 1.25rem; }
.entry { border-top: 1px solid var(--border); padding: .75rem 0; }
.entry pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; background: var(--input); padding: .6rem;
  border-radius: 6px; max-height: 260px; overflow: auto; }

@media (max-width: 900px) {
  .editor, .grid-2 { grid-template-columns: 1fr; }
  .editor .preview-col { position: static; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar.open { display: block; }
  .menu-toggle { display: inline-flex; }
  .main { padding: 1rem 16px; }
  .topbar { padding: .5rem 16px; }
  .topbar .username { display: none; }
}
