:root {
  --ink:        #16233A;
  --ink-2:      #131E33;
  --ink-3:      #1E2E4A;
  --paper:      #EAEEF4;
  --surface:    #FFFFFF;
  --surface-2:  #F5F8FC;
  --line:       #DBE2EC;
  --muted:      #66748C;
  --text:       #16233A;
  --amber:      #E8A33D;
  --amber-deep: #B87A22;
  --steel:      #3E5C8A;
  --steel-soft: #8FA6C9;
  --green:      #2F9E6E;
  --red:        #D64545;
  --red-soft:   #F4DADA;

  --r-lg: 22px;
  --r-md: 15px;
  --r-sm: 10px;
  --shadow: 0 6px 24px rgba(19,30,51,.10), 0 1px 3px rgba(19,30,51,.06);
  --shadow-sm: 0 1px 2px rgba(19,30,51,.06), 0 1px 8px rgba(19,30,51,.05);

  --font-display: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1, "cv05" 1;
  overscroll-behavior-y: none;
}
button { font-family: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }

.app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}

/* ---------- Masthead / cockpit ---------- */
.masthead {
  background:
    radial-gradient(120% 140% at 85% -10%, rgba(232,163,61,.18), transparent 46%),
    linear-gradient(180deg, var(--ink-3) 0%, var(--ink-2) 100%);
  color: #EAF0FA;
  padding: calc(var(--safe-top) + 14px) 18px 20px;
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  box-shadow: 0 8px 26px rgba(19,30,51,.22);
  position: relative;
  z-index: 3;
}

.brand { display: flex; align-items: center; gap: 9px; }
.brand__mark { display: block; border-radius: 7px; }
.brand__name {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: .04em;
  font-size: 17px;
  flex: 1;
}
.brand__menu { margin-right: -6px; }
.brand__menu svg { fill: currentColor; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px;
  border: none; background: transparent; color: inherit;
  border-radius: 999px; cursor: pointer;
  transition: background .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.10); }
.masthead .icon-btn:hover { background: rgba(255,255,255,.12); }

