/* ===================================================
   KOPFRECHNEN – Kindgerechtes CSS
   =================================================== */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --clr-bg:        #fef9f0;
  --clr-primary:   #ff7043;   /* Orange */
  --clr-primary-d: #e64a19;
  --clr-secondary: #42a5f5;   /* Hellblau */
  --clr-success:   #66bb6a;   /* Grün */
  --clr-danger:    #ef5350;   /* Rot */
  --clr-warning:   #ffa726;   /* Gelb */
  --clr-level:     #ab47bc;   /* Lila */
  --clr-text:      #37474f;
  --clr-muted:     #90a4ae;
  --radius-lg:     20px;
  --radius-btn:    50px;
  --shadow:        0 4px 16px rgba(0,0,0,0.12);
  --font-main:     'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
}

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

/* --- Screen System --- */
.screen {
  display: none;
  min-height: 100vh;
  padding: 1.5rem 1rem;
  animation: fadeIn 0.25s ease;
}
.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===================================================
   STARTSCREEN
   =================================================== */
.start-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  max-width: 480px;
  width: 100%;
}

.app-title {
  font-size: 2.8rem;
  font-weight: 800;
  color: var(--clr-primary);
  text-shadow: 2px 3px 0 rgba(255,112,67,0.2);
  letter-spacing: -1px;
}

.app-subtitle {
  font-size: 1.2rem;
  color: var(--clr-muted);
  margin-top: -1rem;
}

/* Level Badge */
.level-badge-container {
  width: 100%;
  display: flex;
  justify-content: center;
}

.level-badge {
  background: linear-gradient(135deg, #ce93d8, #ab47bc);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 1rem 2rem;
  text-align: center;
  box-shadow: var(--shadow);
  min-width: 180px;
}

.level-label {
  display: block;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.85;
}

.level-number {
  display: block;
  font-size: 3.5rem;
  font-weight: 900;
  line-height: 1.1;
}

.level-desc {
  display: block;
  font-size: 0.9rem;
  opacity: 0.85;
  margin-top: 0.25rem;
}

/* ===================================================
   BUTTONS
   =================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  cursor: pointer;
  font-family: var(--font-main);
  font-weight: 700;
  border-radius: var(--radius-btn);
  transition: transform 0.1s, box-shadow 0.1s, filter 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.95);
  filter: brightness(0.92);
}

.btn-primary {
  background: var(--clr-primary);
  color: #fff;
  font-size: 1.4rem;
  padding: 0.8rem 2rem;
  box-shadow: 0 6px 0 var(--clr-primary-d), var(--shadow);
}
.btn-primary:active {
  box-shadow: 0 2px 0 var(--clr-primary-d);
  transform: translateY(4px) scale(0.97);
}

.btn-secondary {
  background: #e3f2fd;
  color: var(--clr-secondary);
  font-size: 1rem;
  padding: 0.65rem 1.4rem;
  box-shadow: var(--shadow);
}

.btn-danger {
  background: #ffebee;
  color: var(--clr-danger);
  font-size: 0.9rem;
  padding: 0.5rem 1.2rem;
  box-shadow: none;
  border: 2px solid #ffcdd2;
}

.btn-huge {
  font-size: 1.6rem;
  padding: 1rem 2.5rem;
  min-height: 70px;
  width: 100%;
  max-width: 360px;
}

.btn-small {
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
}

/* ===================================================
   SPIELSCREEN
   =================================================== */
#screen-game {
  justify-content: flex-start;
  padding: 0;
  gap: 0;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0.75rem 1.2rem;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  font-size: 1rem;
  font-weight: 600;
  color: var(--clr-muted);
}

.level-info {
  background: var(--clr-level);
  color: #fff;
  border-radius: 50px;
  padding: 0.2rem 0.8rem;
  font-size: 0.9rem;
}

/* Timer Bar */
.timer-bar-wrap {
  width: 100%;
  height: 10px;
  background: #eceff1;
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--clr-success);
  transition: width 0.25s linear, background-color 0.5s;
  transform-origin: left;
}

.timer-bar.warning {
  background: var(--clr-warning);
}

.timer-bar.danger {
  background: var(--clr-danger);
}

/* Task Display */
.task-display {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
}

.task-equation {
  font-size: clamp(2.5rem, 10vw, 4.5rem);
  font-weight: 900;
  color: var(--clr-text);
  text-align: center;
  letter-spacing: 2px;
}

/* Feedback */
.feedback {
  min-height: 2.2rem;
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
  padding: 0 1rem;
  transition: opacity 0.3s;
}

