:root {
  --paper: #f3e9d2;
  --paper-dark: #e8dab87c;
  --card: #fffaf0;
  --ink: #2b2320;
  --ink-soft: #5b4f45;
  --accent: #a3313f;
  --accent-dark: #7f2531;
  --pine: #2f6b4f;
  --line-thin: #b9ab93;
  --grid-line: rgba(0, 0, 0, 0.65);
  --shadow: rgba(43, 35, 32, 0.25);
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(255,255,255,0.35), transparent 40%),
    radial-gradient(circle at 85% 90%, rgba(0,0,0,0.05), transparent 45%),
    var(--paper);
  min-height: 100vh;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--paper);
  border-bottom: 3px solid var(--ink);
}

.topbar-inner {
  max-width: 1300px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
}

.logo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1rem);
  grid-template-rows: repeat(3, 1rem);
  gap: 2px;
  padding: 3px;
  background: var(--ink);
  border-radius: 6px;
  transform: rotate(-3deg);
}

.logo-grid span {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: 0.6rem;
  color: var(--accent-dark);
  border-radius: 2px;
}

.logo-grid span:nth-child(5) { color: var(--pine); }

.brand-name {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--ink);
}

.main-nav {
  display: flex;
  gap: 1.5rem;
  margin-right: auto;
  flex-wrap: wrap;
}

.main-nav a {
  font-weight: 700;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 0.3rem 0;
  border-bottom: 3px solid transparent;
}

.main-nav a:hover { color: var(--ink); }

.main-nav a.current {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.lang-switch {
  display: flex;
  border: 2px solid var(--ink);
  border-radius: 8px;
  overflow: hidden;
}

.lang-switch button {
  border: none;
  background: var(--card);
  color: var(--ink-soft);
  font-weight: 700;
  font-family: 'Baloo 2', sans-serif;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  font-size: 0.8rem;
}

.lang-switch button + button { border-left: 2px solid var(--ink); }

.lang-switch button.active {
  background: var(--accent);
  color: #fff8ec;
}

/* ---------- Page hero ---------- */
.page-hero {
  text-align: center;
  padding: 2rem 1rem 1.25rem;
}

.page-hero h1 {
  font-family: 'Baloo 2', sans-serif;
  font-size: 2.1rem;
  font-weight: 800;
  margin: 0;
  color: var(--ink);
  letter-spacing: -0.5px;
}

.page-hero p {
  margin: 0.3rem 0 0;
  color: var(--ink-soft);
  font-weight: 600;
}

.page-hero-note {
  max-width: 640px;
  margin: 0.75rem auto 0 !important;
  font-weight: 400 !important;
  font-size: 0.95rem;
}

/* ---------- Ad slots ---------- */
.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed #c9bda4;
  background: rgba(255, 255, 255, 0.4);
  color: #9a8d78;
  font-weight: 700;
  font-family: 'Nunito', sans-serif;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-size: 0.75rem;
  border-radius: 8px;
  margin: 0 auto;
}

.ad-label { opacity: 0.8; }

.ad-leaderboard {
  max-width: 728px;
  height: 90px;
  margin: 0 auto 1.5rem;
}

.ad-rectangle {
  width: 100%;
  height: 250px;
  margin-top: 1.5rem;
}

.ad-footer {
  max-width: 970px;
  height: 90px;
  margin: 2rem auto;
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1.75rem;
  max-width: 1300px;
  margin: 0 auto;
  padding: 0 1.5rem;
  align-items: start;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------- Control panel ---------- */
.control-panel {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 1.5rem;
  box-shadow: 6px 6px 0 var(--shadow);
  position: sticky;
  top: 1.5rem;
}

.control-panel h2 {
  font-family: 'Baloo 2', sans-serif;
  margin-top: 0;
  font-size: 1.3rem;
  border-bottom: 3px solid var(--paper-dark);
  padding-bottom: 0.5rem;
}

.field {
  margin-bottom: 1.1rem;
}

.field label {
  display: block;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  color: var(--ink-soft);
}

.field select,
.field input[type="number"] {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
}

.field-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.field-inline label { margin-bottom: 0; }

.field-inline input[type="color"] {
  width: 3rem;
  height: 2.2rem;
  border: 2px solid var(--ink);
  border-radius: 6px;
  padding: 0;
  background: none;
  cursor: pointer;
}

.field-checkbox {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.field-checkbox input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
}

.field-checkbox label {
  margin-bottom: 0;
  font-weight: 700;
  color: var(--ink);
}

.btn {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  border: 2px solid var(--ink);
  border-radius: 9px;
  padding: 0.75rem 1rem;
  cursor: pointer;
  width: 100%;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  box-shadow: 3px 3px 0 var(--shadow);
}

.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }
.btn:disabled { opacity: 0.6; cursor: default; }

