:root {
  --primary: #2c3e3e;
  --secondary: #e4c59e;
  --accent: #c04b3c;
  --background: #f8f5f0;
  --surface: #ffffff;
  --ink: #2b2b2b;
  --ink-new: #00aeff;
  --muted: rgba(43, 43, 43, 0.64);
  --outline: rgba(44, 62, 62, 0.18);
  --error: #d64550;
  --ok: #2c3e3e;
  --shadow-soft: 0 14px 32px rgba(44, 62, 62, 0.14);
  --board-max: clamp(220px, calc(100vh - 380px), 560px);
}

@supports (height: 100dvh) {
  :root {
    --board-max: clamp(220px, calc(100dvh - 380px), 560px);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Playfair Display", system-ui, -apple-system, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  background:
    radial-gradient(circle at top right, rgba(228, 197, 158, 0.35), transparent 60%),
    radial-gradient(circle at top left, rgba(44, 62, 62, 0.15), transparent 45%),
    var(--background);
  background-attachment: fixed;
  background-repeat: no-repeat;
  background-size: cover;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

body[data-card-style="classic"] {
  background: url("/assets/ruudy/bg.png") center / cover no-repeat fixed;
}

body * {
  user-select: none;
}

header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 18px 24px;
  background: var(--primary);
  color: var(--secondary);
  box-shadow: 0 4px 18px rgba(44, 62, 62, 0.32);
}

header .brand {
  color: var(--secondary);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  text-decoration: none;
}

header .brand:hover,
header .brand:focus-visible {
  color: #ffffff;
  outline: none;
}

.game-title {
  text-align: center;
  font-size: 2rem;
  font-weight: 600;
  color: #f9f6f1;
}

.controls {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  align-items: center;
}

.controls button {
  background: var(--accent);
  border: none;
  color: #fff;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(192, 75, 60, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.controls button:hover:not(:disabled),
.controls button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(192, 75, 60, 0.28);
  outline: none;
}

.controls button:disabled {
  opacity: 0.6;
  cursor: default;
  box-shadow: none;
}

.options-wrapper {
  position: relative;
}

.options-btn {
  white-space: nowrap;
}

.options-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 200px;
  padding: 16px;
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid rgba(44, 62, 62, 0.12);
  box-shadow: 0 16px 36px rgba(44, 62, 62, 0.24);
  z-index: 25;
}

.options-panel[hidden] {
  display: none !important;
}

.options-title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--primary);
}

.options-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
}

.options-choice input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.options-choice input[type="radio"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.status-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(248, 245, 240, 0.85);
  color: var(--primary);
  font-weight: 600;
  font-size: 0.95rem;
  border-bottom: 1px solid rgba(44, 62, 62, 0.12);
  backdrop-filter: blur(8px);
}

.status-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.status-group.current-stats {
  justify-self: center;
}

.status-group.total-stats {
  justify-self: end;
}

.status-bar span {
  white-space: nowrap;
}

.status-message {
  justify-self: end;
  font-weight: 600;
  color: var(--primary);
  text-align: right;
  min-height: 1.1em;
}

.status-message:empty {
  display: none;
}

.status-message--warning {
  color: var(--accent);
}

.status-message--error {
  color: var(--error);
}

.status-divider {
  font-size: 0.9em;
  color: rgba(44, 62, 62, 0.45);
}

main {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  justify-content: flex-start;
  overflow-y: auto;
  overflow-x: hidden;
}

.board-shell {
  width: min(100%, calc(var(--board-max) + 48px));
  background: rgba(255, 255, 255, 0.82);
  border-radius: 24px;
  padding: 24px 24px 18px;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 0;
  border: 3px solid var(--primary);
  border-radius: 12px;
  overflow: hidden;
  width: min(100%, var(--board-max));
  max-width: 100%;
  max-height: var(--board-max);
  aspect-ratio: 1 / 1;
}

.cell {
  background: var(--surface);
  border: 1px solid rgba(44, 62, 62, 0.2);
  font-size: 1.6rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  padding: 0;
  aspect-ratio: 1 / 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.cell.given {
  color: var(--ink);
  cursor: default;
}
.cell.editable {
  color: var(--ink-new);
}
.cell.editable:hover {
  background: rgba(192, 75, 60, 0.08);
}

.cell.selected {
  background: rgba(192, 75, 60, 0.18);
  box-shadow: inset 0 0 0 2px rgba(192, 75, 60, 0.45);
}

.cell.error {
  background: rgba(214, 69, 80, 0.18);
  color: var(--error);
}

.cell.completed {
  cursor: default;
}

.box-border-right {
  border-right-width: 3px;
}

.box-border-bottom {
  border-bottom-width: 3px;
}

.cell-value {
  line-height: 1;
}

.note-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 4px;
  gap: 1px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-align: center;
}

.note {
  display: flex;
  align-items: center;
  justify-content: center;
}

.note.filled {
  color: var(--ink);
}

