/* =========================================================
   SUDOKU — STYLE SHEET
   Palette:  porcelain #F6F7FB · graphite #1B1F2A · indigo #4A5FFF
             coral #FF5C5C · jade #2FBF87 · amber #FFB020
   Typography: Outfit (display) · Inter (UI) · JetBrains Mono (numbers/code)
   ========================================================= */

:root {
  /* Color */
  --bg: #F6F7FB;
  --bg-elevated: #FFFFFF;
  --ink: #1B1F2A;
  --ink-soft: #5B6172;
  --ink-faint: #9AA0B0;
  --line: #E4E6F0;
  --line-strong: #C7CBE0;

  --accent: #4A5FFF;
  --accent-ink: #FFFFFF;
  --accent-soft: #E9EAFF;
  --accent-softer: #F3F3FF;

  --error: #FF5C5C;
  --error-soft: #FFE6E6;
  --success: #2FBF87;
  --success-soft: #E3FBF2;
  --amber: #FFB020;
  --amber-soft: #FFF3DD;

  --fixed-bg: #EDEFF7;
  --fixed-ink: #33384A;

  --block-alt: #FBFBFF;

  /* Typography */
  --font-display: 'Outfit', 'Inter', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', monospace;

  /* Shape & shadow */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(27, 31, 42, 0.06), 0 1px 1px rgba(27, 31, 42, 0.04);
  --shadow-md: 0 8px 24px rgba(27, 31, 42, 0.08), 0 2px 6px rgba(27, 31, 42, 0.04);
  --shadow-lg: 0 24px 64px rgba(27, 31, 42, 0.16), 0 8px 20px rgba(27, 31, 42, 0.08);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141C;
    --bg-elevated: #1B1E29;
    --ink: #F2F3F8;
    --ink-soft: #B0B4C4;
    --ink-faint: #6C7186;
    --line: #2A2D3C;
    --line-strong: #383C4F;

    --accent: #7C8CFF;
    --accent-soft: #262A4A;
    --accent-softer: #1E2138;

    --error: #FF7373;
    --error-soft: #3A2027;
    --success: #45D9A0;
    --success-soft: #17332A;
    --amber: #FFC24D;
    --amber-soft: #3A2E12;

    --fixed-bg: #232739;
    --fixed-ink: #E4E6F5;

    --block-alt: #191C28;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  height: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button {
  font-family: inherit;
  cursor: pointer;
}

ul { list-style: none; margin: 0; padding: 0; }

:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ========================= LAYOUT SHELL ========================= */

.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 4px 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand__mark {
  width: 38px;
  height: 38px;
  color: var(--accent);
  flex-shrink: 0;
}

.brand__text h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.brand__text span {
  font-size: 0.78rem;
  color: var(--ink-faint);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.topbar__stats {
  display: flex;
  gap: 10px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  box-shadow: var(--shadow-sm);
}

.stat svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
  flex-shrink: 0;
}

.stat#mistakesStat, .stat:nth-child(2) svg { color: var(--error); }
.stat:nth-child(3) svg { color: var(--amber); }

.icon-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.icon-btn svg { width: 20px; height: 20px; }

/* ========================= MAIN LAYOUT ========================= */

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 28px;
  align-items: start;
}

/* ---------- Panel ---------- */

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.panel__title {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  margin: 0 0 12px;
}

.difficulty {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.diff-btn {
  padding: 9px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.83rem;
  transition: all 0.18s var(--ease);
}

.diff-btn:hover { border-color: var(--line-strong); color: var(--ink); }

.diff-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 4px 12px rgba(74, 95, 255, 0.28);
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  color: var(--ink);
  font-weight: 600;
  font-size: 0.87rem;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease), border-color 0.15s var(--ease);
}

.btn svg { width: 17px; height: 17px; flex-shrink: 0; color: var(--ink-faint); }

.btn:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn--primary svg { color: var(--accent-ink); }
.btn--primary:hover { box-shadow: 0 8px 20px rgba(74, 95, 255, 0.3); }

.btn--ghost {
  background: transparent;
  border-style: dashed;
  color: var(--ink-soft);
}

.btn--small {
  padding: 8px 16px;
  font-size: 0.82rem;
  width: fit-content;
  align-self: center;
}

.btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.help-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 0.83rem;
  color: var(--ink-soft);
  line-height: 1.5;
}

.help-list li { padding-left: 14px; position: relative; }
.help-list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.55;
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--fixed-bg);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ---------- Board ---------- */

.board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.board {
  --cell: 58px;
  display: grid;
  grid-template-columns: repeat(9, var(--cell));
  grid-template-rows: repeat(9, var(--cell));
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 10px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--line);
  position: relative;
  gap: 0;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  cursor: pointer;
  position: relative;
  user-select: none;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}

