:root {
  --accent: #f95a36;
  --accent-soft: #f95a3614;
  --accent-strong: #e04722;
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --text: #1b1e24;
  --text-soft: #667085;
  --border: #e6e8ec;
  --code-bg: #14161b;
  --shadow: 0 8px 30px rgba(16, 24, 40, 0.07);
  --radius: 14px;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --bg-soft: #171a21;
  --text: #e8eaee;
  --text-soft: #98a1b0;
  --border: #262b35;
  --accent-soft: #f95a361f;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 220px;
  min-height: 100vh;
  transition: background 0.4s, color 0.4s;
}

/* ---------- ambient aurora (calm, barely-there) ---------- */
body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  width: 55vmax;
  height: 55vmax;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.05;
  pointer-events: none;
  background: radial-gradient(circle, var(--accent), transparent 65%);
}
body::before {
  top: -20vmax;
  right: -15vmax;
  animation: drift-a 70s ease-in-out infinite alternate;
}
body::after {
  bottom: -25vmax;
  left: -10vmax;
  opacity: 0.04;
  animation: drift-b 90s ease-in-out infinite alternate;
}
[data-theme="dark"] body::before { opacity: 0.07; }
[data-theme="dark"] body::after { opacity: 0.05; }
@keyframes drift-a { to { transform: translate(-14vmax, 10vmax) scale(1.15); } }
@keyframes drift-b { to { transform: translate(12vmax, -8vmax) scale(0.9); } }

/* ---------- progress bar ---------- */
#progress-bar {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #ffb199);
  z-index: 50;
  transition: width 0.15s ease-out;
}

/* ---------- sidebar ---------- */
#sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 26px 20px;
  border-right: 1px solid var(--border);
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.logo { display: flex; align-items: center; gap: 12px; }

.logo-mark {
  width: 46px; height: 46px;
  animation: spin-in 1s cubic-bezier(0.2, 0.8, 0.2, 1);
  transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1.4);
}
.logo:hover .logo-mark { transform: rotate(120deg); }

@keyframes spin-in { from { transform: rotate(-180deg) scale(0); opacity: 0; } }

.logo h1 { margin: 0; font-size: 1.25rem; letter-spacing: -0.02em; }
.logo h1 span { color: var(--accent); }
#build-tag { margin: 2px 0 0; font-size: 0.68rem; color: var(--text-soft); }

#search {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

#doc-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }

