* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  padding: 20px 12px 40px;
  background: linear-gradient(180deg, #f3f0e4 0%, #e7e0c8 100%);
  font-family: Georgia, 'Times New Roman', serif;
  color: #3a3320;
  display: flex;
  flex-direction: column;
  align-items: center;
}

h1 {
  margin: 0 0 4px;
  color: #4a6b2a;
  font-size: 26px;
  text-align: center;
}

.sub {
  margin: 0 0 16px;
  color: #8a7a4a;
  font-size: 13px;
  text-align: center;
}
.sub a { color: #4a6b2a; font-weight: 700; }

.panel {
  width: 100%;
  max-width: 560px;
  background: #fffdf5;
  border: 1.5px solid #b8862c;
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

/* controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 14px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field label {
  font-size: 12px;
  font-weight: 700;
  color: #4a6b2a;
}
select {
  font-family: inherit;
  font-size: 15px;
  padding: 8px 10px;
  border: 1.5px solid #b8a86c;
  border-radius: 8px;
  background: #fff;
  color: #1a1a1a;
}
select:focus { outline: none; border-color: #5a8835; }
#diff-field[hidden] { display: none; }

button {
  font-family: inherit;
  cursor: pointer;
}
.btn {
  font-size: 15px;
  font-weight: 700;
  padding: 9px 16px;
  border: 1.5px solid #5a8835;
  border-radius: 10px;
  background: #c8d8a4;
  color: #3a5520;
}
.btn:hover { background: #d6e4b6; }
.btn.secondary {
  background: #fff;
  border-color: #b8a86c;
  color: #5a4a20;
}
.btn.secondary:hover { border-color: #5a8835; }

/* status bar */
.status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 15px;
  color: #5a4a20;
}
.status .stat { display: inline-flex; align-items: center; gap: 6px; }
.status .stat b { color: #3a5520; font-size: 17px; }
.status .errors b.bad { color: #c0552f; }

/* board */
.board-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}
.board {
  display: grid;
  background: #5a4a20;
  border: 3px solid #5a4a20;
  gap: 0;
  touch-action: manipulation;
  max-width: 100%;
}

.cell {
  background: rgba(255, 253, 245, 0.95);
  border: 1px solid #d8c98c;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  position: relative;
  aspect-ratio: 1 / 1;
}
.cell.given { color: #1a1a1a; cursor: default; }
.cell.user { color: #2a5d8a; }
.cell.selected { background: #e8f0d0; box-shadow: inset 0 0 0 3px #5a8835; }
.cell.peer { background: #f3efdc; }
.cell.same { background: #dcecc0; }
.cell.conflict { color: #c0552f; background: #fbe3df; }
.cell.hintflash { animation: flash 0.6s ease; }
@keyframes flash {
  0%, 100% { background: rgba(255,253,245,0.95); }
  50% { background: #f8dd9b; }
}

/* thick block borders */
.cell.br { border-right: 2.5px solid #5a4a20; }
.cell.bb { border-bottom: 2.5px solid #5a4a20; }

/* candidate notes */
.notes {
  position: absolute;
  inset: 0;
  display: grid;
  font-weight: 400;
  color: #8a7a4a;
  pointer-events: none;
  padding: 1px;
}
.notes span {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* numeric keypad */
.pad {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}
.pad button {
  font-size: 22px;
  font-weight: 700;
  padding: 12px 0;
  border: 1.5px solid #b8a86c;
  border-radius: 10px;
  background: #fff;
  color: #3a5520;
}
.pad button:hover { border-color: #5a8835; background: #f3efdc; }
.pad button:active { background: #d6e4b6; }
.pad button.erase { color: #c0552f; }

.pad-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.toggle {
  font-size: 14px;
  font-weight: 700;
  padding: 9px 14px;
  border: 1.5px solid #b8a86c;
  border-radius: 10px;
  background: #fff;
  color: #5a4a20;
}
.toggle[aria-pressed="true"] {
  background: #c8d8a4;
  border-color: #5a8835;
  color: #3a5520;
}
.toggle[disabled] { opacity: 0.4; cursor: not-allowed; }

/* win banner */
.win {
  margin-top: 14px;
  text-align: center;
  padding: 16px;
  border: 1.5px solid #5a8835;
  border-radius: 12px;
  background: #e8f0d0;
  color: #3a5520;
  font-size: 18px;
  font-weight: 700;
  animation: pop 0.5s ease;
}
.win[hidden] { display: none; }
.win .big { font-size: 30px; display: block; margin-bottom: 4px; }
@keyframes pop {
  0% { transform: scale(0.7); opacity: 0; }
  60% { transform: scale(1.06); }
  100% { transform: scale(1); opacity: 1; }
}

.confetti {
  position: fixed;
  top: -10px;
  width: 10px;
  height: 14px;
  z-index: 50;
  pointer-events: none;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(540deg); opacity: 0.9; }
}

@media (max-width: 480px) {
  h1 { font-size: 22px; }
  .pad button { font-size: 19px; padding: 14px 0; }
}
