/* Erfolgsjournal – Dark-first, mobile-first, keine externen Abhängigkeiten. */
:root {
  --bg: #0e0f12;
  --surface: #16181d;
  --surface-2: #1d2027;
  --surface-3: #252932;
  --border: #2a2e37;
  --text: #ebe8e2;
  --muted: #8d909a;
  --accent: #f0b14a;       /* Morgen / primär */
  --accent-ink: #1a1408;
  --accent-soft: rgba(240, 177, 74, .14);
  --done: #5fd0a0;         /* erledigt / Anker */
  --done-soft: rgba(95, 208, 160, .14);
  --evening: #9aa8ff;
  --danger: #ff7a6b;
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 48px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 14px; }

/* ------------------------------------------------------------ Buttons */
.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 600;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:active { filter: brightness(.92); }
.btn-block { width: 100%; }
.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 12px;
  background: transparent; font-size: 26px; line-height: 1; color: var(--text);
}
.icon-btn:hover, .icon-btn:active { background: var(--surface-2); }
.chip-btn {
  height: 34px; padding: 0 12px; flex: none;
  border-radius: 999px; border: 1px solid var(--border);
  background: transparent; font-size: 14px; color: var(--muted);
}
.chip-btn.is-today { color: var(--accent); border-color: var(--accent-soft); background: var(--accent-soft); }
.link-btn {
  border: 0; background: none; padding: 6px 4px;
  color: var(--muted); font-size: 14px; text-decoration: underline; text-underline-offset: 3px;
}

/* ------------------------------------------------------------ Login */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px;
  display: grid; gap: 14px; text-align: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 32px 24px;
}
.login-card h1 { margin: 0; font-size: 24px; letter-spacing: -.01em; }
.login-card p { margin: 0; }
.brand-mark { color: var(--accent); font-size: 28px; }
.login-card input, .task-add input, .task-add select, textarea, .mins input {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  outline: none;
}
.login-card input:focus, .task-add input:focus, .task-add select:focus, textarea:focus, .mins input:focus {
  border-color: var(--accent);
}

/* ------------------------------------------------------------ Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(14, 15, 18, .88);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: center; gap: 4px;
  padding: 6px 8px;
}
.date-pick {
  position: relative; flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center;
  padding: 2px 6px; border-radius: 12px; cursor: pointer;
}
.date-pick:hover { background: var(--surface-2); }
.date-weekday { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.date-label { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.date-pick input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; border: 0;
}
.date-pick input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }

.save-status {
  width: 22px; flex: none; text-align: center;
  font-size: 15px; color: var(--muted); transition: color .2s, opacity .4s;
}
.save-status.is-saving { color: var(--muted); animation: pulse 1s ease-in-out infinite; }
.save-status.is-saved { color: var(--done); }
.save-status.is-error { color: var(--danger); }
.save-status.is-idle { opacity: 0; }
@keyframes pulse { 50% { opacity: .35; } }

.menu-wrap { position: relative; flex: none; }
.menu {
  position: absolute; right: 0; top: 48px; min-width: 230px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px;
  box-shadow: 0 16px 40px rgba(0,0,0,.45);
  display: grid;
}
.menu a, .menu button {
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 11px 12px; border-radius: 10px; border: 0; background: none;
  color: var(--text); text-decoration: none; text-align: left; font-size: 15px;
}
.menu a small { color: var(--muted); font-size: 12px; }
.menu a:hover, .menu button:hover { background: var(--surface-3); }
.menu button { color: var(--danger); }

/* ------------------------------------------------------------ Layout */
.content {
  max-width: 760px; margin: 0 auto;
  padding: 14px 12px calc(40px + env(safe-area-inset-bottom));
  display: grid; gap: 14px;
}
.content > * { min-width: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 0 4px; }
.section-head h2 { margin: 0; font-size: 15px; font-weight: 600; color: var(--muted); }
.kicker { color: var(--accent); text-transform: uppercase; letter-spacing: .1em; font-size: 12px; margin-right: 6px; }

