:root {
  --bg: #f6f3ec;
  --surface: #fffdf8;
  --line: #e6e0d3;
  --text: #1d1b16;
  --muted: #7c7568;
  --accent: #d9622b;
  --accent-ink: #fff;
  --go: #2f7d5b;
  --go-soft: #e3efe8;
  --chip: #efe9dd;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 8px 24px rgba(40, 30, 10, .06);
  /* Paleta kategorii — kolejność stała (zwalidowana pod kątem daltonizmu). */
  --bar-1: #2a78d6; --bar-2: #eb6834; --bar-3: #1baf7a; --bar-4: #eda100;
  --bar-5: #e87ba4; --bar-6: #008300; --bar-7: #4a3aa7; --bar-other: #a39d90;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130f;
    --surface: #1e1c17;
    --line: #302d26;
    --text: #f1ece2;
    --muted: #9a9284;
    --accent: #f07a3e;
    --accent-ink: #1a0f08;
    --go: #5cc596;
    --go-soft: #1c3329;
    --chip: #2a2720;
    --shadow: none;
    --bar-1: #3987e5; --bar-2: #d95926; --bar-3: #199e70; --bar-4: #c98500;
    --bar-5: #d55181; --bar-6: #008300; --bar-7: #9085e9; --bar-other: #6f695e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 ui-sans-serif, -apple-system, "Segoe UI", system-ui, Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

.top { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 2px 0; }
.brand { font-weight: 700; letter-spacing: -.01em; font-size: 18px; }
.today-total { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }

/* --- hero ---------------------------------------------------------------- */
.hero { text-align: center; padding: 26px 0 22px; }
.clock {
  font-size: clamp(64px, 20vw, 104px);
  font-weight: 650;
  letter-spacing: -.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  transition: color .3s;
}
.running .clock { color: var(--text); }
.since { color: var(--muted); font-size: 14px; margin-top: 8px; min-height: 1.45em; }

.big {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 196px; height: 196px;
  margin: 24px auto 26px;
  border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform .12s, background .3s, box-shadow .3s;
  user-select: none;
}
.big:active { transform: scale(.96); }
.big:disabled { opacity: .6; }
.big-label { font-size: 34px; font-weight: 700; letter-spacing: -.02em; }
.big-sub { font-size: 13px; opacity: .85; margin-top: 2px; }
.running .big {
  background: var(--go);
  box-shadow: 0 10px 30px color-mix(in srgb, var(--go) 35%, transparent);
  animation: breathe 3.2s ease-in-out infinite;
}
@keyframes breathe { 50% { box-shadow: 0 10px 44px color-mix(in srgb, var(--go) 55%, transparent); } }
@media (prefers-reduced-motion: reduce) { .running .big { animation: none; } }

.what input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface);
  font-size: 17px; text-align: center;
  outline: none;
}
.what input:focus { border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.chip {
  border: 1px solid transparent; border-radius: 999px;
  background: var(--chip);
  padding: 7px 14px; font-size: 15px;
}
.chip.on { border-color: var(--accent); color: var(--accent); }

/* --- cards --------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
  margin-top: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 16px; margin: 0; }
.tabs { display: flex; background: var(--chip); border-radius: 10px; padding: 3px; }
.tabs button { border: 0; background: none; padding: 5px 11px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.summary { margin: 14px 0 6px; color: var(--muted); font-size: 14px; }
.summary b { color: var(--text); font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-right: 6px; font-variant-numeric: tabular-nums; }

.bars { list-style: none; margin: 8px 0 0; padding: 0; }
.bars li { padding: 8px 0; }
.bar-row { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; }
.bar-row .n { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.track { height: 8px; border-radius: 99px; background: var(--chip); margin-top: 6px; overflow: hidden; }
.fill { height: 100%; border-radius: 99px; }
.empty { color: var(--muted); font-size: 14px; padding: 10px 0 6px; }

.day { margin-top: 14px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .t { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; width: 92px; flex-shrink: 0; }
.row .l { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .l.none { color: var(--muted); font-style: italic; }
.row .d { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.row .x { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 4px 2px 4px 6px; }
.row.live .d { color: var(--go); }
.more { display: block; margin: 12px auto 4px; }

footer { text-align: center; margin-top: 22px; }
.link { border: 0; background: none; color: var(--muted); font-size: 14px; text-decoration: underline; }

/* --- login --------------------------------------------------------------- */
.login {
  max-width: 340px; margin: 18vh auto 0; padding: 0 16px;
  display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login .brand { font-size: 32px; }
.login p { color: var(--muted); margin: 0 0 10px; }
.login input { padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); font-size: 17px; outline: none; }
.login input:focus { border-color: var(--accent); }
.primary { border: 0; border-radius: 14px; padding: 14px; background: var(--accent); color: var(--accent-ink); font-weight: 650; font-size: 17px; }
.err { color: var(--accent); min-height: 1.4em; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px);
}

