* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  background: #f3f5f9;
  color: #2d3a4b;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */
.site-header {
  background: #fff;
  border-bottom: 1px solid #e4e8ef;
  padding: 0.9rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.site-header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: #2d3a4b;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1em;
}
.logo-dot {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #4a8eff, #3a6fd6);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700;
}
.nav-links { display: flex; gap: 1.25rem; align-items: center; position: relative; }
.nav-toggle {
  display: none;
  background: transparent;
  border: none;
  width: 38px;
  height: 38px;
  padding: 0;
  cursor: pointer;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
}
.nav-toggle:hover { background: #f1f4fa; }
.nav-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: #1c2a3a;
  position: relative;
}
.nav-toggle span::before,
.nav-toggle span::after {
  content: '';
  position: absolute;
  left: 0;
  width: 20px;
  height: 2px;
  background: #1c2a3a;
}
.nav-toggle span::before { top: -6px; }
.nav-toggle span::after { top: 6px; }
.nav-links a {
  color: #5b6b80;
  text-decoration: none;
  font-size: 0.92em;
  font-weight: 500;
}
.nav-links a:hover { color: #4a8eff; }

/* ---------- Layout ---------- */
.wrap { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
h1 { margin: 0.5rem 0 0.25rem; font-size: 1.85em; color: #1c2a3a; font-weight: 700; }
h2 { margin: 0 0 1rem; font-size: 1.25em; color: #1c2a3a; }
.page-sub { color: #6b7a8c; font-size: 0.95em; margin: 0 0 1.5rem; }
a { color: #4a8eff; text-decoration: none; }
a:hover { text-decoration: underline; }

.back-link {
  color: #4a8eff;
  font-size: 0.9em;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 1rem;
}

/* ---------- Category Tabs ---------- */
.tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  background: #fff;
  padding: 0.75rem;
  border-radius: 14px;
  box-shadow: 0 2px 10px rgba(40,60,100,0.05);
  margin-bottom: 1.75rem;
}
.tab {
  padding: 0.7rem 1.4rem;
  border-radius: 10px;
  background: transparent;
  color: #5b6b80;
  font-weight: 600;
  font-size: 0.95em;
  border: none;
  cursor: pointer;
  flex: 1;
  min-width: 100px;
  text-align: center;
  transition: all 0.15s;
}
.tab:hover { background: #f1f4fa; color: #1c2a3a; }
.tab.active {
  background: #4a8eff;
  color: #fff;
  box-shadow: 0 4px 12px rgba(74,142,255,0.3);
}
.tab.disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Grid of cards ---------- */
.card-panel {
  background: #fff;
  border-radius: 14px;
  padding: 2rem 1.5rem;
  box-shadow: 0 2px 14px rgba(40,60,100,0.06);
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.5rem;
}
.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1rem 0.75rem;
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: all 0.15s;
  cursor: pointer;
}
.tile:hover {
  background: #f3f7ff;
  transform: translateY(-2px);
  text-decoration: none;
}
.tile-icon {
  width: 96px;
  height: 96px;
  background: #eaf0fb;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.85rem;
  font-size: 3em;
  color: #7a94b8;
  line-height: 1;
}
.tile-icon.small { width: 72px; height: 72px; font-size: 2.2em; }
.tile-title {
  color: #4a8eff;
  font-weight: 600;
  font-size: 1em;
  margin-bottom: 0.35rem;
  line-height: 1.25;
  word-break: break-word;
}
.tile-progress {
  color: #6b7a8c;
  font-size: 0.85em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
}
.tile-progress .star {
  color: #d4d9e0;
  font-size: 0.9em;
}
.tile-progress .star.lit { color: #f5b400; }

/* Private / locked tile state */
.tile-locked { cursor: not-allowed; opacity: 0.85; }
.tile-locked .tile-icon { background: #f3f4f6; color: #9ca3af; position: relative; }
.tile-locked .tile-title { color: #6b7280; }
.tile-icon { position: relative; }
.tile-lock-overlay {
  position: absolute;
  bottom: -4px;
  right: -4px;
  background: #1c2a3a;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1em;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.lock-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.1rem 0.5rem;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #fff;
  border-radius: 999px;
  font-size: 0.7em;
  font-weight: 700;
  vertical-align: middle;
  letter-spacing: 0.02em;
}
.tile-locked .lock-badge { background: linear-gradient(135deg, #6b7280, #4b5563); }

/* ---------- Puzzle row list (section page) ---------- */
.puzzle-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: #fff;
  margin-bottom: 0.5rem;
  box-shadow: 0 1px 4px rgba(40,60,100,0.04);
  text-decoration: none;
  color: inherit;
  transition: all 0.12s;
}
.puzzle-row:hover { background: #f3f7ff; transform: translateX(2px); text-decoration: none; }
.puzzle-row .idx {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: #eaf0fb;
  color: #4a8eff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 0.9em;
  flex-shrink: 0;
}
.puzzle-row.solved .idx { background: #e4f5ec; color: #2b9e68; }
.puzzle-row .title { font-weight: 600; color: #1c2a3a; }
.puzzle-row .meta { color: #6b7a8c; font-size: 0.85em; margin-top: 0.15rem; }
.puzzle-row .arrow { color: #b6c1d1; font-size: 1.2em; margin-left: auto; }
.puzzle-row .badge {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  background: #eaf0fb;
  color: #4a8eff;
  font-size: 0.72em;
  font-weight: 600;
  margin-left: 0.5rem;
  vertical-align: middle;
}
.puzzle-row.solved .badge { background: #e4f5ec; color: #2b9e68; }

/* ---------- Buttons & misc ---------- */
button {
  padding: 0.65rem 1.15rem;
  background: #4a8eff;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.92em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
}
button:hover { background: #3a7aee; }
button.ghost { background: #f1f4fa; color: #1c2a3a; }
button.ghost:hover { background: #e4e9f1; }
button.danger { background: #fff; color: #e24a4a; border: 1px solid #f3c7c7; padding: 0.4rem 0.8rem; font-size: 0.85em; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.muted { color: #6b7a8c; font-size: 0.9em; }
.err { color: #c33; font-size: 0.9em; }
.ok { color: #2b9e68; font-size: 0.9em; }

.loading-dots::after {
  content: '...';
  display: inline-block;
  animation: dots 1s steps(4, end) infinite;
  width: 1.2em;
  text-align: left;
}
@keyframes dots {
  0%, 20% { content: ''; }
  40% { content: '.'; }
  60% { content: '..'; }
  80%, 100% { content: '...'; }
}

/* ---------- Mobile / Tablet ---------- */
@media (max-width: 900px) {
  .site-header { padding: 0.7rem 0.9rem; }
  .site-header-inner { gap: 0.5rem; }
  .logo { font-size: 1em; gap: 0.4rem; }
  .logo-dot { width: 28px; height: 28px; font-size: 0.95em; }
  .nav-links { gap: 0.85rem; }
  .nav-links a { font-size: 0.88em; }
}

@media (max-width: 700px) {
  .site-header { padding: 0.6rem 0.75rem; }
  .site-header-inner { flex-wrap: nowrap; }
  .logo span:not(.logo-dot) { font-size: 0.95em; }
  .nav-links { gap: 0.65rem; flex-wrap: nowrap; }
  .nav-links a { font-size: 0.82em; white-space: nowrap; }
}

@media (max-width: 600px) {
  .wrap { padding: 1rem 0.85rem 2rem; }
  h1 { font-size: 1.4em; }
  h2 { font-size: 1.1em; }
  .page-sub { font-size: 0.88em; margin-bottom: 1rem; }

  /* Mobile: brand wordmark stays. Home/Leaderboard go behind hamburger */
  .site-header-inner { justify-content: flex-start; }
  .logo { font-size: 0.95em; margin-right: auto; }
  .logo span:not(.logo-dot) { font-size: 0.95em; }
  .nav-toggle { display: inline-flex; }
  .nav-links { gap: 0; }
  .nav-links > a { display: none; }
  .nav-links.menu-open {
    display: flex;
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0.75rem;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(40,60,100,0.18);
    padding: 0.4rem 0;
    min-width: 180px;
    flex-direction: column;
    align-items: stretch;
    z-index: 100;
  }
  .nav-links.menu-open > a {
    display: block;
    padding: 0.75rem 1rem;
    font-size: 0.95em;
    color: #1c2a3a;
  }
  .nav-links.menu-open > a:hover { background: #f3f7ff; }

  /* Tabs: horizontal scroll instead of cramming */
  .tabs {
    padding: 0.4rem;
    gap: 0.3rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    padding: 0.55rem 0.85rem;
    min-width: auto;
    font-size: 0.85em;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  /* Card panel + grid */
  .card-panel { padding: 1rem 0.85rem; border-radius: 12px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
  .tile { padding: 0.75rem 0.4rem; }
  .tile-icon { width: 64px; height: 64px; font-size: 1.9em; margin-bottom: 0.5rem; }
  .tile-title { font-size: 0.92em; }
  .tile-progress { font-size: 0.78em; flex-wrap: wrap; }

  /* Auth widget on small screens */
  .auth-widget { margin-left: 0.25rem !important; }
  .auth-widget .signin-link {
    padding: 0.35rem 0.7rem !important;
    font-size: 0.82em !important;
  }
  .auth-widget .user-btn {
    padding: 0.3rem 0.55rem 0.3rem 0.3rem !important;
    font-size: 0.82em !important;
  }
  .auth-widget .user-btn .pts-chip { display: none; }
  .auth-widget .avatar { width: 22px !important; height: 22px !important; }

  /* Buttons a touch smaller */
  button { padding: 0.55rem 0.95rem; font-size: 0.88em; }
}

@media (max-width: 380px) {
  .wrap { padding: 0.85rem 0.65rem 2rem; }
  .nav-links { gap: 0.4rem; }
  .nav-links a { font-size: 0.75em; }
  .tab { padding: 0.5rem 0.7rem; font-size: 0.8em; }
  .grid { gap: 0.6rem; }
  .tile-icon { width: 56px; height: 56px; font-size: 1.7em; }
  .auth-widget .user-btn span:not(.avatar):not(.pts-chip) {
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
