:root {
  --page-bg: #f0efec;
  --card-bg: #ffffff;
  --grid-line: #e6e4df;
  --cell-bg: #fbfaf8;
  --ink: #1c1c1c;
  --muted: #8a8781;
  --accent: #f0431e;
  --accent-dark: #c9330f;
  --halo: #ffd6cc;
  --badge-bg: #161514;
  --badge-fg: #ffffff;
  --mistake: #ff5b4a;
  --success: #2fa84f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page-bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.back-link {
  align-self: flex-start;
  margin-bottom: -8px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
}
.back-link:hover { color: var(--ink); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.02em;
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

select#difficulty {
  border: 1px solid var(--grid-line);
  background: var(--card-bg);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 14px;
  color: var(--ink);
}

.btn {
  border: 1px solid var(--grid-line);
  background: var(--card-bg);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease, background 0.15s ease;
}
.btn:hover:not(:disabled) { background: #f6f5f3; }
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: #333; }

.status-bar {
  display: flex;
  gap: 12px;
}
.status-item {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--grid-line);
  border-radius: 14px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.status-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.status-value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.board-card {
  background: var(--card-bg);
  border-radius: 22px;
  padding: 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.05);
  position: relative;
  transition: box-shadow 0.3s ease;
}
.board-card.solved {
  box-shadow: 0 0 0 3px var(--success), 0 8px 24px rgba(0,0,0,0.05);
}

.board-wrap {
  position: relative;
  width: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.grid {
  display: grid;
  width: 100%;
  aspect-ratio: var(--cols) / var(--rows);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--grid-line);
}

.cell {
  background: var(--cell-bg);
  border: 1px solid var(--grid-line);
  position: relative;
}
.cell.mistake { animation: mistakeFlash 0.35s ease; }
.cell.hint::after {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  border: 3px solid var(--accent);
  animation: hintPulse 1.2s ease;
}

@keyframes mistakeFlash {
  0% { background: var(--mistake); }
  100% { background: var(--cell-bg); }
}
@keyframes hintPulse {
  0% { transform: scale(0.6); opacity: 0; }
  30% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}

.path-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.path-svg .halo {
  fill: none;
  stroke: var(--halo);
  stroke-width: 0.62;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.path-svg .mainline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 0.34;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.path-svg .halo-dot { fill: var(--halo); }
.path-svg .main-dot { fill: var(--accent); }
.path-svg .head-ring {
  fill: none;
  stroke: #ffffff;
  stroke-width: 0.07;
  opacity: 0.9;
}

.numbers-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: grid;
  pointer-events: none;
}

.badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 62%;
  height: 62%;
  margin: auto;
  border-radius: 50%;
  background: var(--badge-bg);
  color: var(--badge-fg);
  font-weight: 700;
  font-size: clamp(12px, 3.6vw, 20px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.25);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.badge.reached {
  opacity: 0.4;
  transform: scale(0.92);
}

.win-banner {
  margin-top: 12px;
  background: #eafbee;
  border: 1px solid #bfe9c6;
  border-radius: 14px;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.win-banner p { margin: 0; font-weight: 600; color: #1d6b32; }
.win-banner.hidden { display: none; }

.actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.toast {
  align-self: center;
  background: var(--ink);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  text-align: center;
}
.toast.hidden { display: none; }

.stats-card {
  background: var(--card-bg);
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.05);
}
.stats-card h2 {
  margin: 0 0 12px;
  font-size: 16px;
}
.stats-card h3 {
  margin: 18px 0 8px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.stat {
  background: var(--cell-bg);
  border: 1px solid var(--grid-line);
  border-radius: 14px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.stat-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}
.history-list li {
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--cell-bg);
  border: 1px solid var(--grid-line);
  color: var(--muted);
}
.history-list:empty::before {
  content: "Zatím žádné odehrané hry.";
  font-size: 13px;
  color: var(--muted);
}
