/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: #f0f2f5; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  color: #1e1e2e;
}

.hidden { display: none !important; }

/* ── App Root ────────────────────────────────────────────── */
#app { width: 100vw; height: 100vh; position: relative; overflow: hidden; }

/* ── Geräte-Freischaltung ────────────────────────────────── */
.auth-overlay {
  position: absolute;
  inset: 0;
  z-index: 200;
  background: linear-gradient(145deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .3s ease;
}
.auth-overlay.hidden { opacity: 0; pointer-events: none; }

.da-card {
  background: white;
  border-radius: 28px;
  padding: 2.5rem 3rem 2rem;
  text-align: center;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 16px 64px rgba(0,0,0,.25);
}
.da-icon { font-size: 3.5rem; }
.da-card h2 { font-size: 1.8rem; font-weight: 800; margin: .4rem 0; color: #2d3436; }
.da-hint { font-size: 1rem; color: #636e72; margin-bottom: 1.5rem; line-height: 1.5; }
.da-input {
  width: 100%;
  padding: .85rem 1rem;
  font-size: 1.1rem;
  border: 2px solid #e0e0e0;
  border-radius: 14px;
  text-align: center;
  letter-spacing: .15em;
  transition: border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.da-input:focus { outline: none; border-color: #6c5ce7; }
.da-error { color: #e17055; font-size: .9rem; margin-top: .6rem; }
.da-btn {
  display: block;
  width: 100%;
  margin-top: 1rem;
  padding: .9rem;
  background: #6c5ce7;
  color: white;
  border: none;
  border-radius: 14px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.da-btn:hover    { background: #5a4bd1; }
.da-btn:disabled { background: #b2bec3; cursor: default; }

/* ── App-Shell ───────────────────────────────────────────── */
.app-shell {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ── Top Bar ─────────────────────────────────────────────── */
.top-bar {
  height: 92px;
  background: white;
  border-bottom: 1px solid #e8eaed;
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 1rem;
  flex-shrink: 0;
  z-index: 10;
}

.app-brand {
  font-size: 1.8rem;
  flex-shrink: 0;
  width: 180px;
}

.top-bar-right {
  width: 180px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .6rem;
}

.player-filter {
  flex: 1;
  display: flex;
  gap: .9rem;
  align-items: center;
  justify-content: center;
}

.player-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .3rem;
  cursor: pointer;
  background: transparent;
  border: none;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  transition: transform .12s ease;
}
.player-chip:active { transform: scale(.91); }

.chip-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: white;
  border: 3px solid var(--chip-color, #ddd);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
  transition: border-width .12s ease, box-shadow .12s ease;
}
.player-chip.active .chip-circle {
  border-width: 4px;
  box-shadow: 0 3px 14px rgba(0,0,0,.15);
}

.chip-name { font-size: .72rem; font-weight: 700; color: #999; }
.player-chip.active .chip-name { color: var(--chip-color, #6c5ce7); }

.chip-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.player-chip.inactive-module {
  opacity: .35;
  cursor: default;
  pointer-events: none;
}
.player-chip.inactive-module .chip-circle {
  border-color: #ccc !important;
  filter: grayscale(1);
}

.player-chip.no-interact {
  cursor: default;
  pointer-events: none;
}

.date-label {
  font-size: .88rem;
  color: #999;
  white-space: nowrap;
  flex-shrink: 0;
  text-transform: capitalize;
}

.sync-indicator {
  width: 18px;
  height: 18px;
  border: 2.5px solid #e0e0e0;
  border-top-color: #6c5ce7;
  border-radius: 50%;
  flex-shrink: 0;
  animation: spin .8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── App Body ────────────────────────────────────────────── */
.app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: 62px;
  background: white;
  border-right: 1px solid #e8eaed;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: .75rem 0;
  gap: .25rem;
  flex-shrink: 0;
}

.nav-item {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-item:hover  { background: #f0f2f5; }
.nav-item.active { background: #f0eeff; }

.nav-item img {
  width: 26px;
  height: 26px;
  filter: grayscale(1) opacity(.4);
  transition: filter .15s;
}
.nav-item:hover img  { filter: grayscale(.3) opacity(.7); }
.nav-item.active img { filter: none; }

/* ── Content Area ────────────────────────────────────────── */
.content-area {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.section {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1.25rem 1.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.section.active { opacity: 1; pointer-events: auto; }

/* ── Datum-Navigation ─────────────────────────────────────── */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  margin-bottom: 1.1rem;
}

.date-nav-btn {
  width: 36px;
  height: 36px;
  border: 1.5px solid #e0e0e0;
  border-radius: 50%;
  background: white;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
  transition: background .12s, border-color .12s;
  -webkit-tap-highlight-color: transparent;
}
.date-nav-btn:hover:not(:disabled) { background: #f0eeff; border-color: #6c5ce7; color: #6c5ce7; }
.date-nav-btn:disabled { opacity: .3; cursor: default; }

.date-nav-label {
  min-width: 160px;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  color: #2d3436;
}

/* ── Spieler-Gruppe ──────────────────────────────────────── */
.player-group {
  margin-bottom: 1.75rem;
}

.player-group-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: .85rem;
  padding-bottom: .6rem;
  border-bottom: 2px solid var(--player-color, #6c5ce7);
}

.pg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}
.pg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.pg-name   { font-size: 1rem; font-weight: 800; color: #2d3436; }
.pg-points { font-size: .85rem; color: #888; }

.pg-progress-wrap {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: .6rem;
}
.pg-progress-text { font-size: .82rem; font-weight: 700; color: #888; white-space: nowrap; }
.pg-progress-bar  { width: 80px; height: 6px; background: #eee; border-radius: 3px; overflow: hidden; }
.pg-progress-fill { height: 100%; background: var(--player-color, #6c5ce7); border-radius: 3px; transition: width .4s ease; }

.players-columns {
  display: flex;
  align-items: flex-start;
  gap: 1.25rem;
  height: 100%;
}

.player-column {
  flex: 1;
  min-width: 0;
}

.player-col-tasks {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .75rem;
  margin-top: .85rem;
}

/* ── Aufgaben-Karte ──────────────────────────────────────── */
.task-card {
  background: white;
  border-radius: 16px;
  padding: .85rem .85rem .7rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  border-left: 4px solid var(--player-color, #6c5ce7);
  display: flex;
  flex-direction: column;
  gap: .3rem;
  transition: transform .12s ease, box-shadow .12s ease;
  -webkit-tap-highlight-color: transparent;
  min-height: 100px;
}
.task-card:active:not(.done) { transform: scale(.97); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

.task-card.done {
  opacity: .42;
  cursor: default;
  border-left-color: #ddd;
}

.task-card.missed {
  opacity: .5;
  cursor: default;
  border-left-color: #e0e0e0;
  background: #fafafa;
}
.task-card.missed .tc-title { color: #aaa; }

.tc-missed { color: #ccc; font-size: 1.1rem; }

@keyframes bounce {
  0%  { transform: scale(1); }
  45% { transform: scale(1.05); }
  100%{ transform: scale(1); }
}
.task-card.completing { animation: bounce .28s cubic-bezier(.36,.07,.19,.97); }

.tc-icon  { font-size: 1.9rem; line-height: 1; }
.tc-title {
  font-size: .95rem;
  font-weight: 700;
  color: #2d3436;
  line-height: 1.3;
}
.task-card.done .tc-title { text-decoration: line-through; color: #bbb; }
.tc-desc  { font-size: .8rem; color: #999; line-height: 1.4; }

.tc-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: .5rem;
  border-top: 1px solid #f3f3f3;
}
.tc-points { font-size: .8rem; font-weight: 700; color: #856404; background: #fff8e1; border-radius: 8px; padding: .18rem .55rem; }
.tc-check  { font-size: 1.2rem; }

/* ── Kalender ────────────────────────────────────────────── */
#calendar-content { height: 100%; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  height: 100%;
  border: 1px solid #e8eaed;
  border-radius: 16px;
  overflow: hidden;
  background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}

.cal-day-col {
  display: flex;
  flex-direction: column;
  border-right: 1px solid #e8eaed;
  overflow: hidden;
}
.cal-day-col:last-child { border-right: none; }

.cal-day-header {
  padding: .55rem .25rem .4rem;
  text-align: center;
  border-bottom: 1px solid #e8eaed;
  flex-shrink: 0;
  background: #fafafa;
}
.cal-day-header.today { background: #f0eeff; }

.cal-weekday {
  font-size: .72rem;
  font-weight: 700;
  color: #999;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.cal-day-header.today .cal-weekday { color: #6c5ce7; }

.cal-date-num {
  font-size: 1.15rem;
  font-weight: 800;
  color: #2d3436;
  width: 32px;
  height: 32px;
  line-height: 32px;
  margin: .15rem auto 0;
  border-radius: 50%;
}
.cal-date-num.today {
  background: #6c5ce7;
  color: white;
}

.cal-day-events {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: .4rem .3rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.cal-event {
  border-left: 3px solid #6c5ce7;
  background: #6c5ce718;
  color: #2d3436;
  border-radius: 0 6px 6px 0;
  padding: .3rem .45rem;
  font-size: .75rem;
  line-height: 1.3;
}

.cal-event--allday {
  border-radius: 6px;
  border-left-width: 3px;
}

.cal-event--cont {
  opacity: .7;
  border-left-style: dashed;
}

.cal-event-time {
  font-size: .68rem;
  font-weight: 700;
  margin-bottom: .1rem;
}

.cal-event-title {
  font-weight: 600;
  word-break: break-word;
}

.cal-sync-hint {
  font-size: 0.75rem;
  color: #888;
  padding: 0.25rem 0.5rem 0;
  margin: 0;
}
.cal-sync-hint.cal-sync-error { color: #e17055; }

/* ── Statistik ───────────────────────────────────────────── */
.stats-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 1rem;
}

.stats-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: #2d3436;
}

.stats-totals {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
}

.stats-total-chip {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: white;
  border-radius: 50px;
  padding: .4rem .9rem .4rem .45rem;
  box-shadow: 0 2px 6px rgba(0,0,0,.07);
  border: 2px solid var(--pcolor, #ddd);
}

.stc-av {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.stc-av img { width: 100%; height: 100%; object-fit: cover; }

.stc-name { font-size: .85rem; font-weight: 700; color: #2d3436; }
.stc-pts  { font-size: .85rem; color: #856404; font-weight: 700; }

.stats-chart-wrap {
  flex: 1;
  min-height: 0;
  background: white;
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: 0 2px 6px rgba(0,0,0,.06);
  position: relative;
}

/* ── Placeholder ─────────────────────────────────────────── */
.placeholder-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: #ccc;
  gap: .5rem;
}
.ph-icon              { font-size: 3.5rem; }
.placeholder-msg h2   { font-size: 1.3rem; font-weight: 700; color: #d0d0d0; }
.placeholder-msg p    { font-size: .95rem; }

.loading-msg { color: #bbb; font-size: 1rem; padding: 2rem; text-align: center; }

/* ── Feier-Overlay ───────────────────────────────────────── */
.celebration {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(100,80,160,.5);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.celebration.hidden { display: none; }

.confetti-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.celebration-card {
  background: white;
  border-radius: 28px;
  padding: 2.5rem 4rem;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,.2);
  animation: pop .4s cubic-bezier(.34,1.56,.64,1) both;
  position: relative;
  z-index: 1;
}
@keyframes pop {
  from { transform: scale(.5); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}

.celeb-icon   { font-size: 4.5rem; }
.celebration-card h2 { font-size: 1.8rem; margin: .4rem 0; color: #2d3436; font-weight: 800; }
.celeb-player { font-size: 1.3rem; color: #636e72; margin: .2rem 0; }
.celeb-score  { font-size: 1.6rem; font-weight: 800; color: #6c5ce7; margin: .35rem 0 .9rem; }

.btn-celeb-ok {
  padding: .8rem 2.5rem;
  background: #6c5ce7;
  color: white;
  border: none;
  border-radius: 50px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .12s;
  -webkit-tap-highlight-color: transparent;
}
.btn-celeb-ok:active { background: #5a4bd1; transform: scale(.97); }

/* ── Konfetti ────────────────────────────────────────────── */
.confetti-piece {
  position: absolute;
  top: -20px;
  border-radius: 3px;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ── iPhone / Mobile ─────────────────────────────────────── */
@media (max-width: 768px) {

  /* Safe Area oben (Notch / Dynamic Island) */
  .top-bar {
    height: calc(72px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    padding-left: max(.75rem, env(safe-area-inset-left));
    padding-right: max(.75rem, env(safe-area-inset-right));
    gap: .5rem;
  }

  /* Top Bar: keine fixen Breiten mehr */
  .app-brand    { width: auto; font-size: 1.4rem; }
  .top-bar-right { width: auto; min-width: 0; gap: .4rem; }
  .date-label   { font-size: .78rem; }

  /* Spieler-Chips kleiner */
  .chip-circle  { width: 52px; height: 52px; font-size: 1.8rem; }
  .chip-name    { font-size: .62rem; }

  /* Layout: Content oben, Nav unten */
  .app-body { flex-direction: column; }

  /* Sidebar → Bottom Nav */
  .sidebar {
    order: 2;
    width: 100%;
    height: calc(56px + env(safe-area-inset-bottom));
    flex-direction: row;
    justify-content: space-around;
    padding: 0 1rem env(safe-area-inset-bottom);
    border-right: none;
    border-top: 1px solid #e8eaed;
    gap: 0;
  }
  .nav-item { width: 56px; height: 48px; }

  /* Content-Bereich */
  .content-area { order: 1; }
  .section      { padding: 1rem; }

  /* Spieler untereinander statt nebeneinander */
  .players-columns { flex-direction: column; gap: 1rem; }

  /* Kalender horizontal scrollbar falls zu schmal */
  #calendar-content { overflow-x: auto; }
  .cal-grid         { min-width: 560px; }

  /* Eingabe-Zoom auf iOS verhindern (min. 16px) */
  .da-input { font-size: 16px; }

  /* Feier-Overlay kompakter */
  .celebration-card { padding: 2rem 2rem; }
}
