:root {
  --red: #d7261e;          /* Ampelrot – Timer gestoppt */
  --green: #12a84a;        /* Ampelgrün – Timer läuft */
  --surface: #17181c;
  --surface-2: #22242a;
  --surface-3: #2d3038;
  --line: #3a3d46;
  --text: #f2f2f0;
  --text-2: #b9bac0;
  --text-3: #85878f;
  /* Kategorische Farben je Würfelart (dunkle Variante, validiert) */
  --p-2x2: #3987e5;
  --p-3x3: #d95926;
  --p-4x4: #199e70;
  --p-pyra: #c98500;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--red);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  transition: background-color .15s ease;
}
body.running { background: var(--green); }
body.panel-open { background: var(--surface); }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

.screen { position: fixed; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* ---------- Timer ---------- */
.topbar {
  display: flex; justify-content: center;
  padding: calc(var(--safe-top) + 12px) 12px 10px;
  transition: opacity .2s ease;
}
.bottombar {
  display: flex; justify-content: center; gap: 10px;
  padding: 10px 12px calc(var(--safe-bottom) + 16px);
  transition: opacity .2s ease;
}
body.running .topbar, body.running .bottombar { opacity: 0; pointer-events: none; }
.nav-btn {
  display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 999px;
  background: rgba(0, 0, 0, .22); padding: 11px 18px; font-size: 15px; font-weight: 600; color: #fff;
}
.nav-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.puzzles {
  display: flex; gap: 4px; padding: 4px; min-width: 0; max-width: 100%;
  background: rgba(0, 0, 0, .22); border-radius: 999px;
  overflow-x: auto; scrollbar-width: none;
}
.puzzles::-webkit-scrollbar { display: none; }
.puzzles button {
  border: 0; background: transparent; padding: 8px 12px; border-radius: 999px;
  font-weight: 600; font-size: 15px; white-space: nowrap; color: rgba(255,255,255,.85);
}
.puzzles button[aria-checked="true"] { background: #fff; color: #1b1b1b; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, .22); display: grid; place-items: center;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.timer-area {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding-bottom: 40px;
  touch-action: none; cursor: pointer;
}
.time {
  font-size: clamp(72px, 24vw, 200px); font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
  text-shadow: 0 2px 12px rgba(0,0,0,.15);
}
.hint { margin-top: 18px; font-size: 16px; color: rgba(255,255,255,.8); min-height: 1.2em; }
.mini-stats {
  margin-top: 28px; display: flex; gap: 22px; font-size: 15px; color: rgba(255,255,255,.85);
  font-variant-numeric: tabular-nums; transition: opacity .2s;
}
.mini-stats b { display: block; font-size: 19px; color: #fff; }
.mini-stats div { text-align: center; }
body.running .hint, body.running .mini-stats { opacity: 0; }

/* ---------- Panels (Liste, Verlauf) ---------- */
.panel {
  background: var(--surface); overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0 16px calc(var(--safe-bottom) + 24px);
  -webkit-user-select: text; user-select: text;
}
.panel > * { flex-shrink: 0; }
.panel-head {
  position: sticky; top: 0; z-index: 2; background: var(--surface);
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-top) + 10px) 0 10px;
}
.panel-head h1 { margin: 0; font-size: 22px; }
.panel .icon-btn { background: var(--surface-2); }

.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 14px; }
.filters button {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2);
  padding: 7px 13px; border-radius: 999px; font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 7px;
}
.filters button[aria-checked="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

.list-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 10px 10px 9px; min-width: 0; }
.tile span { display: block; font-size: 12px; color: var(--text-3); }
.tile b { display: block; font-size: 18px; margin-top: 3px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.day { margin: 18px 0 6px; font-size: 13px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 4px 10px 12px;
  background: var(--surface-2); border-radius: 12px; margin-bottom: 6px;
}
.row .t { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 92px; }
.row .t.best { color: #ffd34d; }
.row .meta { flex: 1; display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--text-2); min-width: 0; }
.row .clock { color: var(--text-3); margin-left: auto; font-variant-numeric: tabular-nums; }
.row .del { border: 0; background: transparent; color: var(--text-3); width: 38px; height: 38px; border-radius: 50%; font-size: 20px; }
.row .del:hover { background: var(--surface-3); color: var(--text); }
.empty { color: var(--text-3); text-align: center; padding: 40px 10px; line-height: 1.5; }

/* ---------- Diagramm ---------- */
.axis-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-3); margin-bottom: 10px; }
.axis-toggle button { border: 0; background: transparent; color: var(--text-2); padding: 5px 9px; border-radius: 8px; font-size: 13px; }
.axis-toggle button[aria-checked="true"] { background: var(--surface-3); color: var(--text); }

.chart-wrap { position: relative; background: var(--surface-2); border-radius: 14px; padding: 8px 6px 4px 0; }
#chart { display: block; width: 100%; height: 300px; touch-action: pan-y; }
#chart .grid { stroke: var(--line); stroke-width: 1; }
#chart .axis-label { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
#chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
#chart .avg { fill: none; stroke: var(--text-2); stroke-width: 1.5; stroke-dasharray: 5 4; }
#chart .pt { stroke: var(--surface-2); stroke-width: 2; }
#chart .pt.hot { stroke: var(--text); }
#chart .cross { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; }
#chart .direct { font-size: 11px; font-weight: 600; fill: var(--text-2); }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface-3); border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 10px; font-size: 13px; white-space: nowrap; box-shadow: 0 6px 18px rgba(0,0,0,.35);
}
.tooltip b { font-size: 16px; font-variant-numeric: tabular-nums; }
.tooltip .sub { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--text-2); margin: 10px 2px 16px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dash { width: 18px; border-top: 2px dashed var(--text-2); }

.stats-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.stats-table th { text-align: right; color: var(--text-3); font-weight: 600; font-size: 12px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.stats-table td { text-align: right; padding: 8px 4px; border-bottom: 1px solid var(--surface-3); }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.stats-table td:first-child { display: flex; align-items: center; gap: 7px; }

@media (min-width: 700px) {
  .panel > * { width: 100%; max-width: 760px; margin-left: auto; margin-right: auto; flex-shrink: 0; }
  #chart { height: 380px; }
}
@media (max-width: 380px) {
  .puzzles button { padding: 8px 9px; font-size: 14px; }
  .list-stats { grid-template-columns: repeat(2, 1fr); }
}
