:root {
  --bg: #070b12;
  --surface: #0f1623;
  --surface2: #151e2e;
  --border: #243047;
  --text: #edf2f8;
  --muted: #8fa3bf;
  --accent: #6366f1;
  --accent2: #22d3ee;
  --gold: #fbbf24;
  --success: #34d399;
  --radius: 14px;
  --font: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
}

.brand { display: flex; gap: 0.75rem; align-items: center; margin-bottom: 2rem; }
.brand-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: grid; place-items: center; font-size: 1.2rem;
}
.brand small { display: block; color: var(--muted); font-size: 0.75rem; }

nav { display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }
nav a {
  color: var(--muted); text-decoration: none; padding: 0.55rem 0.75rem;
  border-radius: 8px; font-size: 0.9rem;
}
nav a:hover, .nav-active { background: var(--surface2); color: var(--text); }

.sidebar-footer { margin-top: auto; padding-top: 1rem; }
.link-muted { color: var(--muted); font-size: 0.8rem; text-decoration: none; }

.main { padding: 1.5rem 2rem; overflow-y: auto; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.5rem;
}
.subtitle { color: var(--muted); font-size: 0.9rem; margin-top: 0.25rem; }

.btn {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 0.55rem 1rem; font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(1.1); }

.hero-card {
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(135deg, #1a1f35, #121a28);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem; margin-bottom: 1.25rem; gap: 1rem; flex-wrap: wrap;
}

.level-block { display: flex; gap: 1.25rem; align-items: center; }

.level-ring {
  width: 88px; height: 88px; border-radius: 50%;
  background: conic-gradient(var(--accent) 0%, var(--surface2) 0%);
  display: grid; place-items: center; position: relative;
}
.level-ring::before {
  content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--surface);
}
.level-ring span { position: relative; font-size: 1.75rem; font-weight: 800; color: var(--accent2); }

.rank { color: var(--gold); font-weight: 700; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; }
.name { font-size: 1.35rem; font-weight: 700; margin: 0.15rem 0 0.75rem; }

.xp-bar {
  width: 280px; max-width: 100%; height: 10px; background: var(--surface2);
  border-radius: 999px; overflow: hidden;
}
.xp-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.6s ease;
}
.xp-label { color: var(--muted); font-size: 0.8rem; margin-top: 0.4rem; }

.streak-card {
  display: flex; align-items: center; gap: 0.75rem;
  background: rgba(251, 191, 36, 0.08); border: 1px solid rgba(251, 191, 36, 0.25);
  border-radius: 12px; padding: 1rem 1.25rem;
}
.streak-icon { font-size: 1.75rem; }
.streak-card strong { font-size: 1.5rem; display: block; line-height: 1; }
.streak-card small { color: var(--muted); }

.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.85rem; margin-bottom: 1.25rem;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem;
}
.stat-card.accent { border-color: rgba(99, 102, 241, 0.4); }
.stat-label { display: block; color: var(--muted); font-size: 0.75rem; margin-bottom: 0.35rem; }
.stat-card strong { font-size: 1.4rem; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem;
}
.panel h2 { font-size: 1rem; margin-bottom: 1rem; }
.sub-heading { font-size: 0.85rem; color: var(--muted); margin: 1rem 0 0.5rem; }
.badge-count {
  font-size: 0.75rem; background: var(--surface2); padding: 0.15rem 0.5rem;
  border-radius: 999px; color: var(--muted); margin-left: 0.35rem;
}

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }

.quests-grid { display: grid; gap: 0.75rem; }
.quest-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.9rem 1rem;
}
.quest-card.done { border-color: rgba(52, 211, 153, 0.4); background: rgba(52, 211, 153, 0.06); }
.quest-top { display: flex; justify-content: space-between; margin-bottom: 0.5rem; font-size: 0.9rem; }
.quest-bar { height: 6px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.quest-fill { height: 100%; background: var(--success); transition: width 0.4s; }
.quest-reward { color: var(--gold); font-size: 0.8rem; margin-top: 0.35rem; }

.achievements-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 0.75rem;
}
.ach-card {
  text-align: center; padding: 1rem 0.5rem; border-radius: 10px;
  background: var(--surface2); border: 1px solid var(--border);
  opacity: 0.45; filter: grayscale(0.8); transition: 0.2s;
}
.ach-card.unlocked {
  opacity: 1; filter: none;
  border-color: rgba(251, 191, 36, 0.35);
  box-shadow: 0 0 20px rgba(251, 191, 36, 0.08);
}
.ach-icon { font-size: 1.75rem; display: block; margin-bottom: 0.35rem; }
.ach-title { font-size: 0.8rem; font-weight: 700; }
.ach-desc { font-size: 0.68rem; color: var(--muted); margin-top: 0.2rem; line-height: 1.3; }