.feedback.correct {
  color: var(--clr-success);
}

.feedback.wrong {
  color: var(--clr-danger);
}

/* Input Display */
.input-display {
  font-size: 2.8rem;
  font-weight: 900;
  color: var(--clr-secondary);
  text-align: center;
  min-height: 3.5rem;
  padding: 0.25rem 1rem;
  border-bottom: 4px solid var(--clr-secondary);
  margin: 0.25rem auto 0.75rem;
  min-width: 140px;
  max-width: 260px;
  letter-spacing: 4px;
}

/* Numpad */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0.75rem 1rem 1.25rem;
  max-width: 360px;
  width: 100%;
  margin: 0 auto;
}

.numpad-btn {
  background: #fff;
  border: 3px solid #e0e0e0;
  border-radius: 16px;
  font-size: 1.8rem;
  font-weight: 700;
  font-family: var(--font-main);
  color: var(--clr-text);
  min-height: 68px;
  cursor: pointer;
  box-shadow: 0 4px 0 #e0e0e0;
  transition: transform 0.08s, box-shadow 0.08s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.numpad-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #e0e0e0;
}

.numpad-del {
  background: #fff3e0;
  border-color: #ffccbc;
  color: var(--clr-primary);
  font-size: 1.5rem;
}

.numpad-ok {
  background: var(--clr-success);
  border-color: #43a047;
  color: #fff;
  box-shadow: 0 4px 0 #388e3c;
  font-size: 1.5rem;
}

.numpad-ok:active {
  box-shadow: 0 1px 0 #388e3c;
}

/* ===================================================
   PARTICLES / STERNE
   =================================================== */
.particles {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}

.particle {
  position: absolute;
  font-size: 1.8rem;
  animation: particleFly 1.2s ease-out forwards;
  will-change: transform, opacity;
}

@keyframes particleFly {
  0%   { transform: translateY(0) scale(1) rotate(0deg); opacity: 1; }
  100% { transform: translateY(-220px) scale(0.4) rotate(360deg); opacity: 0; }
}

/* ===================================================
   BLOCK-ZUSAMMENFASSUNG
   =================================================== */
.summary-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  max-width: 480px;
  width: 100%;
}

.summary-title {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--clr-primary);
}

.score-display {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 1rem 2rem;
  box-shadow: var(--shadow);
}

.score-correct {
  font-size: 4rem;
  font-weight: 900;
  color: var(--clr-success);
}

.score-sep {
  font-size: 2.5rem;
  color: var(--clr-muted);
}

.score-total {
  font-size: 4rem;
  font-weight: 900;
  color: var(--clr-muted);
}

.score-label {
  font-size: 1rem;
  color: var(--clr-muted);
  align-self: center;
  margin-left: 0.5rem;
}

.summary-stats {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 0.8rem 1.4rem;
  box-shadow: var(--shadow);
  min-width: 130px;
}

.stat-icon {
  font-size: 1.6rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--clr-text);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--clr-muted);
  text-align: center;
}

/* Level-Trend Farben */
.trend-up   { color: var(--clr-success); }
.trend-same { color: var(--clr-warning); }
.trend-down { color: var(--clr-danger);  }

/* ===================================================
   STATISTIKSCREEN
   =================================================== */
.stats-inner {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  max-width: 680px;
  width: 100%;
  padding-bottom: 2rem;
}

.stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stats-title {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--clr-text);
}

.chart-container {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow);
  height: 280px;
  position: relative;
}

.table-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--clr-text);
}

.table-wrap {
  overflow-x: auto;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.stats-table th {
  background: #f5f5f5;
  padding: 0.7rem 1rem;
  text-align: left;
  font-weight: 700;
  color: var(--clr-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stats-table td {
  padding: 0.65rem 1rem;
  border-top: 1px solid #f0f0f0;
  color: var(--clr-text);
}

.stats-table tr:hover td {
  background: #f9f9f9;
}

.stats-table .no-data {
  text-align: center;
  color: var(--clr-muted);
  padding: 2rem;
  font-style: italic;
}

/* ===================================================
   RESPONSIVE
   =================================================== */
@media (max-width: 400px) {
  .app-title { font-size: 2.2rem; }
  .numpad-btn { min-height: 60px; font-size: 1.6rem; }
  .task-equation { font-size: 2.4rem; }
  .input-display { font-size: 2.2rem; }
}

@media (min-width: 600px) {
  #screen-game {
    max-width: 480px;
    margin: 0 auto;
    border-radius: 0;
  }
  .numpad {
    max-width: 400px;
  }
}
