:root {
  --bg-gradient-start: #0f1115;
  --bg-gradient-end: #08090d;
  --card-bg: rgba(19, 21, 26, 0.65);
  --card-border: rgba(255, 255, 255, 0.08);
  --accent: #3b82f6; /* Blue-500 accent from pandachess */
  --accent-glow: rgba(59, 130, 246, 0.45);
  --accent-secondary: #4f46e5; /* Indigo-600 accent */
  --text-main: #f1f5f9; /* Slate-100 */
  --text-muted: #94a3b8; /* Slate-400 */
  --success: #22c55e; /* Green-500 from pandachess name winner */
  --warning: #f59e0b; /* Amber-500 from pawn mode active */
  --error: #ef4444; /* Red-500 */
  --console-bg: rgba(15, 23, 42, 0.85);
}

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

body {
  font-family: 'Inter', sans-serif;
  background: linear-gradient(-45deg, #0f172a, #2e1065, #1e3a8a, #0f172a);
  background-size: 400% 400%;
  animation: gradientBG 12s ease infinite;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem;
  overflow-x: hidden;
  position: relative;
}

@keyframes gradientBG {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

body::before, body::after {
  content: '';
  position: absolute;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  filter: blur(180px);
  z-index: 0;
  opacity: 0.15;
  pointer-events: none;
}
body::before { background: var(--accent); top: 10%; left: 5%; }
body::after { background: var(--accent-secondary); bottom: 10%; right: 5%; }

.container {
  width: 100%;
  max-width: 1240px;
  z-index: 10;
}

.dashboard-layout {
  display: grid;
  grid-template-columns: 460px 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 1024px) {
  .dashboard-layout {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 2.5rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-secondary) 100%);
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

.logo-wrapper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: 18px;
  margin-bottom: 0.75rem;
  font-size: 1.8rem;
  color: var(--accent);
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.15);
  animation: pulse-glow 3s infinite ease-in-out;
}

