:root {
  --bg: #0b0b1a;
  --text: #fff;
  --muted: rgba(255, 255, 255, .6);
  --glass: rgba(255, 255, 255, .13);
  --glass-edge: rgba(255, 255, 255, .38);
  --glass-shine: rgba(255, 255, 255, .6);
  --glass-ring: rgba(0, 0, 0, .35);
  --glass-shadow: rgba(0, 0, 0, .35);
  --line: rgba(255, 255, 255, .12);
  --track: rgba(255, 255, 255, .12);
  --seg-on: rgba(255, 255, 255, .24);
  --blob-opacity: 1;
  --card-top: #34345a;
  --card-bottom: #292949;
  --card-line: #0b0b1a;
  --accent: #0a84ff;
  --accent-ink: #64d2ff; /* akcent czytelny na ciemnym szkle */
  --danger: #ff453a;
  --blob1: #5e5ce6;
  --blob2: #ff375f;
  --blob3: #30d5c8;
  /* 6 cyfr + 2 separatory muszą zmieścić się w oknie (max 560px minus marginesy) */
  --w: min(66px, calc((100vw - 130px) / 6));
  --h: calc(var(--w) * 1.5);
  color-scheme: dark;
}

/* Motyw ustawia theme.js (data-theme = light | dark | black); domyślnie ciemny. */
:root[data-theme="light"] {
  --bg: #eef0fa;
  --text: #12122a;
  --accent-ink: #0a84ff;
  --muted: rgba(18, 18, 42, .58);
  --glass: rgba(255, 255, 255, .6);
  --glass-edge: rgba(255, 255, 255, .95);
  --glass-shine: rgba(255, 255, 255, 1);
  --glass-ring: rgba(40, 40, 100, .12);
  --glass-shadow: rgba(40, 40, 100, .18);
  --line: rgba(18, 18, 42, .09);
  --track: rgba(18, 18, 42, .08);
  --seg-on: rgba(255, 255, 255, .95);
  --card-top: #fdfdff;
  --card-bottom: #eceef8;
  --card-line: #c9cce0;
  --blob1: #a5a4ff;
  --blob2: #ffb3c4;
  --blob3: #9ff0e6;
  color-scheme: light;
}

/* Czarny (OLED): czysta czerń, bez kolorowego tła; okienka odcinają się szarą ramką */
:root[data-theme="black"] {
  --bg: #000;
  --glass: rgba(255, 255, 255, .09);
  --glass-edge: rgba(255, 255, 255, .26);
  --glass-shine: rgba(255, 255, 255, .35);
  --glass-ring: rgba(255, 255, 255, .06);
  --glass-shadow: rgba(0, 0, 0, .9);
  --line: rgba(255, 255, 255, .14);
  --track: rgba(255, 255, 255, .14);
  --seg-on: rgba(255, 255, 255, .2);
  --blob-opacity: 0;
  --card-top: #202023;
  --card-bottom: #161618;
  --card-line: #000;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------- tło ---------- */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.bg i {
  position: absolute; width: 70vmax; height: 70vmax; border-radius: 50%;
  filter: blur(70px); opacity: calc(.55 * var(--blob-opacity));
  animation: drift 24s ease-in-out infinite alternate; transition: opacity .4s ease;
}
.bg i:nth-child(1) { background: var(--blob1); top: -25vmax; left: -20vmax; }
.bg i:nth-child(2) { background: var(--blob2); bottom: -30vmax; right: -25vmax; animation-duration: 30s; }
.bg i:nth-child(3) { background: var(--blob3); top: 35%; left: 40%; width: 45vmax; height: 45vmax; opacity: calc(.3 * var(--blob-opacity)); animation-duration: 36s; }
@keyframes drift { to { transform: translate(8vmax, 6vmax) scale(1.12); } }

/* ---------- liquid glass ---------- */
.glass {
  background: linear-gradient(135deg, rgba(255, 255, 255, .2), rgba(255, 255, 255, .04)), var(--glass);
  -webkit-backdrop-filter: blur(28px) saturate(190%);
  backdrop-filter: blur(28px) saturate(190%);
  border: 1px solid var(--glass-edge);
  border-radius: 28px;
  box-shadow:
    inset 0 1px 0 var(--glass-shine),
    inset 0 -1px 0 rgba(255, 255, 255, .08),
    0 0 0 1px var(--glass-ring),
    0 14px 36px var(--glass-shadow);
}

/* ---------- layout ---------- */
main {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 18px calc(env(safe-area-inset-bottom) + 110px);
}
.view { display: none; animation: fade .35s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } }

