:root {
  --background: linear-gradient(145deg, #efe1c6 0%, #d8e4df 50%, #f3f0ea 100%);
  --panel: rgba(255, 252, 247, 0.88);
  --panel-border: rgba(58, 47, 37, 0.14);
  --text: #241d17;
  --muted: #66594d;
  --accent: #bb5a33;
  --accent-strong: #8d3512;
  --board-background: #fffdfa;
  --board-line: #b69b86;
  --board-line-strong: #5b4738;
  --given: #1f1812;
  --empty: #b5aa9f;
  --solution: #1d5d56;
  --entry: #194f86;
  --invalid: #a62d2d;
  --focus: rgba(25, 79, 134, 0.18);
  --shadow: 0 22px 55px rgba(67, 49, 30, 0.12);
}

* {
  box-sizing: border-box;
}

body.logic-mode-page {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
  font-family: "Trebuchet MS", "Gill Sans", sans-serif;
}

.page-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px 56px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.home-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.72);
  border: 1px solid rgba(58, 47, 37, 0.12);
}

.home-link:hover {
  background: rgba(255, 252, 247, 0.92);
}

.topbar-badge {
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(141, 53, 18, 0.08);
  border: 1px solid rgba(141, 53, 18, 0.1);
  color: var(--accent-strong);
  font-size: 0.92rem;
}

.hero {
  margin-bottom: 28px;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 0.85rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.hero h1 {
  margin: 0;
  font-family: "Palatino Linotype", "Book Antiqua", serif;
  font-size: clamp(2.5rem, 6vw, 4.6rem);
  line-height: 0.95;
}

.hero-copy {
  max-width: 640px;
  margin: 14px 0 0;
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: 24px;
  align-items: start;
}

.control-panel,
.board-card {
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.control-panel {
  padding: 24px;
  position: sticky;
  top: 20px;
}

.panel-heading h2,
.board-card-header h2 {
  margin: 0;
  font-family: "Palatino Linotype", "Book Antiqua", serif;
  font-size: 1.6rem;
}

.panel-heading p,
.board-card-header p,
.stats {
  color: var(--muted);
  line-height: 1.55;
}

.field {
  display: block;
  margin-top: 20px;
}

.field span {
  display: block;
  margin-bottom: 8px;
  font-size: 0.95rem;
  color: var(--muted);
}

select,
button {
  width: 100%;
  border: 0;
  border-radius: 14px;
  font: inherit;
}

select {
  padding: 14px 16px;
  background: rgba(244, 238, 229, 0.96);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(78, 60, 43, 0.14);
}

.button-row {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

button {
  padding: 14px 18px;
  cursor: pointer;
  color: #fff9f2;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  transition: transform 160ms ease, box-shadow 160ms ease;
  box-shadow: 0 12px 24px rgba(141, 53, 18, 0.18);
}

button:hover {
  transform: translateY(-1px);
}

button.secondary {
  background: linear-gradient(135deg, #36585d 0%, #17373b 100%);
  box-shadow: 0 12px 24px rgba(23, 55, 59, 0.18);
}

button.print-button {
  background: linear-gradient(135deg, #586045 0%, #2d3322 100%);
  box-shadow: 0 12px 24px rgba(45, 51, 34, 0.18);
}

button:disabled {
  cursor: progress;
  opacity: 0.72;
  transform: none;
}

.stats {
  margin-top: 18px;
  min-height: 88px;
}

.board-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
}

.board-card {
  padding: 22px;
}

.board-card-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 18px;
}

.board-card-header p {
  margin: 0;
  text-align: right;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  border: 2px solid var(--board-line-strong);
  background: var(--board-background);
  aspect-ratio: 1;
  overflow: hidden;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  border-right: 1px solid var(--board-line);
  border-bottom: 1px solid var(--board-line);
  font-family: "Courier New", monospace;
  font-size: clamp(1rem, 2.4vw, 1.5rem);
  background: rgba(255, 253, 250, 0.9);
}

.cell.given {
  color: var(--given);
  font-weight: 700;
}

.cell.editable {
  background: rgba(252, 248, 241, 0.96);
}

.cell.empty {
  color: var(--empty);
}

.cell.filled {
  color: var(--entry);
}

.cell.invalid {
  background: rgba(166, 45, 45, 0.08);
  color: var(--invalid);
}

.cell.solution {
  color: var(--solution);
  font-weight: 700;
}

.cell-input {
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: center;
  font: inherit;
  font-weight: inherit;
  caret-color: var(--entry);
}

.cell-input::placeholder {
  color: var(--empty);
}

.cell-input:focus {
  outline: 0;
  background: var(--focus);
}

.cell.given .cell-input {
  color: var(--given);
  font-weight: 700;
  cursor: default;
}

.cell.editable .cell-input {
  color: var(--entry);
}

.cell.invalid .cell-input {
  color: var(--invalid);
}

.cell.edge-right {
  border-right: 2px solid var(--board-line-strong);
}

.cell.edge-bottom {
  border-bottom: 2px solid var(--board-line-strong);
}

.board .cell:nth-child(9n) {
  border-right: 0;
}

.board .cell:nth-last-child(-n + 9) {
  border-bottom: 0;
}

.is-hidden {
  display: none;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .control-panel {
    position: static;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .board-card,
  .control-panel {
    animation: rise-in 420ms ease both;
  }

  @keyframes rise-in {
    from {
      opacity: 0;
      transform: translateY(16px);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 8mm;
  }

  :root {
    --board-line: #777;
    --board-line-strong: #111;
    --given: #000;
    --empty: #fff;
    --solution: #000;
    --entry: #000;
    --invalid: #000;
    --focus: transparent;
  }

  body.logic-mode-page {
    min-height: auto;
    background: #fff;
    color: #000;
    font-family: "Times New Roman", serif;
    overflow: visible;
  }

  .page-shell {
    max-width: none;
    padding: 0;
    overflow: visible;
  }

  .topbar,
  .eyebrow,
  .hero-copy,
  .control-panel,
  .stats {
    display: none !important;
  }

  .hero {
    margin-bottom: 5mm;
  }

  .hero h1 {
    font-size: 20pt;
    line-height: 1.1;
  }

  .layout,
  .board-panel {
    display: block;
  }

  .board-card {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    padding: 0;
    break-inside: avoid;
  }

  .board-card + .board-card {
    margin-top: 0;
  }

  .board-card-header {
    margin-bottom: 4mm;
  }

  .board-card-header h2 {
    font-size: 15pt;
  }

  .board-card-header p {
    color: #000;
    font-size: 10pt;
  }

  .board {
    width: min(165mm, 100%);
    margin: 0 auto;
    border-width: 2px;
    background: #fff;
  }

  .cell {
    background: #fff;
    font-size: 13pt;
  }

  .cell.empty {
    color: transparent;
  }

  .cell-input::placeholder {
    color: transparent;
  }

  .solution-card {
    display: none !important;
  }
}
