:root {
  --page-bg: #f5f8fb;
  --page-bg-soft: #e6eef7;
  --ink: #172033;
  --muted: #536174;
  --line: #b8c5d4;
  --line-strong: #30445f;
  --panel: rgba(255, 255, 255, 0.84);
  --panel-strong: #ffffff;
  --blue: #315eb8;
  --blue-soft: #dce7f7;
  --blue-cell: #cfe0f1;
  --teal: #18a999;
  --danger: #d94949;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  background: linear-gradient(180deg, var(--page-bg) 0%, #ffffff 46%, var(--page-bg-soft) 100%);
  color: var(--ink);
  margin: 0;
  min-height: 100vh;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.site-header {
  background: rgba(248, 251, 253, 0.92);
  border-bottom: 1px solid rgba(30, 41, 59, 0.1);
  border-top: 3px solid #143a5a;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.07);
  position: sticky;
  top: 0;
  z-index: 20;
}

.site-header__inner {
  align-items: center;
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(230px, 1fr) auto auto;
  margin: 0 auto;
  max-width: 1600px;
  padding: 1.05rem clamp(1rem, 4vw, 2rem);
}

.brand {
  align-items: center;
  display: inline-flex;
  gap: 1rem;
  min-width: 0;
}

.brand img {
  flex: 0 0 auto;
  height: 44px;
  width: 44px;
}

.brand__copy {
  display: grid;
  line-height: 1.12;
  min-width: 0;
}

.brand__name {
  font-size: clamp(1.9rem, 4vw, 2.45rem);
  font-weight: 760;
}

.brand__tagline {
  color: var(--muted);
  font-size: 1rem;
  min-height: 1.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-nav {
  align-items: center;
  display: flex;
  gap: 0.65rem;
}

.main-nav a,
.lang-switch button {
  align-items: center;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(30, 41, 59, 0.12);
  border-radius: 0.55rem;
  display: inline-flex;
  font-size: 1.02rem;
  justify-content: center;
  min-height: 2.55rem;
  padding: 0.5rem 0.75rem;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
  white-space: nowrap;
}

.main-nav a:hover,
.main-nav a.is-active,
.lang-switch button.is-active,
.lang-switch button:hover {
  background: #fff;
  border-color: rgba(49, 94, 184, 0.28);
  color: var(--blue);
}

.lang-switch {
  display: flex;
  gap: 0.35rem;
}

.sudoku-page {
  margin: 0 auto;
  max-width: 1280px;
  padding: clamp(1.25rem, 4vw, 3rem) clamp(1rem, 4vw, 2rem) 1.5rem;
}

.sudoku-app {
  display: grid;
  gap: 1.5rem;
}

.sudoku-topbar {
  align-items: center;
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1fr) auto;
}

.difficulty-tabs {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.65rem;
  min-width: 0;
}

.difficulty-tabs__label {
  color: #536174;
  font-size: 1.12rem;
  font-weight: 700;
  margin-right: 0.35rem;
}

.difficulty-tabs button {
  background: transparent;
  border: 0;
  border-radius: 0.45rem;
  color: #536174;
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 700;
  min-height: 2.2rem;
  padding: 0.3rem 0.45rem;
}

.difficulty-tabs button.is-active {
  color: var(--blue);
}

.score-pill {
  color: #213a5d;
  font-size: 1.9rem;
  font-weight: 800;
  min-width: 4rem;
  text-align: center;
}

.sudoku-layout {
  align-items: start;
  display: grid;
  gap: clamp(1.2rem, 4vw, 2rem);
  grid-template-columns: minmax(0, 1fr) minmax(310px, 440px);
}

.board-panel {
  min-width: 0;
  position: relative;
}

.sudoku-board {
  aspect-ratio: 1;
  background: var(--line-strong);
  border: 2px solid var(--line-strong);
  contain: layout paint;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  margin: 0 auto;
  max-width: min(72vh, 750px);
  width: 100%;
}

.sudoku-cell {
  align-items: center;
  aspect-ratio: 1;
  background: #fdfefe;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  color: #27415f;
  cursor: pointer;
  display: flex;
  font-size: clamp(1.35rem, 4.5vw, 3.25rem);
  font-weight: 420;
  justify-content: center;
  min-height: 0;
  padding: 0;
  position: relative;
  transition: background 120ms ease, color 120ms ease;
}

.sudoku-cell:nth-child(3n) {
  border-right: 2px solid var(--line-strong);
}

.sudoku-cell:nth-child(n + 19):nth-child(-n + 27),
.sudoku-cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 2px solid var(--line-strong);
}

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