.head { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 18px; }
h1 { margin: 0; font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
h1.title { font-size: 24px; padding: 10px 26px; border-radius: 99px; letter-spacing: -.01em; }
h2 { margin: 26px 8px 10px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.muted { color: var(--muted); }
.pill { font-size: 12px; padding: 5px 11px; border-radius: 99px; background: var(--glass); border: 1px solid var(--glass-edge); }

/* ---------- pole nazwy ---------- */
.field { border-radius: 22px; padding: 4px 6px; }
.field input {
  width: 100%; background: none; border: 0; outline: 0; color: inherit;
  font: inherit; font-size: 17px; padding: 14px 14px;
}
.field input::placeholder { color: var(--muted); }
.swatches { display: flex; gap: 12px; flex-wrap: wrap; padding: 4px 16px 16px; }
.swatch {
  width: 28px; height: 28px; padding: 0; border-radius: 50%; border: 0; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), 0 2px 6px rgba(0, 0, 0, .25);
  transition: transform .15s ease;
}
.swatch:active { transform: scale(.88); }
.swatch.on { outline: 2px solid var(--text); outline-offset: 3px; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.seg + .field { margin-top: 14px; }
.seg button:disabled { opacity: .4; cursor: default; }
.chips button { display: inline-flex; align-items: center; gap: 8px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none; font: inherit; font-size: 14px; color: inherit; cursor: pointer;
  padding: 8px 14px; border-radius: 99px; background: var(--glass); border: 1px solid var(--glass-edge);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
}

/* ---------- flip clock ---------- */
.clock-wrap { margin-top: 18px; padding: 30px 12px 22px; text-align: center; border-radius: 36px; }
.clock { display: flex; justify-content: center; align-items: center; gap: 8px; }
.group { display: flex; gap: 4px; }
.sep { display: flex; flex-direction: column; gap: calc(var(--h) * .18); }
.sep i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.clock.running .sep i { animation: blink 1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: .25; } }

.group, .sep { flex: none; }
.digit { flex: none; position: relative; width: var(--w); height: var(--h); perspective: 500px; font-variant-numeric: tabular-nums; }
.half {
  position: absolute; left: 0; width: 100%; height: 50%; overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22);
}
.half span {
  display: block; height: var(--h); line-height: var(--h); text-align: center;
  font-size: calc(var(--h) * .72); font-weight: 700; color: var(--text);
}
.top, .flip-top { top: 0; border-radius: 14px 14px 0 0; background: var(--card-top); }
.bottom, .flip-bottom { bottom: 0; border-radius: 0 0 14px 14px; background: var(--card-bottom); box-shadow: none; }
.bottom span, .flip-bottom span { margin-top: calc(var(--h) / -2); }
.digit::after {
  content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 2px; margin-top: -1px;
  background: var(--card-line); z-index: 5; pointer-events: none;
}
.flip-top, .flip-bottom { visibility: hidden; z-index: 4; }
.flip-top { transform-origin: bottom; }
.flip-bottom { transform-origin: top; }
.flipping .flip-top { visibility: visible; animation: flipTop .28s ease-in forwards; }
.flipping .flip-bottom { visibility: visible; animation: flipBottom .28s ease-out .28s both; }
@keyframes flipTop { to { transform: rotateX(-90deg); } }
@keyframes flipBottom { from { transform: rotateX(90deg); } to { transform: rotateX(0); } }

