/* main.css: CSS variables, reset, base layout, dark/light themes */

/* -------------------------------------------------------------------------
   Editorial palette. Light theme is the priority/default: white +
   neutral cool grays, with a confident cobalt blue as the single accent
------------------------------------------------------------------------- */
:root,
[data-theme="light"] {
  --bg-base:       #ffffff;
  --bg-mantle:     #ffffff;
  --bg-sidebar:    #ffffff;
  --bg-surface0:   #f5f5f7;
  --bg-surface1:   #e9e9ec;
  --bg-surface2:   #dcdce0;
  --text-primary:  #1c1e2b;
  --text-muted:    #55536a;
  --text-faint:    #8a8798;
  --accent:        #3457d9;
  --accent-blue:   #3d8f80;
  --accent-green:  #4f8f3f;
  --accent-red:    #c9424d;
  --accent-yellow: #3457d9;
  --accent-orange: #3457d9;
  --accent-teal:   #3d8f80;
  --accent-purple: #7c3aed;
  --border:        #e4e4e9;
  --font-mono:     'Cascadia Code', 'Consolas', 'Courier New', monospace;
  --font-ui:       'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius:        8px;
  --shadow:        0 2px 8px rgba(0,0,0,.12);
}

/* -------------------------------------------------------------------------
   Dark theme (opt-in)
------------------------------------------------------------------------- */
[data-theme="dark"] {
  --bg-base:       #14151f;
  --bg-mantle:     #1c1e2b;
  --bg-sidebar:    #1c1e2b;
  --bg-surface0:   #262838;
  --bg-surface1:   #2f3142;
  --bg-surface2:   #3a3d52;
  --text-primary:  #f0eee6;
  --text-muted:    #a8a6b8;
  --text-faint:    #6d6b7d;
  --accent:        #6e8fff;
  --accent-blue:   #5fb3a3;
  --accent-green:  #7fb069;
  --accent-red:    #e8646f;
  --accent-yellow: #6e8fff;
  --accent-orange: #6e8fff;
  --accent-teal:   #5fb3a3;
  --accent-purple: #a78bfa;
  --border:        #2f3142;
  --shadow:        0 2px 8px rgba(0,0,0,.4);
}

/* -------------------------------------------------------------------------
   Reset & base
------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-ui);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

/* -------------------------------------------------------------------------
   App shell layout
------------------------------------------------------------------------- */
#app {
  display: grid;
  grid-template-rows: 44px 1fr;
  grid-template-columns: var(--sidebar-w, 280px) 1fr;
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns .2s ease;
}
#app.sidebar-collapsed {
  --sidebar-w: 0px;
}

/* Topbar spans full width */
#topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--bg-mantle);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

#topbar .topbar-brand {
  display: flex;
  align-items: center;
  text-decoration: none;
  margin-right: 8px;
  flex-shrink: 0;
}

.topbar-logo {
  height: 28px;
  width: auto;
  display: block;
  object-fit: contain;
  transition: filter .2s;
}

[data-theme="light"] .topbar-logo {
  filter: brightness(0);
}

#topbar .topbar-sep {
  flex: 1;
}

/* Sidebar */
#sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* Main panel */
#main-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  overflow: hidden;
}

/* -------------------------------------------------------------------------
   Scrollbar styling
------------------------------------------------------------------------- */
/* Scroll stays functional; the bar itself is hidden. */
* {
  scrollbar-width: none;        /* Firefox */
  -ms-overflow-style: none;     /* legacy Edge/IE */
}
::-webkit-scrollbar {           /* WebKit / Chromium */
  width: 0;
  height: 0;
}

/* -------------------------------------------------------------------------
   Buttons
------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  transition: opacity .15s, background .15s;
  white-space: nowrap;
}
.btn:hover { opacity: .85; }
.btn:active { opacity: .7; }

.btn-primary {
  background: var(--accent);
  color: var(--bg-mantle);
}
.btn-secondary {
  background: var(--bg-surface0);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-surface0); color: var(--text-primary); }
.btn-success {
  background: var(--accent-green);
  color: var(--bg-mantle);
}
.btn-danger {
  background: var(--accent-red);
  color: var(--bg-mantle);
}
.btn.running {
  color: transparent;
  pointer-events: none;
  position: relative;
}
.btn.running::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
.btn.done {
  background: var(--accent-green);
  color: var(--bg-mantle);
}

/* -------------------------------------------------------------------------
   Topbar inputs
------------------------------------------------------------------------- */
#search-input {
  padding: 5px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-surface0);
  color: var(--text-primary);
  font-size: 13px;
  width: 180px;
  outline: none;
  transition: border-color .15s;
}
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--text-faint); }

