:root {
  --paper: #f2f5f7;
  --paper-deep: #e6ebee;
  --ink: #142b3a;
  --ink-soft: #536873;
  --blue: #08749a;
  --blue-pale: #dcebf0;
  --orange: #ef6b3c;
  --red: #c73d35;
  --white: #fbfcfc;
  --line: #b9c7cd;
  --shadow: 0 20px 60px rgba(20, 43, 58, .12);
  --sans: Bahnschrift, "Arial Narrow", Arial, sans-serif;
  --body: Aptos, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--body);
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(8, 116, 154, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(8, 116, 154, .035) 1px, transparent 1px);
  background-size: 24px 24px;
}

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(239, 107, 60, .5); outline-offset: 3px; }

.topbar {
  height: 76px;
  padding: 0 clamp(20px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(242, 245, 247, .9);
  backdrop-filter: blur(12px);
  position: relative;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--sans);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .14em;
}

.brand-mark {
  display: grid;
  grid-template-columns: 8px 8px;
  gap: 2px;
  transform: rotate(45deg);
}

.brand-mark i { width: 8px; height: 8px; background: var(--blue); }
.brand-mark i:nth-child(2) { background: var(--orange); }

.top-actions { display: flex; align-items: center; gap: 22px; }
.save-status { color: var(--ink-soft); font-size: 13px; }
.profile-button {
  border: 0;
  background: transparent;
  padding: 5px;
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--sans);
  font-weight: 700;
  cursor: pointer;
}

.avatar {
  width: 34px;
  height: 34px;
  border: 1px solid var(--ink);
  display: grid;
  place-items: center;
  background: var(--white);
  font-size: 14px;
}

.game-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: clamp(42px, 6vw, 82px) 0 70px;
  display: grid;
  grid-template-columns: minmax(460px, 620px) minmax(270px, 340px);
  justify-content: space-between;
  gap: clamp(48px, 8vw, 110px);
}

.game-heading { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 28px; }
.eyebrow, .modal-kicker {
  margin: 0 0 10px;
  color: var(--blue);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: var(--sans);
  font-size: clamp(36px, 5vw, 61px);
  line-height: .91;
  letter-spacing: -.055em;
  text-transform: uppercase;
}

h1 span { color: var(--blue); }

.timer-block {
  min-width: 116px;
  display: grid;
  grid-template-columns: 1fr 30px;
  align-items: center;
  column-gap: 9px;
  padding-bottom: 3px;
}

.timer-block > span { grid-column: 1 / -1; color: var(--ink-soft); font-family: var(--sans); font-size: 10px; letter-spacing: .16em; }
.timer-block strong { font-family: var(--sans); font-size: 25px; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.icon-button { width: 30px; height: 30px; padding: 5px; border: 1px solid var(--line); background: transparent; cursor: pointer; }
.icon-button svg { fill: none; stroke: currentColor; stroke-width: 2; }

.board-wrap { position: relative; box-shadow: var(--shadow); }
.sudoku-board {
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  border: 3px solid var(--ink);
  background: var(--white);
  user-select: none;
}

.sudoku-board.is-loading { opacity: .45; pointer-events: none; }
.cell {
  position: relative;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--white);
  color: var(--blue);
  font-family: var(--sans);
  font-size: clamp(19px, 3vw, 31px);
  font-weight: 650;
  cursor: pointer;
  transition: background-color .12s ease, color .12s ease;
}