/* ------------------------------------------------------------ Kompass */
.goal-strip {
  display: flex; gap: 10px; overflow-x: auto;
  padding: 8px 4px 6px; margin: 0 -12px; padding-left: 16px; padding-right: 16px;
  scroll-snap-type: x proximity; scrollbar-width: none;
}
.goal-strip::-webkit-scrollbar { display: none; }
.goal {
  flex: 0 0 auto; max-width: 78vw; min-width: 150px; min-height: 64px;
  scroll-snap-align: start;
  display: flex; align-items: flex-start; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 10px 6px 10px 12px;
}
.goal-title {
  flex: 1; min-width: 0; font-weight: 600; font-size: 15px;
  background: none; border: 0; padding: 0; text-align: left; line-height: 1.35;
  overflow-wrap: anywhere;
}
.goal-title-input {
  flex: 1; min-width: 160px; background: var(--bg); border: 1px solid var(--accent);
  border-radius: 8px; padding: 6px 8px; outline: none;
}
.goal-x {
  width: 32px; height: 32px; flex: none; border: 0; border-radius: 8px;
  background: none; color: var(--muted); font-size: 15px;
}
.goal-x:hover { background: var(--surface-3); color: var(--text); }
.goal-add {
  flex: 0 0 auto; min-height: 64px; min-width: 110px;
  border: 1px dashed var(--border); border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); padding: 0 16px;
}
.goal-add:hover { color: var(--accent); border-color: var(--accent); }
.goal-empty { color: var(--muted); font-size: 14px; align-self: center; padding: 0 4px; }
.goal-archive {
  margin-top: 8px; display: grid; gap: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px;
}
.goal-archive .row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.goal-archive .row span { flex: 1; text-decoration: line-through; }

/* ------------------------------------------------------------ Panels */
.panel {
  scroll-margin-top: calc(72px + env(safe-area-inset-top));
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; overflow: hidden;
  transition: border-color .3s, box-shadow .3s;
}
.panel.is-focus { border-color: rgba(240, 177, 74, .45); box-shadow: 0 0 0 1px rgba(240,177,74,.15), 0 10px 30px rgba(0,0,0,.25); }
#evening.is-focus { border-color: rgba(154, 168, 255, .45); box-shadow: 0 0 0 1px rgba(154,168,255,.15), 0 10px 30px rgba(0,0,0,.25); }
.panel-head {
  width: 100%; display: flex; align-items: center; gap: 10px;
  min-height: 58px; padding: 12px 16px;
  border: 0; background: none; text-align: left;
}
.panel-icon { font-size: 20px; color: var(--accent); width: 22px; text-align: center; }
#evening .panel-icon { color: var(--evening); }
.panel-title { font-weight: 700; font-size: 18px; }
.panel-summary { flex: 1; text-align: right; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin: -4px 4px 0 4px; transition: transform .2s; }
.panel.is-collapsed .chev { transform: rotate(-45deg); margin-top: 0; }
.panel.is-collapsed .panel-body { display: none; }
.panel-body { padding: 0 16px 18px; display: grid; gap: 10px; }

.field-label { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 8px; text-transform: uppercase; letter-spacing: .06em; }
.field-label .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
.row-between { display: flex; justify-content: space-between; align-items: baseline; }
textarea { resize: vertical; line-height: 1.45; min-height: 52px; }

