/* ============================================================
   SUDOKU - STYLESHEET
   Supports 4x4, 6x6, 9x9, 12x12, Responsive Grid & 4 Themes
   ============================================================ */

:root {
  --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", Monaco, Inconsolata, "Fira Code", monospace;

  /* Theme Cyber Neon (Default) */
  --bg-main: #0b1120;
  --bg-secondary: #131c31;
  --bg-card: #18233c;
  --border-color: rgba(56, 189, 248, 0.22);
  --border-thick: #38bdf8;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-color: #0284c7;
  --accent-glow: rgba(56, 189, 248, 0.4);

  /* Cell states */
  --cell-bg: #111a2e;
  --cell-border: rgba(148, 163, 184, 0.18);
  --fixed-color: #f1f5f9;
  --user-color: #38bdf8;
  --selected-bg: rgba(56, 189, 248, 0.28);
  --selected-border: #38bdf8;
  --related-bg: rgba(30, 41, 59, 0.65);
  --same-digit-bg: rgba(56, 189, 248, 0.18);
  --error-bg: rgba(239, 68, 68, 0.28);
  --error-text: #f87171;
  --note-color: #94a3b8;
  --note-highlight: #38bdf8;
}

/* Theme Paper / Light */
body.theme-paper {
  --bg-main: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-card: #ffffff;
  --border-color: #cbd5e1;
  --border-thick: #1e293b;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --accent-color: #2563eb;
  --accent-glow: rgba(37, 99, 235, 0.3);

  --cell-bg: #ffffff;
  --cell-border: #e2e8f0;
  --fixed-color: #0f172a;
  --user-color: #2563eb;
  --selected-bg: rgba(37, 99, 235, 0.16);
  --selected-border: #2563eb;
  --related-bg: #f1f5f9;
  --same-digit-bg: rgba(37, 99, 235, 0.12);
  --error-bg: rgba(239, 68, 68, 0.18);
  --error-text: #dc2626;
  --note-color: #64748b;
  --note-highlight: #2563eb;
}

/* Theme Warm Sepia */
body.theme-sepia {
  --bg-main: #fcf8ee;
  --bg-secondary: #f4ecdc;
  --bg-card: #fefcf6;
  --border-color: #d6c7b0;
  --border-thick: #78350f;
  --text-main: #3b2816;
  --text-muted: #8c7355;
  --accent-color: #b45309;
  --accent-glow: rgba(180, 83, 9, 0.3);

  --cell-bg: #fdfaf3;
  --cell-border: #e6dac8;
  --fixed-color: #3b2816;
  --user-color: #92400e;
  --selected-bg: rgba(180, 83, 9, 0.16);
  --selected-border: #b45309;
  --related-bg: #ede1cb;
  --same-digit-bg: rgba(180, 83, 9, 0.12);
  --error-bg: rgba(220, 38, 38, 0.18);
  --error-text: #b91c1c;
  --note-color: #8c7355;
  --note-highlight: #b45309;
}

/* Theme Nordic Slate */
body.theme-nordic {
  --bg-main: #181e29;
  --bg-secondary: #222a38;
  --bg-card: #283244;
  --border-color: rgba(125, 211, 252, 0.2);
  --border-thick: #38bdf8;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-color: #0ea5e9;
  --accent-glow: rgba(14, 165, 233, 0.35);

  --cell-bg: #1c2433;
  --cell-border: rgba(148, 163, 184, 0.16);
  --fixed-color: #ffffff;
  --user-color: #38bdf8;
  --selected-bg: rgba(14, 165, 233, 0.25);
  --selected-border: #38bdf8;
  --related-bg: rgba(40, 50, 68, 0.7);
  --same-digit-bg: rgba(14, 165, 233, 0.15);
  --error-bg: rgba(239, 68, 68, 0.25);
  --error-text: #f87171;
  --note-color: #94a3b8;
  --note-highlight: #38bdf8;
}

/* Base Reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-main);
  background-color: var(--bg-main);
  color: var(--text-main);
}

#app {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  max-width: 900px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ================= HEADER ================= */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  gap: 12px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.gry-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  transition: transform 0.15s ease, background 0.15s ease;
}

.gry-back:hover {
  background: var(--bg-secondary);
  transform: translateY(-1px);
}