.board-footer {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

.note-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.keypad {
  width: 96px;
  max-width: 100%;
  background: rgba(255, 255, 255, 0.88);
  border-radius: 24px;
  padding: 18px 20px;
  box-shadow: var(--shadow-soft);
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  transition: box-shadow 0.15s ease, border 0.15s ease;
}

.keypad-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid rgba(44, 62, 62, 0.18);
  border-radius: 18px;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--ink);
  padding: 14px 0;
  min-height: 3.25rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.keypad-btn:hover,
.keypad-btn:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(44, 62, 62, 0.18);
  border-color: var(--primary);
  outline: none;
}

.keypad-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.keypad-btn[data-value="clear"] {
  color: var(--error);
}

.keypad-btn.is-used {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.keypad.note-mode {
  border: 2px solid rgba(192, 75, 60, 0.42);
  box-shadow: 0 18px 30px rgba(192, 75, 60, 0.22);
}

.keypad.note-mode .keypad-btn:not([data-value="clear"]) {
  font-size: 1.05rem;
  justify-content: flex-end;
  align-items: flex-end;
  padding: 12px 12px 10px;
}

.keypad.note-mode .keypad-btn.is-used {
  justify-content: center;
  align-items: center;
  font-size: 1.2rem;
  padding: 14px 0;
}

.win-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 24px;
  z-index: 20;
}

.win-modal.visible {
  opacity: 1;
  pointer-events: auto;
}

.win-modal__content {
  background: var(--surface);
  border-radius: 24px;
  padding: 32px 42px;
  text-align: center;
  box-shadow: var(--shadow-soft);
}

.win-modal__content h2 {
  margin: 0 0 12px;
  font-size: 2.1rem;
  color: var(--primary);
}

.win-modal__time {
  margin: 0 0 22px;
  font-size: 1.2rem;
  color: var(--ink);
}

.win-modal__btn {
  background: var(--accent);
  border: none;
  color: #fff;
  font-weight: 600;
  padding: 12px 26px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 10px 26px rgba(192, 75, 60, 0.26);
}

.win-modal__btn:hover,
.win-modal__btn:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 14px 32px rgba(192, 75, 60, 0.32);
  outline: none;
}

.confirm-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.35);
  z-index: 30;
}

.confirm-modal__content {
  background: var(--surface);
  border-radius: 22px;
  padding: 28px 32px;
  box-shadow: 0 18px 38px rgba(44, 62, 62, 0.28);
  text-align: center;
  max-width: 320px;
  width: 100%;
}

.confirm-modal__content h2 {
  margin: 0 0 12px;
  font-size: 1.9rem;
  color: var(--primary);
}

.confirm-modal__message {
  margin: 0 0 18px;
  color: var(--ink);
  font-weight: 500;
}

.confirm-modal__status {
  margin: 12px 0 0;
  font-weight: 600;
  color: var(--accent);
}

.confirm-modal__status[hidden] {
  display: none;
}

.confirm-modal__actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.confirm-modal__btn {
  padding: 12px 22px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 10px 24px rgba(192, 75, 60, 0.25);
}

.confirm-modal__btn:hover,
.confirm-modal__btn:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 14px 32px rgba(192, 75, 60, 0.32);
  outline: none;
}

.confirm-modal__btn--secondary {
  background: var(--primary);
  box-shadow: 0 10px 22px rgba(44, 62, 62, 0.26);
}

.confirm-modal[hidden] {
  display: none !important;
}

.difficulty-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.difficulty-picker__option {
  padding: 12px 18px;
  border-radius: 16px;
  border: 1px solid rgba(44, 62, 62, 0.18);
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.difficulty-picker__option:hover,
.difficulty-picker__option:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(44, 62, 62, 0.18);
  border-color: var(--accent);
  outline: none;
}

.difficulty-picker__option.is-selected {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 12px 26px rgba(192, 75, 60, 0.32);
}

.generator-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(44, 62, 62, 0.55);
  z-index: 40;
}

.generator-overlay[hidden] {
  display: none !important;
}

.generator-overlay__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 28px 36px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 20px 40px rgba(44, 62, 62, 0.32);
  text-align: center;
  color: var(--primary);
  font-weight: 600;
}

.generator-overlay__spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 5px solid rgba(192, 75, 60, 0.25);
  border-top-color: var(--accent);
  animation: sudoku-spin 0.9s linear infinite;
}

.generator-overlay__content p {
  margin: 0;
  font-size: 1.1rem;
}

.generator-overlay__content p strong {
  color: var(--accent);
}

.generator-overlay__content--error {
  color: var(--error);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 720px) {
  header {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .controls {
    justify-content: center;
  }

  .status-bar {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  main {
    padding: 20px 16px 28px;
  }
}

@media (max-width: 560px) {
  .keypad {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .difficulty-picker {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 440px) {
  .board-shell {
    padding: 20px 20px 16px;
  }

  .cell {
    font-size: 1.3rem;
  }
}

@media (min-width: 960px) {
  main {
    max-width: none;
    width: 100%;
    padding: 32px 40px 48px;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 48px;
  }

  .board-shell {
    width: 100%;
    max-width: calc(var(--board-max) + 48px);
  }

  .keypad {
    width: 100%;
    max-width: 96px;
    align-self: flex-start;
  }
}

#checkBtn.attention,
button.attention {
  animation: pulse 0.9s ease-in-out 2;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes sudoku-spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
