@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  --bg: #EDEFEA;
  --bg-gradient-start: #F5F7F2;
  --bg-gradient-end: #EDEFEA;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-solid: #FFFFFF;
  --surface-border: rgba(0, 0, 0, 0.06);
  --ink: #263230;
  --ink-soft: #63706C;
  --line: #DCDFD7;
  --familie: #2F6F6B;
  --familie-soft: #DCEAE8;
  --sport: #C97D3C;
  --sport-soft: #F3E3D2;
  --beide: #6B5CA5;
  --beide-soft: #E8E4F3;
  --danger: #B45151;
  --radius: 20px;
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --bg: #1C1C1E;
    --bg-gradient-start: #2C2E30;
    --bg-gradient-end: #1C1C1E;
    --surface: rgba(44, 46, 48, 0.9);
    --surface-solid: #2C2E30;
    --surface-border: rgba(255, 255, 255, 0.08);
    --ink: #FFFFFF;
    --ink-soft: #A0A7A5;
    --line: #3A3C3E;
    --familie: #4FB4AF;
    --familie-soft: #2F6F6B40;
    --sport: #FFB76B;
    --sport-soft: #C97D3C40;
    --beide: #A497E6;
    --beide-soft: #6B5CA540;
  }
}

html.dark {
  --bg: #1C1C1E;
  --bg-gradient-start: #2C2E30;
  --bg-gradient-end: #1C1C1E;
  --surface: rgba(44, 46, 48, 0.9);
  --surface-solid: #2C2E30;
  --surface-border: rgba(255, 255, 255, 0.08);
  --ink: #FFFFFF;
  --ink-soft: #A0A7A5;
  --line: #3A3C3E;
  --familie: #4FB4AF;
  --familie-soft: #2F6F6B40;
  --sport: #FFB76B;
  --sport-soft: #C97D3C40;
  --beide: #A497E6;
  --beide-soft: #6B5CA540;
}

.theme-toggle {
  display: flex;
  gap: 10px;
}

.theme-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-solid);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-btn:hover {
  background: var(--surface);
}

.theme-btn.active {
  border-color: var(--familie);
  background: var(--familie-soft);
  color: var(--familie);
  font-weight: 600;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: linear-gradient(180deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  margin: 0;
}

.mono { font-family: 'IBM Plex Mono', monospace; }

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  padding: max(20px, env(safe-area-inset-top)) 18px 40px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 22px;
}
.topbar-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar h1 { font-size: 21px; }
.version-badge {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 100px;
  padding: 2px 8px;
  vertical-align: middle;
  margin-left: 4px;
}

/* ---------- Ladeanimation ---------- */
.loading-screen {
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.loading-vial {
  width: 56px; height: 74px;
  animation: loading-pulse 1.6s ease-in-out infinite;
  transform-origin: center;
}
@keyframes loading-pulse {
  0%, 100% { transform: scale(1) rotate(0deg); opacity: .75; }
  50% { transform: scale(1.08) rotate(8deg); opacity: 1; }
}
.loading-dots { display: flex; gap: 6px; }
.loading-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--familie);
  animation: loading-blink 1.3s infinite ease-in-out;
}
.loading-dots span:nth-child(2) { animation-delay: .18s; background: var(--sport); }
.loading-dots span:nth-child(3) { animation-delay: .36s; background: var(--beide); }
@keyframes loading-blink {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-4px); }
}
.btn-spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: white;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: -1px;
  animation: loading-spin .6s linear infinite;
}
.btn-ghost .btn-spinner, .btn-danger-ghost .btn-spinner {
  border-color: rgba(99,112,108,0.25);
  border-top-color: var(--ink-soft);
}
@keyframes loading-spin { to { transform: rotate(360deg); } }
.topbar .who {
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 100px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.who .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------- Profile picker ---------- */
.picker {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 40px;
  padding: max(40px, env(safe-area-inset-top)) 20px max(40px, env(safe-area-inset-bottom));
  box-sizing: border-box;
}

.picker-header {
  text-align: center;
  padding-top: 20px;
}

.picker-logo {
  margin-bottom: 28px;
}

.logo-vial {
  width: 80px;
  height: 105px;
  margin: 0 auto;
  animation: logoFloat 4s ease-in-out infinite;
  filter: drop-shadow(0 8px 24px rgba(0, 122, 255, 0.12));
}

@keyframes logoFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

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

.picker .eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 14px;
  font-weight: 600;
}

.picker h1 { 
  font-size: 32px; 
  margin-bottom: 8px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.7px;
}

.picker-subtitle {
  font-size: 18px;
  color: var(--ink-soft);
  margin: 0;
  font-weight: 400;
}

.profile-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 380px;
  margin: 0 auto;
  width: 100%;
}

.profile-card {
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
}

.profile-card::after {
  content: '';
  position: absolute;
  right: 20px;
  top: 50%;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--ink-soft);
  border-bottom: 2px solid var(--ink-soft);
  transform: translateY(-50%) rotate(-45deg);
  opacity: 0.4;
}