.group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 4px;
  margin-top: 8px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-soft);
  cursor: pointer;
  border-radius: 8px;
  user-select: none;
  transition: color 0.2s, background 0.2s;
}
.group-header:hover { color: var(--accent); }
.group-header .chevron { font-size: 0.75rem; width: 12px; }
.group-header .count {
  margin-left: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0 8px;
  font-weight: 600;
}
.group-header.drag-over {
  background: var(--accent-soft);
  color: var(--accent);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

.doc-link.dragging { opacity: 0.4; transform: scale(0.98); }

.new-group-zone {
  margin-top: 10px;
  padding: 12px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-soft);
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.new-group-zone.drag-over {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.doc-link {
  display: block;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.92rem;
  border-left: 3px solid transparent;
  animation: slide-in 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
  cursor: pointer;
}
.doc-link:hover { background: var(--accent-soft); transform: translateX(4px); }
.doc-link.active { background: var(--accent-soft); border-left-color: var(--accent); font-weight: 600; }
.doc-link .badge {
  font-size: 0.62rem;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 20px;
  padding: 1px 7px;
  margin-left: 6px;
  vertical-align: middle;
}

@keyframes slide-in { from { opacity: 0; transform: translateX(-18px); } }

.sidebar-footer { display: flex; gap: 8px; flex-wrap: wrap; }
/* Long emails must never push past the sidebar */
#login-btn {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- buttons ---------- */
.ghost-btn, .accent-btn {
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.2s;
  font-family: inherit;
}
.ghost-btn {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.ghost-btn.danger:hover { border-color: #d33; color: #d33; }
.accent-btn {
  background: var(--accent);
  border: 1.5px solid var(--accent);
  color: #fff;
  font-weight: 600;
}
.accent-btn:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(249, 90, 54, 0.35);
}
.accent-btn:active, .ghost-btn:active { transform: translateY(1px); }

/* ---------- main ---------- */
#main { padding: 34px 52px 90px; max-width: 900px; width: 100%; justify-self: center; }

#doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 18px;
  margin-bottom: 26px;
}
#doc-title { margin: 0; font-size: 2rem; letter-spacing: -0.03em; }
#doc-meta { margin: 6px 0 0; color: var(--text-soft); font-size: 0.8rem; }
.header-actions { display: flex; gap: 8px; flex-shrink: 0; }

#content { animation: content-in 0.5s cubic-bezier(0.2, 0.8, 0.2, 1); }
#content.switching { opacity: 0; transform: translateY(14px); transition: 0.18s; }
@keyframes content-in { from { opacity: 0; transform: translateY(14px); } }

/* ---------- markdown ---------- */
.markdown-body { line-height: 1.75; font-size: 1.0rem; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { letter-spacing: -0.02em; scroll-margin-top: 20px; }
.markdown-body h2 { border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-top: 2.2em; }
.markdown-body a { color: var(--accent); text-decoration: none; border-bottom: 1px dashed var(--accent); }
.markdown-body a:hover { border-bottom-style: solid; }
.markdown-body blockquote {
  margin: 1em 0;
  padding: 10px 20px;
  border-left: 3px solid var(--accent);
  background: var(--bg-soft);
  border-radius: 0 10px 10px 0;
  color: var(--text-soft);
}
.markdown-body table { border-collapse: collapse; width: 100%; margin: 1.2em 0; font-size: 0.92rem; display: block; overflow-x: auto; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 9px 13px; text-align: left; }
.markdown-body th { background: var(--bg-soft); border-bottom: 2px solid var(--accent); }
.markdown-body tr { transition: background 0.15s; }
.markdown-body tbody tr:hover { background: var(--bg-soft); }
.markdown-body code { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; font-size: 0.88em; }
.markdown-body pre code { background: none; padding: 0; }

.code-block {
  position: relative;
  background: var(--code-bg);
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow-x: auto;
  box-shadow: var(--shadow);
  transition: transform 0.2s;
}
.code-block:hover { transform: scale(1.005); }
.copy-btn {
  position: absolute;
  top: 10px; right: 10px;
  background: #ffffff14;
  color: #ddd;
  border: 1px solid #ffffff2a;
  border-radius: 8px;
  padding: 4px 9px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
}
.code-block:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- editor ---------- */
#editor { animation: content-in 0.35s; }
.editor-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  color: var(--text-soft);
  font-size: 0.85rem;
}
.editor-bar div { display: flex; gap: 8px; }
#editor-text {
  width: 100%;
  min-height: 62vh;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  padding: 20px;
  font-family: Consolas, "Fira Code", monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s;
}
#editor-text:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

/* ---------- toc ---------- */
#toc-panel { position: sticky; top: 0; height: 100vh; padding: 40px 18px; font-size: 0.82rem; overflow-y: auto; }
#toc-panel h3 { color: var(--text-soft); text-transform: uppercase; font-size: 0.68rem; letter-spacing: 0.1em; }
#toc a {
  display: block;
  color: var(--text-soft);
  text-decoration: none;
  padding: 4px 0 4px 10px;
  border-left: 2px solid var(--border);
  transition: color 0.2s, border-color 0.2s, padding-left 0.2s;
}
#toc a.lvl-3 { padding-left: 24px; }
#toc a:hover, #toc a.current { color: var(--accent); border-left-color: var(--accent); padding-left: 14px; }

