/* ═══════════════════════════════════════════════════════════
   Hundertertafel – Interaktives Lernspiel · Grundschule
   ═══════════════════════════════════════════════════════════ */

@font-face {
  font-family: 'Grundschrift';
  src: url('/grundschrift-beta.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

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

/* ── Tokens ── */
:root {
  --primary:   #6C5CE7;
  --primary-d: #5849c4;
  --accent:    #FDCB6E;
  --green:     #00B894;
  --red:       #FF7675;

  --bg:      #F0F4FF;
  --surface: #FFFFFF;
  --text:    #2D3436;
  --muted:   #636E72;
  --border:  #DFE6E9;

  --radius:    12px;
  --cs:        clamp(38px, 8.5vw, 62px); /* cell size */
  --cell-fs:   1.2rem;                   /* adjustable font size */
  --gap:       4px;
  --sans: 'Grundschrift', 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', system-ui, sans-serif;

  /* Decade colors — rainbow progression */
  --d1:  #FFB3B3; /* 1–10   coral pink    */
  --d2:  #FFD4A8; /* 11–20  peach         */
  --d3:  #FFF09A; /* 21–30  yellow        */
  --d4:  #B8F0B8; /* 31–40  light green   */
  --d5:  #9AEED8; /* 41–50  mint          */
  --d6:  #A8DAFF; /* 51–60  sky blue      */
  --d7:  #C8B3FF; /* 61–70  lavender      */
  --d8:  #F4B3F4; /* 71–80  lilac/pink    */
  --d9:  #FFB3D4; /* 81–90  rose          */
  --d10: #FFD4A8; /* 91–100 warm peach    */
}

/* ── Base ── */
html { font-size: 16px; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── App shell ── */
.app {
  max-width: 820px;
  margin: 0 auto;
  padding-bottom: 48px;
}

/* ── Header ── */
.header {
  background: white;
  border-bottom: 3px solid #E8EAFF;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 20px rgba(108,92,231,.12);
}

/* ── Font-size control ── */
.font-ctrl {
  display: flex;
  align-items: center;
  gap: 4px;
}
.font-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: white;
  font-family: var(--sans);
  font-size: .82rem;
  font-weight: 800;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.font-btn:hover { border-color: var(--primary); color: var(--primary); }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-icon { font-size: 1.8rem; line-height: 1; }
.brand-name {
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--primary);
  letter-spacing: -.02em;
}

/* ── Tab nav ── */
.tab-nav { display: flex; gap: 6px; }

.tab-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 100px;
  border: 2px solid var(--border);
  background: white;
  cursor: pointer;
  font-family: var(--sans);
  font-size: .85rem;
  font-weight: 700;
  color: var(--muted);
  transition: all .18s;
}
.tab-btn:hover { border-color: var(--primary); color: var(--primary); }
.tab-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 4px 16px rgba(108,92,231,.35);
}

.tab-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: .75rem;
  font-weight: 900;
  background: rgba(255,255,255,.25);
}
.tab-btn:not(.active) .tab-num {
  background: var(--border);
  color: var(--muted);
}

/* ── Sections ── */
.tab-section { padding: 20px 20px 0; }

.section-bar { margin-bottom: 16px; }

.instruction {
  font-size: .95rem;
  color: var(--muted);
  background: white;
  border-left: 5px solid var(--primary);
  padding: 10px 16px;
  border-radius: 0 10px 10px 0;
  margin-bottom: 12px;
  box-shadow: 0 1px 6px rgba(0,0,0,.05);
}

/* ── Grid ── */
.grid-wrap { overflow-x: auto; padding-bottom: 8px; }

.grid {
  display: grid;
  grid-template-columns: repeat(10, var(--cs));
  gap: var(--gap);
  width: fit-content;
  margin: 0 auto;
}

/* ── Cell ── */
.cell {
  width: var(--cs);
  height: var(--cs);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--cell-fs);
  font-weight: 900;
  user-select: none;
  transition: transform .15s, box-shadow .15s, opacity .25s;
  border: 2px solid transparent;
  position: relative;
  font-family: var(--sans);
  color: rgba(0,0,0,.72);
  cursor: default;
}

