/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f4f8;
  --bg-card: #ffffff;
  --text: #1a2a3a;
  --text-muted: #6b7c8d;
  --text-light: #94a3b5;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: #dbeafe;
  --filled: #1e293b;
  --filled-hover: #334155;
  --crossed-color: #94a3b5;
  --error-color: #ef4444;
  --error-bg: #fef2f2;
  --success-color: #10b981;
  --success-bg: #ecfdf5;
  --border: #e2e8f0;
  --border-strong: #94a3b5;
  --border-separator: #64748b;
  --cell-bg: #ffffff;
  --cell-hover: #f1f5f9;
  --clue-bg: #f8fafc;
  --clue-satisfied: #94a3b5;
  --corner-bg: #f0f4f8;
  --hint-flash: #fbbf24;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius: 8px;
  --radius-lg: 12px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

html { font-size: 16px; -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(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === LAYOUT === */
.site-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.site-logo:hover { text-decoration: none; color: var(--accent); }

.logo-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 4px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 2px;
  padding: 3px;
}
.logo-icon span {
  background: white;
  border-radius: 1px;
}
.logo-icon span:nth-child(2),
.logo-icon span:nth-child(4),
.logo-icon span:nth-child(5),
.logo-icon span:nth-child(8) { background: transparent; }

.site-nav {
  display: flex;
  gap: 1.25rem;
  align-items: center;
}

.site-nav a {
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  transition: color 0.2s;
}
.site-nav a:hover { color: var(--accent); text-decoration: none; }

.nav-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text);
  padding: 0.25rem;
}

/* === AD SLOTS === */
.ad-slot {
  max-width: 728px;
  margin: 0.5rem auto;
  text-align: center;
  min-height: 50px;
  background: var(--bg);
  border-radius: var(--radius);
}

.ad-slot-sidebar {
  width: 300px;
  min-height: 250px;
  background: var(--bg);
  border-radius: var(--radius);
}

/* === MAIN CONTENT === */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

.game-layout {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  justify-content: center;
}

.game-area {
  flex: 1;
  max-width: 800px;
  min-width: 0;
}

.sidebar {
  width: 300px;
  flex-shrink: 0;
  display: none; /* show on desktop */
}

/* === GAME CONTROLS === */
.game-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
}