.state { margin-top: 20px; font-size: 14px; color: var(--muted); letter-spacing: .04em; }
.extra:empty { display: none; }
.extra { margin-top: 16px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.stepper { display: flex; align-items: center; }
.stepper input {
  width: 68px; padding: 8px 4px; text-align: center; font: inherit; font-size: 20px; font-weight: 700; color: inherit;
  background: rgba(255, 255, 255, .12); border: 1px solid var(--glass-edge); border-radius: 14px; outline: 0;
  -moz-appearance: textfield; appearance: textfield;
}
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper { gap: 10px; }
.prow { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; max-width: 380px; font-size: 15px; }
.prow .stepper { flex: none; }
.round {
  width: 40px; height: 40px; border-radius: 50%; font: inherit; font-size: 22px; line-height: 1; color: inherit; cursor: pointer;
  background: var(--glass); border: 1px solid var(--glass-edge); box-shadow: inset 0 1px 0 var(--glass-shine);
}
.presets { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.presets button {
  font: inherit; font-size: 14px; color: inherit; cursor: pointer; padding: 7px 14px; border-radius: 99px;
  background: var(--glass); border: 1px solid var(--glass-edge);
}
.presets button.on { background: var(--seg-on); box-shadow: inset 0 1px 0 var(--glass-shine); }
.pdots { display: flex; gap: 10px; }
.pdots i { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--muted); }
.pdots i.on { background: var(--text); border-color: var(--text); }

/* ---------- przyciski ---------- */
.controls { display: flex; gap: 12px; margin-top: 22px; }
.btn {
  flex: 1; font: inherit; font-size: 18px; font-weight: 600; color: var(--text); cursor: pointer;
  padding: 18px; border-radius: 99px; border: 1px solid var(--glass-edge);
  background: var(--glass); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  box-shadow: inset 0 1px 0 var(--glass-shine), 0 8px 24px rgba(0, 0, 0, .2);
  transition: transform .15s ease;
}
.btn:active { transform: scale(.96); }
.btn.primary { background: linear-gradient(180deg, rgba(10, 132, 255, .95), rgba(10, 100, 230, .9)); color: #fff; border-color: rgba(255, 255, 255, .35); }
.btn.danger { color: var(--danger); }
.btn.ghost { box-shadow: none; }
.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: 14px; padding: 10px; cursor: pointer; text-decoration: underline; }
.controls-col { flex-direction: column; align-items: stretch; }
.controls-col .row { display: flex; gap: 12px; }

/* ---------- tryb pełnoekranowy (po Start) ---------- */
.focus-bar { display: none; }
.round svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stage.focus {
  position: fixed; inset: 0; z-index: 30; overflow: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px;
  padding: calc(env(safe-area-inset-top) + 16px) 10px calc(env(safe-area-inset-bottom) + 16px);
  background: color-mix(in srgb, var(--bg) 45%, transparent);
  -webkit-backdrop-filter: blur(40px) saturate(160%); backdrop-filter: blur(40px) saturate(160%);
  --w: min(calc((100vw - 90px) / 6.3), calc((100dvh - 330px) / 1.5), 240px);
  --h: calc(var(--w) * 1.5);
}
/* Płynne powiększanie: zegar i przyciski "przelatują" na swoje nowe miejsce */
#clock-wrap { view-transition-name: clock; }
#controls { view-transition-name: controls; }
::view-transition-group(*) { animation-duration: .6s; animation-timing-function: cubic-bezier(.32, .72, 0, 1); }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .5s; }
::view-transition-old(clock), ::view-transition-new(clock),
::view-transition-old(controls), ::view-transition-new(controls) { height: 100%; width: 100%; object-fit: fill; }
@supports not (view-transition-name: none) { .stage.focus { animation: fade .35s ease; } }
.stage.focus .focus-bar {
  position: absolute; top: calc(env(safe-area-inset-top) + 16px); left: 16px; right: 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.focus-label { display: inline-flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.stage.focus .clock-wrap { margin: 0; width: 100%; max-width: 1500px; cursor: default; padding: 28px 12px 22px; container-type: inline-size; }
/* Cyfry liczone z faktycznej szerokości okienka (cqw), więc zawsze mieszczą się w obręczy.
   6 cyfr + 2 separatory + odstępy = 6.24 * w + 44px */
@supports (width: 1cqw) {
  .stage.focus .clock {
    --w: min(calc((100cqw - 60px) / 6.4), calc((100dvh - 380px) / 1.5), 240px);
    --h: calc(var(--w) * 1.5);
  }
}
.stage.focus .sep i { width: calc(var(--w) * .12); height: calc(var(--w) * .12); }
.stage.focus .state { font-size: 18px; }
.stage.focus .controls { width: 100%; max-width: 440px; margin: 0; }
body.focus-on { overflow: hidden; }
body.focus-on .tabbar { display: none; }
.clock-wrap.clickable { cursor: pointer; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 10;
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  display: flex; gap: 4px; padding: 6px; border-radius: 99px;
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 88px;
  padding: 9px 14px; border: 0; border-radius: 99px; background: none; color: var(--muted);
  font: inherit; font-size: 11px; font-weight: 600; cursor: pointer; transition: background .25s, color .25s;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.on { background: var(--seg-on); color: var(--accent-ink); box-shadow: inset 0 1px 0 var(--glass-shine); }

/* ---------- analiza ---------- */
.seg { display: flex; padding: 4px; border-radius: 99px; }
.seg button {
  flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-size: 14px; font-weight: 600;
  padding: 10px 4px; border-radius: 99px; cursor: pointer; transition: background .25s, color .25s;
}
.seg button.on { background: var(--seg-on); color: var(--text); box-shadow: inset 0 1px 0 var(--glass-shine), 0 2px 8px rgba(0, 0, 0, .12); }

.total { margin-top: 14px; padding: 22px; display: flex; flex-direction: column; gap: 4px; }
.total strong { font-size: 44px; font-weight: 800; letter-spacing: -.02em; }

.list { padding: 8px 18px; }
.empty { padding: 18px 0; text-align: center; color: var(--muted); }
.bar-row { padding: 12px 0; }
.bar-row + .bar-row, .sess + .sess { border-top: 1px solid var(--line); }
.bar-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; font-size: 16px; }
.bar-head b { font-weight: 600; overflow-wrap: anywhere; display: flex; align-items: center; gap: 10px; }
.bar-head span { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.track { height: 10px; border-radius: 99px; background: var(--track); overflow: hidden; }
.fill { height: 100%; border-radius: 99px; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5); transition: width .6s cubic-bezier(.2, .8, .2, 1); }

.sess { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.sess .info { flex: 1; min-width: 0; }
.sess .info b { display: block; font-weight: 600; overflow-wrap: anywhere; }
.sess .info small { color: var(--muted); }
.sess .dur { font-variant-numeric: tabular-nums; }
.sess .del { border: 0; background: none; color: var(--danger); font-size: 22px; line-height: 1; padding: 6px; cursor: pointer; opacity: .8; }

/* ---------- ustawienia ---------- */
.opts { padding: 4px 18px; }
.opt {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 0; background: none; border: 0;
  color: inherit; font: inherit; font-size: 17px; text-align: left; cursor: pointer;
}
.opt + .opt { border-top: 1px solid var(--line); }
.opt .name { flex: 1; }
.opt .prev { flex: none; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--glass-edge); box-shadow: inset 0 1px 0 var(--glass-shine); }
.prev.auto { background: linear-gradient(90deg, #eef0fa 50%, #0b0b1a 50%); }
.prev.light { background: #eef0fa; }
.prev.dark { background: #0b0b1a; }
.prev.black { background: #000; }
.opt svg { flex: none; width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transition: opacity .2s; }
.opt.on svg { opacity: 1; }
.opt.danger .name { color: var(--danger); font-weight: 600; }

/* ---------- logowanie ---------- */
.authscreen {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  -webkit-backdrop-filter: blur(30px); backdrop-filter: blur(30px); overflow: auto;
}
.authscreen[hidden] { display: none; }
.authcard { width: min(100%, 400px); padding: 30px 26px 22px; display: flex; flex-direction: column; gap: 12px; }
.authcard h1 { font-size: 30px; }
.authcard p { margin: 0 0 6px; font-size: 14px; }
.authcard input {
  width: 100%; padding: 15px 16px; font: inherit; font-size: 17px; color: inherit; outline: 0;
  background: var(--glass); border: 1px solid var(--glass-edge); border-radius: 16px; box-shadow: inset 0 1px 0 var(--glass-shine);
}
.authcard input::placeholder { color: var(--muted); }
.authcard .btn { margin-top: 6px; }
.auth-error { min-height: 1.2em; color: var(--danger); font-weight: 600; }
body.auth-on { overflow: hidden; }
.opt.static { cursor: default; }
.opt .val { color: var(--muted); font-size: 15px; }
.opt .chev { color: var(--muted); font-size: 24px; line-height: 1; }
.opt .name { font-size: 16px; }
.switch {
  flex: none; position: relative; width: 51px; height: 31px; margin: 0; border-radius: 99px; cursor: pointer;
  -webkit-appearance: none; appearance: none; background: rgba(120, 120, 128, .4); transition: background .25s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, .35); transition: transform .25s cubic-bezier(.3, .7, .3, 1);
}
.switch:checked { background: #30d158; }
.switch:checked::after { transform: translateX(20px); }
.opts .stepper input { width: 60px; }
.goal:empty { display: none; }
.goal { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.btn.stop { background: linear-gradient(180deg, rgba(255, 69, 58, .97), rgba(215, 40, 40, .95)); color: #fff; border-color: rgba(255, 255, 255, .35); }
.hint { margin: 10px 10px 0; font-size: 13px; color: var(--muted); }

/* ---------- dialog ---------- */
.modal { color: var(--text); padding: 22px; width: min(88vw, 340px); border-radius: 32px; }
.modal::backdrop { background: rgba(0, 0, 0, .4); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.modal h3 { margin: 0 0 6px; font-size: 20px; }
.modal input {
  width: 100%; margin: 12px 0 16px; padding: 14px; font: inherit; font-size: 16px; color: inherit;
  background: rgba(255, 255, 255, .1); border: 1px solid var(--glass-edge); border-radius: 16px; outline: 0;
}
.modal .row { display: flex; gap: 10px; }
.modal .btn { font-size: 16px; padding: 14px; }

@media (prefers-reduced-motion: reduce) {
  .bg i, .view, .clock.running .sep i { animation: none; }
  .flipping .flip-top, .flipping .flip-bottom { animation-duration: .01s; animation-delay: 0s; }
}
