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

.app-header {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
}

.app-logo-icon {
  background: rgba(255, 255, 255, 0.2);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
}

.app-logo-text {
  font-size: 18px;
  font-weight: 700;
}

.app-nav {
  display: flex;
  gap: 8px;
}

.nav-link {
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 15px;
  transition: background 0.2s;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.15);
}

.nav-link.active {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.app-main {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px;
}

.app-footer {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 14px;
  border-top: 1px solid var(--border);
  background: var(--card-bg);
}

/* ===== HomePage ===== */
.hero {
  text-align: center;
  margin-bottom: 28px;
}

.hero h1 {
  font-size: 32px;
  color: var(--primary);
  margin-bottom: 8px;
}

.hero-subtitle {
  color: var(--text-muted);
  font-size: 16px;
}

.config-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.config-card h2 {
  margin-bottom: 20px;
  color: var(--text);
}

.config-section {
  margin-bottom: 24px;
}

.config-section h3 {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Tryb */
.mode-selector {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  transition: all 0.2s;
}

.mode-btn:hover {
  border-color: var(--primary-light);
}

.mode-btn.active {
  border-color: var(--primary);
  background: #eef2ff;
}

.mode-icon {
  font-size: 28px;
}

.mode-name {
  font-weight: 700;
  font-size: 16px;
}

.mode-desc {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

/* Zakres - interaktywna tabliczka mnożenia */
.range-configurator {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.range-instruction {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}

.multiplication-grid {
  display: grid;
  grid-template-columns: 40px repeat(10, 1fr);
  gap: 4px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.grid-corner {
  /* pusty róg siatki */
}

.grid-header {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--primary);
  font-size: 14px;
  height: 32px;
}

.grid-row {
  display: contents;
}

.grid-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  transition: all 0.15s;
  padding: 0;
  cursor: pointer;
  user-select: none;
}

.grid-cell:hover {
  border-color: var(--primary-light);
  background: #eef2ff;
}

.grid-cell.selected {
  background: var(--primary-light);
  border-color: var(--primary);
  color: #fff;
}

.grid-cell.start,
.grid-cell.end {
  background: var(--primary);
  border-color: var(--primary-dark);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--primary);
}

.range-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #eef2ff;
  border-radius: 8px;
  padding: 10px 16px;
}

.range-summary-label {
  font-size: 14px;
  color: var(--text-muted);
}

.range-summary-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}

/* Liczba pytań / czas */
.number-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.num-btn {
  padding: 10px 18px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 15px;
  font-weight: 600;
  transition: all 0.2s;
}

.num-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  cursor: pointer;
}

.checkbox-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.start-btn {
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 18px;
  font-weight: 700;
  transition: background 0.2s;
}

.start-btn:hover {
  background: var(--primary-dark);
}

/* ===== GamePage ===== */
.game-page {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Licznik czasu w trybie sprawdzianu */
.exam-timer {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #eef2ff;
  border: 2px solid var(--primary);
  border-radius: 10px;
  padding: 8px 16px;
  min-width: 120px;
  justify-content: center;
}

.exam-timer-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.exam-timer-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

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

.game-progress {
  flex: 1;
}

.game-progress span {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 600;
}

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  margin-top: 8px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s;
}

/* Timer */
.timer {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 120px;
}

.timer-bar {
  flex: 1;
  height: 10px;
  background: var(--border);
  border-radius: 5px;
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  background: var(--green);
  border-radius: 5px;
  transition: width 1s linear;
}

.timer.low .timer-fill {
  background: var(--red);
}

.timer-value {
  font-weight: 700;
  font-size: 16px;
  min-width: 32px;
  text-align: right;
}

.timer.low .timer-value {
  color: var(--red);
}

/* QuestionCard */
.question-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 28px;
  text-align: center;
  transition: border 0.2s;
  border: 3px solid transparent;
}

.question-card.correct {
  border-color: var(--green);
}

.question-card.wrong {
  border-color: var(--red);
}

.question-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

.question-number {
  font-size: 56px;
  font-weight: 800;
  color: var(--text);
}

.question-op {
  font-size: 40px;
  color: var(--primary);
  font-weight: 700;
}

.question-answer {
  font-size: 56px;
  font-weight: 800;
  color: var(--primary);
}

.answer-input-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  max-width: 360px;
  margin: 0 auto;
}

.answer-input {
  flex: 1;
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border 0.2s;
}

.answer-input:focus {
  border-color: var(--primary);
}

.submit-btn {
  padding: 12px 24px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
}

.submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Feedback */
.feedback {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  border-radius: 10px;
  font-size: 20px;
  font-weight: 700;
  max-width: 360px;
  margin: 0 auto;
}

.feedback.correct {
  background: var(--green-light);
  color: var(--green);
}