/* Default cell background — gray; 10er cells get inline color from JS */
.cell { background: #E4E4E4; }

/* ── Cell states ── */
.cell.clickable { cursor: pointer; }
.cell.clickable:hover {
  transform: scale(1.13);
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
  z-index: 2;
  border-color: rgba(0,0,0,.15);
}

.cell.selected {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(108,92,231,.45) !important;
  transform: scale(1.15);
  z-index: 4;
}

.cell.neighbor {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(253,203,110,.7);
  animation: neighborPulse 1s ease infinite alternate;
}
@keyframes neighborPulse {
  from { box-shadow: 0 0 0 2px rgba(253,203,110,.7); }
  to   { box-shadow: 0 0 0 5px rgba(253,203,110,.3); }
}

/* Structure highlighting */
.cell.highlighted {
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(0,0,0,.22);
  border-color: rgba(0,0,0,.2);
  z-index: 2;
}
.cell.dimmed { opacity: 0.15; }

/* ── GAP cells (Lücken) ── */
.cell.gap {
  background: #EDEDED !important;
  border: 2.5px dashed #C0C0C0 !important;
  cursor: pointer;
  color: transparent !important;
  box-shadow: none;
}
.cell.gap::after {
  content: '?';
  position: absolute;
  color: #BDBDBD;
  font-size: var(--cell-fs);
  font-weight: 900;
}
.cell.gap:hover {
  background: #E8E0FF !important;
  border-color: var(--primary) !important;
  transform: scale(1.12);
  box-shadow: 0 6px 20px rgba(108,92,231,.25) !important;
}
.cell.gap:hover::after { color: var(--primary); }

/* Revealed gap */
.cell.revealed {
  cursor: default !important;
  animation: popIn .5s cubic-bezier(.34,1.56,.64,1) forwards;
}
.cell.revealed::after { display: none; }

@keyframes popIn {
  0%   { transform: scale(0.2) rotate(-8deg); opacity: 0; }
  70%  { transform: scale(1.18) rotate(2deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* ── Progress bar ── */
.progress-bar-wrap {
  height: 8px;
  background: #E0E7FF;
  border-radius: 100px;
  overflow: hidden;
  margin-top: 10px;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #a29bfe);
  border-radius: 100px;
  width: 0%;
  transition: width .5s cubic-bezier(.34,1.3,.64,1);
}

/* ── Aufgabe controls ── */
.aufgabe-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.diff-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.bar-label {
  font-size: .82rem;
  font-weight: 700;
  color: var(--muted);
}

.diff-btn {
  padding: 7px 15px;
  border-radius: 100px;
  border: 2px solid var(--border);
  background: white;
  font-family: var(--sans);
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
}
.diff-btn:hover { border-color: var(--primary); color: var(--primary); }
.diff-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 2px 10px rgba(108,92,231,.3);
}

.progress-pill {
  background: white;
  border: 2px solid #E8EAFF;
  border-radius: 100px;
  padding: 7px 18px;
  font-size: .9rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.progress-pill b { color: var(--primary); font-size: 1rem; }

/* ── Struktur controls ── */
.str-btns {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}
.str-btn {
  padding: 8px 18px;
  border-radius: 100px;
  border: 2px solid var(--border);
  background: white;
  font-family: var(--sans);
  font-size: .83rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  transition: all .15s;
}
.str-btn:hover { border-color: var(--primary); color: var(--primary); background: #F0EEFF; }
.str-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 2px 10px rgba(108,92,231,.3);
}
.str-reset { font-size: .78rem; color: var(--muted); border-color: #ddd; }
.str-reset:hover { border-color: var(--red); color: var(--red); background: #FFF5F5; }

.str-legend {
  margin-top: 10px;
  font-size: .82rem;
  color: var(--muted);
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
}

/* ── Info panel (Entdecken) ── */
.info-panel {
  margin-top: 20px;
  background: white;
  border-radius: var(--radius);
  border: 2px solid #E8EAFF;
  padding: 18px 22px;
  box-shadow: 0 4px 20px rgba(108,92,231,.08);
  animation: fadeUp .3s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.info-main {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.info-big {
  width: 76px;
  height: 76px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.1rem;
  font-weight: 900;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(0,0,0,.12);
}

.info-facts {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: .88rem;
}
.info-fact { color: var(--muted); }
.info-fact span { font-weight: 800; color: var(--text); }
.info-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 100px;
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-gerade { background: #E8FFF0; color: #00B894; border: 1px solid #b2f0da; }
.badge-ungerade { background: #FFF0F0; color: #FF7675; border: 1px solid #ffc9c9; }

.info-neighbors {
  margin-top: 16px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.nbr-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.nbr-label {
  font-size: .62rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.nbr-val {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .95rem;
  font-weight: 900;
  color: rgba(0,0,0,.72);
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
}
.nbr-none {
  background: #F5F5F5;
  color: #DDD;
  font-size: .7rem;
  box-shadow: none;
  border: 1.5px dashed #DDD;
}
.nbr-self {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  font-size: 1.2rem;
  box-shadow: 0 4px 14px rgba(0,0,0,.15);
  border: 2.5px solid rgba(0,0,0,.12);
}

/* ── Buttons ── */
.aufgabe-footer { text-align: center; margin-top: 20px; }

.btn-primary {
  padding: 13px 36px;
  background: linear-gradient(135deg, var(--primary), #a29bfe);
  color: white;
  border: none;
  border-radius: 100px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  font-family: var(--sans);
  transition: all .18s;
  box-shadow: 0 6px 20px rgba(108,92,231,.38);
  letter-spacing: .01em;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(108,92,231,.45); }
.btn-primary:active { transform: translateY(0); }

/* ── Celebration ── */
.celebration[hidden] { display: none !important; }
.celebration {
  position: fixed;
  inset: 0;
  background: rgba(30,20,60,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn .35s ease;
  backdrop-filter: blur(4px);
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.celebration-box {
  background: white;
  border-radius: 28px;
  padding: 52px 44px;
  text-align: center;
  max-width: 400px;
  width: 92%;
  animation: bounceIn .55s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 32px 80px rgba(0,0,0,.3);
  position: relative;
}
@keyframes bounceIn {
  from { transform: scale(0.4); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.celebration-stars {
  font-size: 1.5rem;
  letter-spacing: 4px;
  margin-bottom: 10px;
  animation: spin 2s linear infinite;
}
@keyframes spin {
  0%   { letter-spacing: 4px; }
  50%  { letter-spacing: 12px; }
  100% { letter-spacing: 4px; }
}

.celebration-emoji { font-size: 4.5rem; margin-bottom: 10px; }
.celebration-box h2 {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--primary);
  margin-bottom: 8px;
}
.celebration-box p {
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 28px;
}
.celebration-btn { width: 100%; }

/* ── Confetti ── */
.confetti {
  position: fixed;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  top: -12px;
  animation: fall linear forwards;
  pointer-events: none;
  z-index: 300;
}
@keyframes fall {
  0%   { transform: translateY(0) rotate(0deg) scale(1); opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg) scale(0.6); opacity: 0; }
}

/* ── Responsive ── */
@media (max-width: 600px) {
  :root { --cs: clamp(32px, 8.8vw, 46px); --gap: 3px; }
  .tab-label { display: none; }
  .tab-btn { padding: 9px 12px; }
  .aufgabe-bar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .info-panel { padding: 14px; }
  .brand-name { font-size: .95rem; }
  .celebration-box { padding: 36px 24px; }
  .celebration-box h2 { font-size: 1.7rem; }
}
@media (max-width: 400px) {
  :root { --cs: 30px; --gap: 2px; }
  .str-btn, .diff-btn { padding: 6px 12px; font-size: .75rem; }
}

/* ── Count + Mode buttons (Tab 4) ── */
.reihen-count-btn {
  padding: 7px 15px;
  border-radius: 100px;
  border: 2px solid var(--border);
  background: white;
  font-family: var(--sans);
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
}
.reihen-count-btn:hover { border-color: var(--primary); color: var(--primary); }
.reihen-count-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 2px 10px rgba(108,92,231,.3);
}

.mode-btn {
  padding: 7px 15px;
  border-radius: 100px;
  border: 2px solid var(--border);
  background: white;
  font-family: var(--sans);
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
}
.mode-btn:hover { border-color: var(--primary); color: var(--primary); }
.mode-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 2px 10px rgba(108,92,231,.3);
}

/* ── Reihen: puzzle containers ── */
.puzzle-wrap { margin-bottom: 20px; }

.balken-row {
  display: flex;
  gap: var(--gap);
  justify-content: center;
}

.zickzack-grid {
  display: grid;
  grid-template-columns: repeat(6, var(--cs));
  gap: var(--gap);
  width: fit-content;
  margin: 0 auto;
}

/* ── Reihen: cell base ── */
.reihen-cell {
  width: var(--cs);
  height: var(--cs);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--cell-fs);
  font-weight: 900;
  font-family: var(--sans);
  color: rgba(0,0,0,.75);
  border: 2px solid transparent;
  background: #E4E4E4;
  cursor: default;
  position: relative;
  transition: transform .15s, box-shadow .15s;
}

/* Known anchor cell */
.reihen-cell.anchor {
  border: 3px solid var(--primary);
  box-shadow: 0 0 0 3px rgba(108,92,231,.22);
}

/* Gap cell */
.reihen-cell.gap {
  background: #EDEDED;
  border: 2.5px dashed #C0C0C0;
  cursor: pointer;
  color: transparent;
}
.reihen-cell.gap::after {
  content: '?';
  position: absolute;
  color: #BDBDBD;
  font-size: var(--cell-fs);
  font-weight: 900;
}
.reihen-cell.gap:hover {
  background: #E8E0FF;
  border-color: var(--primary);
  transform: scale(1.12);
  box-shadow: 0 6px 20px rgba(108,92,231,.25);
}
.reihen-cell.gap:hover::after { color: var(--primary); }

/* Revealed gap */
.reihen-cell.r-revealed {
  pointer-events: none;
  animation: popIn .5s cubic-bezier(.34,1.56,.64,1) forwards;
}

/* Blank spacer (Zickzack x positions) */
.reihen-spacer {
  width: var(--cs);
  height: var(--cs);
}

/* ── Subtle print button ── */
.btn-print-subtle {
  padding: 6px 14px;
  background: white;
  color: var(--muted);
  border: 1.5px solid var(--border);
  border-radius: 100px;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--sans);
  transition: all .15s;
  white-space: nowrap;
}
.btn-print-subtle:hover { border-color: var(--primary); color: var(--primary); }

/* ══════════════════════════════════════════════════════════════
   DRUCKVERSION / @media print
   ══════════════════════════════════════════════════════════════ */
@media print {
  body { background: white !important; }

  /* Hide everything except reihen container */
  .header,
  #tab-entdecken,
  #tab-strukturen,
  #tab-aufgabe,
  .celebration,
  .confetti,
  .section-bar,
  .aufgabe-footer { display: none !important; }

  /* Show reihen section even if hidden attribute is set */
  #tab-reihen {
    display: block !important;
    padding: 16px !important;
  }

  .app { max-width: none !important; padding: 0 !important; }

  /* Page heading */
  #tab-reihen::before {
    content: 'Reihen-Aufgabe';
    display: block;
    font-family: 'Grundschrift', sans-serif;
    font-size: 18pt;
    font-weight: bold;
    margin-bottom: 20pt;
  }

  /* Puzzle spacing */
  .puzzle-wrap {
    margin-bottom: 20pt !important;
    break-inside: avoid;
  }

  /* All reihen cells: clean black border, white background */
  .reihen-cell {
    border: 1pt solid #999 !important;
    background: white !important;
    box-shadow: none !important;
    transform: none !important;
    animation: none !important;
    color: black !important;
  }

  /* Anchor: bold border so it stands out as the given number */
  .reihen-cell.anchor {
    border: 2pt solid black !important;
    color: black !important;
  }

  /* Gap: plain empty box — no ? mark, no color */
  .reihen-cell.gap {
    border: 1pt solid #bbb !important;
    color: transparent !important;
  }
  .reihen-cell.gap::after { display: none !important; }

  /* Already-revealed cells also print as empty boxes */
  .reihen-cell.r-revealed {
    border: 1pt solid #bbb !important;
    color: transparent !important;
    animation: none !important;
  }

  /* Spacers: invisible */
  .reihen-spacer {
    background: transparent !important;
    border: none !important;
  }
}