.feed-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.feed-list li {
  font-size: 0.85rem; padding: 0.55rem 0.65rem; background: var(--surface2);
  border-radius: 8px; border-left: 3px solid var(--accent);
}
.feed-list.compact li { font-size: 0.78rem; border-left-color: var(--gold); }
.feed-meta { color: var(--muted); font-size: 0.72rem; display: block; margin-top: 0.15rem; }

.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: linear-gradient(135deg, #312e81, #1e3a5f);
  border: 1px solid var(--accent); border-radius: 12px;
  padding: 1rem 1.25rem; max-width: 320px; font-size: 0.9rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  animation: slideIn 0.3s ease;
}
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } }

/* Settings page */
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn-secondary { background: var(--surface2); border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--border); }

.banner {
  padding: 0.85rem 1rem; border-radius: 10px; margin-bottom: 1rem;
  border: 1px solid var(--border); background: var(--surface2);
}
.banner-info { border-color: rgba(99, 102, 241, 0.4); }
.banner label { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.85rem; }
.banner input { margin-top: 0.25rem; padding: 0.5rem; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }

.group-desc { color: var(--muted); font-size: 0.82rem; margin: -0.5rem 0 1rem; }

.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem;
}

.keys-summary {
  display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center;
  padding: 1rem 1.1rem; margin-bottom: 1rem; border-radius: 12px;
  background: linear-gradient(135deg, rgba(99,102,241,0.12), rgba(34,211,238,0.08));
  border: 1px solid rgba(99,102,241,0.35);
}
.summary-stat {
  display: flex; flex-direction: column; gap: 0.1rem; min-width: 90px;
  padding-right: 1rem; border-right: 1px solid var(--border);
}
.summary-stat:last-of-type { border-right: none; }
.summary-stat strong { font-size: 1.15rem; color: var(--text); }
.summary-stat span { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.summary-highlight strong { color: var(--accent2); }
.summary-note { flex: 1 1 220px; font-size: 0.78rem; color: var(--muted); }

.key-field {
  display: flex; flex-direction: column; gap: 0.4rem;
  padding: 0.85rem; border-radius: 10px; border: 2px solid var(--border);
  background: var(--bg); transition: border-color 0.2s, box-shadow 0.2s;
}
.key-field-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.key-field-title { font-size: 0.88rem; font-weight: 600; }
.key-active {
  border-color: var(--success);
  box-shadow: 0 0 0 1px rgba(52,211,153,0.25), 0 4px 20px rgba(52,211,153,0.08);
}
.key-stored { border-color: rgba(99,102,241,0.55); }
.key-missing { border-color: rgba(248,113,113,0.35); opacity: 0.92; }
.key-pending { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(251,191,36,0.3); }
.key-live { border-color: #22c55e; box-shadow: 0 0 12px rgba(34,197,94,0.2); }
.key-error { border-color: #f87171; }

.key-pill {
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.06em;
  padding: 0.2rem 0.45rem; border-radius: 999px; white-space: nowrap;
}
.key-pill-active { color: #052e1c; background: var(--success); }
.key-pill-stored { color: #e0e7ff; background: rgba(99,102,241,0.55); }
.key-pill-miss { color: #fecaca; background: rgba(248,113,113,0.25); }
.key-pill-pending { color: #422006; background: var(--gold); }
.key-pill-live { color: #052e1c; background: #4ade80; animation: pulse-live 2s infinite; }
.key-pill-error { color: #fff; background: #ef4444; }
@keyframes pulse-live { 0%,100% { opacity: 1; } 50% { opacity: 0.75; } }

.key-preview {
  padding: 0.45rem 0.55rem; border-radius: 6px;
  background: var(--surface2); border: 1px dashed var(--border);
  font-size: 0.78rem;
}
.key-preview-empty { color: var(--muted); font-style: italic; border-style: dotted; }
.key-preview-label {
  display: block; font-size: 0.65rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.2rem;
}
.key-preview code { color: var(--accent2); font-family: monospace; word-break: break-all; }
.key-live-msg { font-size: 0.72rem; }
.key-live-msg.ok { color: var(--success); }
.key-live-msg.fail { color: #f87171; }

.field-label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; }
.field-hint { color: var(--muted); font-size: 0.7rem; font-family: monospace; }
.key-field input, .key-field select, .field-label input, .field-label select {
  padding: 0.55rem 0.7rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 0.9rem;
}
.tag-ok { font-size: 0.65rem; color: var(--success); margin-left: 0.35rem; }
.tag-miss { font-size: 0.65rem; color: var(--danger, #f87171); margin-left: 0.35rem; }
.field-saved { font-size: 0.75rem; color: var(--success); }

.status-panel { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.4rem; }
.status-item { padding: 0.55rem 0.75rem; border-radius: 8px; font-size: 0.85rem; background: var(--surface2); }
.status-item.ok { border-left: 3px solid var(--success); }
.status-item.fail { border-left: 3px solid #f87171; }

.export-preview {
  margin-top: 0.75rem; padding: 1rem; background: var(--bg); border-radius: 8px;
  font-size: 0.78rem; overflow-x: auto; border: 1px solid var(--border); color: var(--muted);
}
