:root {
  --bg: #0f1419;
  --surface: #1a2129;
  --surface-2: #232c36;
  --border: #2d3742;
  --text: #e8eef5;
  --text-dim: #8a9ba8;
  --accent: #00c853;
  --accent-soft: rgba(0, 200, 83, 0.15);
  --gold: #ffc107;
  --danger: #ef5350;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.15);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

body {
  display: flex;
  flex-direction: column;
}

/* ========== Top bar ========== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 24px;
  background: linear-gradient(135deg, #1a3a5c 0%, #0d2540 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.subtitle {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, auto) 200px auto auto;
  align-items: center;
  gap: 20px;
}

.sync-status {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 80px;
  text-align: right;
}

.sync-status.error { color: var(--danger); }
.sync-status.saving { color: var(--gold); }

.btn-logout {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}

.btn-logout:hover {
  color: var(--text);
  border-color: var(--danger);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.stat-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.progress-bar {
  height: 10px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent) 0%, #00e676 100%);
  transition: width 280ms ease;
}

/* ========== Layout ========== */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  flex: 1;
  min-height: 0;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  position: sticky;
  top: 73px;
  height: calc(100vh - 73px);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.controls input[type="search"] {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
}

.controls input[type="search"]:focus {
  border-color: var(--accent);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}

.checkbox input { accent-color: var(--accent); }

.legend {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.legend kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 4px;
  font-family: ui-monospace, monospace;
  font-size: 10px;
}

.export-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 4px;
}

.export-title {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.8px;
  font-weight: 600;
  padding: 0 2px;
}

.btn-export {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

.btn-export:hover {
  background: var(--border);
  border-color: rgba(0, 200, 83, 0.4);
}

.btn-export:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-export::before {
  content: "↓ ";
  color: var(--accent);
  font-weight: 700;
}

/* Section nav */
.nav-group {
  margin-bottom: 14px;
}

.nav-group-title {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.8px;
  padding: 6px 8px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  border: 1px solid transparent;
}

.nav-item:hover {
  background: var(--surface-2);
}

.nav-item.active {
  background: var(--accent-soft);
  border-color: rgba(0, 200, 83, 0.35);
}

.nav-item.complete .nav-name::after {
  content: " ✓";
  color: var(--gold);
}

.nav-flag { font-size: 16px; line-height: 1; }
.nav-name { flex: 1; }

.nav-count {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 999px;
}

.nav-item.complete .nav-count {
  color: var(--gold);
  background: rgba(255, 193, 7, 0.12);
}

/* ========== Main / album ========== */
main#album {
  padding: 20px 28px 80px;
  overflow-y: auto;
}

.section {
  margin-bottom: 36px;
  scroll-margin-top: 90px;
}

.section-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.section-flag { font-size: 24px; }
.section-title { margin: 0; font-size: 18px; font-weight: 700; }
.section-conf { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; }
.section-progress { margin-left: auto; font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.section-progress.complete { color: var(--gold); font-weight: 600; }

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px;
}

/* ========== Sticker card ========== */
.sticker {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 10px 8px;
  text-align: center;
  cursor: pointer;
  transition: transform 80ms ease, background 180ms, border-color 180ms;
  user-select: none;
  box-shadow: var(--shadow);
}

.sticker:hover { transform: translateY(-1px); border-color: #3d4956; }
.sticker:active { transform: translateY(0); }

.sticker.owned {
  background: linear-gradient(160deg, #1d3a2a 0%, #15291e 100%);
  border-color: rgba(0, 200, 83, 0.4);
}

.sticker.owned::before {
  content: "✓";
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.sticker-id {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.4px;
}

.sticker.owned .sticker-id { color: rgba(0, 200, 83, 0.8); }

.sticker-label {
  font-size: 13px;
  font-weight: 500;
  margin: 6px 0 8px;
  color: var(--text);
  line-height: 1.2;
}

.sticker-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  opacity: 0.6;
}

.sticker:hover .sticker-controls,
.sticker.owned .sticker-controls,
.sticker.has-dupes .sticker-controls { opacity: 1; }

.btn-step {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

.btn-step:hover { background: var(--border); }
.btn-step:disabled { opacity: 0.3; cursor: not-allowed; }

.dupe-count {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 24px;
  color: var(--text-dim);
}

.sticker.has-dupes .dupe-count { color: var(--gold); }

.sticker.has-dupes::after {
  content: attr(data-dupes);
  position: absolute;
  top: 6px;
  right: 8px;
  background: var(--gold);
  color: #1a1300;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}

.sticker.hidden { display: none; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

/* ========== Login overlay ========== */
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 25, 0.96);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

body.locked .login-overlay { display: flex; }
body.locked .topbar,
body.locked .layout { display: none; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.login-card p {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
}

.login-card input[type="password"] {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
}

.login-card input[type="password"]:focus {
  border-color: var(--accent);
}

.login-card button {
  background: var(--accent);
  color: #062814;
  border: none;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.login-card button:hover { background: #00e676; }
.login-card button:disabled { opacity: 0.5; cursor: wait; }

.login-error {
  font-size: 12px;
  color: var(--danger);
  min-height: 16px;
}

/* ========== Responsive ========== */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: relative; top: 0; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .stats { grid-template-columns: repeat(3, auto); }
  .progress-bar { grid-column: 1 / -1; width: 100%; }
  .sync-status, .btn-logout { grid-column: span 1; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 12px; }
}