select.filter-select {
  padding: 5px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-surface0);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  outline: none;
}
select.filter-select:focus { border-color: var(--accent); }

/* -------------------------------------------------------------------------
   Toast container
------------------------------------------------------------------------- */
#toast-container {
  position: fixed;
  top: 56px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity .25s, transform .25s;
  pointer-events: auto;
  max-width: 280px;
  box-shadow: var(--shadow);
}
.toast.visible { opacity: 1; transform: translateX(0); }

.toast-success { background: var(--accent-green); color: var(--bg-mantle); }
.toast-error   { background: var(--accent-red);   color: var(--bg-mantle); }
.toast-info    { background: var(--accent-blue);  color: var(--bg-mantle); }

/* -------------------------------------------------------------------------
   Modal overlay
------------------------------------------------------------------------- */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 900;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#modal-overlay.visible { display: flex; }

#modal {
  background: var(--bg-mantle);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}

#modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
#modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}
#modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
#modal-close:hover { color: var(--text-primary); background: var(--bg-surface0); }

#modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* -------------------------------------------------------------------------
   Dashboard
------------------------------------------------------------------------- */
.dashboard h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  margin: 16px 0 8px;
}
.dashboard h3:first-child { margin-top: 0; }

.dash-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.stat-card {
  background: var(--bg-surface0);
  border-radius: var(--radius);
  padding: 10px;
  text-align: center;
}
.stat-val { font-size: 22px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.level-progress-grid { display: flex; flex-direction: column; gap: 6px; }
.lp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.lp-name { width: 60px; color: var(--text-muted); }
.lp-bar-track { flex: 1; height: 6px; background: var(--bg-surface0); border-radius: 3px; overflow: hidden; }
.lp-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }
.lp-count { width: 32px; text-align: right; color: var(--text-faint); }

.badges-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.badge-card {
  background: var(--bg-surface0);
  border-radius: var(--radius);
  padding: 12px 6px;
  text-align: center;
  cursor: default;
  transition: background .15s;
}
.badge-card.locked { opacity: .4; }
.badge-card.earned { border: 1px solid var(--accent); }
.badge-icon-lg { font-size: 26px; line-height: 1; }
.badge-name { font-size: 10px; color: var(--text-muted); margin-top: 4px; }

.dash-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* -------------------------------------------------------------------------
   Glossary
------------------------------------------------------------------------- */
.glossary-search {
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 14px;
  background: var(--bg-surface0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13.5px;
}
.glossary-search:focus { outline: none; border-color: var(--accent); }

.glossary-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.glossary-entry {
  background: var(--bg-surface0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.glossary-term-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}
.glossary-term {
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--accent-teal);
}
.glossary-topic-tag {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-faint);
  flex-shrink: 0;
}
.glossary-def {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 8px;
}
.glossary-example {
  background: var(--bg-mantle);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 0 0 8px;
  font-size: 12px;
  overflow-x: auto;
}
.glossary-source {
  display: inline-block;
  background: none;
  border: none;
  padding: 0;
  font-size: 11.5px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}
.glossary-source--extra {
  color: var(--text-faint);
  cursor: default;
  text-decoration: none;
}
.glossary-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 20px 0;
}

/* -------------------------------------------------------------------------
   Badge unlock modal
------------------------------------------------------------------------- */
.badge-unlock {
  text-align: center;
  padding: 16px;
}
.badge-unlock .badge-icon { font-size: 56px; margin-bottom: 12px; }
.badge-unlock .badge-label { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.badge-unlock .badge-desc { color: var(--text-muted); }

/* -------------------------------------------------------------------------
   Responsive
------------------------------------------------------------------------- */
@media (max-width: 900px) {
  #app {
    --sidebar-w: 220px;
  }
}

@media (max-width: 640px) {
  #search-input { width: 120px; }
}
