:root {
  --ink: #132019;
  --muted: #68736c;
  --paper: #f3f6f1;
  --surface: #fbfcf9;
  --line: #d8dfd8;
  --green: #22563c;
  --lime: #cdea3d;
  --soft-green: #e4eee6;
  --danger: #b34d43;
  --shadow: 0 20px 60px rgba(25, 55, 37, .1);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: radial-gradient(circle at 80% 8%, rgba(205,234,61,.12), transparent 24rem), var(--paper);
  font-family: "Aptos", "Segoe UI", system-ui, sans-serif;
}
button, input { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.app-shell {
  width: min(1120px, 100%); min-height: 100vh; margin: 0 auto; padding: 0 18px;
  display: flex; flex-direction: column;
}
.topbar {
  height: 76px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: 10px; color: var(--ink);
  text-decoration: none; font-size: 18px; letter-spacing: -.4px;
}
.brand b { color: var(--green); }
.brand-mark { width: 31px; height: 31px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
.brand-mark i { display: block; background: var(--green); }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { background: var(--lime); }
.topbar-actions { display: flex; gap: 8px; }
.account-button, .icon-button {
  min-height: 40px; border: 1px solid var(--line); border-radius: 999px;
  background: rgba(255,255,255,.55); cursor: pointer;
}
.account-button {
  display: flex; align-items: center; gap: 8px; padding: 0 15px;
  font-size: 13px; font-weight: 600;
}
.account-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--lime);
  box-shadow: 0 0 0 3px rgba(205,234,61,.25);
}
.icon-button { width: 40px; }
main { flex: 1; }

