@import url('https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@400;600;700&family=JetBrains+Mono:wght@400;500&family=Inter:wght@400;500;600&display=swap');

/* ------------------------------------------------------------------ */
/* Variables                                                            */
/* ------------------------------------------------------------------ */
:root {
  --bg:           #0d1117;
  --surface:      #161b22;
  --surface-2:    #21262d;
  --border:       #30363d;
  --border-hover: #484f58;
  --text:         #e6edf3;
  --text-muted:   #8b949e;
  --text-dim:     #6e7681;

  --gold:         #c9a227;
  --gold-dim:     #8a6e1a;
  --gold-glow:    rgba(201,162,39,0.15);

  --win:          #3fb950;
  --win-bg:       rgba(63,185,80,0.12);
  --loss:         #f85149;
  --loss-bg:      rgba(248,81,73,0.12);
  --draw:         #d29922;
  --draw-bg:      rgba(210,153,34,0.12);

  --deviation:    #f85149;
  --out-of-prep:  #d29922;
  --in-book:      #3fb950;

  --radius:       8px;
  --radius-sm:    4px;
  --nav-height:   56px;
}

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

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ */
/* Navigation                                                           */
/* ------------------------------------------------------------------ */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  padding: 0 24px;
  background: rgba(13,17,23,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  gap: 32px;
}

.nav-brand {
  font-family: 'Crimson Pro', serif;
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.02em;
  white-space: nowrap;
  text-decoration: none;
}
.nav-brand:hover { text-decoration: none; opacity: 0.85; }

.nav-links {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-link {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.15s;
  text-decoration: none;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav-link.active { color: var(--gold); background: var(--gold-glow); }

.nav-user {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
  white-space: nowrap;
}
.nav-username {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}
.nav-logout {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 4px 10px;
  transition: all 0.15s;
}
.nav-logout:hover { color: var(--text); border-color: var(--text-muted); }

/* ------------------------------------------------------------------ */
/* Layout                                                               */
/* ------------------------------------------------------------------ */
.main { max-width: 1200px; margin: 0 auto; padding: 32px 24px 64px; }

.page-header { margin-bottom: 32px; }
.page-title {
  font-family: 'Crimson Pro', serif;
  font-size: 2rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.page-subtitle { color: var(--text-muted); margin-top: 4px; font-size: 0.9rem; }

/* ------------------------------------------------------------------ */
/* Cards                                                                */
/* ------------------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}
.card-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ------------------------------------------------------------------ */
/* Stat numbers                                                         */
/* ------------------------------------------------------------------ */
.stat-big {
  font-family: 'Crimson Pro', serif;
  font-size: 2.4rem;
  font-weight: 600;
  line-height: 1;
  color: var(--gold);
}
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

/* ------------------------------------------------------------------ */
/* Buttons                                                              */
/* ------------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:hover:not(:disabled) { text-decoration: none; }

.btn-primary {
  background: var(--gold);
  color: #0d1117;
  border-color: var(--gold);
}
.btn-primary:hover:not(:disabled) { background: #d4ab2d; border-color: #d4ab2d; color: #0d1117; }

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover:not(:disabled) { border-color: var(--border-hover); background: var(--surface-2); color: var(--text); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-lg { padding: 11px 28px; font-size: 1rem; }
.btn-sm { padding: 4px 12px; font-size: 0.8rem; }

/* ------------------------------------------------------------------ */
/* Form                                                                 */
/* ------------------------------------------------------------------ */
.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 0.8rem; font-weight: 500; color: var(--text-muted); }
.form-select, .form-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.875rem;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s;
  min-width: 140px;
}
.form-select:focus, .form-input:focus { border-color: var(--gold); }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.8); cursor: pointer; }

/* ------------------------------------------------------------------ */
/* Badges                                                               */
/* ------------------------------------------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-win  { background: var(--win-bg);  color: var(--win); }
.badge-loss { background: var(--loss-bg); color: var(--loss); }
.badge-draw { background: var(--draw-bg); color: var(--draw); }

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.tag-deviation  { background: rgba(248,81,73,0.15);  color: var(--loss); }
.tag-not-prepped{ background: rgba(130,80,255,0.15); color: #a78bfa; }
.tag-out-prep   { background: rgba(210,153,34,0.15); color: var(--draw); }
.tag-in-book    { background: rgba(63,185,80,0.15);  color: var(--win); }

/* ------------------------------------------------------------------ */
/* Table                                                                */
/* ------------------------------------------------------------------ */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 20px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
thead tr {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
th {
  padding: 10px 14px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
}
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }
tr.row-deviation   td { border-left: 2px solid var(--loss); }
tr.row-not-prepped td { border-left: 2px solid #a78bfa; }
tr.row-out-prep    td { border-left: 2px solid var(--draw); }
tr.row-in-book     td { border-left: 2px solid var(--in-book); }

.mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
}
.move-arrow { color: var(--text-dim); margin: 0 4px; }
.move-wrong { color: var(--loss); }
.move-right { color: var(--win); font-weight: 500; }

