/* ===========================================================
   Schlaf-Rechner – eigenes Nacht-Design (Indigo/Navy + Mond)
   =========================================================== */

:root {
  --bg-0: #0b0a2a;
  --bg-1: #1e1b4b;
  --bg-2: #2a2563;
  --surface: rgba(30, 27, 75, 0.72);
  --surface-solid: #211d54;
  --surface-2: rgba(255, 255, 255, 0.06);
  --border: rgba(148, 163, 232, 0.22);
  --border-strong: rgba(165, 180, 252, 0.45);

  --text: #eef0ff;
  --text-dim: #b9bdf0;
  --text-mute: #8c90c9;

  --accent: #a5b4fc;        /* helles Indigo */
  --accent-2: #c4b5fd;      /* lavendel */
  --accent-strong: #818cf8;
  --gold: #fcd34d;          /* Mond/Stern-Gold */
  --best: #34d399;          /* beste Option */
  --best-soft: rgba(52, 211, 153, 0.16);

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 18px 50px rgba(5, 4, 30, 0.55);
  --maxw: 640px;
}

/* Heller Modus */
[data-theme="light"] {
  --bg-0: #e8eaff;
  --bg-1: #f3f4ff;
  --bg-2: #ffffff;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --surface-2: rgba(30, 27, 75, 0.05);
  --border: rgba(99, 102, 178, 0.22);
  --border-strong: rgba(99, 102, 241, 0.45);

  --text: #1e1b4b;
  --text-dim: #3f3a78;
  --text-mute: #6b6ba0;

  --accent: #6366f1;
  --accent-2: #7c3aed;
  --accent-strong: #4f46e5;
  --gold: #d97706;
  --best: #059669;
  --best-soft: rgba(5, 150, 105, 0.12);

  --shadow: 0 16px 40px rgba(99, 102, 178, 0.22);
}

* { 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 700px at 80% -10%, var(--bg-2), transparent 60%),
    radial-gradient(900px 600px at 10% 110%, var(--accent-strong), transparent 55%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1) 60%, var(--bg-0));
  background-attachment: fixed;
  min-height: 100vh;
  padding:
    max(12px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  overflow-x: hidden;
  position: relative;
}

[data-theme="light"] body {
  background:
    radial-gradient(1000px 600px at 80% -10%, #ffffff, transparent 60%),
    radial-gradient(800px 500px at 10% 110%, #dfe3ff, transparent 55%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1) 60%, var(--bg-0));
}

/* Sternen-Schicht */
.stars {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(1.4px 1.4px at 20% 30%, rgba(255,255,255,0.9), transparent),
    radial-gradient(1.2px 1.2px at 70% 20%, rgba(255,255,255,0.7), transparent),
    radial-gradient(1.6px 1.6px at 40% 70%, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 85% 60%, rgba(255,255,255,0.6), transparent),
    radial-gradient(1.3px 1.3px at 60% 85%, rgba(255,255,255,0.7), transparent),
    radial-gradient(1px 1px at 10% 80%, rgba(255,255,255,0.55), transparent),
    radial-gradient(1.5px 1.5px at 90% 35%, rgba(252,211,77,0.8), transparent);
  opacity: 0.7;
  animation: twinkle 6s ease-in-out infinite alternate;
}
[data-theme="light"] .stars { opacity: 0.18; }

@keyframes twinkle {
  from { opacity: 0.45; }
  to   { opacity: 0.85; }
}

.app-header, .app-main, .app-footer { position: relative; z-index: 1; }

/* Header */
.app-header {
  max-width: var(--maxw);
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-icon {
  width: 38px;
  height: 38px;
  color: var(--gold);
  flex: 0 0 auto;
  filter: drop-shadow(0 2px 8px rgba(252, 211, 77, 0.35));
}

.brand-text { min-width: 0; }

.brand-text h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.2px;
  line-height: 1.1;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--text-mute);
}

.theme-toggle {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease;
}
.theme-toggle:hover { border-color: var(--border-strong); }
.theme-toggle:active { transform: scale(0.92); }

/* Main */
.app-main {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Tabs */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  backdrop-filter: blur(8px);
}

.mode-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 12px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.1s ease;
  line-height: 1.2;
}
.mode-tab:hover { color: var(--text); }
.mode-tab.is-active {
  background: linear-gradient(135deg, var(--accent-strong), var(--accent-2));
  color: #0b0a2a;
}
[data-theme="light"] .mode-tab.is-active { color: #fff; }
.mode-tab:active { transform: scale(0.98); }

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.panel.is-hidden { display: none; }

.panel-intro {
  margin: 0 0 16px;
  color: var(--text-dim);
  font-size: 0.92rem;
  line-height: 1.5;
}
.panel-intro strong { color: var(--text); }

/* Felder */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}
.field-row .field { flex: 1 1 160px; margin-bottom: 14px; }