.setup-view { display: grid; gap: 28px; padding: 64px 0 48px; }
.setup-copy { max-width: 620px; }
.eyebrow {
  margin: 0 0 18px; color: var(--green);
  font: 500 11px/1 "DM Mono", monospace; letter-spacing: .16em;
}
.setup-copy h1 {
  margin: 0; font-size: clamp(49px, 11vw, 88px); line-height: .93;
  letter-spacing: -.075em; font-weight: 600;
}
.setup-copy h1 em { color: var(--green); font-weight: 400; font-style: italic; }
.intro {
  max-width: 480px; margin: 26px 0 0; color: var(--muted);
  font-size: 15px; line-height: 1.65;
}
.setup-card {
  padding: 24px; border: 1px solid rgba(210,219,211,.9); border-radius: 18px;
  background: rgba(255,255,255,.62); box-shadow: var(--shadow); backdrop-filter: blur(16px);
}
.setup-section + .setup-section {
  padding-top: 26px; margin-top: 25px; border-top: 1px solid var(--line);
}
.section-heading { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 20px; }
.section-heading > span {
  color: var(--green); font: 500 10px "DM Mono", monospace; padding-top: 5px;
}
.section-heading h2 { margin: 0 0 3px; font-size: 17px; letter-spacing: -.03em; }
.section-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.difficulty-list {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0; border: 0; margin: 0;
}
.difficulty-list label {
  position: relative; min-height: 68px; display: grid; grid-template-columns: 20px 1fr;
  grid-template-rows: auto auto; column-gap: 10px; align-items: center; padding: 12px;
  border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.5);
  cursor: pointer; transition: .18s ease;
}
.difficulty-list input { position: absolute; opacity: 0; }
.difficulty-list .check {
  grid-row: 1 / 3; width: 18px; height: 18px; border: 1.5px solid #9aa59e; border-radius: 4px;
}
.difficulty-list label > span:nth-of-type(2) { font-size: 13px; font-weight: 600; }
.difficulty-list small { color: var(--muted); font-size: 10px; }
.difficulty-list label.selected { border-color: var(--green); background: var(--soft-green); }
.difficulty-list label.selected .check {
  display: grid; place-items: center; border-color: var(--green); background: var(--green);
}
.difficulty-list label.selected .check::after { content: "✓"; color: white; font-size: 11px; }
.size-picker {
  display: grid; grid-template-columns: repeat(5, 1fr); padding: 4px;
  border-radius: 10px; background: #edf1ec;
}
.size-picker button {
  min-height: 42px; padding: 4px; border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); font: 500 12px "DM Mono", monospace; cursor: pointer;
}
.size-picker button.active {
  background: var(--surface); color: var(--green); box-shadow: 0 3px 10px rgba(30,62,42,.1);
}
.primary-button, .secondary-button, .continue-button {
  width: 100%; min-height: 54px; border: 0; border-radius: 9px; cursor: pointer;
}
.primary-button {
  display: flex; align-items: center; justify-content: space-between; margin-top: 22px;
  padding: 0 21px; background: var(--green); color: white; font-weight: 600;
}
.primary-button:hover { background: #17452f; }
.primary-button span { color: var(--lime); font-size: 22px; }
.continue-button {
  display: grid; grid-template-columns: 1fr auto; align-items: center; margin-top: 10px;
  padding: 8px 18px; border: 1px solid var(--green); background: transparent;
  color: var(--green); text-align: left; font-weight: 600;
}
.continue-button small { color: var(--muted); font-weight: 400; }
.guest-note { display: flex; gap: 12px; align-items: flex-start; padding: 0 6px; color: var(--muted); }
.guest-note > span {
  width: 23px; height: 23px; flex: 0 0 auto; display: grid; place-items: center;
  border-radius: 50%; background: var(--soft-green); color: var(--green); font-size: 12px;
}
.guest-note p { margin: 0; font-size: 11px; line-height: 1.55; }
.guest-note b { color: var(--ink); font-size: 12px; }
.app-footer {
  display: flex; justify-content: space-between; padding: 22px 0 28px;
  border-top: 1px solid var(--line); color: var(--muted);
  font: 400 9px "DM Mono", monospace; letter-spacing: .04em;
}

.game-view { width: min(760px, 100%); margin: 0 auto; padding: 28px 0 50px; }
.game-heading {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-bottom: 22px;
}
.game-meta { display: flex; align-items: center; gap: 12px; font-size: 12px; }
.game-meta strong { font: 500 15px "DM Mono", monospace; }
.game-meta span:first-child {
  padding: 5px 9px; border-radius: 999px; background: var(--soft-green);
  color: var(--green); text-transform: capitalize;
}
.game-meta span:last-child { color: var(--muted); }
.text-button { border: 0; background: transparent; font-size: 12px; cursor: pointer; }
#restartButton { justify-self: end; }
.board-wrap {
  width: min(100%, 610px); margin: 0 auto; padding: 10px;
  border-radius: 14px; background: #dfe6de;
}
.sudoku-board {
  --size: 9; display: grid; grid-template-columns: repeat(var(--size), 1fr);
  overflow: hidden; border: 2px solid var(--ink); background: var(--ink);
  gap: 1px; aspect-ratio: 1;
}
.cell {
  position: relative; display: grid; place-items: center; min-width: 0; padding: 0;
  border: 0; background: var(--surface); color: var(--green);
  font: 500 clamp(11px, calc(34vw / var(--size)), 29px) "DM Mono", monospace; cursor: pointer;
}
.cell.box-right { border-right: 2px solid var(--ink); }
.cell.box-bottom { border-bottom: 2px solid var(--ink); }
.cell.given { color: var(--ink); font-weight: 600; }
.cell.peer { background: #eef3ec; }
.cell.same { background: #e1ebdf; }
.cell.selected { background: var(--lime); color: var(--ink); }
.cell.wrong { color: var(--danger); background: #f7e8e5; }
.mistake-notice {
  width: min(100%, 610px); margin: 10px auto -6px; padding: 10px 13px;
  border: 1px solid rgba(179,77,67,.24); border-radius: 8px;
  background: #f7e8e5; color: var(--danger); font-size: 12px; text-align: center;
}
.notes {
  position: absolute; inset: 3px; display: grid; grid-template-columns: repeat(var(--note-cols), 1fr);
  align-items: center; font-size: clamp(5px, calc(17vw / var(--size)), 10px);
  color: var(--muted); line-height: 1;
}
.notes i { font-style: normal; text-align: center; }
.game-tools { width: min(100%, 610px); margin: 18px auto 0; }
.number-pad {
  display: grid; grid-template-columns: repeat(var(--pad-cols), 1fr); gap: 6px;
}
.number-pad button {
  min-height: 44px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--green);
  font: 500 16px "DM Mono", monospace; cursor: pointer;
}
.number-pad button:active { transform: translateY(1px); background: var(--soft-green); }
.tool-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.tool-row button {
  min-height: 46px; border: 1px solid var(--line); border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.tool-row button.active { border-color: var(--green); background: var(--soft-green); color: var(--green); }

.modal {
  width: min(430px, calc(100% - 28px)); padding: 32px; border: 1px solid var(--line);
  border-radius: 18px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(15,31,21,.5); backdrop-filter: blur(4px); }
.modal-close {
  position: absolute; top: 14px; right: 14px; width: 34px; height: 34px;
  border: 0; border-radius: 50%; background: var(--paper); cursor: pointer; font-size: 20px;
}
.modal h2 { margin: 0; font-size: 30px; letter-spacing: -.05em; }
.modal-copy { color: var(--muted); font-size: 13px; line-height: 1.55; }
.modal form { margin-top: 24px; }
.modal label { display: grid; gap: 7px; margin-top: 13px; font-size: 11px; font-weight: 600; }
.modal input {
  width: 100%; height: 45px; padding: 0 13px; border: 1px solid var(--line);
  border-radius: 8px; background: white; outline: none;
}
.modal input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(34,86,60,.1); }
.form-error { min-height: 18px; margin: 10px 0 -8px; color: var(--danger); font-size: 11px; }
.auth-switch { width: 100%; margin-top: 18px; border: 0; background: transparent; font-size: 12px; cursor: pointer; }
.auth-switch b { color: var(--green); }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 28px 0; }
.stats-grid div {
  display: grid; gap: 4px; padding: 16px 8px; border-radius: 10px;
  background: var(--paper); text-align: center;
}
.stats-grid strong { font: 500 22px "DM Mono", monospace; }
.stats-grid span { color: var(--muted); font-size: 10px; }
.preference-section { padding: 0; margin: 0 0 24px; border: 0; }
.preference-section legend { padding: 0; font-size: 13px; font-weight: 700; }
.preference-section > p {
  margin: 5px 0 12px; color: var(--muted); font-size: 11px; line-height: 1.45;
}
.feedback-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.feedback-options label { position: relative; margin: 0; cursor: pointer; }
.feedback-options input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.feedback-options label > span {
  min-height: 68px; display: flex; flex-direction: column; justify-content: center;
  gap: 4px; padding: 9px 7px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--paper); text-align: center; transition: .18s ease;
}
.feedback-options small { color: var(--muted); font-size: 9px; font-weight: 400; line-height: 1.25; }
.feedback-options input:checked + span {
  border-color: var(--green); background: var(--soft-green); color: var(--green);
  box-shadow: inset 0 0 0 1px var(--green);
}
.feedback-options input:focus-visible + span {
  outline: 3px solid rgba(34,86,60,.18); outline-offset: 2px;
}
.preference-section > .preference-status {
  min-height: 16px; margin: 7px 0 0; color: var(--green); text-align: right;
}
.secondary-button { border: 1px solid var(--line); background: transparent; }
.win-modal { text-align: center; }
.win-modal .primary-button { text-align: left; }

@media (min-width: 760px) {
  .app-shell { padding: 0 34px; }
  .setup-view {
    grid-template-columns: minmax(0, 1.12fr) minmax(410px, .88fr);
    grid-template-rows: auto auto; align-items: center;
    min-height: calc(100vh - 144px); padding: 52px 0;
  }
  .setup-card { grid-column: 2; grid-row: 1 / 3; padding: 30px; }
  .setup-copy { grid-column: 1; grid-row: 1; align-self: end; padding-bottom: 20px; }
  .guest-note { grid-column: 1; grid-row: 2; align-self: start; max-width: 380px; }
}

@media (max-width: 520px) {
  .topbar { height: 66px; }
  .setup-view { padding-top: 40px; }
  .difficulty-list { grid-template-columns: 1fr; }
  .difficulty-list label { min-height: 58px; }
  .size-picker button { font-size: 10px; }
  .app-footer span:last-child { display: none; }
  .game-heading { margin-bottom: 14px; }
  .game-meta { gap: 7px; font-size: 10px; }
  .board-wrap { padding: 5px; border-radius: 8px; }
  .game-tools {
    position: sticky; bottom: 0; z-index: 4; margin-top: 10px;
    padding: 8px 0 max(8px, env(safe-area-inset-bottom));
    background: linear-gradient(transparent, var(--paper) 12%);
  }
  .number-pad { gap: 4px; }
  .number-pad button { min-height: 39px; font-size: 14px; }
}