/* ---------- brain break ---------- */
#brain-btn {
  position: fixed;
  bottom: 26px; right: 26px;
  width: 58px; height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(249, 90, 54, 0.45);
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1.6);
  z-index: 40;
}
#brain-btn:hover { transform: scale(1.15) rotate(-8deg); }
#brain-btn.wiggle { animation: wiggle 0.8s ease-in-out 3; }
@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-14deg) scale(1.1); }
  75% { transform: rotate(14deg) scale(1.1); }
}

/* ---------- dialogs (minimal glass) ---------- */
dialog {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg); /* fallback if color-mix unsupported */
  background: color-mix(in srgb, var(--bg) 74%, transparent);
  backdrop-filter: blur(22px) saturate(1.5);
  -webkit-backdrop-filter: blur(22px) saturate(1.5);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  padding: 26px;
  width: min(500px, 92vw);
}
dialog::backdrop { background: rgba(15, 12, 10, 0.45); backdrop-filter: blur(4px); }
dialog[open] { animation: pop 0.35s cubic-bezier(0.2, 0.8, 0.2, 1.4); }
@keyframes pop { from { transform: scale(0.85) translateY(20px); opacity: 0; } }

#login-form, #password-form { display: flex; flex-direction: column; gap: 12px; }
#login-form h3, #password-form h3 { margin: 0 0 4px; }
#password-form .game-sub { margin: 0; }
#login-form input, #password-form input {
  padding: 11px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}
#login-form input:focus, #password-form input:focus { border-color: var(--accent); }
.form-error { color: #d33; font-size: 0.8rem; min-height: 1em; margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- game ---------- */
#game-dialog { width: min(520px, 94vw); }
.game-head { display: flex; justify-content: space-between; align-items: center; }
.game-head h3 { margin: 0; }
.game-sub { color: var(--text-soft); font-size: 0.85rem; margin-top: 4px; }
#game-canvas {
  width: 100%;
  border-radius: var(--radius);
  background: var(--bg-soft);
  border: 1.5px solid var(--border);
  cursor: crosshair;
  touch-action: manipulation;
}
.game-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
#game-score { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
#leaderboard { margin-top: 14px; }
#leaderboard h4 { margin: 0 0 6px; color: var(--text-soft); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }
#scores { margin: 0; padding-left: 22px; font-size: 0.88rem; }
#scores li { padding: 2px 0; }
#scores li:first-child { color: var(--accent); font-weight: 700; }

/* ---------- users panel ---------- */
#users-dialog { width: min(560px, 94vw); max-height: 88vh; overflow-y: auto; }
.public-badge { font-size: 0.75rem; }
.group-lock {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0 2px;
  opacity: 0.55;
  transition: opacity 0.2s, transform 0.2s;
}
.group-lock:hover { opacity: 1; transform: scale(1.2); }

#users-list { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; }
.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.88rem;
  background: color-mix(in srgb, var(--bg-soft) 55%, transparent);
  transition: border-color 0.2s, transform 0.2s;
}
.user-row:hover { border-color: var(--accent); transform: translateX(3px); }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.75rem;
  flex-shrink: 0;
}
.user-id { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.user-id strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-id .user-perms { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-radius: 20px;
  padding: 3px 10px;
  flex-shrink: 0;
}
.chip-admin { background: var(--accent); color: #fff; }
.chip-editor { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent); }
.chip-reader { background: transparent; color: var(--text-soft); border: 1px solid var(--border); }
.user-perms { color: var(--text-soft); font-size: 0.78rem; }
.ghost-btn.small { padding: 4px 9px; font-size: 0.75rem; }

#user-form { display: flex; flex-direction: column; gap: 12px; border-top: 1px solid var(--border); padding-top: 14px; }
#user-form h4 { margin: 0; font-size: 0.85rem; color: var(--text-soft); }
.user-form-row { display: flex; gap: 8px; }
.user-form-row input {
  flex: 1;
  padding: 10px 13px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  outline: none;
}
.user-form-row input:focus { border-color: var(--accent); }
#user-form fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
#user-form legend { font-size: 0.72rem; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.07em; padding: 0 6px; }
/* Selection pills: the checkbox hides, the label becomes the control */
.check-grid { display: flex; flex-wrap: wrap; gap: 8px; max-height: 170px; overflow-y: auto; padding: 2px; }
label.check {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 0.82rem;
  color: var(--text-soft);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.2s, background 0.2s, color 0.2s, transform 0.15s;
}
label.check:hover { border-color: var(--accent); transform: translateY(-1px); }
label.check:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
label.check:has(input:checked)::before { content: "✓ "; font-weight: 700; }
label.check input { position: absolute; opacity: 0; pointer-events: none; }

/* ---------- back to top ---------- */
#top-btn {
  position: fixed;
  bottom: 100px;
  right: 34px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text-soft);
  font-size: 1.05rem;
  cursor: pointer;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.35s, transform 0.35s, border-color 0.2s, color 0.2s;
  z-index: 40;
}
#top-btn.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
#top-btn:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-3px); }

