/* ==========================================================================
   Gym Tracker - Stylesheet
   Modernes Glassmorphism-Design, gruener Akzent, Dark Mode als Standard.
   ========================================================================== */

:root {
  --accent: #22c55e;
  --accent-dark: #16a34a;
  --accent-glow: rgba(34, 197, 94, 0.45);
  --danger: #ef4444;
  --warning: #f59e0b;
  --ice: #38bdf8;

  --bg-1: #0b1220;
  --bg-2: #101a2c;
  --bg-3: #0d1526;

  --glass-bg: rgba(255, 255, 255, 0.06);
  --glass-bg-strong: rgba(255, 255, 255, 0.1);
  --glass-border: rgba(255, 255, 255, 0.14);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-strong: 0 20px 50px rgba(0, 0, 0, 0.45);

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 10px;

  color-scheme: dark;
}

[data-theme='light'] {
  --bg-1: #eef4f8;
  --bg-2: #e4edf3;
  --bg-3: #f7fafc;
  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-bg-strong: rgba(255, 255, 255, 0.75);
  --glass-border: rgba(15, 23, 42, 0.08);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --shadow-soft: 0 10px 30px rgba(15, 23, 42, 0.12);
  --shadow-strong: 0 20px 50px rgba(15, 23, 42, 0.18);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

html {
  /* Verhindert schwarze Flaechen beim Overscroll/Bounce auf iOS, wenn der
     Viewport (z. B. unter der Home-Indicator-Safe-Area) ueber den Inhalt
     der <body> hinausragt. */
  background: var(--bg-1);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  background:
    radial-gradient(circle at 15% 10%, rgba(34, 197, 94, 0.16), transparent 45%),
    radial-gradient(circle at 85% 0%, rgba(56, 189, 248, 0.10), transparent 40%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2) 55%, var(--bg-3));
  background-attachment: fixed;
  min-height: 100%;
  min-height: 100dvh;
  transition: background-color 0.3s ease, color 0.3s ease;
  /* Safe-Area am unteren Rand (Home-Indicator auf iPhones ohne Home-Button)
     mit ins Padding einrechnen, statt sie ungestyled zu lassen. */
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: inherit; }

.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow-soft);
  /* Eigene Compositing-Layer erzwingen: verhindert einen bekannten iOS-Safari-
     Renderfehler, bei dem verschachtelte/gestapelte backdrop-filter-Elemente
     beim Scrollen kurzzeitig schwarz oder unstyled aufblitzen. */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

/* --------------------------------------------------------------------- */
/* Layout                                                                 */
/* --------------------------------------------------------------------- */

.app-shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand .emoji { font-size: 1.6rem; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: transform 0.15s ease, background 0.2s ease;
}
.icon-btn:hover { transform: translateY(-2px); background: var(--glass-bg); }
.icon-btn:active { transform: translateY(0); }

.btn {
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #06210f;
  box-shadow: 0 8px 20px var(--accent-glow);
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-secondary {
  background: var(--glass-bg-strong);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
}
.btn-secondary:hover { background: var(--glass-bg); }

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

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

/* --------------------------------------------------------------------- */
/* Quote banner                                                           */
/* --------------------------------------------------------------------- */

.quote-banner {
  padding: 16px 22px;
  margin-bottom: 18px;
  font-style: italic;
  color: var(--text-secondary);
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.quote-banner .quote-icon { font-size: 1.2rem; flex-shrink: 0; }

/* --------------------------------------------------------------------- */
/* Tabs                                                                   */
/* --------------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  padding: 6px;
  overflow-x: auto;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}
.tab-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #06210f;
  box-shadow: 0 6px 16px var(--accent-glow);
}
.tab-panel { display: none; animation: fadeIn 0.35s ease; }
.tab-panel.active { display: block; }

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

/* --------------------------------------------------------------------- */
/* Streak / status cards                                                  */
/* --------------------------------------------------------------------- */

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.status-card {
  padding: 18px 20px;
  text-align: center;
}
.status-card .status-value {
  font-size: 1.9rem;
  font-weight: 800;
  margin: 4px 0;
}
.status-card .status-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* --------------------------------------------------------------------- */
/* Weekly progress                                                        */
/* --------------------------------------------------------------------- */

.week-progress-card {
  padding: 22px 24px;
  margin-bottom: 22px;
}
.week-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.week-progress-header h2 { margin: 0; font-size: 1.15rem; }
.week-progress-header .week-range { color: var(--text-secondary); font-size: 0.9rem; }

.progress-bar-track {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  height: 14px;
  overflow: hidden;
  margin: 10px 0 8px;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-dark), var(--accent));
  width: 0%;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 0 0 12px var(--accent-glow);
}
.progress-caption {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.goal-banner {
  margin-top: 14px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.22), rgba(34, 197, 94, 0.08));
  border: 1px solid rgba(34, 197, 94, 0.35);
  font-weight: 700;
  text-align: center;
  display: none;
}
.goal-banner.visible { display: block; animation: popIn 0.5s ease; }

