:root {
  --ink: #173126;
  --muted: #52675d;
  --green-900: #174f36;
  --green-800: #206b45;
  --green-700: #2f7d4f;
  --green-500: #66bf46;
  --green-100: #e8f7df;
  --green-50: #f4fbef;
  --blue: #155da8;
  --cream: #fffdf8;
  --line: #9cad9f;
  --danger: #b42d2d;
  --shadow: 0 18px 55px rgba(23, 49, 38, 0.13);
  --cell-size: clamp(2.4rem, 6vw, 4.15rem);
  color-scheme: light;
  font-family: ui-rounded, "Arial Rounded MT Bold", "Avenir Next", Arial, sans-serif;
  font-size: 18px;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: #f1f7ed; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 95% 0%, rgba(102, 191, 70, .18), transparent 32rem),
    linear-gradient(180deg, #f9fcf6 0%, #edf6e8 100%);
}

button, select { font: inherit; }

button { cursor: pointer; }

button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 4px solid #f4b942;
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 30;
  padding: .8rem 1rem;
  color: #fff;
  background: var(--green-900);
  border-radius: .6rem;
}

.skip-link:focus { top: 1rem; }

.site-header {
  width: min(1180px, calc(100% - 2rem));
  min-height: 74px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .7rem;
  color: var(--green-900);
  text-decoration: none;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: .02em;
}

.brand > span:last-child > span { color: var(--green-500); }

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  color: #fff;
  background: var(--green-800);
  font-size: .84rem;
  letter-spacing: -.08em;
}

.text-size-button {
  min-height: 46px;
  padding: .55rem .9rem;
  border: 2px solid #a9beae;
  border-radius: 12px;
  color: var(--green-900);
  background: #fff;
  font-weight: 800;
}

.text-size-button span { font-size: 1.15em; }

.game-shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto 2rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 1.25rem;
  align-items: start;
}

.game-card,
.koko-card {
  border: 1px solid rgba(67, 108, 81, .18);
  border-radius: 24px;
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow);
}

.game-card { padding: clamp(1rem, 3vw, 1.6rem); }

.game-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
}

.eyebrow {
  margin: 0 0 .2rem;
  color: var(--green-700);
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1;
  letter-spacing: -.045em;
}

.game-settings {
  display: flex;
  align-items: center;
  gap: .55rem;
}

.game-settings label {
  color: var(--muted);
  font-weight: 700;
}

select,
.primary-button,
.secondary-button {
  min-height: 48px;
  border-radius: 12px;
  font-weight: 800;
}

select {
  padding: .55rem 2rem .55rem .75rem;
  border: 2px solid #9daf9f;
  color: var(--ink);
  background: #fff;
}

.primary-button {
  padding: .62rem 1rem;
  border: 2px solid var(--green-800);
  color: #fff;
  background: var(--green-800);
}

.primary-button:hover { background: var(--green-900); }

.status-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 1rem 0 .7rem;
  border-block: 1px solid #d5e1d6;
}

.status-row > div {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: .5rem;
  padding: .65rem .4rem;
}

.status-row > div + div { border-left: 1px solid #d5e1d6; }

.status-row span { color: var(--muted); }
.status-row strong { font-size: 1.08rem; }

.instructions {
  margin: .7rem 0 1rem;
  text-align: center;
  color: var(--muted);
  line-height: 1.45;
}

.board-wrap { display: grid; place-items: center; }

.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, var(--cell-size));
  grid-template-rows: repeat(9, var(--cell-size));
  overflow: hidden;
  width: fit-content;
  border: 4px solid var(--ink);
  border-radius: 10px;
  background: #fff;
}

.cell {
  display: grid;
  place-items: center;
  width: var(--cell-size);
  height: var(--cell-size);
  padding: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--blue);
  background: #fff;
  font-size: clamp(1.25rem, 4vw, 2rem);
  font-weight: 800;
}

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

