:root {
  --cream: #efe7da;
  --purple: #6353b1;
  --gold: #ecc405;
  --ink: #161044;
  --line: #c8c5d7;
  --soft: #fbf7ef;
  --white: #ffffff;
  --error: #d93a3a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, #fff 0%, var(--cream) 58%, #e7dccd 100%);
}

.app-shell {
  width: min(1010px, 94vw);
  margin: 0 auto;
  padding: 10px 0 18px;
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
}

.brand-logo {
  width: 70px;
  height: 70px;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid var(--purple);
  background: var(--cream);
  box-shadow: 0 8px 22px rgba(99, 83, 177, 0.22);
}

h1 {
  margin: 0;
  color: var(--purple);
  font-size: clamp(2rem, 4.2vw, 3.2rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.tagline {
  margin: 8px 0 0;
  font-weight: 800;
  font-size: 1.05rem;
}

.toolbar,
.board-card,
.side-card {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(99, 83, 177, 0.18);
  box-shadow: 0 16px 40px rgba(43, 36, 68, 0.10);
}

.toolbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 22px;
  margin-bottom: 14px;
}

.difficulty-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

label { font-weight: 800; color: var(--purple); }

select,
button {
  font: inherit;
  font-weight: 800;
  border-radius: 999px;
  cursor: pointer;
}

select {
  min-width: 128px;
  padding: 10px 18px;
  border: 2px solid var(--purple);
  background: var(--white);
  color: var(--ink);
}

button {
  border: 2px solid var(--purple);
  background: var(--purple);
  color: var(--white);
  padding: 11px 17px;
  transition: transform 0.15s ease, filter 0.15s ease;
}

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

.outline-button {
  background: var(--white);
  color: var(--purple);
}

.timer-pill {
  margin-left: auto;
  min-width: 96px;
  height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--gold);
  color: var(--ink);
  font-weight: 900;
  box-shadow: 0 10px 26px rgba(236, 196, 5, 0.28);
}

.timer-label {
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1;
}

#timer { font-size: 1.05rem; line-height: 1.1; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 286px;
  gap: 14px;
  align-items: start;
}

.board-card,
.side-card {
  border-radius: 22px;
  padding: 14px 16px;
}

.grid-wrap {
  position: relative;
  width: min(65vh, 510px, 100%);
  height: min(65vh, 510px, calc(94vw - 32px));
  margin: 0 auto 10px;
}

.sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  height: 100%;
  border: 4px solid var(--purple);
  background: var(--line);
}

.cell {
  width: 100%;
  height: 100%;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  text-align: center;
  font-size: clamp(1.25rem, 3.1vw, 1.9rem);
  font-weight: 900;
  outline: none;
  cursor: pointer;
}

.cell:nth-child(3n) { border-right: 3px solid var(--purple); }
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 3px solid var(--purple); }

.cell.given {
  background: var(--soft);
  color: var(--purple);
  cursor: default;
}

.cell.peer {
  background: #f8f0df;
}

.cell.same-number {
  background: #fff0a8;
  color: var(--ink);
}

.cell.selected {
  background: #fff5c4;
  box-shadow: inset 0 0 0 3px var(--gold);
}

.cell.error {
  background: #ffe0e0;
  color: var(--error);
  animation: shake 0.24s ease-in-out;
}


.grid-victory {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(22, 16, 68, 0.22);
  backdrop-filter: blur(2px);
  z-index: 4;
  border-radius: 2px;
}