@keyframes popIn {
  0% { transform: scale(0.85); opacity: 0; }
  60% { transform: scale(1.03); opacity: 1; }
  100% { transform: scale(1); }
}

/* --------------------------------------------------------------------- */
/* Calendar                                                               */
/* --------------------------------------------------------------------- */

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

@media (max-width: 820px) {
  .calendar-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 520px) {
  .calendar-grid { grid-template-columns: repeat(2, 1fr); }
}

.day-card {
  padding: 16px 10px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  position: relative;
}
.day-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-strong); }
.day-card:active { transform: scale(0.96); }

.day-card.is-today { border-color: var(--accent); }
.day-card.is-future { opacity: 0.45; cursor: not-allowed; }
.day-card.is-future:hover { transform: none; box-shadow: var(--shadow-soft); }

.day-card.completed {
  background: linear-gradient(160deg, rgba(34, 197, 94, 0.22), var(--glass-bg));
  border-color: rgba(34, 197, 94, 0.45);
}

.day-weekday {
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 2px;
}
.day-date {
  color: var(--text-secondary);
  font-size: 0.78rem;
  margin-bottom: 10px;
}
.day-icon {
  font-size: 1.9rem;
  display: block;
  line-height: 1;
}
.day-status-label {
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--text-secondary);
}
.preferred-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.18);
  color: var(--ice);
  border: 1px solid rgba(56, 189, 248, 0.35);
}

/* --------------------------------------------------------------------- */
/* History                                                                */
/* --------------------------------------------------------------------- */

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-row {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.history-week-label { font-weight: 700; min-width: 64px; }
.history-range { color: var(--text-secondary); font-size: 0.85rem; }
.history-count { font-size: 0.85rem; color: var(--text-secondary); }

.history-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
}
.history-status.success { background: rgba(34, 197, 94, 0.18); color: var(--accent); }
.history-status.freeze_used { background: rgba(56, 189, 248, 0.18); color: var(--ice); }
.history-status.failed { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------- */
/* Achievements                                                           */
/* --------------------------------------------------------------------- */

.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin: 20px 0;
}

.achievement-card {
  padding: 16px;
  text-align: center;
  opacity: 0.4;
  filter: grayscale(1);
  transition: all 0.3s ease;
}
.achievement-card.unlocked {
  opacity: 1;
  filter: none;
  border-color: rgba(34, 197, 94, 0.4);
}
.achievement-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 6px;
}
.achievement-icon svg {
  width: 38px;
  height: 48px;
}
.achievement-title { font-weight: 700; font-size: 0.9rem; }
.achievement-desc { font-size: 0.76rem; color: var(--text-secondary); margin-top: 4px; }

/* --------------------------------------------------------------------- */
/* Sections / misc                                                        */
/* --------------------------------------------------------------------- */

.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 26px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.hidden-file-input { display: none; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 22px;
  border-radius: 999px;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-strong);
  opacity: 0;
  transition: all 0.35s ease;
  pointer-events: none;
  z-index: 60;
  font-size: 0.9rem;
  max-width: 90vw;
  text-align: center;
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error { border-color: rgba(239, 68, 68, 0.4); color: #fecaca; }

#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

/* --------------------------------------------------------------------- */
/* Matcha-Gutschein Easter Egg                                           */
/* --------------------------------------------------------------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 16, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 70;
}
.modal-overlay.visible {
  display: flex;
  animation: fadeIn 0.25s ease;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  padding: 32px 28px;
  text-align: center;
  animation: popIn 0.4s ease;
  background: linear-gradient(160deg, rgba(34, 197, 94, 0.14), var(--glass-bg-strong));
}

.modal-icon {
  font-size: 2.6rem;
  margin-bottom: 10px;
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.modal-card p {
  color: var(--text-secondary);
  font-size: 0.92rem;
  margin: 0 0 18px;
}

.coupon-code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: rgba(34, 197, 94, 0.14);
  border: 1px dashed rgba(34, 197, 94, 0.5);
  color: var(--accent);
  margin-bottom: 20px;
}

.modal-card .btn-primary { width: 100%; justify-content: center; }

/* --------------------------------------------------------------------- */
/* Login page                                                             */
/* --------------------------------------------------------------------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 36px 32px;
  text-align: center;
}

.login-logo {
  font-size: 2.4rem;
  margin-bottom: 6px;
}

.login-card h1 {
  font-size: 1.4rem;
  margin: 0 0 4px;
}

.login-card p.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin: 0 0 24px;
}

.form-field {
  text-align: left;
  margin-bottom: 16px;
}
.form-field label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-size: 0.95rem;
}
.form-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fecaca;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: none;
}
.login-error.visible { display: block; }

.login-card .btn-primary { width: 100%; justify-content: center; padding: 12px; }

.login-quote {
  margin-top: 22px;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
}

@media (max-width: 480px) {
  .topbar { padding: 14px 16px; }
  .brand { font-size: 1.05rem; }
}