.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.fixed { color: var(--ink); font-weight: 800; cursor: default; }
.cell.peer { background: #edf3f5; }
.cell.same { background: #d8e9ee; }
.cell.selected { background: var(--orange); color: var(--white); }
.cell.error { color: var(--red); background: #f8e1dd; }
.cell.selected.error { color: var(--white); background: var(--red); }
.cell:disabled { opacity: 1; }

.notes-grid {
  position: absolute;
  inset: 4px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  font-family: var(--body);
  font-size: clamp(7px, 1vw, 11px);
  font-weight: 700;
  color: var(--blue);
}

.notes-grid i { font-style: normal; min-height: 1em; }
.pause-screen {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  background: rgba(242, 245, 247, .96);
}
.pause-screen[hidden] { display: none; }
.pause-glyph { font-family: var(--sans); color: var(--blue); font-size: 50px; letter-spacing: 8px; }
.pause-screen strong { font-family: var(--sans); font-size: 22px; text-transform: uppercase; }

.number-pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 7px; margin-top: 18px; }
.number-button {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  background: rgba(251, 252, 252, .75);
  font-family: var(--sans);
  font-size: clamp(18px, 2vw, 24px);
  font-weight: 700;
  cursor: pointer;
}
.number-button:hover { border-color: var(--blue); color: var(--blue); }
.number-button.completed { opacity: .28; pointer-events: none; }

.tool-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.tool-button {
  min-height: 52px;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 12px;
  cursor: pointer;
}
.tool-button span { color: var(--ink); font-size: 21px; }
.tool-button b { padding: 2px 4px; background: var(--paper-deep); font-size: 8px; text-transform: uppercase; }
.tool-button.active { color: var(--blue); background: var(--blue-pale); }
.tool-button:disabled { opacity: .35; cursor: default; }

.side-panel { padding-top: 110px; }
.difficulty-section, .session-card { border-top: 3px solid var(--ink); }
.section-label, .session-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 0;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .14em;
}
.section-label button { border: 0; background: none; color: var(--blue); font-size: 10px; font-weight: 800; text-transform: uppercase; cursor: pointer; }
.difficulty-switch { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); }
.difficulty-switch button { padding: 12px 5px; border: 0; border-right: 1px solid var(--line); background: var(--white); font-size: 12px; cursor: pointer; }
.difficulty-switch button:last-child { border-right: 0; }
.difficulty-switch button.active { color: var(--white); background: var(--ink); font-weight: 700; }

.session-card { margin-top: 44px; }
.session-card-head { border-bottom: 1px solid var(--line); }
.live-dot { color: var(--orange); font-size: 8px; }
.live-dot::before { content: ''; display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: var(--orange); }
.session-card dl { margin: 0; }
.session-card dl div { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 0; border-bottom: 1px solid var(--line); }
.session-card dt { color: var(--ink-soft); font-size: 13px; }
.session-card dd { margin: 0; font-family: var(--sans); font-weight: 700; }
.session-card dd strong { color: var(--orange); font-size: 21px; }
.session-card dd span { color: var(--ink-soft); font-family: var(--body); font-size: 11px; font-weight: 400; }
.progress-track { height: 4px; margin-top: 14px; background: var(--paper-deep); }
.progress-track i { display: block; width: 0; height: 100%; background: var(--blue); transition: width .3s ease; }

blockquote { margin: 52px 0 0; padding: 0 0 0 18px; border-left: 3px solid var(--orange); }
blockquote p { margin: 0 0 8px; font-family: var(--sans); font-size: 17px; line-height: 1.35; font-weight: 650; }
blockquote cite { color: var(--ink-soft); font-size: 11px; font-style: normal; }
.keyboard-help { margin-top: 48px; display: flex; flex-wrap: wrap; gap: 12px; color: var(--ink-soft); font-size: 10px; }
kbd { padding: 3px 5px; border: 1px solid var(--line); border-bottom-width: 2px; background: var(--white); color: var(--ink); font-family: var(--sans); }

