:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-light: #818cf8;
  --accent: #f59e0b;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --success: #10b981;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--primary-dark); }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ============ Header ============ */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.nav-logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 4px;
}

.nav-logo-icon span {
  background: #fff;
  border-radius: 2px;
}

.nav-logo-icon span:nth-child(1),
.nav-logo-icon span:nth-child(5),
.nav-logo-icon span:nth-child(9) { background: var(--accent); }

.nav-menu {
  display: flex;
  gap: 8px;
  list-style: none;
}

.nav-menu a {
  display: block;
  padding: 8px 16px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-weight: 500;
  transition: all 0.2s;
}

.nav-menu a:hover {
  color: var(--primary);
  background: #eef2ff;
}

.nav-menu a.active {
  color: var(--primary);
  background: #eef2ff;
}

.nav-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text);
}

/* ============ Hero ============ */
.hero {
  padding: 80px 0 60px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle at 20% 80%, rgba(255,255,255,0.1) 0%, transparent 50%),
                    radial-gradient(circle at 80% 20%, rgba(255,255,255,0.1) 0%, transparent 50%);
}

.hero-content {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 60px;
  align-items: center;
}

.hero-text h1 {
  font-size: 48px;
  font-weight: 800;
  margin-bottom: 20px;
  line-height: 1.2;
}

.hero-text p {
  font-size: 18px;
  opacity: 0.9;
  margin-bottom: 30px;
}

.hero-buttons {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: #fff;
  color: var(--primary);
}

.btn-primary:hover {
  background: #f1f5f9;
  transform: translateY(-2px);
  color: var(--primary);
}

.btn-outline {
  background: transparent;
  color: #fff;
  border: 2px solid rgba(255,255,255,0.5);
}

.btn-outline:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border-color: #fff;
}

.btn-lg {
  padding: 16px 36px;
  font-size: 16px;
}

/* Sudoku preview in hero */
.hero-puzzle {
  display: flex;
  justify-content: center;
}

.demo-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  background: #1e293b;
  border-radius: 10px;
  overflow: hidden;
  width: 360px;
  height: 360px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
  border: 3px solid #1e293b;
}

.demo-cell {
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid #cbd5e1;
  border-right: 1px solid #cbd5e1;
}