/* ------------------------------------------------------------------ */
/* Stats row                                                            */
/* ------------------------------------------------------------------ */
.stats-row {
  display: flex;
  gap: 12px;
  margin: 24px 0 8px;
  flex-wrap: wrap;
}
.stat-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat-chip-num {
  font-family: 'Crimson Pro', serif;
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1;
}
.stat-chip-label { font-size: 0.78rem; color: var(--text-muted); }
.stat-chip.deviation  .stat-chip-num { color: var(--loss); }
.stat-chip.not-prepped .stat-chip-num { color: #a78bfa; }
.stat-chip.out-prep   .stat-chip-num  { color: var(--draw); }
.stat-chip.in-book    .stat-chip-num  { color: var(--win); }

/* ------------------------------------------------------------------ */
/* Log output                                                           */
/* ------------------------------------------------------------------ */
.log-box {
  background: #010409;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  line-height: 1.7;
  color: #7ee787;
  max-height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.log-box.hidden { display: none; }

/* ------------------------------------------------------------------ */
/* Alert / Notice                                                       */
/* ------------------------------------------------------------------ */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 16px;
}
.alert-error { background: rgba(248,81,73,0.1); border: 1px solid rgba(248,81,73,0.3); color: #ff7b72; }
.alert-info  { background: rgba(201,162,39,0.08); border: 1px solid rgba(201,162,39,0.2); color: var(--gold); }

/* ------------------------------------------------------------------ */
/* Spinner                                                              */
/* ------------------------------------------------------------------ */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row { display: flex; align-items: center; gap: 10px; color: var(--text-muted); padding: 16px 0; }

/* ------------------------------------------------------------------ */
/* Dashboard hero                                                       */
/* ------------------------------------------------------------------ */
.dashboard-hero {
  margin-bottom: 32px;
  padding: 28px 0 20px;
  border-bottom: 1px solid var(--border);
}
.dashboard-hero h1 {
  font-family: 'Crimson Pro', serif;
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.dashboard-hero .username { color: var(--gold); }
.hero-subtitle { color: var(--text-muted); margin-top: 4px; }

/* ------------------------------------------------------------------ */
/* Repertoire card accent                                               */
/* ------------------------------------------------------------------ */
.rep-card { position: relative; overflow: hidden; }
.rep-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.rep-card.white::before { background: linear-gradient(90deg, var(--gold), transparent); }
.rep-card.black::before { background: linear(90deg, #6e7681, transparent); }

.rep-piece {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 8px;
  opacity: 0.6;
}

/* ------------------------------------------------------------------ */
/* Scraper progress card                                                */
/* ------------------------------------------------------------------ */
.scraper-card { display: flex; flex-direction: column; gap: 16px; }
.scraper-header { display: flex; justify-content: space-between; align-items: flex-start; }
.sync-time { font-size: 0.75rem; color: var(--text-dim); }

/* ------------------------------------------------------------------ */
/* Empty state                                                          */
/* ------------------------------------------------------------------ */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.4; }
.empty-state h3 { color: var(--text); margin-bottom: 6px; }

/* ------------------------------------------------------------------ */
/* Chapter link                                                         */
/* ------------------------------------------------------------------ */
.link-train { color: var(--gold); font-size: 0.8rem; }
.link-game  { color: var(--text-muted); font-size: 0.8rem; }
.link-train:hover, .link-game:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ */
/* Stub pages                                                           */
/* ------------------------------------------------------------------ */
.coming-soon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
  gap: 16px;
  text-align: center;
  color: var(--text-muted);
}
.coming-soon-icon { font-size: 4rem; opacity: 0.2; }
.coming-soon h2 { font-family: 'Crimson Pro', serif; font-size: 1.5rem; color: var(--text); }

/* ------------------------------------------------------------------ */
/* Responsive                                                           */
/* ------------------------------------------------------------------ */
@media (max-width: 720px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; align-items: stretch; }
  .form-select, .form-input { min-width: unset; }
  .nav-links { gap: 0; }
  .nav-link { padding: 6px 10px; font-size: 0.8rem; }
}