.btn:hover { background: var(--cell-hover); border-color: var(--border-strong); }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn.mode-cross { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.game-stats {
  display: flex;
  gap: 1rem;
  align-items: center;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.stat-label { font-weight: 500; }

.controls-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
}

/* === PUZZLE SIZE SELECTOR === */
.size-selector {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

.size-btn {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font);
}
.size-btn:hover { border-color: var(--accent); color: var(--accent); }
.size-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.difficulty-selector {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

.diff-btn {
  padding: 0.25rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font);
}
.diff-btn:hover { border-color: var(--accent); color: var(--accent); }
.diff-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

/* === NONOGRAM BOARD === */
.nonogram-board {
  display: flex;
  justify-content: center;
  padding: 0.5rem;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
}

.nonogram-board.completed .game-cell.filled {
  background: var(--success-color);
  border-color: var(--success-color);
}

.nonogram-table {
  border-collapse: collapse;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.corner-cell {
  background: var(--corner-bg);
  min-width: 20px;
}

.clue-cell {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  padding: 2px 4px;
  background: var(--clue-bg);
  min-width: 24px;
  line-height: 1.3;
  transition: color 0.2s, opacity 0.2s;
}

.clue-cell.clue-satisfied {
  color: var(--clue-satisfied);
  opacity: 0.5;
}

.row-clue { text-align: right; padding-right: 6px; }
.col-clue { vertical-align: bottom; padding-bottom: 4px; }

.game-cell {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  background: var(--cell-bg);
  cursor: pointer;
  transition: background 0.1s ease;
  position: relative;
}

.game-cell:hover { background: var(--cell-hover); }

.game-cell.filled {
  background: var(--filled);
  border-color: var(--filled);
}

.game-cell.crossed::after {
  content: '✕';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--crossed-color);
  font-size: 0.75rem;
  font-weight: 600;
  pointer-events: none;
}

.game-cell.error {
  background: var(--error-color) !important;
  border-color: var(--error-color) !important;
  animation: shake 0.3s ease;
}

.game-cell.hint-reveal {
  animation: hintFlash 0.6s ease;
}

/* Separator lines every 5 cells */
.game-cell.col-separator { border-left: 2px solid var(--border-separator); }
.clue-cell.col-separator { border-left: 2px solid var(--border-separator); }
tr.row-separator .game-cell,
tr.row-separator .clue-cell,
tr.row-separator .row-clue { border-top: 2px solid var(--border-separator); }

/* === FEEDBACK === */
.game-feedback {
  text-align: center;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.game-feedback.visible {
  opacity: 1;
  transform: translateY(0);
}

.game-feedback.success { background: var(--success-bg); color: var(--success-color); }
.game-feedback.error { background: var(--error-bg); color: var(--error-color); }

/* === FOOTER === */
.site-footer {
  margin-top: 2rem;
  padding: 1.5rem 1rem;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  justify-content: center;
  margin-bottom: 1rem;
}

.footer-links a {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.footer-variants {
  text-align: center;
  margin-bottom: 1rem;
}

.footer-variants h3 {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.variant-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  justify-content: center;
}

.variant-links a {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  background: var(--bg);
  border-radius: 4px;
  color: var(--text-muted);
}
.variant-links a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }

.footer-copy {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-light);
}

/* === SEO CONTENT === */
.seo-content {
  max-width: 800px;
  margin: 2rem auto;
  padding: 0 1rem;
  color: var(--text-muted);
  font-size: 0.9375rem;
  line-height: 1.8;
}

.seo-content h2 {
  color: var(--text);
  font-size: 1.25rem;
  margin: 1.5rem 0 0.75rem;
}

.seo-content p { margin-bottom: 0.75rem; }

/* === CONTENT PAGES (rules, strategy, about) === */
.content-page {
  max-width: 800px;
  margin: 2rem auto;
  padding: 2rem;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.content-page h1 {
  font-size: 2rem;
  margin-bottom: 1rem;
  color: var(--text);
}

.content-page h2 {
  font-size: 1.375rem;
  margin: 2rem 0 0.75rem;
  color: var(--text);
}

.content-page h3 {
  font-size: 1.125rem;
  margin: 1.5rem 0 0.5rem;
  color: var(--text);
}

.content-page p {
  margin-bottom: 1rem;
  color: var(--text-muted);
  line-height: 1.8;
}

.content-page ul, .content-page ol {
  margin: 0.75rem 0 1rem 1.5rem;
  color: var(--text-muted);
}

.content-page li { margin-bottom: 0.5rem; line-height: 1.7; }

.breadcrumb {
  font-size: 0.8125rem;
  color: var(--text-light);
  margin-bottom: 1.5rem;
}

.breadcrumb a { color: var(--text-muted); }
.breadcrumb span { margin: 0 0.375rem; }

/* === ANIMATIONS === */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

@keyframes hintFlash {
  0% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.7); }
  50% { box-shadow: 0 0 0 6px rgba(251, 191, 36, 0); }
  100% { box-shadow: none; }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.game-area { animation: fadeInUp 0.3s ease; }

/* === RESPONSIVE === */
@media (min-width: 1024px) {
  .sidebar { display: block; }
  .game-cell { width: 36px; height: 36px; }
  .clue-cell { font-size: 0.875rem; min-width: 28px; }
}

@media (max-width: 768px) {
  .site-nav { display: none; }
  .site-nav.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    gap: 0.75rem;
  }
  .nav-toggle { display: block; }
  
  .game-controls { gap: 0.375rem; padding: 0.5rem; }
  .btn { padding: 0.4rem 0.75rem; font-size: 0.8125rem; }
  .game-stats { gap: 0.5rem; font-size: 0.75rem; }
  .controls-divider { display: none; }
  
  .game-cell { width: 28px; height: 28px; }
  .clue-cell { font-size: 0.6875rem; min-width: 18px; padding: 1px 2px; }
  .row-clue { padding-right: 4px; }
  
  .content-page { padding: 1.25rem; margin: 1rem; }
  .content-page h1 { font-size: 1.5rem; }
}

/* Small phones — 5x5 still comfortable, 10x10 tight */
@media (max-width: 400px) {
  .game-cell { width: 24px; height: 24px; }
  .clue-cell { font-size: 0.625rem; min-width: 16px; }
  .size-btn, .diff-btn { padding: 0.25rem 0.5rem; font-size: 0.6875rem; }
}

/* Nonogram table sizing based on grid size */
.nonogram-table[data-size="15"] .game-cell { width: 26px; height: 26px; }
.nonogram-table[data-size="20"] .game-cell { width: 22px; height: 22px; }

@media (max-width: 768px) {
  .nonogram-table[data-size="15"] .game-cell { width: 22px; height: 22px; }
  .nonogram-table[data-size="15"] .clue-cell { font-size: 0.5625rem; }
  .nonogram-table[data-size="20"] .game-cell { width: 18px; height: 18px; }
  .nonogram-table[data-size="20"] .clue-cell { font-size: 0.5rem; }
}

/* === PRINT HIDDEN === */
@media print {
  .site-header, .site-footer, .game-controls, .ad-slot, .seo-content { display: none; }
}