.grid-victory-card {
  width: min(82%, 380px);
  padding: 26px 18px;
  text-align: center;
  border-radius: 28px;
  background: linear-gradient(135deg, var(--purple), #8f7fea);
  color: var(--white);
  box-shadow: 0 22px 70px rgba(22, 16, 68, 0.40);
  border: 3px solid rgba(236, 196, 5, 0.95);
}

.grid-victory-icon {
  font-size: 3.2rem;
  line-height: 1;
  margin-bottom: 8px;
}

.grid-victory-title {
  color: var(--gold);
  font-size: clamp(1.8rem, 5vw, 2.7rem);
  line-height: 1;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: -0.04em;
}

.grid-victory-time {
  margin-top: 12px;
  font-size: 1.2rem;
  font-weight: 900;
}

.grid-victory-animate .grid-victory-card {
  animation: gridVictoryPop 1.05s ease-in-out 3;
}

@keyframes gridVictoryPop {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.08); filter: brightness(1.25); }
}

.status {
  min-height: 26px;
  text-align: center;
  color: var(--purple);
  font-weight: 900;
}

.status-warning {
  color: var(--error);
  animation: warningPulse 0.8s ease-in-out 2;
}

@keyframes warningPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.side-card h2 {
  margin: 0 0 18px;
  color: var(--purple);
  font-size: 1.55rem;
}

.side-card p {
  margin: 0 0 14px;
  line-height: 1.22;
}

.check-help {
  margin: 12px 0 14px;
  padding: 12px;
  border: 1px solid rgba(99, 83, 177, 0.22);
  border-radius: 18px;
  background: var(--soft);
  font-size: 0.88rem;
}

.check-help h3 {
  margin: 0 0 8px;
  color: var(--purple);
  font-size: 1rem;
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.number-pad button {
  min-height: 46px;
  background: var(--gold);
  border-color: var(--gold);
  color: var(--ink);
  font-size: 1.2rem;
}

.clear-button {
  width: 100%;
  margin-top: 14px;
  background: var(--white);
  color: var(--purple);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(22, 16, 68, 0.35);
  z-index: 10;
}

.modal-card {
  position: relative;
  width: min(520px, 100%);
  padding: 30px 24px 24px;
  border-radius: 28px;
  background: linear-gradient(135deg, var(--purple), #8b7be0);
  color: var(--white);
  text-align: center;
  box-shadow: 0 26px 80px rgba(22, 16, 68, 0.38);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  padding: 0;
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.34);
}

.trophy { font-size: 3rem; }
.modal-card h2 { margin: 6px 0 8px; color: var(--gold); font-size: 2rem; }
.modal-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.modal-actions button:first-child { background: var(--gold); border-color: var(--gold); color: var(--ink); }

.hidden { display: none !important; }
.victory-flash { animation: victoryFlash 0.9s ease-in-out 3; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(-4px); }
  70% { transform: translateX(4px); }
}

@keyframes victoryFlash {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.03); filter: brightness(1.22); }
}

@media (max-width: 880px) {
  .toolbar { flex-wrap: wrap; }
  .timer-pill { margin-left: 0; }
  .game-layout { grid-template-columns: 1fr; }
  .side-card { order: 2; }
  .grid-wrap { width: min(88vw, 510px); height: min(88vw, 510px); }
}

@media (max-height: 760px) and (min-width: 881px) {
  .brand-logo { width: 58px; height: 58px; }
  h1 { font-size: 2.55rem; }
  .toolbar { min-height: 58px; padding: 8px 10px; margin-bottom: 10px; }
  button, select { padding: 8px 14px; }
  .timer-pill { height: 44px; }
  .board-card, .side-card { padding: 12px 16px; }
  .grid-wrap { width: min(62vh, 500px); height: min(62vh, 500px); }
  .side-card h2 { margin-bottom: 12px; }
  .check-help { font-size: 0.82rem; padding: 10px; }
  .number-pad button { min-height: 44px; }
}

@media print {
  body { background: #fff; }
  .brand-header, .toolbar, .side-card, .status, .modal { display: none !important; }
  .app-shell { width: 100%; padding: 0; }
  .board-card { box-shadow: none; border: none; }
  .game-layout { display: block; }
  .grid-wrap, .sudoku-grid { width: 17cm; height: 17cm; }
  .grid-victory { display: none !important; }
}
