:root {
  --bg: #0f1419;
  --surface: #1a222c;
  --surface-2: #243040;
  --text: #e8eef4;
  --muted: #8b9aab;
  --accent: #3d9cf0;
  --accent-2: #2a7bc8;
  --danger: #e85d5d;
  --ok: #3ecf8e;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, #1c3348 0%, transparent 55%),
              radial-gradient(900px 500px at 100% 0%, #1a2a22 0%, transparent 50%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { width: min(880px, calc(100% - 2rem)); margin-inline: auto; }
.content { padding: 1.5rem 0 3rem; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.row.gap { justify-content: flex-start; }
.wrap-row { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 0.6rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.error { color: #ffb4b4; background: rgba(232, 93, 93, 0.15); padding: 0.6rem 0.8rem; border-radius: 8px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(10px);
  background: rgba(15, 20, 25, 0.85);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding: 0.85rem 0;
}

/* Top nav dropdown menu */
.nav-menu { position: relative; }
.nav-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.45rem);
  min-width: 210px;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.45rem;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 30;
}
.nav-menu-panel[hidden] { display: none !important; }
.nav-menu-item {
  appearance: none;
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
}
.nav-menu-item:hover {
  background: rgba(255,255,255,0.06);
  text-decoration: none;
  color: var(--text);
}
.nav-menu.open #nav-menu-toggle {
  background: rgba(61, 156, 240, 0.15);
  border-color: rgba(61, 156, 240, 0.4);
}


.btn {
  appearance: none; border: 1px solid rgba(255,255,255,0.12);
  background: var(--surface-2); color: var(--text);
  padding: 0.55rem 0.95rem; border-radius: 999px;
  cursor: pointer; font: inherit; font-size: 0.95rem;
}
.btn:hover { filter: brightness(1.08); }
.btn.primary { background: var(--accent); border-color: transparent; color: #061018; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: rgba(232,93,93,0.4); color: #ffb4b4; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

input[type="text"], input[type="password"], textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  font: inherit;
}
textarea { resize: vertical; min-height: 110px; }
label { font-size: 0.9rem; color: var(--muted); }

.auth-page {
  display: grid; place-items: center; padding: 2rem 1rem;
}
.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  padding: 1.75rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.06);
}
.auth-card h1 { margin: 0 0 0.25rem; font-size: 1.6rem; }

.section-card, .section-editor, .toolbar {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.section-card h2 { margin: 0 0 0.75rem; font-size: 1.35rem; }
.section-body { white-space: normal; }
.section-img {
  display: block; max-width: 100%; max-height: 360px;
  border-radius: 10px; margin: 0.5rem 0 1rem;
  object-fit: cover;
}
.section-video {
  max-height: 480px;
  object-fit: contain;
  background: #000;
  width: 100%;
}

.section-editor.sortable-ghost { opacity: 0.45; }
.section-editor.sortable-chosen { outline: 2px solid var(--accent); }
.section-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.65rem;
}
.drag-handle {
  cursor: grab; background: transparent; border: none; color: var(--muted);
  font-size: 1.1rem; padding: 0.35rem 0.5rem; line-height: 1;
}
.drag-handle:active { cursor: grabbing; }
.file-btn { display: inline-flex; align-items: center; }
.media-row { margin-top: 0.65rem; }
#status.ok { color: var(--ok); }
#status.err { color: #ffb4b4; }

footer { padding-bottom: 2rem; }

@media (max-width: 560px) {
  .section-head { grid-template-columns: auto 1fr; }
  .section-head .btn-delete { grid-column: 2; justify-self: end; }
}

