:root {
  --bg: #070604;
  --bg-soft: #171410;
  --bg-softer: #211c14;
  --text: #f6f2e9;
  --text-muted: #a89e8a;
  --gold: #c9a227;
  --gold-light: #e9d28a;
  --gradient: linear-gradient(135deg, #8a6a1f 0%, #c9a227 55%, #e9d28a 100%);
  --danger: #d4574b;
  --radius: 16px;
}

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

[hidden] {
  display: none !important;
}

html {
  height: 100%;
}

body {
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* Dezenter Goldschimmer im Hintergrund */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 20% 0%, rgba(201, 162, 39, 0.10), transparent 70%),
    radial-gradient(ellipse 50% 40% at 85% 100%, rgba(233, 210, 138, 0.06), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 27rem;
  margin: 0 auto;
  padding: calc(1.25rem + env(safe-area-inset-top)) 1.25rem calc(6.5rem + env(safe-area-inset-bottom));
}

.gradient-text {
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

h1 {
  font-size: clamp(1.6rem, 6vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.date-line {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.3rem;
}

.icon-btn {
  width: 2.75rem;
  height: 2.75rem;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: var(--bg-soft);
  border: 1px solid rgba(201, 162, 39, 0.25);
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.icon-btn svg {
  width: 1.3rem;
  height: 1.3rem;
}

.icon-btn:hover {
  color: var(--gold-light);
  border-color: rgba(201, 162, 39, 0.55);
}

.icon-btn:active {
  transform: scale(0.94);
}

/* ---------- Habit-Liste ---------- */

.habit-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.habit {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  background: var(--bg-soft);
  border: 1px solid rgba(201, 162, 39, 0.14);
  border-radius: var(--radius);
  padding: 0.875rem 0.875rem 0.875rem 1rem;
  transition: border-color 0.25s ease, background-color 0.25s ease;
}

.habit.done {
  border-color: rgba(201, 162, 39, 0.4);
  background: linear-gradient(135deg, rgba(201, 162, 39, 0.08), rgba(23, 20, 16, 1) 60%);
}

/* Abhak-Button */

.check {
  position: relative;
  width: 2.75rem;
  height: 2.75rem;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid rgba(201, 162, 39, 0.45);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.check svg {
  width: 1.5rem;
  height: 1.5rem;
  fill: none;
  stroke: #171204;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.check .tick {
  stroke-dasharray: 26;
  stroke-dashoffset: 26;
  transition: stroke-dashoffset 0.25s ease;
}

.habit.done .check {
  background: var(--gradient);
  border-color: transparent;
  box-shadow: 0 4px 18px rgba(201, 162, 39, 0.35);
}

.habit.done .check .tick {
  stroke-dashoffset: 0;
}

/* Abhak-Animation (nur beim Klick, nicht beim Neuzeichnen) */

.habit.celebrate .check {
  animation: check-pop 0.5s cubic-bezier(0.22, 1.6, 0.36, 1);
}

.habit.celebrate .check .tick {
  animation: tick-draw 0.35s ease-out 0.08s both;
}

.habit.celebrate .check::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 2px solid var(--gold-light);
  animation: ring-pulse 0.6s ease-out 0.05s both;
  pointer-events: none;
}

@keyframes check-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@keyframes tick-draw {
  from { stroke-dashoffset: 26; }
  to { stroke-dashoffset: 0; }
}

@keyframes ring-pulse {
  from { opacity: 0.9; transform: scale(1); }
  to { opacity: 0; transform: scale(1.8); }
}

/* Titel + Wochenübersicht */

.habit-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.habit-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.habit-emoji {
  font-size: 1.15rem;
  line-height: 1;
}

.habit-emoji:empty {
  display: none;
}

.habit-name {
  font-weight: 600;
  font-size: 1.02rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.25s ease;
}

.habit.done .habit-name {
  color: var(--text-muted);
}

.week {
  display: flex;
  gap: 0.55rem;
}

.day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.day-label {
  font-size: 0.55rem;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  opacity: 0.75;
}

.day-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: rgba(246, 242, 233, 0.13);
}

.day.filled .day-dot {
  background: var(--gradient);
  box-shadow: 0 0 6px rgba(201, 162, 39, 0.55);
}

.day.today .day-label {
  color: var(--gold-light);
  opacity: 1;
  font-weight: 700;
}

.day.today .day-dot {
  outline: 1px solid rgba(233, 210, 138, 0.55);
  outline-offset: 2px;
}

/* Tage, die noch kommen, treten zurück */
.day.future {
  opacity: 0.4;
}

/* Streak + Bearbeiten */

.habit-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
  flex-shrink: 0;
}

.streak {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(246, 242, 233, 0.05);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  white-space: nowrap;
}

.streak.active {
  color: var(--gold-light);
  background: rgba(201, 162, 39, 0.12);
}

.edit-btn {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--text-muted);
  opacity: 0.7;
  cursor: pointer;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.edit-btn svg {
  width: 1.05rem;
  height: 1.05rem;
}

.edit-btn:hover {
  opacity: 1;
  color: var(--gold-light);
}

/* ---------- Leerer Zustand ---------- */

.empty-state {
  text-align: center;
  padding: 3.5rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.875rem;
}

.empty-emoji {
  font-size: 3rem;
  line-height: 1;
}

.empty-state h2 {
  font-size: 1.35rem;
  font-weight: 700;
}

.empty-state p {
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 18rem;
  margin-bottom: 0.5rem;
}

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  border: none;
  border-radius: var(--radius);
  padding: 0.9rem 1.5rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--gradient);
  color: #171204;
  box-shadow: 0 8px 28px rgba(201, 162, 39, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 12px 36px rgba(201, 162, 39, 0.45);
}

.btn-secondary {
  background: var(--bg-soft);
  border: 1px solid rgba(201, 162, 39, 0.35);
}

.btn-secondary:hover {
  background: var(--bg-softer);
  border-color: rgba(201, 162, 39, 0.6);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger-ghost {
  background: transparent;
  border: 1px solid rgba(212, 87, 75, 0.45);
  color: var(--danger);
}

.btn-danger-ghost:hover {
  background: rgba(212, 87, 75, 0.1);
  border-color: rgba(212, 87, 75, 0.7);
}

/* ---------- FAB ---------- */

.fab {
  position: fixed;
  right: max(1.25rem, calc(50% - 13.5rem + 1.25rem));
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
  width: 3.6rem;
  height: 3.6rem;
  border-radius: 50%;
  border: none;
  background: var(--gradient);
  color: #171204;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(201, 162, 39, 0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  z-index: 5;
}

.fab svg {
  width: 1.5rem;
  height: 1.5rem;
}

.fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 38px rgba(201, 162, 39, 0.55);
}

.fab:active {
  transform: scale(0.94);
}

/* Solange ein Modal offen ist, tritt der FAB zurück */
body:has(.overlay:not([hidden])) .fab {
  opacity: 0;
  pointer-events: none;
}

/* ---------- Modals ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  animation: overlay-in 0.2s ease both;
}

.overlay[hidden] {
  display: none;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sheet {
  width: 100%;
  max-width: 27rem;
  background: var(--bg-soft);
  border: 1px solid rgba(201, 162, 39, 0.2);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  padding: 1.5rem 1.5rem calc(1.5rem + env(safe-area-inset-bottom));
  animation: sheet-up 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes sheet-up {
  from { transform: translateY(2rem); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
}

.field {
  display: block;
  margin-bottom: 1.1rem;
}

.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
}

input[type="text"] {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: #0f0d09;
  border: 1px solid rgba(201, 162, 39, 0.25);
  border-radius: 12px;
  padding: 0.8rem 0.95rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]::placeholder {
  color: rgba(168, 158, 138, 0.6);
}

input[type="text"]:focus {
  border-color: rgba(201, 162, 39, 0.65);
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.12);
}

.emoji-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.6rem;
}

.emoji-chip {
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.25rem;
  display: grid;
  place-items: center;
  background: #0f0d09;
  border: 1px solid rgba(201, 162, 39, 0.2);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
}

.emoji-chip:hover {
  border-color: rgba(201, 162, 39, 0.5);
}

.emoji-chip:active {
  transform: scale(0.92);
}

.emoji-chip.selected {
  background: rgba(201, 162, 39, 0.18);
  border-color: var(--gold);
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

#btn-delete {
  width: 100%;
  margin-top: 0.6rem;
}

#btn-reset {
  width: 100%;
}

.settings-hint {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 1.1rem;
}

/* Sicherheitsabfrage: zentrierte Karte */

#modal-confirm {
  justify-content: center;
  padding: 1.5rem;
}

.confirm-card {
  width: 100%;
  max-width: 21rem;
  background: var(--bg-soft);
  border: 1px solid rgba(201, 162, 39, 0.25);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  animation: sheet-up 0.25s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.confirm-card h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
}

.confirm-card p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.55;
  margin-bottom: 1.25rem;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

/* ---------- Sonstiges ---------- */

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