/* ---------- end-of-doc mark ---------- */
.end-mark {
  text-align: center;
  color: var(--accent);
  opacity: 0.45;
  font-size: 0.8rem;
  letter-spacing: 1.2em;
  padding: 44px 0 10px;
  text-indent: 1.2em; /* balance the letter-spacing */
  user-select: none;
}

/* ---------- accessibility: calm means optional ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}

/* ---------- audit panel ---------- */
#audit-dialog { width: min(620px, 94vw); max-height: 86vh; overflow-y: auto; }
#audit-filter {
  width: 100%;
  margin: 12px 0 6px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
#audit-filter:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.audit-day {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-soft);
  padding: 16px 4px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.audit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-radius: 10px;
  font-size: 0.86rem;
  transition: background 0.15s;
}
.audit-row:hover { background: var(--bg-soft); }
.audit-row .avatar.small { width: 28px; height: 28px; font-size: 0.65rem; }
.audit-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.audit-main b { word-break: break-all; }
.audit-detail { color: var(--text-soft); font-size: 0.76rem; }
.audit-row time { color: var(--text-soft); font-size: 0.75rem; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.chip-danger { background: transparent; color: #d33; border: 1px solid #d33; }

/* ---------- contributors hover (ⓘ) ---------- */
.info-wrap { position: relative; display: inline-block; }
.info-icon {
  cursor: help;
  color: var(--accent);
  font-style: normal;
  padding: 0 3px;
  transition: transform 0.2s;
  display: inline-block;
}
.info-wrap:hover .info-icon { transform: scale(1.25); }
.info-pop {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translate(-50%, -6px);
  min-width: 260px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px 14px;
  font-size: 0.8rem;
  opacity: 0;
  visibility: hidden; /* fully skipped by the compositor until hovered */
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s, visibility 0.25s;
  z-index: 45;
}
.info-wrap:hover .info-pop { opacity: 1; visibility: visible; transform: translate(-50%, 0); pointer-events: auto; }
.info-row { display: flex; align-items: baseline; gap: 8px; padding: 4px 0; white-space: nowrap; }
.info-row strong { color: var(--text); }
.info-row a { color: var(--accent); text-decoration: none; font-size: 0.75rem; }
.info-row a:hover { text-decoration: underline; }
.info-row em { color: var(--text-soft); font-size: 0.75rem; }
.info-row time { margin-left: auto; color: var(--text-soft); font-size: 0.72rem; }

/* ---------- toast (popover = above open dialogs) ---------- */
#toast {
  position: fixed;
  inset: auto;
  bottom: 30px; left: 50%;
  margin: 0;
  border: none;
  transform: translate(-50%, 80px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 22px;
  border-radius: 30px;
  font-size: 0.9rem;
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1.3), opacity 0.4s;
  z-index: 60;
  pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  body { grid-template-columns: 270px minmax(0, 1fr); }
  #toc-panel { display: none; }
}
@media (max-width: 780px) {
  body { grid-template-columns: 1fr; }
  #sidebar { position: relative; height: auto; }
  #main { padding: 24px 20px 90px; }
}

/* ---------- login dialog (branded, theme-independent) ---------- */
#login-dialog {
  width: min(520px, 94vw);
  max-height: calc(100vh - 32px);
  padding: 0;
  border: none;
  border-radius: 22px;
  overflow-y: auto;
  overflow-x: hidden;
  background: #0d0f14;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
}
#login-dialog::backdrop {
  background: rgba(10, 8, 6, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.login-stage {
  position: relative;
  overflow: hidden;
  border-radius: 22px;
  padding: 78px 46px 22px;
  background:
    radial-gradient(120% 90% at 15% -10%, #5a2c18 0%, transparent 55%),
    radial-gradient(120% 90% at 100% 110%, #40200f 0%, transparent 55%),
    #14100e;
}

.stage-glow {
  position: absolute;
  width: 40%;
  height: 40%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent), transparent 70%);
  filter: blur(46px);
  opacity: 0.4;
  pointer-events: none;
}
.stage-glow.g1 { top: -18%; left: -14%; animation: glow-drift-a 9s ease-in-out infinite alternate; }
.stage-glow.g2 { bottom: -20%; right: -12%; animation: glow-drift-b 11s ease-in-out infinite alternate; }
@keyframes glow-drift-a {
  0%, 100% { opacity: 0.45; transform: translate(0, 0) scale(1); }
  50% { opacity: 0.8; transform: translate(10%, 8%) scale(1.15); }
}
@keyframes glow-drift-b {
  0%, 100% { opacity: 0.32; transform: translate(0, 0) scale(1); }
  50% { opacity: 0.62; transform: translate(-8%, -10%) scale(0.9); }
}

.stage-line {
  position: absolute;
  height: 1px;
  width: 140%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 8px 1px var(--accent);
  opacity: 0.22;
  transform-origin: left center;
  pointer-events: none;
}
.stage-line.ln1 { top: 14%; left: -20%; transform: rotate(-14deg); animation: line-drift 14s ease-in-out infinite alternate; }
.stage-line.ln2 { bottom: 24%; left: -30%; transform: rotate(9deg); opacity: 0.16; animation: line-drift 17s ease-in-out infinite alternate-reverse; }
.stage-line.ln3 { top: 46%; left: -25%; transform: rotate(-4deg); opacity: 0.18; animation: line-drift 12s ease-in-out infinite alternate; animation-delay: 2.5s; }
.stage-line.ln4 { top: 30%; left: -28%; transform: rotate(20deg); opacity: 0.14; animation: line-drift 15.5s ease-in-out infinite alternate-reverse; animation-delay: 1.2s; }
.stage-line.ln5 { bottom: 8%; left: -22%; transform: rotate(-8deg); opacity: 0.16; animation: line-drift 13s ease-in-out infinite alternate; animation-delay: 3.8s; }
@keyframes line-drift {
  0% { transform: translateX(0) rotate(0deg) scaleX(1); opacity: 0.12; }
  50% { transform: translateX(6%) rotate(-11deg) scaleX(1.08); opacity: 0.32; }
  100% { transform: translateX(0) rotate(0deg) scaleX(1); opacity: 0.12; }
}

.stage-star {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #ffd7c2;
  box-shadow: 0 0 6px 1px var(--accent), 0 0 14px 3px rgba(249, 90, 54, 0.5);
  opacity: 0;
  pointer-events: none;
  animation: star-twinkle 6s ease-in-out infinite;
}
.stage-star.st1 { top: 10%; left: 18%; animation-delay: 0s; }
.stage-star.st2 { top: 16%; left: 66%; width: 2px; height: 2px; animation-delay: 1.1s; }
.stage-star.st3 { top: 30%; left: 88%; animation-delay: 2.4s; }
.stage-star.st4 { top: 58%; left: 8%; width: 2px; height: 2px; animation-delay: 3.6s; }
.stage-star.st5 { top: 68%; left: 58%; animation-delay: 0.7s; }
.stage-star.st6 { top: 82%; left: 32%; width: 2px; height: 2px; animation-delay: 4.8s; }
.stage-star.st7 { top: 6%; left: 42%; animation-delay: 2.9s; }
.stage-star.st8 { top: 40%; left: 6%; width: 2px; height: 2px; animation-delay: 5.4s; }
.stage-star.st9 { top: 88%; left: 72%; animation-delay: 1.8s; }
.stage-star.st10 { top: 22%; left: 94%; width: 2px; height: 2px; animation-delay: 4.1s; }
.stage-star.st11 { top: 48%; left: 3%; animation-delay: 2.1s; }
.stage-star.st12 { top: 75%; left: 16%; width: 2px; height: 2px; animation-delay: 0.3s; }
@keyframes star-twinkle {
  0%, 100% { opacity: 0; transform: scale(0.6); }
  50% { opacity: 0.9; transform: scale(1.3); }
}

.stage-shape {
  position: absolute;
  color: var(--accent);
  width: 30px;
  height: 30px;
  opacity: 0;
  pointer-events: none;
  animation: shape-cycle 15s ease-in-out infinite;
}
.stage-shape.sh1 { top: 10%; left: 8%; width: 26px; height: 26px; animation-delay: 0s; }
.stage-shape.sh2 { top: 62%; left: 82%; width: 22px; height: 22px; animation-delay: 3s; }
.stage-shape.sh3 { top: 26%; left: 88%; width: 10px; height: 10px; animation-delay: 6s; }
.stage-shape.sh4 { top: 78%; left: 14%; width: 22px; height: 22px; animation-delay: 9s; }
.stage-shape.sh5 { top: 46%; left: 4%; width: 18px; height: 18px; animation-delay: 11.5s; }
.stage-shape.sh6 { top: 4%; left: 60%; width: 14px; height: 14px; animation-delay: 5s; }
.stage-shape.sh7 { top: 90%; left: 46%; width: 20px; height: 20px; animation-delay: 8s; }
.stage-shape.sh8 { top: 34%; left: 2%; width: 16px; height: 16px; animation-delay: 4.5s; }
.stage-shape.sh9 { top: 58%; left: 16%; width: 24px; height: 24px; animation-delay: 13s; }
@keyframes shape-cycle {
  0% { opacity: 0; transform: translate(0, 14px) scale(0.8); }
  12% { opacity: 0.6; transform: translate(0, 0) scale(1); }
  38% { opacity: 0.6; transform: translate(8px, -12px) scale(1); }
  48% { opacity: 0; transform: translate(20px, -30px) scale(0.8); }
  52% { opacity: 0; transform: translate(-24px, 26px) scale(0.8); }
  74% { opacity: 0.55; transform: translate(-6px, 8px) scale(1); }
  100% { opacity: 0; transform: translate(0, 14px) scale(0.8); }
}

/* Magical comet: a bright head plus five time-lagged echoes tracing the
   same path. Each echo starts later, so at any instant it sits behind the
   head in space too — a real fading trail, not a rigid painted shape. */
.comet {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle, #fff8f2 0%, var(--accent) 60%, transparent 100%);
  animation: comet-path 12s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
}
.comet-0 {
  width: 6px; height: 6px;
  filter: blur(0.3px);
  box-shadow: 0 0 8px 2px #fff8f2, 0 0 22px 7px var(--accent), 0 0 40px 14px rgba(249, 90, 54, 0.35);
  animation-delay: 0s;
}
.comet-1 { width: 5px; height: 5px; filter: blur(1px); box-shadow: 0 0 10px 4px rgba(249, 90, 54, 0.75); animation-delay: 0.12s; }
.comet-2 { width: 4.5px; height: 4.5px; filter: blur(1.5px); box-shadow: 0 0 9px 4px rgba(249, 90, 54, 0.6); animation-delay: 0.28s; }
.comet-3 { width: 4px; height: 4px; filter: blur(2px); box-shadow: 0 0 8px 3px rgba(249, 90, 54, 0.45); animation-delay: 0.48s; }
.comet-4 { width: 3px; height: 3px; filter: blur(2.5px); box-shadow: 0 0 7px 3px rgba(249, 90, 54, 0.3); animation-delay: 0.72s; }
.comet-5 { width: 2px; height: 2px; filter: blur(3px); box-shadow: 0 0 6px 2px rgba(249, 90, 54, 0.18); animation-delay: 1s; }

@keyframes comet-path {
  0%   { opacity: 0; top: 16%; left: 112%; }
  8%   { opacity: 1; top: 19%; left: 100%; }
  16%  { top: 23%; left: 86%; }
  28%  { top: 35%; left: 56%; }
  40%  { top: 58%; left: 14%; }
  46%  { opacity: 1; top: 66%; left: 0%; }
  52%  { top: 56%; left: -6%; }
  56%  { opacity: 0; top: 44%; left: -12%; }
  100% { opacity: 0; top: 16%; left: 112%; }
}

@media (prefers-reduced-motion: reduce) {
  .stage-glow, .stage-line, .stage-star, .stage-shape { animation: none !important; opacity: 0.12; }
  .comet { display: none; }
}

.login-card {
  position: relative;
  width: 88%;
  margin: 0 auto;
  background: #ffffff;
  border-radius: 18px;
  padding: 24px 22px 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  text-align: center;
  animation: card-in 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) 0.05s backwards;
}
@keyframes card-in { from { opacity: 0; transform: translateY(22px) scale(0.97); } }