dialog { color: var(--ink); }
dialog::backdrop { background: rgba(20, 43, 58, .56); backdrop-filter: blur(4px); }
.modal, .profile-drawer {
  width: min(440px, calc(100% - 28px));
  border: 0;
  padding: 42px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.modal-close { position: absolute; top: 14px; right: 16px; width: 34px; height: 34px; border: 0; background: transparent; font-size: 28px; cursor: pointer; }
.modal h2, .profile-drawer h2 { margin: 0; font-family: var(--sans); font-size: 29px; line-height: 1; text-transform: uppercase; }
.modal-copy { color: var(--ink-soft); line-height: 1.5; font-size: 14px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; margin: 25px 0; border-bottom: 1px solid var(--line); }
.auth-tabs button { padding: 11px; border: 0; border-bottom: 3px solid transparent; background: transparent; cursor: pointer; }
.auth-tabs button.active { border-color: var(--orange); font-weight: 700; }
form { display: grid; gap: 15px; }
form label { display: grid; gap: 6px; font-family: var(--sans); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
form input { width: 100%; height: 45px; border: 1px solid var(--line); padding: 0 12px; background: var(--white); color: var(--ink); font-family: var(--body); font-size: 16px; }
.form-warning { margin: -2px 0 0; padding: 9px; border-left: 2px solid var(--orange); background: rgba(239, 107, 60, .08); color: var(--ink-soft); font-size: 11px; line-height: 1.4; }
.form-error { min-height: 16px; margin: 0; color: var(--red); font-size: 12px; }
.primary-button, .secondary-button { min-height: 44px; padding: 0 18px; border: 0; font-family: var(--sans); font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; cursor: pointer; }
.primary-button { color: var(--white); background: var(--blue); }
.secondary-button { border: 1px solid var(--line); background: transparent; }
.wide { width: 100%; }

.profile-drawer { width: min(520px, calc(100% - 28px)); }
.profile-head { display: flex; align-items: center; gap: 17px; padding-bottom: 24px; border-bottom: 3px solid var(--ink); }
.profile-avatar { width: 64px; height: 64px; display: grid; place-items: center; color: var(--white); background: var(--blue); font-family: var(--sans); font-size: 28px; font-weight: 800; }
.profile-head p { margin: 0 0 5px; color: var(--blue); font-family: var(--sans); font-size: 9px; font-weight: 800; letter-spacing: .15em; }
.profile-head span:not(.profile-avatar) { color: var(--ink-soft); font-size: 11px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; margin: 25px 0 30px; border: 1px solid var(--line); }
.stat-grid div { padding: 18px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat-grid div:nth-child(2n) { border-right: 0; }
.stat-grid div:nth-child(n+3) { border-bottom: 0; }
.stat-grid strong, .stat-grid span { display: block; }
.stat-grid strong { font-family: var(--sans); font-size: 26px; }
.stat-grid span { color: var(--ink-soft); font-size: 11px; }
.profile-drawer h3 { margin: 22px 0 9px; font-family: var(--sans); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; }
.best-times { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.best-time { padding: 12px 7px; border-right: 1px solid var(--line); }
.best-time:last-child { border: 0; }
.best-time span, .best-time strong { display: block; }
.best-time span { color: var(--ink-soft); font-size: 10px; }
.best-time strong { margin-top: 3px; font-family: var(--sans); font-size: 16px; }
.recent-games { min-height: 45px; margin-bottom: 25px; }
.recent-row { display: grid; grid-template-columns: 1fr auto auto; gap: 14px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.recent-row span:first-child { font-weight: 700; }
.recent-row time { color: var(--ink-soft); }
.empty-note { color: var(--ink-soft); font-size: 12px; }

.result-modal { text-align: center; }
.result-mark { width: 82px; height: 82px; margin: 0 auto 22px; display: grid; place-items: center; border: 3px solid var(--ink); color: var(--orange); font-family: var(--sans); font-size: 20px; font-weight: 800; }
.result-modal h2 { margin-bottom: 12px; }
.result-stats { display: grid; grid-template-columns: 1fr 1fr; margin: 25px 0; border-block: 1px solid var(--line); }
.result-stats div { padding: 14px; }
.result-stats div:first-child { border-right: 1px solid var(--line); }
.result-stats span, .result-stats strong { display: block; }
.result-stats span { color: var(--ink-soft); font-size: 10px; }
.result-stats strong { font-family: var(--sans); font-size: 22px; }

.toast { position: fixed; left: 50%; bottom: 25px; z-index: 20; max-width: calc(100% - 30px); padding: 12px 18px; color: var(--white); background: var(--ink); font-size: 13px; transform: translate(-50%, 120px); transition: transform .25s ease; box-shadow: var(--shadow); }
.toast.visible { transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .game-shell { grid-template-columns: minmax(0, 620px); justify-content: center; }
  .side-panel { padding-top: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 30px; }
  .session-card { margin-top: 0; }
  blockquote, .keyboard-help { display: none; }
}

@media (max-width: 600px) {
  .topbar { height: 62px; padding: 0 14px; }
  .brand { font-size: 15px; letter-spacing: .1em; }
  .save-status { display: none; }
  .profile-button { font-size: 12px; }
  .game-shell { width: calc(100% - 20px); padding: 30px 0 40px; gap: 38px; }
  .game-heading { align-items: flex-end; margin: 0 5px 20px; }
  h1 { font-size: clamp(31px, 11vw, 47px); }
  .eyebrow { max-width: 150px; }
  .timer-block { min-width: 102px; }
  .timer-block strong { font-size: 20px; }
  .sudoku-board { border-width: 2px; }
  .cell:nth-child(9n+3), .cell:nth-child(9n+6) { border-right-width: 2px; }
  .cell:nth-child(n+19):nth-child(-n+27), .cell:nth-child(n+46):nth-child(-n+54) { border-bottom-width: 2px; }
  .number-pad { gap: 3px; margin-top: 10px; }
  .tool-row { gap: 0; }
  .tool-button { min-width: 0; padding: 2px; flex-direction: column; gap: 1px; font-size: 9px; }
  .tool-button span { font-size: 19px; }
  .side-panel { display: block; }
  .session-card { margin-top: 34px; }
  .modal, .profile-drawer { padding: 38px 22px 24px; }
}

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