.gry-back:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.logo-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.title-area h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 5px 9px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  border-color: var(--border-thick);
  transform: translateY(-1px);
}

/* ================= STATUS & INFO BAR ================= */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(19, 28, 49, 0.4);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.status-left, .status-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.timer-box {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.95rem;
  background: var(--bg-card);
  padding: 3px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.pause-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0 2px;
}

.mistakes-box {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.mistakes-box span {
  color: var(--error-text);
  font-family: var(--font-mono);
}

/* Hint Alert Banner */
.hint-banner {
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid var(--border-thick);
  color: var(--text-main);
  padding: 8px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  margin: 4px 16px 0 16px;
  border-radius: 8px;
  animation: pulse-hint 1.5s infinite ease-in-out;
  flex-shrink: 0;
}

.hint-banner.hidden {
  display: none !important;
}

@keyframes pulse-hint {
  0%, 100% { box-shadow: 0 0 10px rgba(56, 189, 248, 0.4); }
  50% { box-shadow: 0 0 4px rgba(56, 189, 248, 0.2); }
}

/* ================= GRID CONTAINER ================= */
.grid-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

#sudoku-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-size, 9), 1fr);
  grid-template-rows: repeat(var(--grid-size, 9), 1fr);
  width: min(88vw, 56vh);
  max-width: 540px;
  aspect-ratio: 1 / 1;
  background: var(--bg-card);
  border: 3px solid var(--border-thick);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  position: relative;
}

/* Adjust board size for 12x12 */
#sudoku-grid[data-size="12"] {
  width: min(92vw, 58vh);
  max-width: 580px;
}

/* Adjust board size for 4x4 */
#sudoku-grid[data-size="4"] {
  width: min(70vw, 42vh);
  max-width: 360px;
}

/* Pause Overlay */
.pause-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(11, 17, 32, 0.88);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 20;
}

.pause-overlay.hidden {
  display: none !important;
}

.pause-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-main);
}

/* ================= SUDOKU CELL ================= */
.sudoku-cell {
  background: var(--cell-bg);
  border: 1px solid var(--cell-border);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: background-color 0.12s ease;
  user-select: none;
}

.sudoku-cell.border-right-thick {
  border-right: 2.5px solid var(--border-thick) !important;
}

.sudoku-cell.border-bottom-thick {
  border-bottom: 2.5px solid var(--border-thick) !important;
}

/* Selection and Highlight States */
.sudoku-cell.selected {
  background: var(--selected-bg) !important;
  outline: 2.5px solid var(--selected-border);
  outline-offset: -2.5px;
  z-index: 5;
}

.sudoku-cell.related {
  background: var(--related-bg);
}

.sudoku-cell.same-digit {
  background: var(--same-digit-bg);
}

.sudoku-cell.conflict {
  background: var(--error-bg) !important;
  color: var(--error-text) !important;
}

.sudoku-cell.hint-pulse {
  animation: cell-hint-anim 1.2s ease-in-out;
}

@keyframes cell-hint-anim {
  0% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.08); filter: brightness(1.6); box-shadow: 0 0 12px var(--border-thick); z-index: 10; }
  100% { transform: scale(1); filter: brightness(1); }
}

/* Cell Digits */
.cell-digit {
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1;
}

.fixed-clue {
  color: var(--fixed-color);
  font-weight: 900;
}

.user-entry {
  color: var(--user-color);
  font-weight: 700;
}

/* Responsive font sizes per board dimension */
#sudoku-grid[data-size="4"] .cell-digit { font-size: clamp(2rem, 6vw, 3rem); }
#sudoku-grid[data-size="6"] .cell-digit { font-size: clamp(1.4rem, 4.5vw, 2.2rem); }
#sudoku-grid[data-size="9"] .cell-digit { font-size: clamp(1.15rem, 3.4vw, 1.75rem); }
#sudoku-grid[data-size="12"] .cell-digit { font-size: clamp(0.85rem, 2.4vw, 1.25rem); }

/* ================= PENCIL NOTES MINI-GRID ================= */
.cell-notes-grid {
  display: grid;
  width: 100%;
  height: 100%;
  padding: 1px;
}