.profile-card:hover, .profile-card:active { 
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
  transform: translateY(-2px);
  background: var(--surface);
}

.profile-card:active {
  transform: translateY(0) scale(0.98);
}

.profile-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.08);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.avatar-text {
  color: white;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', sans-serif;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.5px;
}

.profile-info {
  flex: 1;
}

.profile-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 3px;
  letter-spacing: -0.3px;
}

.profile-role {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 500;
}

/* ---------- Summary bar ---------- */
.summary-bar {
  background: var(--sport-soft);
  color: #8A5423;
  border-radius: 100px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 16px;
}
.summary-bar.done {
  background: var(--familie-soft);
  color: var(--familie);
}

/* ---------- Daily bar chart ---------- */
.daily-chart {
  width: 100%;
  height: 140px;
  margin-top: 8px;
}

/* ---------- Sand-vial progress ---------- */
.vials {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 22px;
}
.vial-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 14px 14px;
  text-align: center;
}
.vial-card .label { font-size: 13px; color: var(--ink-soft); margin-bottom: 8px; }
.vial-svg { width: 64px; height: 84px; }
.vial-card .value { margin-top: 6px; font-size: 15px; font-weight: 600; }
.vial-card .goal { font-size: 12px; color: var(--sport); font-weight: 600; }
.vial-card .goal.done { color: var(--familie); }

.head-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 100px;
  margin-left: auto;
}
.head-badge.done { background: var(--familie-soft); color: var(--familie); }

/* ---------- Section headings ---------- */
.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-soft);
  margin: 26px 0 10px;
}
.section-title.toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.section-title.toggle .chevron { font-size: 11px; }

.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 22px 0 4px;
}
.week-nav .week-nav-label { font-size: 13px; color: var(--ink-soft); }
.week-nav button:disabled { opacity: .35; cursor: default; }

.sibling-block {
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.sibling-block .head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }

/* ---------- Due-today cards ---------- */
.due-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--sport);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.due-card.familie { border-left-color: var(--familie); }
.due-card.beide { border-left-color: var(--beide); }
.due-card.task-done { opacity: .6; }
.due-card .top { display: flex; justify-content: space-between; align-items: baseline; }
.due-card .top strong { font-size: 15px; }
.due-card .top span { font-size: 13px; color: var(--ink-soft); }
.due-card .actions { display: flex; gap: 8px; margin-top: 10px; }

/* ---------- Buttons ---------- */
button { font-family: inherit; cursor: pointer; border: none; }
.btn {
  padding: 9px 15px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 600;
}
.btn-primary { background: var(--ink); color: white; }
.btn-familie { background: var(--familie); color: white; }
.btn-sport { background: var(--sport); color: white; }
.btn-beide { background: var(--beide); color: white; }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 1px solid #E7CFCF; }
.btn-block { width: 100%; text-align: center; padding: 13px; font-size: 15px; margin-top: 14px; }

/* ---------- Entry list ---------- */
.entry-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.entry-row:last-child { border-bottom: none; }
.entry-row-clickable { cursor: pointer; transition: background .1s ease; margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: 8px; }
.entry-row-clickable:active { background: var(--bg); }
.entry-row .left .name { font-size: 14px; font-weight: 600; }
.entry-row .left .desc { font-size: 13px; color: var(--ink-soft); }
.entry-row .right { text-align: right; font-size: 14px; }
.entry-row .right .cat-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 100px;
  display: inline-block;
  margin-top: 2px;
}
.cat-tag.familie { background: var(--familie-soft); color: var(--familie); }
.cat-tag.sport { background: var(--sport-soft); color: var(--sport); }
.cat-tag.beide { background: var(--beide-soft); color: var(--beide); }
.skipped { opacity: .5; text-decoration: line-through; }

/* ---------- Forms / modal sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(38,50,48,0.35);
  display: flex; align-items: flex-end; z-index: 40;
}
.sheet {
  background: var(--surface);
  width: 100%;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px max(20px, env(safe-area-inset-bottom));
  max-height: 86vh;
  overflow-y: auto;
}
.sheet h2 { font-size: 19px; margin-bottom: 14px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
}
.field textarea { resize: vertical; min-height: 60px; }
.segmented { display: flex; gap: 8px; }
.segmented .opt {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--bg);
}
.segmented .opt.active.familie { background: var(--familie); color: white; border-color: var(--familie); }
.segmented .opt.active.sport { background: var(--sport); color: white; border-color: var(--sport); }
.segmented .opt.active.beide { background: var(--beide); color: white; border-color: var(--beide); }
.sheet-actions { display: flex; gap: 10px; margin-top: 4px; }
.sheet-actions .btn { flex: 1; }

/* ---------- Parent overview ---------- */
.child-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.child-block .head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }

.empty-state {
  text-align: center;
  padding: 30px 10px;
  color: var(--ink-soft);
  font-size: 14px;
}

.fab-row { display: flex; gap: 10px; margin-top: 18px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: white; padding: 10px 18px; border-radius: 100px;
  font-size: 14px; z-index: 60;
}