/* Markdown body */
.section-body { white-space: normal; }
.section-body > *:first-child { margin-top: 0; }
.section-body > *:last-child { margin-bottom: 0; }
.section-body p { margin: 0.55rem 0; }
.section-body h1, .section-body h2, .section-body h3,
.section-body h4, .section-body h5, .section-body h6 {
  margin: 1rem 0 0.45rem; line-height: 1.25; font-weight: 650;
}
.section-body h1 { font-size: 1.35rem; }
.section-body h2 { font-size: 1.2rem; }
.section-body h3 { font-size: 1.08rem; }
.section-body ul, .section-body ol { margin: 0.5rem 0; padding-left: 1.4rem; }
.section-body li { margin: 0.2rem 0; }
.section-body blockquote {
  margin: 0.7rem 0; padding: 0.35rem 0.85rem;
  border-left: 3px solid var(--accent);
  color: var(--muted); background: rgba(255,255,255,0.03);
}
.section-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em; background: rgba(0,0,0,0.35);
  padding: 0.1em 0.35em; border-radius: 5px;
}
.section-body pre {
  background: rgba(0,0,0,0.4); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px; padding: 0.85rem 1rem; overflow-x: auto;
  margin: 0.7rem 0;
}
.section-body pre code { background: transparent; padding: 0; font-size: 0.88rem; }
.section-body table { width: 100%; border-collapse: collapse; margin: 0.7rem 0; font-size: 0.95rem; }
.section-body th, .section-body td {
  border: 1px solid rgba(255,255,255,0.1); padding: 0.45rem 0.65rem; text-align: left;
}
.section-body th { background: rgba(255,255,255,0.05); }
.section-body hr { border: none; border-top: 1px solid rgba(255,255,255,0.1); margin: 1rem 0; }
.section-body img { max-width: 100%; border-radius: 8px; }
.section-body a { word-break: break-word; }

/* Reactions */
.react-bar {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  margin-top: 1rem; padding-top: 0.85rem;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.react-btn {
  appearance: none; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.03); color: var(--text);
  border-radius: 999px; padding: 0.25rem 0.55rem;
  cursor: pointer; font: inherit; font-size: 0.95rem;
  display: inline-flex; align-items: center; gap: 0.3rem;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.react-btn:hover { background: rgba(255,255,255,0.08); }
.react-btn:active { transform: scale(0.96); }
.react-btn.active {
  background: rgba(61, 156, 240, 0.18);
  border-color: rgba(61, 156, 240, 0.55);
}
.react-emoji { font-size: 1.05rem; line-height: 1; }
.react-count { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.react-btn.active .react-count { color: var(--accent); }

/* Live chat layout */
.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: start;
  padding-bottom: 2rem;
}
.feed { padding: 1.5rem 0 0; min-width: 0; }
.has-live-chat .content { padding-top: 0; }

.live-chat { position: relative; }
.chat-panel {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  min-height: 420px;
  max-height: min(70vh, 640px);
}
.live-chat.open .chat-panel { display: flex; }

.chat-head {
  display: flex; flex-direction: column; gap: 0.2rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.15);
}
.chat-head-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
}
.chat-close {
  padding: 0.25rem 0.55rem;
  line-height: 1;
  font-size: 1.1rem;
}
footer a { color: var(--muted); }
footer a:hover { color: var(--accent); }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 0.75rem 1rem;
  display: flex; flex-direction: column; gap: 0.65rem;
}
.chat-msg {
  display: flex; flex-direction: column; gap: 0.15rem;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
}
.chat-meta {
  display: flex; justify-content: space-between; gap: 0.5rem;
  font-size: 0.8rem;
}
.chat-nick { color: var(--accent); font-weight: 650; }
.chat-time { color: var(--muted); }
.chat-text { word-break: break-word; white-space: pre-wrap; }
.chat-compose {
  border-top: 1px solid rgba(255,255,255,0.06);
  padding: 0.75rem;
  display: flex; flex-direction: column; gap: 0.45rem;
  background: rgba(0,0,0,0.12);
}
.chat-row { display: flex; gap: 0.45rem; }
.chat-row #chat-text { flex: 1; }
#chat-online { word-break: break-word; }

@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 340px;
    width: min(1180px, calc(100% - 2rem));
  }
  .live-chat { position: sticky; top: 4.5rem; }
  .live-chat .chat-panel { display: flex; }
  #chat-toggle { display: none; }
}

@media (max-width: 899px) {
  .live-chat.open {
    position: fixed; inset: 0; z-index: 40;
    background: rgba(0,0,0,0.55);
    padding: 1rem;
    display: flex; align-items: flex-end;
  }
  .live-chat.open .chat-panel {
    width: 100%; max-height: 80vh; min-height: 50vh;
  }
}
