:root {
  --lav: #c4b5fd;
  --lav-deep: #a78bfa;
  --rose: #fbcfe8;
  --rose-deep: #f9a8d4;

  --bg: #faf5ff;
  --bg-grad-a: #ede9fe;
  --bg-grad-b: #fce7f3;
  --surface: #ffffff;
  --surface-2: #faf7ff;
  --border: #ecdcf7;
  --text: #3b2f4a;
  --text-soft: #7a6e88;
  --primary: #a78bfa;
  --primary-ink: #ffffff;
  --shadow: 0 10px 30px rgba(167, 139, 250, 0.18);
  --shadow-soft: 0 4px 14px rgba(167, 139, 250, 0.12);
  --radius: 20px;
  --radius-sm: 12px;
  --focus: #7c3aed;

  /* Stimmungsfarben (5 Stufen) */
  --m1: #b08fd6; /* sehr schlecht – gedämpftes Violett */
  --m2: #c4b5fd; /* schlecht – Lavendel */
  --m3: #e9d5ff; /* neutral – helles Flieder */
  --m4: #fbcfe8; /* gut – Rosé */
  --m5: #f9a8d4; /* sehr gut – kräftiges Rosa */
  --empty: #f1ecf7;
}

[data-theme="dark"] {
  --bg: #1a1426;
  --bg-grad-a: #241a33;
  --bg-grad-b: #2a1a2c;
  --surface: #251d34;
  --surface-2: #2d2440;
  --border: #3a2f4f;
  --text: #f1eafc;
  --text-soft: #b6a9c9;
  --primary: #c4b5fd;
  --primary-ink: #2a1a40;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --shadow-soft: 0 4px 14px rgba(0, 0, 0, 0.35);
  --focus: #d8b4fe;

  --m1: #8b6fb8;
  --m2: #9d86e0;
  --m3: #b89cd9;
  --m4: #e09bc4;
  --m5: #ec84b8;
  --empty: #2e2542;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--bg-grad-b), transparent 60%),
    radial-gradient(1000px 500px at -10% 0%, var(--bg-grad-a), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
  overflow-x: hidden;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  z-index: 100;
}
.skip-link:focus { left: 12px; top: 12px; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(135deg, var(--lav) 0%, var(--rose) 100%);
  box-shadow: var(--shadow-soft);
}
[data-theme="dark"] .app-header {
  background: linear-gradient(135deg, #3a2c55 0%, #4a2c47 100%);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.45);
  color: #5b3a7a;
  flex: none;
}
[data-theme="dark"] .brand-mark { background: rgba(255,255,255,0.12); color: #efe2ff; }
.brand h1 {
  font-size: 1.1rem;
  margin: 0;
  color: #4a2f63;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
[data-theme="dark"] .brand h1 { color: #f3e9ff; }

.icon-btn {
  appearance: none;
  border: none;
  background: rgba(255, 255, 255, 0.4);
  color: #4a2f63;
  width: 38px; height: 38px;
  border-radius: 12px;
  font-size: 1.15rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex: none;
  transition: transform 0.15s ease, background 0.15s ease;
}
[data-theme="dark"] .icon-btn { background: rgba(255,255,255,0.12); color: #efe2ff; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.65); }
.icon-btn:active { transform: scale(0.94); }

.tabs {
  display: flex;
  gap: 6px;
  max-width: 720px;
  margin: 0 auto;
  padding: 4px 12px 12px;
}
.tab {
  flex: 1;
  appearance: none;
  border: none;
  background: rgba(255, 255, 255, 0.35);
  color: #4a2f63;
  padding: 9px 6px;
  border-radius: 12px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
[data-theme="dark"] .tab { background: rgba(255,255,255,0.08); color: #e7d8ff; }
.tab:hover { background: rgba(255, 255, 255, 0.55); }
.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

/* Main + views */
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  outline: none;
}
.view { display: none; animation: fade 0.25s ease; }
.view.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.hero-card h2 { margin: 2px 0 4px; font-size: 1.3rem; }
.date-line {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: capitalize;
}
.hint { color: var(--text-soft); font-size: 0.9rem; margin: 0 0 14px; }

/* Mood picker */
.mood-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}
.mood-opt {
  appearance: none;
  border: 2px solid transparent;
  background: var(--surface-2);
  border-radius: 16px;
  padding: 12px 4px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  min-width: 0;
}
.mood-opt .emoji {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  line-height: 1;
}
.mood-opt .lbl {
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--text-soft);
  text-align: center;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.mood-opt:hover { transform: translateY(-2px); }
.mood-opt.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(167, 139, 250, 0.18);
  transform: translateY(-2px);
}
.mood-opt.is-selected .lbl { color: var(--text); }

/* Note */
.note-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.note-input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px;
  font: inherit;
  font-size: 0.95rem;
  resize: vertical;
  min-height: 64px;
}
.note-input::placeholder { color: var(--text-soft); opacity: 0.8; }
.note-meta {
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-soft);
  margin-top: 4px;
}

/* Buttons */
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.data-actions { margin-top: 18px; }
.btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--lav-deep), var(--rose-deep));
  color: var(--primary-ink);
  flex: 1;
  box-shadow: var(--shadow-soft);
}
[data-theme="dark"] .btn.primary { color: #1a1426; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.ghost:hover { background: var(--border); }
.btn.danger {
  background: var(--surface-2);
  color: #c2410c;
  border: 1px solid #f3c6a8;
}
[data-theme="dark"] .btn.danger { color: #fca5a5; border-color: #5a3030; }
.btn.danger:hover { background: #fff0e7; }
[data-theme="dark"] .btn.danger:hover { background: #3a2020; }

/* Streak card */
.streak-card { display: flex; gap: 14px; }
.streak-item {
  flex: 1;
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 8px;
}
.streak-num {
  display: block;
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--lav-deep), var(--rose-deep));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.streak-lbl { display: block; font-size: 0.78rem; color: var(--text-soft); margin-top: 2px; }

/* Calendar */
.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.cal-title { margin: 0; font-size: 1.1rem; text-align: center; flex: 1; text-transform: capitalize; }
.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
.weekdays span {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-soft);
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-cell {
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--empty);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 4px 6px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-soft);
  cursor: pointer;
  position: relative;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
  min-width: 0;
}
.cal-cell.empty { visibility: hidden; cursor: default; }
.cal-cell.has-mood { color: #4a2f63; }
[data-theme="dark"] .cal-cell.has-mood { color: #1a1426; }
.cal-cell.today { outline: 2px solid var(--focus); outline-offset: 1px; }
.cal-cell.has-note::before {
  content: "•";
  position: absolute;
  left: 6px; top: 2px;
  font-size: 1rem;
  line-height: 1;
  color: rgba(74, 47, 99, 0.7);
}
[data-theme="dark"] .cal-cell.has-note::before { color: rgba(26,20,38,0.7); }
.cal-cell:not(.empty):hover { transform: translateY(-2px); box-shadow: var(--shadow-soft); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  justify-content: center;
}
.legend .leg {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-soft);
}
.legend .swatch {
  width: 16px; height: 16px;
  border-radius: 5px;
  border: 1px solid var(--border);
  flex: none;
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin: 16px 0 8px;
}
.stat-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 12px;
  text-align: center;
}
.stat-box .big {
  font-size: 1.6rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.stat-box .lbl { font-size: 0.78rem; color: var(--text-soft); margin-top: 4px; }
.sub { margin: 22px 0 10px; font-size: 1rem; }

.dist { display: flex; flex-direction: column; gap: 10px; }
.dist-row { display: flex; align-items: center; gap: 10px; }
.dist-emoji { width: 30px; text-align: center; font-size: 1.2rem; flex: none; }
.dist-track {
  flex: 1;
  background: var(--surface-2);
  border-radius: 999px;
  height: 18px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.dist-fill { height: 100%; border-radius: 999px; transition: width 0.5s ease; min-width: 2px; }
.dist-val { width: 34px; text-align: right; font-size: 0.8rem; color: var(--text-soft); flex: none; }

.empty-state {
  text-align: center;
  color: var(--text-soft);
  padding: 24px 8px;
  font-size: 0.95rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(40, 25, 55, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
  animation: fade 0.2s ease;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 8px; }
.modal p { margin: 0 0 18px; color: var(--text-soft); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  background: var(--text);
  color: var(--surface);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Focus visibility */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

@media (max-width: 380px) {
  .brand h1 { font-size: 1rem; }
  .mood-opt .emoji { width: 38px; height: 38px; font-size: 1.3rem; }
  .card { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