.notes-grid-4 { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); }
.notes-grid-6 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); }
.notes-grid-9 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.notes-grid-12 { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(3, 1fr); }

.note-digit {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: clamp(0.55rem, 1.1vw, 0.72rem);
  font-weight: 600;
  color: var(--note-color);
  line-height: 1;
}

#sudoku-grid[data-size="12"] .note-digit {
  font-size: clamp(0.45rem, 0.9vw, 0.58rem);
}

.note-digit.note-highlight {
  color: var(--note-highlight);
  font-weight: 900;
  transform: scale(1.2);
}

/* ================= ACTION TOOLBAR ================= */
.action-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.tool-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.tool-btn:hover:not(:disabled) {
  border-color: var(--border-thick);
  transform: translateY(-1px);
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tool-btn.active {
  background: var(--accent-color);
  color: #ffffff;
  border-color: var(--border-thick);
  box-shadow: 0 0 10px var(--accent-glow);
}

.badge-pill {
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 800;
}

.badge-on { background: #10b981; color: #ffffff; }
.badge-off { background: rgba(148, 163, 184, 0.2); color: var(--text-muted); }

/* ================= NUMPAD ================= */
.numpad-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px 14px 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.numpad-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 8px;
  padding: 6px 0;
  width: 44px;
  height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.numpad-btn:hover:not(.completed) {
  border-color: var(--border-thick);
  background: rgba(56, 189, 248, 0.12);
  transform: translateY(-2px);
}

.numpad-num {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
}

.numpad-remain {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 700;
  margin-top: 2px;
}

.numpad-btn.completed {
  opacity: 0.28;
  cursor: default;
  border-color: transparent;
}

/* ================= MODALS ================= */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.active {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 22px;
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  z-index: 101;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 800;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-main);
}

/* Option Grids in Modals */
.select-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 10px;
}

.select-card-btn {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 10px;
  padding: 14px;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  transition: all 0.18s ease;
}

.select-card-btn:hover {
  border-color: var(--border-thick);
  transform: translateY(-2px);
  background: rgba(56, 189, 248, 0.08);
}

.card-title {
  font-size: 1rem;
  font-weight: 800;
}

.card-desc {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.35;
}

/* Win Modal Specifics */
.win-content {
  text-align: center;
  max-width: 420px;
}

.win-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

.win-stats-list {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px 16px;
  margin: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
}

.win-stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.win-stat-val {
  font-weight: 800;
  font-family: var(--font-mono);
}

.btn-primary {
  background: var(--accent-color);
  color: #ffffff;
  border: 1px solid var(--border-thick);
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 800;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

/* Rules list */
.rules-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rule-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px;
}

.rule-title {
  font-weight: 800;
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.rule-box p {
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px 0;
}

.stat-item-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.stat-num {
  font-size: 1.6rem;
  font-weight: 900;
  font-family: var(--font-mono);
}

.stat-lbl {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Confetti */
#confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 105;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  animation: fall linear forwards;
}

@keyframes fall {
  to { transform: translateY(105vh) rotate(720deg); }
}

/* ================= MOBILE OPTIMIZATIONS ================= */
@media (max-width: 600px) {
  header {
    padding: 8px 10px;
  }
  .title-area h1 {
    font-size: 0.95rem;
  }
  .status-bar {
    padding: 6px 10px;
    font-size: 0.78rem;
  }
  #sudoku-grid {
    width: 95vw;
  }
  .tool-btn {
    padding: 6px 10px;
    font-size: 0.75rem;
  }
  .numpad-btn {
    width: 34px;
    height: 44px;
  }
  .numpad-num {
    font-size: 1.1rem;
  }
  .select-grid {
    grid-template-columns: 1fr;
  }
}

/* Komunikat na czas generowania dużej planszy (12×12 ekspert) */
.generowanie-box {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  display: none;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 14px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  z-index: 500;
}

.generowanie-box.widoczne {
  display: flex;
  animation: generowanie-wejscie 0.2s ease-out forwards;
}

.generowanie-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent);
  animation: generowanie-obrot 0.8s linear infinite;
}

@keyframes generowanie-wejscie {
  to { transform: translate(-50%, 0); }
}

@keyframes generowanie-obrot {
  to { transform: rotate(360deg); }
}