/* Score hero */
.score {
  width: 100%;
  margin-top: 16px;
  padding: 4px 4px 2px;
  background: transparent; border: none; cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "label   chevron"
    "value   value"
    "caption caption";
  align-items: baseline;
  text-align: left;
  column-gap: 8px;
  color: inherit;
}
.score__label {
  grid-area: label;
  font-size: 12px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--steel-soft); font-weight: 600;
}
.score__chevron {
  grid-area: chevron; justify-self: end; color: var(--steel-soft);
  transition: transform .25s ease;
}
.score[aria-expanded="true"] .score__chevron { transform: rotate(180deg); }
.score__value {
  grid-area: value;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(56px, 20vw, 82px);
  line-height: .98;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  transition: color .2s;
}
.score__unit {
  display: none; /* folded into caption for clarity */
}
.score__caption {
  grid-area: caption;
  margin-top: 8px;
  font-size: 13.5px; line-height: 1.4;
  color: #C3D0E6;
  max-width: 46ch;
}
.score.is-pos .score__value { color: #7BD1A7; }
.score.is-neg .score__value { color: #F0968F; }
.score.is-zero .score__value { color: #EAF0FA; }

/* Trend panel */
.trend {
  margin-top: 16px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(143,166,201,.20);
  border-radius: var(--r-md);
  padding: 14px 14px 10px;
}
.trend__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 8px;
}
.trend__title {
  font-family: var(--font-display); font-weight: 500;
  font-size: 13px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--steel-soft);
}
.trend__chart { width: 100%; }
.trend__chart svg { display: block; width: 100%; height: auto; }
.trend__legend {
  display: flex; flex-wrap: wrap; gap: 14px;
  margin-top: 6px; font-size: 12px; color: #B8C6DE;
}
.trend__legend .dot { display:inline-block; width:16px; height:3px; border-radius:2px; margin-right:6px; vertical-align: middle; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  width: 38px; height: 22px; border-radius: 999px;
  background: rgba(143,166,201,.28); position: relative; transition: background .18s;
  flex: none;
}
.switch__thumb {
  position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 999px; background: #EAF0FA; transition: transform .18s;
}
.switch input:checked + .switch__track { background: var(--amber); }
.switch input:checked + .switch__track .switch__thumb { transform: translateX(16px); }
.switch input:focus-visible + .switch__track { outline: 2px solid #EAF0FA; outline-offset: 2px; }
.switch__text { font-size: 12.5px; color: #C3D0E6; }

/* ---------- Tabs ---------- */
.tabs {
  position: sticky; top: 0; z-index: 4;
  display: flex; gap: 4px;
  padding: 10px 16px;
  background: var(--paper);
}
.tab {
  flex: 1; padding: 11px 8px; border: none; cursor: pointer;
  background: transparent; color: var(--muted);
  font-family: var(--font-display); font-weight: 500; font-size: 15px;
  border-radius: 999px; position: relative;
  transition: color .15s, background .15s;
}
.tab.is-active { color: var(--ink); background: var(--surface); box-shadow: var(--shadow-sm); }
.tab .badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px;
  padding: 0 6px; margin-left: 7px;
  font-family: var(--font-body); font-size: 11.5px; font-weight: 600;
  border-radius: 999px; background: var(--red); color: #fff; vertical-align: middle;
}
.tab.is-active .badge { transform: translateY(-1px); }

/* ---------- List / cards ---------- */
.list {
  flex: 1;
  padding: 4px 16px calc(120px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 14px;
}

.section-label {
  font-family: var(--font-display); font-size: 11.5px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted); font-weight: 600;
  margin: 12px 2px 0;
  display: flex; align-items: center; gap: 8px;
}
.section-label::after { content:""; flex:1; height:1px; background: var(--line); }

.termin {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.termin.is-urgent { border-color: rgba(214,69,69,.45); box-shadow: 0 0 0 1px rgba(214,69,69,.18), var(--shadow-sm); }
.termin.is-archived { opacity: .72; }

.termin__head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px; align-items: center;
  padding: 14px 14px 12px;
  cursor: pointer;
}
.when {
  display: grid; place-items: center; text-align: center;
  width: 52px; padding: 7px 0;
  border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--line);
  line-height: 1;
}
.when__num {
  font-family: var(--font-display); font-weight: 600; font-size: 22px;
  color: var(--ink); font-variant-numeric: tabular-nums;
}
.when__mon { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-top: 3px; }
.when--past .when__num { color: var(--muted); }
.when--multi { width: 56px; padding-bottom: 5px; }
.when__end {
  margin-top: 3px; padding-top: 3px; border-top: 1px dashed var(--line);
  font-size: 10px; font-weight: 700; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

.termin__title { min-width: 0; }
.termin__title h3 {
  font-size: 16.5px; font-weight: 600; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.termin__meta {
  margin-top: 3px; font-size: 12.5px; color: var(--muted);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.rel {
  font-weight: 600; font-variant-numeric: tabular-nums;
}
.rel--soon { color: var(--amber-deep); }
.rel--over { color: var(--red); }
.rel--far  { color: var(--steel); }

.termin__edit {
  color: var(--muted); flex: none;
}
.termin__edit:hover { color: var(--ink); }

/* task groups */
.tasks { padding: 0 14px 12px; }
.tasks__group + .tasks__group { margin-top: 8px; }
.tasks__grouphead {
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; margin: 6px 2px 5px;
}

.task {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: 11px; padding: 8px 4px; border-top: 1px solid var(--surface-2);
}
.task:first-child { border-top: none; }
.task__check {
  appearance: none; -webkit-appearance: none;
  width: 22px; height: 22px; border-radius: 7px; flex: none;
  border: 2px solid var(--line); background: var(--surface); cursor: pointer;
  display: grid; place-items: center; transition: border-color .15s, background .15s;
}
.task__check:hover { border-color: var(--steel-soft); }
.task__check:checked { background: var(--green); border-color: var(--green); }
.task__check:checked::after {
  content:""; width: 6px; height: 11px; margin-top: -2px;
  border: 2.4px solid #fff; border-top: 0; border-left: 0; transform: rotate(42deg);
}
.task__body { min-width: 0; cursor: pointer; }
.task__title { font-size: 14.5px; line-height: 1.3; }
.task.is-done .task__title { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(102,116,140,.5); }
.task__tags { display: flex; gap: 6px; margin-top: 3px; }
.chip {
  font-size: 10.5px; font-weight: 600; letter-spacing: .03em;
  padding: 2px 7px; border-radius: 999px; line-height: 1.5;
}
.chip--ex { background: #FBEAD2; color: var(--amber-deep); }
.chip--overprep { background: var(--red-soft); color: var(--red); }
.task__more { color: var(--muted); }
.task__more:hover { color: var(--ink); }

.task-add {
  display: inline-flex; align-items: center; gap: 7px;
  margin: 8px 2px 2px; padding: 7px 12px 7px 9px;
  background: var(--surface-2); border: 1px dashed var(--line);
  border-radius: 999px; color: var(--steel); cursor: pointer;
  font-weight: 500; font-size: 13px;
}
.task-add:hover { border-color: var(--steel-soft); color: var(--ink); }
.task-add svg { width: 16px; height: 16px; }

/* empty state */
.empty {
  text-align: center; padding: 54px 24px; color: var(--muted);
}
.empty h3 { font-family: var(--font-display); font-weight: 500; color: var(--ink); font-size: 19px; margin-bottom: 6px; }
.empty p { font-size: 14px; line-height: 1.5; max-width: 34ch; margin: 0 auto; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; z-index: 6;
  right: max(16px, calc(50% - 380px + 16px));
  bottom: calc(18px + var(--safe-bottom));
  display: inline-flex; align-items: center; gap: 8px;
  padding: 14px 20px 14px 16px;
  background: var(--amber); color: #2A1B04; border: none; cursor: pointer;
  border-radius: 999px; font-family: var(--font-display); font-weight: 600; font-size: 15px;
  box-shadow: 0 8px 22px rgba(184,122,34,.4);
  transition: transform .12s, box-shadow .12s;
}
.fab:hover { transform: translateY(-1px); box-shadow: 0 12px 26px rgba(184,122,34,.5); }
.fab:active { transform: translateY(0); }

/* ---------- Menu sheet ---------- */
.menu {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(19,30,51,.4);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px;
}
.menu__panel {
  width: 100%; max-width: 440px;
  background: var(--surface); border-radius: var(--r-lg);
  padding: 8px; box-shadow: var(--shadow);
  margin-bottom: var(--safe-bottom);
}
.menu__item {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 14px 14px; border: none; background: transparent;
  border-radius: var(--r-sm); cursor: pointer; font-size: 15px; text-align: left;
}
.menu__item:hover { background: var(--surface-2); }
.menu__item--danger { color: var(--red); }
.menu__state { font-size: 13px; color: var(--muted); font-weight: 600; }

/* ---------- Modals ---------- */
.modal {
  width: min(520px, calc(100vw - 24px));
  border: none; border-radius: var(--r-lg); padding: 0;
  box-shadow: var(--shadow); color: var(--text);
  background: var(--surface);
}
.modal::backdrop { background: rgba(19,30,51,.45); backdrop-filter: blur(2px); }
.modal__form { padding: 18px 18px calc(16px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 14px; }
.modal__head { display: flex; align-items: center; justify-content: space-between; }
.modal__head h2 { font-family: var(--font-display); font-weight: 600; font-size: 19px; }
.modal__head .icon-btn { color: var(--muted); }
.modal__foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.modal__foot .spacer { flex: 1; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field input, .field textarea {
  font: inherit; color: var(--text);
  padding: 11px 12px; border: 1.5px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface-2); resize: vertical;
}
.field input:focus, .field textarea:focus {
  outline: none; border-color: var(--steel); background: var(--surface);
}
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.segmented { display: flex; gap: 4px; background: var(--surface-2); border: 1.5px solid var(--line); border-radius: var(--r-sm); padding: 4px; }
.segmented__opt {
  flex: 1; padding: 9px 8px; border: none; background: transparent; cursor: pointer;
  border-radius: 8px; font-weight: 500; font-size: 14px; color: var(--muted);
}
.segmented__opt.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.check-field {
  display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start;
  padding: 12px; border: 1.5px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface-2); cursor: pointer;
}
.check-field input { position: absolute; opacity: 0; }
.check-field__box {
  width: 22px; height: 22px; border-radius: 7px; margin-top: 1px;
  border: 2px solid var(--line); background: var(--surface); display: grid; place-items: center;
}
.check-field input:checked + .check-field__box { background: var(--amber); border-color: var(--amber); }
.check-field input:checked + .check-field__box::after {
  content:""; width: 6px; height: 11px; border: 2.4px solid #fff; border-top: 0; border-left: 0;
  transform: rotate(42deg); margin-top: -2px;
}
.check-field input:focus-visible + .check-field__box { outline: 2px solid var(--steel); outline-offset: 2px; }
.check-field__text strong { display: block; font-size: 14.5px; }
.check-field__text small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; line-height: 1.4; }

.btn {
  padding: 11px 18px; border-radius: 999px; border: none; cursor: pointer;
  font-family: var(--font-display); font-weight: 600; font-size: 14.5px;
  transition: background .15s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--ink); color: #fff; }
.btn--primary:hover { background: #22334F; }
.btn--ghost { background: transparent; color: var(--muted); }
.btn--ghost:hover { color: var(--ink); background: var(--surface-2); }
#deleteTerminBtn, #deleteAufgabeBtn { color: var(--red); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + var(--safe-bottom)); z-index: 30;
  background: var(--ink); color: #EAF0FA; padding: 12px 18px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

/* chart bits */
.chart-line { fill: none; stroke: var(--amber); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-line--alt { stroke: var(--steel-soft); stroke-width: 2; stroke-dasharray: 3 4; }
.chart-zero { stroke: rgba(143,166,201,.4); stroke-width: 1; stroke-dasharray: 2 4; }
.chart-axis { stroke: rgba(143,166,201,.22); stroke-width: 1; }
.chart-dot { fill: var(--amber); }
.chart-lbl { fill: #9FB2D0; font-size: 10px; font-family: var(--font-body); }
.chart-hover-line { stroke: rgba(234,240,250,.5); stroke-width: 1; }
.chart-tip { fill: #EAF0FA; font-family: var(--font-display); font-size: 12px; font-weight: 600; }
.chart-tip-sub { fill: #9FB2D0; font-size: 10px; }

@media (min-width: 620px) {
  .fab { right: max(16px, calc(50% - 380px + 24px)); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