h1 {
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 2rem;
  background: linear-gradient(135deg, #FFF 30%, #93C5FD 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.subtitle { color: var(--text-muted); font-size: 0.9rem; font-weight: 400; }

.form-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.form-group {
  flex: 1;
  margin-bottom: 1.25rem;
  position: relative;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
  color: var(--text-muted);
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 0.85rem;
  color: var(--text-muted);
  font-size: 1rem;
}

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  padding: 0.75rem 0.85rem 0.75rem 2.5rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  color: var(--text-main);
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  transition: all 0.25s ease;
  appearance: none;
}

input.no-icon, select.no-icon, textarea.no-icon { padding-left: 0.85rem; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: rgba(15, 23, 42, 0.8);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2.5 4.5L6 8L9.5 4.5' stroke='%239CA3AF' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  cursor: pointer;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.checkbox-group input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.checkbox-group label { margin-bottom: 0; cursor: pointer; text-transform: none; font-size: 0.85rem; font-weight: 400; }

.btn {
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-secondary) 100%);
  border: none;
  border-radius: 10px;
  color: #FFF;
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 10px 20px rgba(59, 130, 246, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(59, 130, 246, 0.3);
  background: linear-gradient(135deg, var(--accent-secondary) 0%, var(--accent) 100%);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  box-shadow: none;
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.65; cursor: not-allowed; box-shadow: none; }

.progress-container { margin-top: 1.5rem; display: none; }
.progress-header { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.4rem; }
.progress-bar { width: 100%; height: 6px; background: rgba(255, 255, 255, 0.05); border-radius: 99px; overflow: hidden; }
.progress-fill { width: 0%; height: 100%; background: linear-gradient(90deg, var(--accent) 0%, var(--accent-secondary) 100%); border-radius: 99px; transition: width 0.3s ease; }

.console-wrapper { margin-top: 1.5rem; }
.console-title { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 0.4rem; display: flex; justify-content: space-between; }
.console { background: var(--console-bg); border: 1px solid var(--card-border); border-radius: 10px; height: 180px; overflow-y: auto; padding: 0.75rem; font-family: 'JetBrains Mono', monospace; font-size: 0.8rem; line-height: 1.5; display: flex; flex-direction: column; gap: 0.3rem; box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.5); }
.console-line { display: flex; gap: 0.4rem; }
.console-line.info { color: #FFF; }
.console-line.success { color: var(--success); }
.console-line.warning { color: var(--warning); }
.console-line.error { color: var(--error); }

.tag { font-weight: 700; font-size: 0.7rem; padding: 0.05rem 0.25rem; border-radius: 4px; text-transform: uppercase; white-space: nowrap; }
.tag-info { background: rgba(59, 130, 246, 0.15); color: #93C5FD; border: 1px solid rgba(59, 130, 246, 0.3); }
.tag-success { background: rgba(34, 197, 94, 0.15); color: #4ADE80; border: 1px solid rgba(34, 197, 94, 0.3); }
.tag-warning { background: rgba(245, 158, 11, 0.15); color: #FBBF24; border: 1px solid rgba(245, 158, 11, 0.3); }
.tag-error { background: rgba(239, 68, 68, 0.15); color: #F87171; border: 1px solid rgba(239, 68, 68, 0.3); }

.console::-webkit-scrollbar, .chapter-list::-webkit-scrollbar, .editor-pane::-webkit-scrollbar { width: 5px; }
.console::-webkit-scrollbar-track, .chapter-list::-webkit-scrollbar-track, .editor-pane::-webkit-scrollbar-track { background: transparent; }
.console::-webkit-scrollbar-thumb, .chapter-list::-webkit-scrollbar-thumb, .editor-pane::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 99px; }
.console::-webkit-scrollbar-thumb:hover, .chapter-list::-webkit-scrollbar-thumb:hover, .editor-pane::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

/* Inspector Layout */
.inspector-panel {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1.5rem;
  margin-top: 1rem;
  height: 70vh;
  min-height: 560px;
}

.chapter-list {
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.chapter-item {
  padding: 0.65rem 0.85rem;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-muted);
  text-align: left;
}

.chapter-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.chapter-item.active {
  background: var(--accent);
  color: #FFF;
  font-weight: 500;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.editor-pane {
  background: rgba(15, 23, 42, 0.2);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.editor-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 2rem;
}

.editor-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 8px 20px rgba(59, 130, 246, 0.15); border-color: rgba(59, 130, 246, 0.2); }
  50% { box-shadow: 0 8px 25px rgba(59, 130, 246, 0.4); border-color: rgba(59, 130, 246, 0.5); }
}

.spinner { border: 2px solid rgba(255, 255, 255, 0.1); border-top: 2px solid #FFF; border-radius: 50%; width: 18px; height: 18px; animation: spin 0.8s linear infinite; display: none; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Toast Notification System */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 10000;
  pointer-events: none;
}

.toast {
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--card-border);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 0.85rem 1.25rem;
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  animation: toast-slide-in 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  min-width: 280px;
  max-width: 400px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: all 0.4s ease;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--error); }
.toast.info { border-left-color: var(--accent); }
.toast.warning { border-left-color: var(--warning); }

@keyframes toast-slide-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Context Menu */
.context-menu {
  position: absolute;
  z-index: 10000;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 0.5rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 190px;
  pointer-events: auto;
  animation: context-menu-fade 0.15s ease-out;
}

@keyframes context-menu-fade {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.context-menu-item {
  padding: 0.6rem 0.85rem;
  font-size: 0.85rem;
  color: var(--text-main);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transition: background 0.15s ease, color 0.15s ease;
  background: transparent;
  border: none;
  text-align: left;
  width: 100%;
}

.context-menu-item:hover {
  background: var(--accent);
  color: #fff;
}

/* Star Filter Chips */
.star-chip {
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
  border-radius: 99px;
  border: 1px solid var(--card-border);
  background: rgba(255,255,255,0.04);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  font-family: 'Inter', sans-serif;
}
.star-chip:hover {
  background: rgba(59,130,246,0.15);
  border-color: var(--accent);
  color: var(--text-main);
}
.star-chip-active {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
  font-weight: 600;
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* DB Stats Pills */
.stat-pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  white-space: nowrap;
}
.stat-pill-total   { background: rgba(59,130,246,0.12); color: #93C5FD; border: 1px solid rgba(59,130,246,0.25); }
.stat-pill-ranked  { background: rgba(34,197,94,0.12);  color: #4ADE80; border: 1px solid rgba(34,197,94,0.25); }
.stat-pill-unranked{ background: rgba(245,158,11,0.12); color: #FBBF24; border: 1px solid rgba(245,158,11,0.25); }
.stat-pill-sched   { background: rgba(168,85,247,0.12); color: #C084FC; border: 1px solid rgba(168,85,247,0.25); }