.cell.given { color: var(--ink); background: #f8faf8; }
.cell.related { background: var(--green-50); }
.cell.same-number { background: #dff2ff; }
.cell.selected { background: #caedb8; box-shadow: inset 0 0 0 4px var(--green-800); }
.cell.error { color: var(--danger); background: #ffe7e3; }
.cell.hint-value { color: var(--green-800); background: #e5f6da; }

.number-pad {
  width: min(100%, calc(var(--cell-size) * 9 + 8px));
  margin: 1rem auto .8rem;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: .4rem;
}

.number-pad button {
  min-width: 0;
  min-height: 52px;
  border: 2px solid #a4b5a7;
  border-radius: 12px;
  color: var(--green-900);
  background: #fff;
  font-size: 1.35rem;
  font-weight: 900;
}

.number-pad button:hover { background: var(--green-100); border-color: var(--green-700); }

.action-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .55rem;
  width: min(100%, calc(var(--cell-size) * 9 + 8px));
  margin: 0 auto;
}

.secondary-button {
  padding: .55rem .7rem;
  border: 2px solid #9caf9f;
  color: var(--ink);
  background: #f8fbf7;
}

.secondary-button:hover { background: var(--green-100); }
.secondary-button:disabled { opacity: .45; cursor: not-allowed; }

.koko-card {
  position: sticky;
  top: 1rem;
  overflow: hidden;
}

.koko-image-wrap {
  height: 255px;
  overflow: hidden;
  background: linear-gradient(145deg, #153625, #2f6d46);
}

.koko-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 12%;
}

.koko-copy { padding: 1rem 1.15rem 1.1rem; background: var(--green-900); color: #fff; }
.koko-name { margin: 0 0 .45rem; font-size: 1.25rem; font-weight: 900; }
.koko-message { margin: 0; line-height: 1.5; }

.tips { padding: 1rem 1.15rem 1.2rem; }
.tips h2 { margin: 0 0 .6rem; font-size: 1.22rem; }
.tips ul { margin: 0; padding-left: 1.25rem; color: var(--muted); }
.tips li { margin: .45rem 0; line-height: 1.4; }

.pause-overlay,
.celebration {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(10, 31, 21, .72);
}

.pause-overlay[hidden],
.celebration[hidden] { display: none; }

.pause-dialog,
.celebration-card {
  width: min(430px, 100%);
  padding: 1.5rem;
  border-radius: 24px;
  background: #fff;
  box-shadow: var(--shadow);
  text-align: center;
}

.pause-dialog img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  object-position: 50% 8%;
  border-radius: 50%;
  background: var(--green-900);
}

.pause-dialog h2,
.celebration-card h2 { margin: .7rem 0 .3rem; font-size: 1.8rem; }
.pause-dialog p,
.celebration-card p { margin: .3rem 0 1.1rem; color: var(--muted); }
.celebration-icon { display: block; color: #e39c14; font-size: 3rem; }

body.large-text { font-size: 21px; }
body.large-text .cell { font-size: clamp(1.5rem, 4vw, 2.2rem); }

@media (max-width: 980px) {
  .game-shell { grid-template-columns: 1fr; }
  .koko-card { position: static; display: grid; grid-template-columns: 220px 1fr; }
  .koko-image-wrap { height: 100%; min-height: 220px; grid-row: span 2; }
  .tips { align-self: start; }
}

@media (max-width: 700px) {
  :root { --cell-size: calc((100vw - 2.9rem) / 9); font-size: 17px; }
  .site-header { width: min(100% - 1rem, 1180px); min-height: 66px; }
  .brand > span:last-child { display: none; }
  .game-shell { width: min(100% - 1rem, 1180px); }
  .game-card { padding: .8rem .55rem 1rem; border-radius: 18px; }
  .game-heading { display: block; padding-inline: .35rem; }
  .game-settings { margin-top: .8rem; display: grid; grid-template-columns: auto 1fr 1fr; }
  .game-settings label { font-size: .92rem; }
  .status-row span { display: block; font-size: .8rem; }
  .status-row > div { display: block; text-align: center; }
  .instructions { padding-inline: .4rem; font-size: .92rem; }
  .number-pad { grid-template-columns: repeat(5, 1fr); padding-inline: .35rem; }
  .number-pad button { min-height: 50px; }
  .action-row { grid-template-columns: repeat(2, 1fr); padding-inline: .35rem; }
  .koko-card { grid-template-columns: 118px 1fr; border-radius: 18px; }
  .koko-image-wrap { min-height: 175px; }
  .koko-copy { padding: .85rem; }
  .koko-name { font-size: 1.05rem; }
  .tips { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