.login-logo {
  position: relative;
  width: 84px;
  height: 84px;
  margin: -60px auto 14px;
  border-radius: 50%;
  background: linear-gradient(150deg, var(--accent), var(--accent-strong));
  display: grid;
  place-items: center;
  box-shadow: 0 10px 26px rgba(249, 90, 54, 0.45), 0 0 0 6px #ffffff;
  animation: logo-in 0.6s cubic-bezier(0.2, 0.8, 0.2, 1.5) 0.15s backwards;
}
.login-logo::before {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  pointer-events: none;
  animation: logo-ring 1s ease-out 0.35s 1;
}
.login-logo svg { width: 38px; height: 38px; }
@keyframes logo-in { from { opacity: 0; transform: scale(0.4) rotate(-40deg); } }
@keyframes logo-ring {
  0% { opacity: 0.7; transform: scale(0.6); }
  100% { opacity: 0; transform: scale(1.7); }
}

#login-dialog h3 { margin: 0 0 4px; font-size: 1.3rem; letter-spacing: -0.02em; color: #1b1e24; }
.login-sub { margin: 0 0 16px; color: #667085; font-size: 0.85rem; }

#login-dialog form#login-form { display: flex; flex-direction: column; gap: 12px; text-align: left; }

.field {
  position: relative;
  display: block;
  animation: field-in 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}
.field:nth-of-type(1) { animation-delay: 0.22s; }
.field:nth-of-type(2) { animation-delay: 0.28s; }
@keyframes field-in { from { opacity: 0; transform: translateY(10px); } }

.field-icon {
  position: absolute;
  top: 50%;
  left: 14px;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  color: #98a1b0;
  pointer-events: none;
  transition: color 0.2s;
}
.field:focus-within .field-icon { color: var(--accent); }

#login-dialog .field input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  border-radius: 12px;
  border: 1.5px solid #e6e8ec;
  background: #f6f7f9;
  color: #1b1e24;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
#login-dialog .field input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.login-actions { justify-content: stretch; gap: 10px; margin-top: 2px; }
.login-actions .accent-btn {
  flex: 1;
  padding: 12px 14px;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-actions .accent-btn:hover { box-shadow: 0 8px 22px rgba(249, 90, 54, 0.4); }