.field label {
  font-size: 0.82rem;
  color: var(--text-mute);
  font-weight: 600;
}

.field input[type="time"],
.field input[type="number"],
.field select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.field select {
  background-image: linear-gradient(45deg, transparent 50%, var(--accent) 50%),
                    linear-gradient(135deg, var(--accent) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

.field input:focus-visible,
.field select:focus-visible,
.btn-primary:focus-visible,
.mode-tab:focus-visible,
.theme-toggle:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-color: transparent;
}
.field input:focus,
.field select:focus {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.18);
}

/* Primärbutton */
.btn-primary {
  width: 100%;
  appearance: none;
  border: none;
  border-radius: var(--radius-sm);
  padding: 15px 18px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  color: #0b0a2a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 8px 24px rgba(129, 140, 248, 0.3);
}
[data-theme="light"] .btn-primary { color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: translateY(1px) scale(0.99); }

/* Ergebnisse */
.results { margin-top: 18px; display: flex; flex-direction: column; gap: 12px; }
.results:empty { margin-top: 0; }

.results-head {
  font-size: 0.85rem;
  color: var(--text-mute);
  margin: 0 0 2px;
  line-height: 1.45;
}
.results-head strong { color: var(--text); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.time-card {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform 0.12s ease, border-color 0.2s ease, background 0.2s ease;
  overflow: hidden;
}
.time-card:hover { transform: translateY(-2px); border-color: var(--border-strong); }

.time-card.is-best {
  border-color: var(--best);
  background: var(--best-soft);
}
.time-card.is-best::after {
  content: "★ empfohlen";
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--best);
  background: rgba(52, 211, 153, 0.14);
  border: 1px solid var(--best);
  border-radius: 999px;
  padding: 2px 7px;
}

.time-card .tc-time {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.time-card .tc-meta {
  font-size: 0.78rem;
  color: var(--text-dim);
}
.time-card .tc-hours {
  font-size: 0.72rem;
  color: var(--text-mute);
}
.time-card.is-best .tc-meta { color: var(--text); }

/* Info-Karte */
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(10px);
}
.info-card h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}
.info-card ul {
  margin: 0 0 4px;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.45;
}
.info-card li strong { color: var(--text); }
.info-card .cycle-field { margin: 16px 0 0; max-width: 220px; }

/* Footer */
.app-footer {
  max-width: var(--maxw);
  margin: 22px auto 6px;
  text-align: center;
}
.app-footer p {
  margin: 0;
  font-size: 0.74rem;
  color: var(--text-mute);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(120%);
  background: var(--surface-solid);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  z-index: 50;
  opacity: 0;
  transition: transform 0.32s cubic-bezier(.2,.9,.3,1), opacity 0.32s ease;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.is-show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Responsive feinjustierung */
@media (max-width: 380px) {
  .brand-text h1 { font-size: 1.2rem; }
  .time-card .tc-time { font-size: 1.5rem; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

/* Reduzierte Bewegung */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .stars { animation: none; }
}
