:root {
  --bg: #ffffff;
  --text: #111111;
  --muted: #6b7280;
  --line: #d8dce2;
  --strong: #111111;
  --accent: #13a45b;
  --accent-soft: #e8f7ef;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.topbar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 28px;
  border-bottom: 1px solid #e6e8eb;
}

h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1;
  letter-spacing: 0;
}

.actions,
.number-pad,
.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.button,
.segmented button {
  height: 44px;
  border: 1px solid #dfe3e8;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 18px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.button:hover,
.segmented button:hover {
  border-color: #b9c1cb;
}

.button:active,
.segmented button:active {
  transform: translateY(1px);
}

.primary,
.segmented button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 96px);
  overflow: hidden;
  border: 1px solid #dfe3e8;
  border-radius: 8px;
}

.size-select {
  grid-template-columns: repeat(5, 82px);
}

.segmented button {
  width: 100%;
  border: 0;
  border-radius: 0;
}

.game {
  display: grid;
  justify-items: center;
  gap: 18px;
  padding: 26px 20px 22px;
}

.board-wrap {
  width: min(58vh, 520px, calc(100vw - 32px));
  aspect-ratio: 1;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--size, 9), 1fr);
  grid-template-rows: repeat(var(--size, 9), 1fr);
  width: 100%;
  height: 100%;
  border: 3px solid var(--strong);
  background: var(--strong);
  gap: 1px;
}

.cell {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 0;
  background: #fff;
  color: #111;
  font-size: var(--cell-font, clamp(20px, 4.4vh, 38px));
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  outline: none;
}

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

.cell.row-end {
  border-right: 0;
}

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

.cell.given {
  font-weight: 800;
}

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

.cell.related {
  background: var(--accent-soft);
}

.cell.same {
  background: #d8f1e5;
}

.cell.wrong {
  color: var(--danger);
}

.numbers {
  display: grid;
  grid-template-columns: repeat(var(--size, 9), var(--num-size, 54px));
  gap: var(--num-gap, 10px);
}

.num {
  width: var(--num-size, 54px);
  height: var(--num-size, 54px);
  padding: 0;
  border: 1px solid #dfe3e8;
  border-radius: 8px;
  background: #fff;
  font-size: var(--num-font, 26px);
  font-weight: 700;
  cursor: pointer;
}

.num:hover {
  border-color: var(--accent);
}

.divider,
.status-divider {
  width: 1px;
  height: 38px;
  background: #d7dbe1;
}

.status {
  min-height: 28px;
  color: #30343a;
  font-size: 18px;
}

.message {
  min-width: 120px;
  color: var(--accent);
  font-weight: 800;
}

@media (max-width: 760px) {
  body {
    display: flex;
    flex-direction: column;
  }

  body,
  button,
  .button,
  .segmented button,
  .cell,
  .num {
    cursor: default;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px;
  }

  h1 {
    font-size: 30px;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
    gap: 8px;
  }

  .button,
  .segmented button {
    height: 38px;
    padding: 0 12px;
    border-radius: 7px;
  }

  .segmented {
    width: 100%;
  }

  .size-select {
    grid-column: 1 / -1;
    grid-row: 1;
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .actions .segmented:not(.size-select) {
    grid-column: 1 / -1;
    grid-row: 2;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #newGame {
    grid-column: 1;
    grid-row: 3;
  }

  #check {
    grid-column: 2;
    grid-row: 3;
  }

  .actions .button {
    width: 100%;
  }

  .game {
    flex: 1;
    align-content: center;
    gap: 16px;
    padding: 14px 20px 24px;
  }

  .board-wrap {
    width: min(51vh, calc(100vw - 28px));
  }

  .cell {
    font-size: var(--cell-font, clamp(18px, 4vh, 34px));
  }

  .number-pad {
    flex-wrap: wrap;
    gap: 10px;
  }

  .numbers {
    grid-template-columns: repeat(var(--size, 9), minmax(0, 1fr));
    width: 100%;
    gap: 6px;
  }

  .num {
    width: 100%;
    height: 40px;
    font-size: 22px;
  }

  .status {
    flex-wrap: wrap;
    gap: 10px;
    font-size: 17px;
  }

  .divider {
    display: none;
  }
}
