/*
 * Sudoku for MRBD — "pencil & grid" design system.
 * Flat surfaces, square corners, no glow. Focus = solid amber fill with
 * black text (highest possible contrast on an additive display).
 */

@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('fonts/SpaceGrotesk.woff2') format('woff2');
}

:root {
  --bg: #000000; /* pure black = transparent on additive display */
  --surface: #0c0c12;
  --surface-2: #15151d;
  --surface-3: #1e1e28;
  --line: #26262f;
  --line-strong: #4a4a58;
  --ink: #ffffff;
  --ink-2: #9b9ba8;
  --ink-3: #5c5c6a;
  --accent: #ffc233;
  --accent-dim: rgba(255, 194, 51, 0.14);
  --error: #ff5468;
  --error-dim: rgba(255, 84, 104, 0.16);
  --ok: #7dff9b;
  --ease-out: cubic-bezier(0.2, 0.6, 0.3, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 600px;
  height: 600px;
  overflow: hidden;
  background: var(--bg);
}

body {
  font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--ink);
}

#app { width: 100%; height: 100%; position: relative; }

.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0; left: 0;
  padding: 8px; /* safe margin */
}
.screen.hidden { display: none; }
.hidden { display: none !important; }

button {
  font-family: inherit;
  background: none;
  border: none;
  color: inherit;
}

.icon {
  width: 22px;
  height: 22px;
  display: block;
  flex-shrink: 0;
}

/* ============ FOCUS ============ */
.focusable {
  cursor: pointer;
  border: 2px solid var(--line);
  transition: background 140ms var(--ease-out),
              border-color 140ms var(--ease-out),
              color 140ms var(--ease-out);
}
.focusable:focus,
.focusable.kfocus {
  outline: none;
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #000000 !important;
}
.focusable:focus *,
.focusable.kfocus * {
  color: #000000 !important;
}

/* ============ HOME ============ */
.home-header {
  padding: 30px 20px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.logo-row {
  display: flex;
  align-items: center;
  gap: 18px;
}
.logo-grid {
  display: grid;
  grid-template-columns: repeat(3, 14px);
  grid-template-rows: repeat(3, 14px);
  gap: 3px;
}
.logo-grid span {
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
}
.logo-grid span.on { background: var(--accent); border-color: var(--accent); }
.home-title {
  font-size: 46px;
  font-weight: 700;
  letter-spacing: 12px;
  margin-right: -12px;
  line-height: 1;
}
.home-tagline {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--ink-3);
}

.menu-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 96px;
  justify-content: center;
}
.menu-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 62px;
  padding: 10px 22px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}
.menu-btn-label {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 4px;
  text-transform: uppercase;
}
.menu-btn-meta {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-2);
  text-align: right;
  line-height: 1.35;
}
.menu-btn.primary { border-color: var(--accent); }
.menu-btn.primary .menu-btn-label { color: var(--accent); }

.hint-bar {
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 1px;
  color: var(--ink-3);
  padding: 8px 0 4px;
}

/* ============ GAME HEADER ============ */
.game-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px 8px;
  flex-shrink: 0;
}
.hdr-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 8px 16px;
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
}
.hdr-btn.notes-on { color: var(--accent); border-color: var(--accent); }
.hdr-stat {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--ink-2);
  text-transform: uppercase;
}
#hdr-difficulty { margin-left: auto; color: var(--ink); }
.hdr-mistakes { color: var(--error); }
.hdr-timer {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  min-width: 62px;
  text-align: right;
}

