:root {
  --bg: #faf8f5;
  --bg-dark: #f0ece6;
  --surface: #ffffff;
  --text: #2d2a26;
  --text-muted: #8a857d;
  --primary: #e85d26;
  --primary-hover: #d04f1c;
  --primary-light: #fff0ea;
  --border: #e8e4de;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --max-w: 1200px;
  --header-h: 56px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh; overflow-x: hidden; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; height: auto; display: block; }
button { cursor: pointer; font-family: var(--font); -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

/* =================== HEADER =================== */
.header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; height: var(--header-h); }
.header-inner { max-width: var(--max-w); margin: 0 auto; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; height: 100%; }
.logo { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 800; color: var(--text); white-space: nowrap; }
.logo span { color: var(--primary); }
.logo svg { width: 28px; height: 28px; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 8px 14px; border-radius: var(--radius-sm); color: var(--text-muted); font-weight: 500; font-size: 14px; transition: all 0.2s; }
.nav a:hover, .nav a.active { background: var(--primary-light); color: var(--primary); }

/* =================== HERO =================== */
.hero { text-align: center; padding: 48px 16px 32px; }
.hero h1 { font-size: 42px; font-weight: 800; line-height: 1.15; margin-bottom: 14px; }
.hero h1 .highlight { color: var(--primary); }
.hero p { font-size: 18px; color: var(--text-muted); max-width: 540px; margin: 0 auto 28px; }
.hero-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* =================== BUTTONS =================== */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 12px 24px; border-radius: var(--radius-sm); font-weight: 600; font-size: 15px; border: none; transition: all 0.2s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }

/* =================== STATS =================== */
.stats { display: flex; justify-content: center; gap: 36px; padding: 16px; margin-bottom: 16px; }
.stat { text-align: center; }
.stat-num { font-size: 28px; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 13px; color: var(--text-muted); }

/* =================== LAYOUT =================== */
.container { max-width: var(--max-w); margin: 0 auto; padding: 0 16px; }
.section { padding: 32px 0; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.section-title { font-size: 22px; font-weight: 700; }
.section-link { font-size: 14px; font-weight: 500; }

/* =================== CATEGORY BAR =================== */
.diff-bar { display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 4px; }
.diff-bar::-webkit-scrollbar { display: none; }
.diff-btn { padding: 7px 16px; border-radius: 20px; border: 2px solid var(--border); background: var(--surface); font-weight: 600; font-size: 13px; color: var(--text-muted); transition: all 0.2s; white-space: nowrap; flex-shrink: 0; }
.diff-btn:hover, .diff-btn.active { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

/* =================== PUZZLE GRID =================== */
.puzzle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.puzzle-card { background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); transition: all 0.25s; cursor: pointer; }
.puzzle-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.puzzle-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; }
.puzzle-card-body { padding: 12px 14px; }
.puzzle-card-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.puzzle-card-meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 10px; align-items: center; }
.puzzle-card-meta .pieces { background: var(--primary-light); color: var(--primary); padding: 2px 7px; border-radius: 4px; font-weight: 600; font-size: 11px; }

/* =================== PUZZLE PIECES (used by engine) =================== */
.puzzle-piece { position: absolute; cursor: grab; border-radius: 2px; touch-action: none; }
.puzzle-piece:hover { box-shadow: 0 0 0 2px var(--primary); z-index: 10; }
.puzzle-piece.dragging { cursor: grabbing; z-index: 100; box-shadow: var(--shadow-lg); opacity: 0.85; transform: scale(1.05); }
.puzzle-piece.placed { cursor: default; pointer-events: none; }
.puzzle-piece.placed canvas { opacity: 0.95; }
.puzzle-piece canvas { display: block; pointer-events: none; }

/* =================== PROGRESS =================== */
.progress-bar { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; margin: 10px 0; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width 0.3s; }

/* =================== FOOTER =================== */
.footer { background: var(--surface); border-top: 1px solid var(--border); padding: 24px 16px; margin-top: 48px; }
.footer-inner { max-width: var(--max-w); margin: 0 auto; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.footer-links { display: flex; gap: 16px; }
.footer-links a { font-size: 13px; color: var(--text-muted); }
.footer-copy { font-size: 13px; color: var(--text-muted); }

/* =================== AD SLOTS =================== */
.ad-slot { background: var(--bg-dark); border-radius: var(--radius-sm); margin: 16px auto; text-align: center; min-height: 90px; max-width: 728px; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 12px; }
.ad-slot-rect { min-height: 250px; max-width: 300px; }

/* =================== LOADING =================== */
.spinner { display: inline-block; width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =================== TOAST =================== */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 12px 24px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; z-index: 1000; opacity: 0; transition: opacity 0.3s; pointer-events: none; white-space: nowrap; }
.toast.show { opacity: 1; }

/* ======================================================
   MOBILE — < 768px
   ====================================================== */
@media (max-width: 768px) {
  .header-inner { padding: 0 12px; }
  .logo { font-size: 18px; gap: 6px; }
  .logo svg { width: 24px; height: 24px; }
  .nav a { padding: 6px 10px; font-size: 13px; }

  .hero { padding: 32px 16px 24px; }
  .hero h1 { font-size: 28px; margin-bottom: 10px; }
  .hero p { font-size: 15px; margin-bottom: 20px; }
  .hero-actions { gap: 8px; }
  .btn { padding: 10px 20px; font-size: 14px; }

  .stats { gap: 20px; padding: 12px 0; }
  .stat-num { font-size: 22px; }

  .puzzle-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .puzzle-card-body { padding: 10px 12px; }
  .puzzle-card-title { font-size: 13px; }
  .puzzle-card-meta { font-size: 11px; gap: 6px; }

  .diff-bar { gap: 6px; padding-bottom: 6px; margin: 12px 0; }
  .diff-btn { padding: 6px 14px; font-size: 12px; }

  .section { padding: 24px 0; }
  .section-title { font-size: 19px; }

  .footer { padding: 20px 12px; margin-top: 32px; }
  .footer-inner { flex-direction: column; text-align: center; }

  .ad-slot { margin: 12px auto; min-height: 60px; }
  .ad-slot-rect { min-height: 200px; max-width: 100%; }
}

@media (max-width: 400px) {
  .hero h1 { font-size: 24px; }
  .hero p { font-size: 14px; }
  .btn { padding: 9px 16px; font-size: 13px; }
  .stats { gap: 14px; }
  .stat-num { font-size: 20px; }
  .stat-label { font-size: 12px; }
  .puzzle-grid { gap: 8px; }
  .puzzle-card-body { padding: 8px 10px; }
  .puzzle-card-title { font-size: 12px; }
}
