:root {
  --background: #f4f6f7;
  --surface: #ffffff;
  --surface-strong: #eef4f3;
  --ink: #1f2933;
  --muted: #66717d;
  --line: #d9e1e7;
  --line-strong: #1f2933;
  --accent: #0f766e;
  --accent-dark: #0a5f59;
  --accent-soft: #dff3f0;
  --focus: rgba(15, 118, 110, 0.26);
  --danger: #b84632;
  --danger-soft: #fff0ec;
  --warn: #d28b16;
  --shadow: 0 12px 28px rgba(30, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--background);
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button,
input,
select {
  border-radius: 8px;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 0.65rem 0.85rem;
  touch-action: manipulation;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 0.7rem 0.75rem;
}

.app-shell {
  width: min(100%, 1160px);
  margin: 0 auto;
  padding: 0.8rem;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0 0.85rem;
}

.app-header h1 {
  margin: 0;
  font-size: 1.9rem;
  line-height: 1;
}

.public-stats {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.45rem;
}

.header-actions button {
  min-height: 36px;
  padding: 0.45rem 0.65rem;
  font-size: 0.88rem;
  font-weight: 750;
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.copy,
.form-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.landing-page {
  display: grid;
  justify-items: center;
  padding: 0.5rem 0 1.2rem;
}

.landing-card {
  display: grid;
  gap: 1rem;
  width: min(100%, 34rem);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.landing-card h2,
.recovery-panel h2 {
  margin: 0;
  line-height: 1.1;
}

.landing-card > h2 {
  font-size: 1.55rem;
}

.form-grid,
.recover-form,
.recovery-panel {
  display: grid;
  gap: 0.75rem;
}

.recovery-panel {
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.field {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
}

.field span,
.mode-field legend {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 750;
}

.mode-field {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  border: 1px solid var(--line);
  padding: 0.7rem;
}

.mode-field label {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.1rem 0.5rem;
  align-items: start;
}

.mode-field input {
  grid-row: span 2;
  width: 1rem;
  min-height: 1rem;
  margin-top: 0.25rem;
}

.mode-field span {
  font-weight: 800;
}

.mode-field small {
  color: var(--muted);
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.primary-button:hover {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.puzzle-page {
  display: grid;
  gap: 0.75rem;
}

.puzzle-banner {
  display: grid;
  gap: 0.8rem;
  border: 1px solid var(--accent-dark);
  background: var(--accent);
  color: #ffffff;
  box-shadow: var(--shadow);
  padding: 0.9rem;
}

.puzzle-banner .eyebrow,
.puzzle-banner .copy {
  color: rgba(255, 255, 255, 0.86);
}

.puzzle-banner h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.1;
}

.banner-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.banner-actions button {
  min-height: 38px;
  padding: 0.45rem 0.5rem;
  font-size: 0.85rem;
  font-weight: 800;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.stats-strip div {
  display: grid;
  gap: 0.1rem;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 0.55rem 0.65rem;
}

.stats-strip span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stats-strip strong {
  overflow-wrap: anywhere;
  font-size: 1rem;
}

.connection-status {
  min-height: 1.2rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.connection-status.is-error {
  color: var(--danger);
}

.game-layout {
  display: grid;
  gap: 0.8rem;
}

.board-wrap {
  display: grid;
  justify-items: center;
  width: 100%;
  min-width: 0;
}

.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: min(100%, 36rem);
  aspect-ratio: 1;
  border: 3px solid var(--line-strong);
  background: var(--line-strong);
  box-shadow: var(--shadow);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-right: 1px solid #aebac4;
  border-bottom: 1px solid #aebac4;
  border-radius: 0;
  background: var(--surface);
  color: #24313d;
  padding: 0;
  font-size: clamp(1.25rem, 7vw, 2rem);
  font-weight: 650;
  line-height: 1;
}

.cell:nth-child(3n) {
  border-right-width: 3px;
  border-right-color: var(--line-strong);
}

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

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

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

.cell.is-given {
  background: #f3f6f8;
  color: #111827;
  font-weight: 900;
}

.cell.is-peer,
.cell.is-related {
  background: #edf7f5;
}

.cell.is-same-number {
  background: #dcefed;
}

.cell.is-selected {
  z-index: 1;
  background: #cae7e3;
  box-shadow: inset 0 0 0 3px var(--accent);
}

.cell.is-mistake {
  background: var(--danger-soft);
  color: var(--danger);
}

.cell.is-selected.is-mistake {
  box-shadow: inset 0 0 0 3px var(--danger);
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 90%;
  height: 90%;
  color: var(--muted);
  font-size: clamp(0.45rem, 2.6vw, 0.72rem);
  font-weight: 800;
  line-height: 1;
}

.notes-grid span {
  display: grid;
  place-items: center;
}

.controls-panel {
  display: grid;
  gap: 0.65rem;
  align-content: start;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 0.75rem;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  background: var(--surface-strong);
}

.segmented-control button {
  min-height: 38px;
  border-color: transparent;
  background: transparent;
  font-weight: 800;
}

.segmented-control button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--surface);
  color: var(--accent-dark);
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 0.35rem;
}

.number-pad button {
  min-width: 0;
  min-height: 46px;
  padding: 0;
  font-size: 1.1rem;
  font-weight: 900;
}

.number-pad button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

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

.tool-grid button {
  min-width: 0;
  padding: 0.55rem 0.4rem;
  font-size: 0.9rem;
  font-weight: 750;
}

.check-toggle {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 750;
}

.check-toggle input {
  width: 1.1rem;
  min-height: 1.1rem;
}

.share-note {
  display: grid;
  gap: 0.45rem;
  border-top: 1px solid var(--line);
  padding-top: 0.65rem;
}

.share-note h3 {
  margin: 0;
  font-size: 0.96rem;
}

.share-note p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.modal-dialog {
  width: min(92vw, 31rem);
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
}

.modal-dialog::backdrop {
  background: rgba(31, 41, 51, 0.42);
}

.modal-card {
  display: grid;
  gap: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.modal-header h2,
.modal-card h2 {
  margin: 0;
  font-size: 1.25rem;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.recent-list {
  display: grid;
  gap: 0.5rem;
}

.recent-link {
  display: grid;
  gap: 0.15rem;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--ink);
  padding: 0.65rem;
  text-decoration: none;
}

.recent-link strong {
  font-size: 0.98rem;
}

.recent-link span {
  color: var(--muted);
  font-size: 0.84rem;
}

.pause-overlay {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(244, 246, 247, 0.86);
  padding: 1rem;
}

.pause-card {
  display: grid;
  gap: 0.7rem;
  width: min(92vw, 22rem);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 1rem;
  text-align: center;
}

.pause-card h2 {
  margin: 0;
}

@media (min-width: 760px) {
  .app-shell {
    padding: 1.2rem;
  }

  .app-header h1 {
    font-size: 2.35rem;
  }

  .puzzle-banner {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .banner-actions {
    width: 18rem;
  }

  .stats-strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr) minmax(17rem, 21rem);
    align-items: start;
  }

  .number-pad {
    grid-template-columns: repeat(3, 1fr);
  }

  .number-pad button {
    min-height: 54px;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding: 0.5rem;
  }

  .tool-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .banner-actions,
  .modal-actions {
    grid-template-columns: 1fr;
  }
}