.sudoku-cell:nth-child(n + 73) {
  border-bottom: 0;
}

.sudoku-cell.is-given {
  background: #e4edf6;
  color: #2f4867;
  font-weight: 500;
}

.sudoku-cell.is-related {
  background: #eef4fa;
}

.sudoku-cell.is-same {
  background: var(--blue-cell);
}

.sudoku-cell.is-selected {
  background: #bfd6ec;
  box-shadow: inset 0 0 0 2px rgba(49, 94, 184, 0.34);
}

.sudoku-cell.is-user {
  color: var(--blue);
  font-weight: 500;
}

.sudoku-cell.is-error {
  background: #ffe8e8;
  color: var(--danger);
}

.sudoku-cell:focus-visible,
.number-pad button:focus-visible,
.quick-number-pad button:focus-visible,
.tool-button:focus-visible,
.new-game-button:focus-visible,
.pause-button:focus-visible,
.difficulty-tabs button:focus-visible,
.main-nav a:focus-visible,
.lang-switch button:focus-visible {
  outline: 3px solid rgba(49, 94, 184, 0.32);
  outline-offset: 2px;
}

.notes-grid {
  color: #536f91;
  display: grid;
  font-size: clamp(0.58rem, 1.5vw, 0.92rem);
  font-weight: 700;
  grid-template-columns: repeat(3, 1fr);
  height: 78%;
  line-height: 1;
  width: 78%;
}

.notes-grid span {
  align-items: center;
  display: flex;
  justify-content: center;
}

.control-panel {
  display: grid;
  gap: 0.85rem;
}

.stats-row {
  align-items: end;
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr 1fr auto;
}

.stats-row div {
  display: grid;
  gap: 0.1rem;
}

.stats-row span {
  color: #536174;
  font-size: 1rem;
  font-weight: 700;
}

.stats-row strong {
  color: #45566c;
  font-size: 1.3rem;
  line-height: 1.1;
}

.pause-button,
.tool-button {
  align-items: center;
  background: #e9eef6;
  border: 0;
  border-radius: 999px;
  color: var(--blue);
  cursor: pointer;
  display: inline-flex;
  font-size: 1.9rem;
  font-weight: 700;
  height: 4.35rem;
  justify-content: center;
  position: relative;
  transition: background 150ms ease, transform 150ms ease, color 150ms ease;
  width: 4.35rem;
}

.pause-button {
  color: #65758b;
  font-size: 1rem;
  height: 2.9rem;
  width: 2.9rem;
}

.tool-row {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(4, 1fr);
  justify-items: center;
  padding: 0.75rem 0 0.1rem;
}

.tool-button:hover,
.pause-button:hover,
.tool-button.is-active {
  background: #dde7f4;
  transform: translateY(-1px);
}

.tool-button:disabled,
.pause-button:disabled,
.number-pad button:disabled,
.new-game-button:disabled {
  cursor: default;
  opacity: 0.52;
  transform: none;
}

.tool-badge {
  align-items: center;
  background: #a8b2c0;
  border-radius: 999px;
  color: #fff;
  display: inline-flex;
  font-size: 0.72rem;
  font-weight: 800;
  justify-content: center;
  min-height: 1.45rem;
  min-width: 1.45rem;
  padding: 0 0.35rem;
  position: absolute;
  right: -0.35rem;
  top: -0.35rem;
}

.tool-button.is-active .tool-badge,
#hint .tool-badge {
  background: var(--blue);
}