/* --- nawigacja ------------------------------------------------------------ */
.top-right { display: flex; align-items: baseline; gap: 14px; }
.nav { color: var(--accent); text-decoration: none; font-size: 15px; font-weight: 600; }

/* --- analiza -------------------------------------------------------------- */
.analysis .top { align-items: center; }
.analysis .top .brand { font-size: 18px; }
.range { margin: 16px 0 0; width: 100%; }
.range button { flex: 1; padding: 8px 6px; font-size: 15px; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 16px; }
@media (min-width: 540px) { .tiles { grid-template-columns: repeat(4, 1fr); } .tile .v { font-size: 19px; white-space: nowrap; } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); }
.tile .k { font-size: 13px; color: var(--muted); }
.tile .v { font-size: 22px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; line-height: 1.2; }
.tile .sub { font-size: 12px; color: var(--muted); }

.insights { margin: 10px 0 2px; padding: 0; list-style: none; }
.insights li { padding: 9px 0 9px 18px; border-bottom: 1px solid var(--line); position: relative; font-size: 15px; }
.insights li:last-child { border-bottom: 0; }
.insights li::before { content: ''; position: absolute; left: 2px; top: 17px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

.table-wrap { overflow-x: auto; margin-top: 8px; }
.rank { width: 100%; border-collapse: collapse; font-size: 14px; }
.rank th { text-align: right; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.rank th:first-child, .rank td:first-child { text-align: left; padding-left: 0; }
.rank td { padding: 9px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.rank tfoot td { border-bottom: 0; color: var(--muted); }
.rank .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }
.rank .strong { color: var(--text); font-weight: 600; }
.rank .name { min-width: 110px; }
.rank .name .track { height: 4px; margin-top: 6px; }
.sw { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 7px; vertical-align: 0; }
@media (max-width: 480px) { .rank .opt { display: none; } }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 12px 0 4px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i, .tip i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.chart { margin-top: 6px; touch-action: pan-y; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .base { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.chart .ax { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; }
.chart .hit.on { fill: var(--text); opacity: .06; }

.hint { color: var(--muted); font-size: 13px; margin: 6px 0 10px; }
.heat { --cols: 12; touch-action: pan-y; }
.hrow { display: grid; grid-template-columns: 26px repeat(var(--cols), 1fr); gap: 3px; margin-bottom: 3px; }
.hrow.head span { font-size: 10px; color: var(--muted); text-align: left; font-variant-numeric: tabular-nums; }
.hrow .wd { font-size: 12px; color: var(--muted); align-self: center; }
.cell { aspect-ratio: 1; border-radius: 4px; background: var(--chip); min-width: 0; }
.cell.l1 { background: color-mix(in srgb, var(--accent) 22%, var(--chip)); }
.cell.l2 { background: color-mix(in srgb, var(--accent) 42%, var(--chip)); }
.cell.l3 { background: color-mix(in srgb, var(--accent) 62%, var(--chip)); }
.cell.l4 { background: color-mix(in srgb, var(--accent) 82%, var(--chip)); }
.cell.l5 { background: var(--accent); }
.hscale { display: flex; align-items: center; justify-content: flex-end; gap: 3px; margin-top: 10px; font-size: 11px; color: var(--muted); }
.hscale .cell { width: 13px; aspect-ratio: 1; }
.hscale span:first-child { margin-right: 4px; }
.hscale span:last-child { margin-left: 4px; }

.empty-card { margin-top: 16px; color: var(--muted); text-align: center; padding: 28px 18px; }

.tip {
  position: fixed; left: 0; top: 0; z-index: 10; pointer-events: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .25);
  padding: 9px 12px; font-size: 13px; min-width: 170px; max-width: 240px;
}
.tip .th { font-weight: 600; margin-bottom: 4px; }
.tip .tl { display: flex; align-items: center; gap: 7px; padding: 1px 0; }
.tip .tl span { flex: 1; color: var(--muted); }
.tip .tl b { font-weight: 600; font-variant-numeric: tabular-nums; }
.tip .sum { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
.tip .muted { color: var(--muted); }