/* ============ BOARD ============ */
.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.board {
  display: grid;
  grid-template-columns: repeat(9, 56px);
  grid-template-rows: repeat(9, 56px);
  border: 3px solid var(--line-strong);
  background: var(--line);
}
.cell {
  position: relative;
  width: 56px;
  height: 56px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms var(--ease-out), box-shadow 120ms var(--ease-out);
  cursor: pointer;
}
.cell.box-alt { background: #111119; }
.cell.br { border-right: 3px solid var(--line-strong); }
.cell.bb { border-bottom: 3px solid var(--line-strong); }
.cell:nth-child(9n) { border-right: none; }
.cell:nth-child(n+73) { border-bottom: none; }

.cell .cv {
  font-size: 30px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1;
}
.cell.user .cv { color: var(--accent); font-weight: 700; }
.cell.error .cv { color: var(--error); font-weight: 700; }
.cell.error { background: var(--error-dim); }

.cell .cn {
  position: absolute;
  inset: 2px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}
.cell .cn span {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* highlights */
.cell.peer { background: #191922; }
.cell.peer.box-alt { background: #1d1d27; }
.cell.same { background: var(--accent-dim); }
.cell.same .cv { color: var(--accent); }
.cell.cursor {
  background: var(--accent-dim);
  box-shadow: inset 0 0 0 3px var(--accent);
  z-index: 2;
}
.cell.cursor .cv { color: var(--accent); }
.cell.cursor.error {
  background: var(--error-dim);
  box-shadow: inset 0 0 0 3px var(--error);
}
.cell.cursor.error .cv { color: var(--error); }

@keyframes pop {
  0% { transform: scale(0.5); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
.cell.pop .cv { animation: pop 180ms var(--ease-out); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.cell.shake { animation: shake 160ms ease-in-out 2; }

/* ============ OVERLAYS ============ */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(3, 3, 6, 0.86);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.overlay > * { animation: modal-in 200ms var(--ease-out); }
@keyframes modal-in {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---- number picker ---- */
.picker-panel {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: 10px 10px 0 rgba(255, 194, 51, 0.08);
  padding: 18px;
}
.picker-title {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 14px;
}
.picker-title.notes-on { color: var(--accent); }
.picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 88px);
  grid-auto-rows: 72px;
  gap: 6px;
}
.pk {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 2px solid var(--line);
  color: var(--ink);
  font-size: 30px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms var(--ease-out),
              border-color 120ms var(--ease-out),
              color 120ms var(--ease-out);
}
.pk:focus,
.pk.kfocus {
  outline: none;
  background: var(--accent);
  border-color: var(--accent);
  color: #000000;
}
.pk.pk-action { color: var(--ink-2); }
.pk.pk-action .icon { width: 26px; height: 26px; }
.pk.pk-noted { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.pk.complete { opacity: 0.3; }
.pk.notes-on { border-color: var(--accent); color: var(--accent); }

/* ---- modal (pause / win) ---- */
.modal-panel {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: 10px 10px 0 rgba(255, 194, 51, 0.08);
  padding: 26px;
  width: 372px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modal-title {
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 6px;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.modal-panel .menu-btn { min-height: 60px; }
.win-panel { align-items: stretch; text-align: center; }
.win-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 6px;
  color: var(--accent);
}
.win-stats {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
}
.win-stats #win-time {
  font-size: 38px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.win-stats #win-detail {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 1px;
  color: var(--ink-2);
}

/* ---- loading ---- */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.loading-grid {
  display: grid;
  grid-template-columns: repeat(3, 16px);
  grid-template-rows: repeat(3, 16px);
  gap: 4px;
}
.loading-grid span {
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  animation: cell-blink 0.9s infinite;
}
.loading-grid span:nth-child(1) { animation-delay: 0s; }
.loading-grid span:nth-child(2) { animation-delay: 0.1s; }
.loading-grid span:nth-child(3) { animation-delay: 0.2s; }
.loading-grid span:nth-child(6) { animation-delay: 0.3s; }
.loading-grid span:nth-child(9) { animation-delay: 0.4s; }
.loading-grid span:nth-child(8) { animation-delay: 0.5s; }
.loading-grid span:nth-child(7) { animation-delay: 0.6s; }
.loading-grid span:nth-child(4) { animation-delay: 0.7s; }
.loading-grid span:nth-child(5) { animation-delay: 0.8s; }
@keyframes cell-blink {
  0%, 100% { background: var(--surface-3); border-color: var(--line-strong); }
  40% { background: var(--accent); border-color: var(--accent); }
}
.loading-text {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--ink-2);
}

/* ============ TOAST ============ */
.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-90px);
  background: var(--surface-2);
  color: var(--ink);
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--accent);
  transition: transform 0.3s var(--ease-out);
  z-index: 100;
  pointer-events: none;
  max-width: 536px;
}
.toast.visible { transform: translateX(-50%) translateY(0); }
.toast.error { border-left-color: var(--error); }
.toast.success { border-left-color: var(--ok); }