/* ------------------------------------------------------------ Aufgaben */
.task-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.task {
  display: flex; align-items: center; gap: 4px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 4px 4px 4px 2px;
}
.task.is-done { background: var(--done-soft); border-color: transparent; }
.check {
  width: var(--tap); height: var(--tap); flex: none;
  display: grid; place-items: center; border: 0; background: none;
}
.check span {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--muted);
  display: grid; place-items: center; font-size: 15px; color: transparent; transition: all .15s;
}
.task.is-done .check span { background: var(--done); border-color: var(--done); color: #0b1a13; }
.task-main { flex: 1; min-width: 0; display: grid; gap: 2px; padding: 4px 0; }
.task-title {
  width: 100%; background: none; border: 0; outline: none; padding: 2px 0;
  font-size: 16px; text-overflow: ellipsis;
}
.task.is-done .task-title { color: var(--muted); text-decoration: line-through; }
.task-goal {
  justify-self: start; max-width: 100%;
  appearance: none; -webkit-appearance: none;
  border: 0; border-radius: 999px; padding: 2px 10px;
  background: var(--accent-soft); color: var(--accent); font-size: 12px;
  text-overflow: ellipsis;
}
.task-goal.is-empty { background: transparent; color: var(--muted); padding-left: 0; }
.task-del {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 10px;
  background: none; color: var(--muted); font-size: 18px;
}
.task-del:hover { color: var(--danger); background: var(--surface-3); }
.task-add { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.task-add select { grid-column: 1; color: var(--muted); }
.task-add button { grid-column: 2; grid-row: 1; width: var(--tap); padding: 0; font-size: 22px; }
@media (min-width: 560px) {
  .task-add { grid-template-columns: 1fr 200px auto; }
  .task-add select { grid-column: 2; grid-row: 1; }
  .task-add button { grid-column: 3; }
}
.hint {
  margin: 0; font-size: 14px; color: var(--accent);
  background: var(--accent-soft); border-radius: var(--radius-sm); padding: 10px 12px;
}

/* ------------------------------------------------------------ Gewohnheiten */
.score-row { display: grid; gap: 8px; margin-top: 2px; }
.score-text { font-size: 15px; color: var(--muted); }
.score-text strong { color: var(--text); font-size: 20px; }
.score-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.score-bar span { height: 8px; border-radius: 4px; background: var(--surface-3); transition: background .25s; }
.score-bar span.on { background: var(--done); }
.score-bar.is-full span.on { background: linear-gradient(90deg, var(--done), var(--accent)); }

.habit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.habit {
  width: 100%; min-height: 92px;
  display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: 14px; text-align: left;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  transition: background .15s, border-color .15s, transform .08s;
  user-select: none;
}
.habit:active { transform: scale(.98); }
.habit-icon { font-size: 20px; color: var(--muted); line-height: 1; }
.habit-name { font-weight: 600; font-size: 15px; line-height: 1.25; }
.habit[aria-pressed="true"] { background: var(--done-soft); border-color: var(--done); }
.habit[aria-pressed="true"] .habit-icon { color: var(--done); }
.habit[aria-pressed="true"] .habit-icon::before { content: "✓ "; }
.mins {
  display: flex; align-items: center; gap: 10px;
  background: var(--done-soft); border-radius: var(--radius-sm);
  padding: 6px 12px; color: var(--muted); font-size: 14px;
}
.mins-icon { color: var(--done); }
.mins-text { flex: 1; min-width: 0; }
.mins input { min-height: 40px; padding: 6px 8px; width: 76px; flex: none; text-align: center; font-variant-numeric: tabular-nums; }

.scale-block { display: grid; gap: 6px; }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.scale button {
  height: var(--tap); border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  font-weight: 700; font-size: 17px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.scale button.in-range { background: var(--surface-3); color: var(--text); }
.scale button[aria-checked="true"] { background: var(--evening); border-color: var(--evening); color: #10132a; }

/* ------------------------------------------------------------ Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 30;
  display: flex; align-items: center; gap: 14px;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 10px 8px 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); font-size: 14px;
  max-width: calc(100vw - 24px);
}
.toast .link-btn { color: var(--accent); font-weight: 600; text-decoration: none; }

.noscript { padding: 24px; text-align: center; }

@media (min-width: 760px) {
  .content { padding-top: 22px; gap: 18px; }
  .habit-grid { grid-template-columns: repeat(4, 1fr); }
  .goal-strip { margin: 0; padding-left: 4px; padding-right: 4px; flex-wrap: wrap; overflow: visible; }
  .goal { max-width: 340px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