.demo-cell:nth-child(9n) { border-right: none; }
.demo-cell:nth-last-child(-n+9) { border-bottom: none; }
.demo-cell.thick-right { border-right: 3px solid #1e293b !important; }
.demo-cell.thick-bottom { border-bottom: 3px solid #1e293b !important; }

.demo-cell.given { color: var(--primary); }
.demo-cell.user { color: var(--accent); }

/* ============ Sections ============ */
.section {
  padding: 80px 0;
}

.section-title {
  text-align: center;
  margin-bottom: 50px;
}

.section-title h2 {
  font-size: 36px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 12px;
}

.section-title p {
  font-size: 17px;
  color: var(--text-secondary);
}

/* ============ Stats ============ */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform 0.2s;
}

.stat-card:hover {
  transform: translateY(-4px);
}

.stat-number {
  font-size: 42px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-label {
  color: var(--text-secondary);
  margin-top: 8px;
  font-size: 14px;
}

/* ============ Features ============ */
.features {
  background: #fff;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 32px;
}

.feature-card {
  padding: 32px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: all 0.2s;
}

.feature-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
}

.feature-icon {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-bottom: 20px;
}

.feature-card:nth-child(1) .feature-icon { background: #eef2ff; color: var(--primary); }
.feature-card:nth-child(2) .feature-icon { background: #fef3c7; color: var(--accent); }
.feature-card:nth-child(3) .feature-icon { background: #d1fae5; color: var(--success); }
.feature-card:nth-child(4) .feature-icon { background: #fce7f3; color: #ec4899; }
.feature-card:nth-child(5) .feature-icon { background: #dbeafe; color: #3b82f6; }
.feature-card:nth-child(6) .feature-icon { background: #f3e8ff; color: #a855f7; }

.feature-card h3 {
  font-size: 18px;
  margin-bottom: 10px;
}

.feature-card p {
  color: var(--text-secondary);
  font-size: 15px;
}

/* ============ Knowledge ============ */
.knowledge {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 48px;
  align-items: start;
}

.knowledge-text h3 {
  font-size: 24px;
  margin-bottom: 16px;
  color: var(--primary-dark);
}

.knowledge-text p {
  margin-bottom: 16px;
  color: var(--text-secondary);
}

.knowledge-list {
  list-style: none;
}

.knowledge-list li {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.knowledge-list li::before {
  content: '✓';
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  background: var(--success);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  margin-top: 2px;
}

.knowledge-board-demo {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.mini-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  background: #1e293b;
  border: 3px solid #1e293b;
  border-radius: 6px;
  overflow: hidden;
}

.mini-cell {
  background: #fff;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  border-bottom: 1px solid #cbd5e1;
  border-right: 1px solid #cbd5e1;
}

.mini-cell:nth-child(9n) { border-right: none; }
.mini-cell:nth-last-child(-n+9) { border-bottom: none; }
.mini-cell.thick-right { border-right: 3px solid #1e293b !important; }
.mini-cell.thick-bottom { border-bottom: 3px solid #1e293b !important; }

.mini-cell.given { color: var(--text); background: #f1f5f9; }
.mini-cell.highlight { background: #eef2ff; }

/* ============ Difficulty Badges ============ */
.diff-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.diff-easy { background: #d1fae5; color: #065f46; }
.diff-medium { background: #fef3c7; color: #92400e; }
.diff-hard { background: #fee2e2; color: #991b1b; }
.diff-expert { background: #fce7f3; color: #9d174d; }

/* ============ Puzzle Card ============ */
.puzzle-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.puzzle-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  transition: all 0.2s;
  border: 1px solid transparent;
}

.puzzle-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-light);
}

.puzzle-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.puzzle-date {
  font-size: 15px;
  color: var(--text-secondary);
}

.puzzle-diff {
  margin-bottom: 16px;
}

.puzzle-meta {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

.puzzle-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ============ Filter Bar ============ */
.filter-bar {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 32px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-secondary);
}

.filter-select {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s;
}

.filter-select:focus {
  outline: none;
  border-color: var(--primary);
}

.filter-stats {
  margin-left: auto;
  font-size: 14px;
  color: var(--text-secondary);
}

.filter-stats strong {
  color: var(--primary);
  font-size: 18px;
  margin: 0 4px;
}

/* ============ Ranking Table ============ */
.table-container {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table thead {
  background: #f1f5f9;
}

.table th {
  padding: 16px 20px;
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table td {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 14px;
}

.table tbody tr:hover {
  background: #f8fafc;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 14px;
  background: #f1f5f9;
  color: var(--text-secondary);
}

.rank-badge.top1 { background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #fff; }
.rank-badge.top2 { background: linear-gradient(135deg, #94a3b8, #64748b); color: #fff; }
.rank-badge.top3 { background: linear-gradient(135deg, #d97706, #b45309); color: #fff; }

.time-cell {
  font-family: 'SF Mono', Consolas, monospace;
  font-weight: 600;
  color: var(--primary);
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
}

/* ============ Page Header ============ */
.page-header {
  padding: 60px 0 40px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
}

.page-header h1 {
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 8px;
}

.page-header p {
  opacity: 0.9;
}

/* ============ Tabs ============ */
.tabs {
  display: flex;
  gap: 4px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 32px;
}

.tab {
  flex: 1;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  text-align: center;
  color: var(--text-secondary);
  transition: all 0.2s;
  border: none;
  background: transparent;
}

.tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow);
}

/* ============ Loading ============ */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

/* ============ Footer ============ */
.footer {
  background: #1e293b;
  color: #94a3b8;
  padding: 48px 0 24px;
  margin-top: 80px;
}

.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 40px;
  margin-bottom: 40px;
}

.footer-brand h3 {
  color: #fff;
  font-size: 20px;
  margin-bottom: 12px;
}

.footer-brand p {
  font-size: 14px;
  line-height: 1.8;
}

.footer-col h4 {
  color: #fff;
  font-size: 14px;
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.footer-col ul {
  list-style: none;
}

.footer-col li {
  margin-bottom: 10px;
}

.footer-col a {
  color: #94a3b8;
  font-size: 14px;
  transition: color 0.2s;
}

.footer-col a:hover {
  color: #fff;
}

.footer-bottom {
  border-top: 1px solid #334155;
  padding-top: 24px;
  text-align: center;
  font-size: 13px;
}

.footer-bottom a {
  color: #94a3b8;
}

.footer-bottom a:hover {
  color: #fff;
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
  .nav-menu { display: none; position: absolute; top: 64px; left: 0; right: 0; background: #fff; flex-direction: column; padding: 16px; border-bottom: 1px solid var(--border); box-shadow: var(--shadow-lg); }
  .nav-menu.open { display: flex; }
  .nav-toggle { display: block; }

  .hero-content { grid-template-columns: 1fr; text-align: center; }
  .hero-text h1 { font-size: 32px; }
  .hero-buttons { justify-content: center; }
  .demo-board { width: 280px; height: 280px; }

  .stats { grid-template-columns: repeat(2, 1fr); }
  .feature-grid { grid-template-columns: 1fr; }
  .knowledge { grid-template-columns: 1fr; }

  .footer-grid { grid-template-columns: 1fr 1fr; }

  .table-container { overflow-x: auto; }
}

@media (max-width: 480px) {
  .hero-text h1 { font-size: 28px; }
  .section { padding: 60px 0; }
  .section-title h2 { font-size: 28px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat-number { font-size: 32px; }
  .footer-grid { grid-template-columns: 1fr; gap: 24px; }
}
/* ============ Modal ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: #fff;
  border-radius: 16px;
  max-width: 480px;
  width: 92%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  transform: translateY(20px) scale(0.98);
  transition: transform 0.25s ease;
  box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}

.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #f1f5f9;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  z-index: 10;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: #e2e8f0;
  transform: rotate(90deg);
}

.modal-body {
  padding: 28px 24px;
  text-align: center;
}

.modal-body .sudoku-board {
  margin: 12px auto;
  display: grid;
}

.modal-body .sudoku-cell.given {
  color: var(--primary);
}

.modal-body .hint-box {
  background: var(--bg);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 16px;
  text-align: left;
  font-size: 13px;
  line-height: 1.8;
  color: var(--text-secondary);
}

/* ============ Sudoku Board (通用) ============ */
.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, 40px);
  grid-template-rows: repeat(9, 40px);
  background: #1e293b;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 3px solid #1e293b;
  width: max-content;
  height: max-content;
}

.sudoku-cell {
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  border-right: 1px solid #cbd5e1;
  border-bottom: 1px solid #cbd5e1;
  position: relative;
}

.sudoku-cell:nth-child(9n) {
  border-right: none;
}

.sudoku-cell:nth-last-child(-n+9) {
  border-bottom: none;
}

.sudoku-cell.thick-right {
  border-right: 3px solid #1e293b !important;
}

.sudoku-cell.thick-bottom {
  border-bottom: 3px solid #1e293b !important;
}

.sudoku-cell.given {
  color: var(--primary);
  background: #f8fafc;
}

@media (max-width: 768px) {
  .sudoku-board {
    grid-template-columns: repeat(9, 30px);
    grid-template-rows: repeat(9, 30px);
    border-width: 2px;
  }
  .sudoku-cell { font-size: 14px; }
  .sudoku-cell.thick-right { border-right-width: 2px !important; }
  .sudoku-cell.thick-bottom { border-bottom-width: 2px !important; }
}

.puzzle-card {
  cursor: pointer;
}