/* thicker block borders */
.cell[data-col="0"] { border-left: 2px solid var(--line-strong); }
.cell[data-col="8"] { border-right: 2px solid var(--line-strong); }
.cell[data-row="0"] { border-top: 2px solid var(--line-strong); }
.cell[data-row="8"] { border-bottom: 2px solid var(--line-strong); }
.cell[data-col="2"], .cell[data-col="5"] { border-right: 2px solid var(--line-strong); }
.cell[data-row="2"], .cell[data-row="5"] { border-bottom: 2px solid var(--line-strong); }

.cell.is-alt-block { background: var(--block-alt); }

.cell.is-fixed {
  color: var(--fixed-ink);
  font-weight: 600;
  background: var(--fixed-bg);
}
.cell.is-fixed.is-alt-block { background: var(--fixed-bg); }

.cell.is-peer { background: var(--accent-softer); }
.cell.is-alt-block.is-peer { background: var(--accent-softer); }

.cell.is-same-value:not(.is-selected) { box-shadow: inset 0 0 0 1.5px var(--accent-soft); }

.cell.is-selected {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent);
  z-index: 2;
}
.cell.is-selected.is-fixed { background: var(--accent-soft); }

.cell.is-error {
  color: var(--error);
  background: var(--error-soft);
  animation: shake 0.4s var(--ease);
}

.cell.is-hint {
  animation: hint-pop 0.5s var(--ease);
}

.cell.is-complete-flash {
  animation: complete-flash 0.7s var(--ease);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

@keyframes hint-pop {
  0% { transform: scale(1); background: var(--amber-soft); }
  40% { transform: scale(1.14); background: var(--amber-soft); }
  100% { transform: scale(1); }
}

@keyframes complete-flash {
  0% { background: var(--success-soft); }
  100% { background: inherit; }
}

.cell:hover:not(.is-fixed):not(.is-selected) {
  background: var(--accent-softer);
}

/* ---------- Numpad (mobile-first quick entry) ---------- */

.numpad {
  display: none;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 420px;
}

.num-btn {
  padding: 12px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s var(--ease), background 0.12s var(--ease);
}

.num-btn:active { transform: scale(0.93); background: var(--accent-soft); }

.num-btn--erase svg { width: 18px; height: 18px; }

/* ========================= FOOTER ========================= */

.app-footer {
  text-align: center;
  padding: 18px 0 4px;
  font-size: 0.78rem;
  color: var(--ink-faint);
}

/* ========================= TOASTS ========================= */

.toast-stack {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 90;
  width: min(360px, 90vw);
  pointer-events: none;
}

.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in 0.3s var(--ease), toast-out 0.3s var(--ease) 2.4s forwards;
}

.toast::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.toast.is-error::before { background: var(--error); }
.toast.is-success::before { background: var(--success); }
.toast.is-info::before { background: var(--amber); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-8px); }
}

/* ========================= WIN MODAL ========================= */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 20, 28, 0.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--ease);
}

.modal-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  position: relative;
  width: min(420px, 92vw);
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: scale(0.9) translateY(20px);
  transition: transform 0.35s var(--ease);
}

.modal-overlay.is-open .modal {
  transform: scale(1) translateY(0);
}

.confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.modal__content {
  position: relative;
  z-index: 2;
  padding: 36px 28px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
}

.modal__badge {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--success-soft);
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: badge-pop 0.5s var(--ease) 0.1s both;
}

.modal__badge svg { width: 28px; height: 28px; }

@keyframes badge-pop {
  0% { transform: scale(0); }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.modal h2 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  margin: 0;
  line-height: 1.35;
}

.modal__meta {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.88rem;
  font-family: var(--font-mono);
}

.promo {
  width: 100%;
  background: var(--accent-softer);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.promo__label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}

.promo__code {
  display: flex;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.promo__char {
  display: inline-block;
  width: 24px;
  text-align: center;
  animation: char-decode 0.4s var(--ease) both;
}

@keyframes char-decode {
  0% { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ========================= RESPONSIVE ========================= */

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .panel {
    order: 2;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 16px 24px;
  }

  .panel__section { flex: 1 1 220px; }

  .board-wrap { order: 1; }
}

@media (max-width: 600px) {
  .app { padding: 14px 12px 28px; }

  .topbar__stats { display: none; }
  .icon-btn { display: flex; }

  .panel {
    display: none;
  }
  .panel.is-open {
    display: flex;
    flex-direction: column;
  }

  .board { --cell: min(9.6vw, 42px); padding: 6px; }
  .cell { font-size: 1.05rem; }

  .numpad { display: grid; }

  .brand__text h1 { font-size: 1.25rem; }
}

@media (max-width: 380px) {
  .board { --cell: min(9.2vw, 38px); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
