* { box-sizing: border-box; }

:root {
  --bg: #1e1f22;
  --panel: #2b2d31;
  --panel-2: #313338;
  --border: #3f4248;
  --text: #dbdee1;
  --muted: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --danger: #da373c;
  --chip: #3f4248;
}

html, body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "gg sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.45;
}

code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.92em;
}

/* ---- login hero ---- */
.hero {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.hero-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  max-width: 460px;
  text-align: center;
}
.hero-emoji { font-size: 56px; }
.hero-card h1 { margin: 12px 0 8px; font-size: 26px; }
.hero-card p { color: var(--muted); margin: 0 0 24px; }

/* ---- app shell ---- */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
header .guild-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--panel-2);
  display: grid; place-items: center;
  font-size: 20px;
  overflow: hidden;
}
header .guild-icon img { width: 100%; height: 100%; object-fit: cover; }
header .titles { flex: 1; min-width: 0; }
header .titles h1 { margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header .titles .sub { color: var(--muted); font-size: 12px; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px 4px 4px;
  font-size: 14px;
}
.user-chip img, .user-chip .initial {
  width: 26px; height: 26px; border-radius: 50%;
}
.badge {
  background: #f0b232; color: #1e1f22;
  font-size: 11px; font-weight: 700;
  border-radius: 4px; padding: 2px 6px;
  text-transform: uppercase;
}

main { max-width: 1080px; margin: 0 auto; padding: 26px 22px 60px; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin: 4px 0 16px;
}
.section-head h2 { margin: 0; font-size: 19px; }

/* ---- buttons ---- */
.btn {
  display: inline-block;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--border); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: #ff7a7e; }
.btn.danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 5px 12px; font-size: 13px; }

/* ---- character grid ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card .top { display: flex; gap: 12px; align-items: center; }
.avatar, .initial {
  width: 48px; height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}
.initial {
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-size: 20px; font-weight: 700;
}
.card h3 { margin: 0; font-size: 16px; word-break: break-word; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--chip);
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 12.5px;
  font-family: Consolas, monospace;
}
.chip.taken { opacity: 0.42; text-decoration: line-through; }
.card .bio {
  color: var(--muted);
  font-size: 13.5px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .actions { display: flex; gap: 8px; margin-top: auto; }

.empty {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

/* ---- help panel ---- */
.help {
  margin-top: 34px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}
.help h2 { font-size: 16px; margin: 0 0 10px; }
.help ul { margin: 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.help li { margin: 6px 0; }
.help li strong { color: var(--text); }

/* ---- editor dialog ---- */
dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: min(480px, 92vw);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin: 0 0 14px; font-size: 18px; }
dialog label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 5px; }
dialog input, dialog textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
dialog input:focus, dialog textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.avatar-row { display: flex; gap: 10px; align-items: center; }
.avatar-row input { flex: 1; }
#f-avatar-preview { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.error { color: #ff7a7e; font-size: 13px; margin: 10px 0 0; min-height: 1em; }
.muted { color: var(--muted); font-weight: 400; }
.row { display: flex; gap: 10px; margin-top: 16px; }
.row.end { justify-content: flex-end; }

/* ---- converter panels ---- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 16px;
}
.panel h2 { font-size: 17px; margin: 0 0 8px; }
.panel summary {
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}
.panel label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 5px; }
.panel input, .panel textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.panel input:focus, .panel textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.muted-text { color: var(--muted); font-size: 13.5px; margin: 0 0 6px; }
.notice {
  background: rgba(240, 178, 50, 0.12);
  border: 1px solid #f0b232;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 14px;
  margin-bottom: 16px;
}
.result-text, .lore-text {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 14px;
  font-family: inherit;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 480px;
  overflow-y: auto;
  margin: 10px 0;
}
.row .hint { align-self: center; margin-right: auto; }
button:disabled { opacity: 0.55; cursor: wait; }
#ch-layout { font-family: Consolas, monospace; font-size: 13px; margin-top: 8px; }
.diff-section { margin-top: 10px; font-size: 13.5px; }
.diff-section ul { margin: 4px 0 0; padding-left: 20px; color: var(--muted); }
.diff-section li { margin: 2px 0; }

/* ---- toast ---- */
#toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  z-index: 20;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
#toast.error { border-color: var(--danger); color: #ff7a7e; }