.number-pad {
  display: grid;
  gap: 0.62rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.number-pad button {
  align-items: center;
  aspect-ratio: 1.18;
  background: #e8edf5;
  border: 0;
  border-radius: 0.45rem;
  color: var(--blue);
  cursor: pointer;
  display: flex;
  font-size: clamp(2.2rem, 6vw, 3.75rem);
  font-weight: 360;
  justify-content: center;
  min-height: 4.8rem;
  transition: background 150ms ease, transform 150ms ease;
}

.number-pad button:hover,
.number-pad button.is-active,
.quick-number-pad button:hover,
.quick-number-pad button.is-active {
  background: #dbe6f5;
  box-shadow: inset 0 0 0 2px rgba(49, 94, 184, 0.16);
  transform: translateY(-1px);
}

.quick-number-pad {
  display: none;
}

.new-game-button {
  background: #5c7dc7;
  border: 0;
  border-radius: 0.42rem;
  color: #fff;
  cursor: pointer;
  font-size: 1.12rem;
  font-weight: 800;
  min-height: 5rem;
  transition: background 150ms ease, transform 150ms ease;
  width: 100%;
}

.new-game-button:hover {
  background: #4e70bb;
  transform: translateY(-1px);
}

.status-line {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 650;
  min-height: 1.45rem;
  margin: 0;
  text-align: center;
}

.site-footer {
  color: #536174;
  font-size: 0.9rem;
  padding: 1.25rem;
  text-align: center;
}

body.is-paused .sudoku-board {
  filter: grayscale(0.28);
  opacity: 0.72;
}

body.is-paused .sudoku-cell {
  cursor: default;
}

body.is-complete .status-line {
  color: var(--teal);
}

body.is-game-over .status-line {
  color: var(--danger);
}

@media (max-width: 1040px) {
  .site-header__inner {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .brand {
    grid-column: 1;
    grid-row: 1;
  }

  .lang-switch {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }

  .main-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    overflow-x: auto;
    padding-bottom: 0.15rem;
    scrollbar-width: none;
  }

  .main-nav::-webkit-scrollbar {
    display: none;
  }

  .main-nav a {
    flex: 0 0 auto;
  }

  .sudoku-layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    margin: 0 auto;
    max-width: 560px;
    width: 100%;
  }

  .sudoku-board {
    max-width: min(92vw, 680px);
  }
}

@media (max-width: 640px) {
  .site-header__inner {
    gap: 0.65rem;
    padding: 0.75rem 0.9rem 0.65rem;
  }

  .brand {
    gap: 0.6rem;
  }

  .brand img {
    height: 36px;
    width: 36px;
  }

  .brand__name {
    font-size: 1.65rem;
  }

  .brand__tagline {
    font-size: 0.82rem;
    max-width: 58vw;
  }

  .main-nav {
    gap: 0.35rem;
  }

  .main-nav a,
  .lang-switch button {
    font-size: 0.9rem;
    min-height: 2.25rem;
    padding: 0.38rem 0.58rem;
  }

  .sudoku-page {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .sudoku-topbar {
    grid-template-columns: 1fr;
  }

  .score-pill {
    display: none;
  }

  .difficulty-tabs {
    gap: 0.25rem 0.35rem;
  }

  .difficulty-tabs__label {
    flex: 0 0 100%;
    font-size: 1rem;
  }

  .difficulty-tabs button {
    font-size: 0.94rem;
    padding: 0.25rem 0.33rem;
  }

  .sudoku-layout {
    gap: 1rem;
  }

  .tool-row {
    gap: 0.45rem;
  }

  .tool-button {
    height: 3.65rem;
    width: 3.65rem;
  }

  .number-pad {
    display: none;
  }

  .quick-number-pad {
    background: #f8fbfd;
    border: 1px solid #c6d5ea;
    border-radius: 0.65rem;
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.44);
    gap: 0.35rem;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    left: var(--quick-pad-left, 50%);
    padding: 0.4rem;
    position: absolute;
    top: var(--quick-pad-top, 50%);
    transform: translate(-50%, calc(-100% - 0.45rem));
    z-index: 30;
  }

  .quick-number-pad:not([hidden]) {
    display: grid;
  }

  .quick-number-pad.is-below {
    transform: translate(-50%, 0.45rem);
  }

  .quick-number-pad button {
    align-items: center;
    aspect-ratio: 1.15;
    background: #e8edf5;
    border: 1px solid #c2d0e5;
    border-radius: 0.45rem;
    color: var(--blue);
    cursor: pointer;
    display: flex;
    font-size: 1.45rem;
    font-weight: 420;
    justify-content: center;
    min-height: 2.55rem;
    padding: 0;
    touch-action: manipulation;
    transition: background 150ms ease, transform 150ms ease;
  }

  .quick-number-pad button:hover,
  .quick-number-pad button.is-active {
    background: #dbe6f5;
    box-shadow: inset 0 0 0 2px rgba(49, 94, 184, 0.18);
  }
}

@media (max-width: 380px) {
  .brand__tagline {
    display: none;
  }

  .tool-button {
    height: 3.25rem;
    width: 3.25rem;
  }

  .quick-number-pad button {
    min-height: 2.35rem;
  }
}