.btn-primary {
  background: var(--accent);
  color: #fff8ec;
}

.btn-secondary {
  background: var(--pine);
  color: #fff8ec;
  margin-top: 0.75rem;
}

.btn-small {
  width: auto;
  font-size: 0.85rem;
  padding: 0.5rem 0.8rem;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 2px 2px 0 var(--shadow);
}

/* ---------- Results ---------- */
.results {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  min-height: 300px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  text-align: center;
  padding: 3.5rem 1.5rem;
  border: 3px dashed var(--line-thin);
  border-radius: 14px;
  color: var(--ink-soft);
}

.empty-icon {
  font-family: 'Baloo 2', sans-serif;
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--accent);
  background: var(--card);
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  border: 3px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

.puzzle-card {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 1.5rem;
  box-shadow: 6px 6px 0 var(--shadow);
}

.puzzle-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.puzzle-card-header h3 {
  font-family: 'Baloo 2', sans-serif;
  margin: 0;
  font-size: 1.3rem;
}

.badge {
  background: var(--paper-dark);
  border: 2px solid var(--ink);
  border-radius: 20px;
  padding: 0.3rem 0.8rem;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.grids-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  justify-content: center;
}

.grid-block h4 {
  font-family: 'Baloo 2', sans-serif;
  text-align: center;
  margin: 0 0 0.6rem;
  color: var(--ink-soft);
}

.grid-block { max-width: 100%; overflow-x: auto; }

/* ---------- Sudoku table ---------- */
.sudoku-table {
  border-collapse: collapse;
  margin: 0 auto;
  /* A real border (not box-shadow) so it collapses evenly with the cell borders
     on every side — box-shadow rendered inconsistently thicker on the top edge. */
  border: 1px solid var(--grid-line);
}

.sudoku-table td {
  width: 2.6rem;
  height: 2.6rem;
  text-align: center;
  vertical-align: middle;
  font-family: 'Kdam Thmor', 'Baloo 2', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  border: 1px solid var(--grid-line);
}

.sudoku-table td.box-top { border-top: 3px solid var(--grid-line); }
.sudoku-table td.box-left { border-left: 3px solid var(--grid-line); }

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-top: 1.25rem;
}

/* ---------- Content section (about text, FAQ) ---------- */
.content-section {
  max-width: 800px;
  margin: 1rem auto 2.5rem;
  padding: 0 1.5rem;
  line-height: 1.65;
  color: var(--ink);
}

.content-section h2 {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.5rem;
  border-bottom: 3px solid var(--paper-dark);
  padding-bottom: 0.5rem;
}

.content-section h3 {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.15rem;
  margin-top: 1.75rem;
  color: var(--ink);
}

.content-section p { margin: 0.6rem 0; }
.content-section a { color: var(--accent-dark); font-weight: 700; }

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--ink-soft);
  font-weight: 600;
}

/* ---------- Cookie banner ---------- */
.cookie-banner {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 900px;
  margin: 0 auto;
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  box-shadow: 6px 6px 0 var(--shadow);
}

.cookie-banner[hidden] { display: none; }

.cookie-banner p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.cookie-banner a {
  color: var(--accent-dark);
}

/* Below this width the layout is a single column, so the settings panel must
   flow above the puzzles/board instead of staying pinned (sticky) over them. */
@media (max-width: 860px) {
  .control-panel { position: static; top: auto; }
}

/* ---------- Small screens ---------- */
@media (max-width: 480px) {
  .topbar-inner { justify-content: center; padding: 0.6rem 1rem; }
  .main-nav { margin-right: 0; justify-content: center; width: 100%; order: 3; }
  .page-hero { padding: 1.5rem 1rem 1rem; }
  .page-hero h1 { font-size: 1.6rem; }
  .layout { padding: 0 0.85rem; gap: 1.25rem; }
  .control-panel, .puzzle-card, .empty-state { padding: 1rem; }
  .sudoku-table td { width: 2rem; height: 2rem; font-size: 1rem; }
  .cookie-banner { left: 0.5rem; right: 0.5rem; bottom: 0.5rem; padding: 0.85rem 1rem; }
  .cookie-banner p { font-size: 0.8rem; }
}

/* ---------- Print ---------- */
@media print {
  .site-header, .ad-slot, .control-panel, .site-footer, .card-actions, .empty-state, .cookie-banner, .content-section {
    display: none !important;
  }
  body { background: #fff; }
  .layout { display: block; padding: 0; }
  .puzzle-card {
    box-shadow: none;
    border: 2px solid #000;
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 1.5cm;
  }
}