.feedback.wrong {
  background: var(--red-light);
  color: var(--red);
}

.feedback-icon {
  font-size: 28px;
}

/* ===== ResultsPage ===== */
.results-page {
  display: flex;
  justify-content: center;
}

.results-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 560px;
  text-align: center;
}

.results-card h2 {
  margin-bottom: 24px;
}

.score-circle {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  border: 6px solid;
}

.score-circle.green {
  border-color: var(--green);
  color: var(--green);
  background: var(--green-light);
}

.score-circle.yellow {
  border-color: var(--yellow);
  color: var(--yellow);
  background: var(--yellow-light);
}

.score-circle.red {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-light);
}

.score-value {
  font-size: 40px;
  font-weight: 800;
}

.score-label {
  font-size: 14px;
}

.grade {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 24px;
}

.grade.green {
  color: var(--green);
}

.grade.yellow {
  color: var(--yellow);
}

.grade.red {
  color: var(--red);
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.result-item {
  background: var(--bg);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.result-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.result-value {
  font-size: 18px;
  font-weight: 700;
}

.result-value.correct {
  color: var(--green);
}

.result-value.wrong {
  color: var(--red);
}

.save-section {
  border-top: 1px solid var(--border);
  padding-top: 20px;
  margin-bottom: 20px;
}

.save-section h3 {
  margin-bottom: 12px;
}

.save-row {
  display: flex;
  gap: 10px;
}

.nick-input {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
}

.nick-input:focus {
  border-color: var(--primary);
}

.save-btn,
.stats-btn {
  padding: 12px 20px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

.save-btn:disabled,
.stats-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.error-text {
  color: var(--red);
  margin-top: 10px;
  font-size: 14px;
}

.saved-confirmation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--green-light);
  color: var(--green);
  padding: 16px;
  border-radius: 8px;
  font-weight: 600;
  margin-bottom: 20px;
}

.saved-icon {
  font-size: 24px;
}

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

.secondary-btn {
  padding: 12px 20px;
  border: 2px solid var(--primary);
  color: var(--primary);
  background: #fff;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  transition: all 0.2s;
}

.secondary-btn:hover {
  background: #eef2ff;
}

/* ===== RankingPage ===== */
.ranking-page {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.ranking-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.ranking-header h2 {
  font-size: 24px;
}

.ranking-mode-toggle {
  display: flex;
  gap: 8px;
}

.rank-mode-btn {
  padding: 10px 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-weight: 600;
}

.rank-mode-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.ranking-table {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ranking-row {
  display: grid;
  grid-template-columns: 50px 1fr 80px 90px 80px 1fr;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.ranking-row:last-child {
  border-bottom: none;
}

.ranking-row.header {
  background: var(--bg);
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 12px;
}

.rank-col {
  font-weight: 700;
}

.nick-col {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-col {
  font-weight: 700;
  color: var(--primary);
}

.loading-text,
.empty-text {
  text-align: center;
  color: var(--text-muted);
  padding: 32px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stats-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.stats-section h3 {
  margin-bottom: 16px;
}

.stats-row {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}

.stat-item {
  background: var(--bg);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Responsywność ===== */
@media (max-width: 640px) {
  .app-header-inner {
    padding: 12px 16px;
  }

  .app-logo-text {
    font-size: 16px;
  }

  .app-main {
    padding: 16px;
  }

  .hero h1 {
    font-size: 26px;
  }

  .mode-selector {
    grid-template-columns: 1fr;
  }

  .config-card {
    padding: 20px;
  }

  .multiplication-grid {
    grid-template-columns: 28px repeat(10, 1fr);
    gap: 2px;
  }

  .grid-header {
    font-size: 12px;
    height: 26px;
  }

  .grid-cell {
    font-size: 11px;
    border-radius: 4px;
  }

  .question-number,
  .question-answer {
    font-size: 42px;
  }

  .question-op {
    font-size: 30px;
  }

  .results-grid {
    grid-template-columns: 1fr 1fr;
  }

  .ranking-row {
    grid-template-columns: 36px 1fr 70px 70px;
    font-size: 13px;
  }

  .time-col,
  .range-col {
    display: none;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .save-row,
  .stats-row {
    flex-direction: column;
  }

  .results-actions {
    flex-direction: column;
  }
}
:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #6366f1;
  --green: #16a34a;
  --green-light: #dcfce7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --yellow: #d97706;
  --yellow-light: #fef3c7;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --radius: 12px;
}

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

html,
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

#root {
  min-height: 100vh;
}

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

input,
select {
  font-family: inherit;
}

/* Ukrycie strzałek w input type=number */
input[type='number']::-webkit-outer-spin-button,
input[type='number']::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type='number'] {
  -moz-appearance: textfield;
  appearance: textfield;
}
