:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #1f2328;
  --muted: #5d6670;
  --track: #e6e2d8;
  --shadow: 0 10px 30px rgba(31, 35, 40, 0.08);

  --z1: #2e9e5b;
  --z2: #8cbf3f;
  --z3: #f2c230;
  --z4: #f08a24;
  --z5: #e0412f;
}

/* Ciemny motyw: gdy system ma tryb ciemny, oraz zawsze na telefonach/tabletach (ekran dotykowy). */
@media (prefers-color-scheme: dark), (hover: none) and (pointer: coarse) {
  :root {
    --bg: #15171a;
    --card: #1e2126;
    --ink: #eceff3;
    --muted: #9aa3ad;
    --track: #2c3037;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px 16px;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

.card {
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border-radius: 20px;
  padding: 32px 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0 0 12px;
  font-size: clamp(1.7rem, 5vw, 2.3rem);
  line-height: 1.15;
}

.lead {
  margin: 0 auto 20px;
  max-width: 46ch;
  color: var(--muted);
}

.gauge { margin: 0; }

.gauge svg {
  display: block;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  overflow: visible;
}

.gauge .zone {
  fill: none;
  stroke-width: 24;
}

.gauge .tick { stroke: var(--muted); stroke-width: 2; }
.gauge .tick.minor { stroke-width: 1; opacity: 0.5; }
.gauge .tick-label {
  fill: var(--muted);
  font-size: 11px;
  text-anchor: middle;
  dominant-baseline: middle;
}

#needle polygon,
#needle circle { fill: var(--ink); }
#needle .hub { fill: var(--card); }

.value {
  margin-top: 4px;
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.value .unit { font-size: 1.6rem; margin-left: 2px; color: var(--muted); }

.status {
  margin-top: 8px;
  font-size: 1.15rem;
  font-weight: 600;
}

.kawa-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
  padding: 10px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--level, var(--z1));
  color: #111;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: transform 0.1s ease, filter 0.15s ease;
}
.kawa-btn:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.kawa-btn:active:not(:disabled) { transform: translateY(1px); }
.kawa-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.kawa-btn:disabled { cursor: default; opacity: 0.7; }
.kawa-btn[hidden] { display: none; }

.kawa-podpis {
  margin: 8px auto 0;
  max-width: 40ch;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--muted);
}

.gif {
  display: block;
  height: 220px;
  width: auto;
  max-width: 100%;
  margin: 20px auto 0;
  border-radius: 12px;
  object-fit: contain;
  box-shadow: 0 0 0 4px var(--level, var(--track));
}
.gif[hidden] { display: none; }

/* ---------- Legenda i zasady ---------- */

.legenda { text-align: left; }
.legenda[hidden] { display: none; }

.legenda-tytul {
  margin: 0 0 12px;
  font-size: 1.3rem;
  line-height: 1.2;
}

.zasady {
  margin: 0 0 22px;
  padding-left: 1.2em;
  font-size: 0.9rem;
  color: var(--muted);
}
.zasady li { margin-bottom: 8px; }
.zasady strong { color: var(--ink); }

.legenda-podtytul {
  margin: 0 0 10px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stany {
  display: grid;
  gap: 10px;
}

.stan {
  padding: 12px;
  border-radius: 12px;
  background: var(--track);
}

.stan-naglowek {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.stan-znak {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--card);
  font-size: 16px;
  line-height: 1;
}

.stan-nazwa { font-weight: 700; }
.stan-kiedy {
  margin-left: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}
.stan-opis {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.stan-gify {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.stan-gify img {
  height: 72px;
  width: auto;
  max-width: 128px;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
}

/* ---------- Dzień zapinki ---------- */

.dzien {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--track);
  text-align: left;
}
.dzien[hidden] { display: none; }

.dzien-tytul {
  margin: 0 0 14px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.dzien-weekend { margin: 0 0 12px; color: var(--muted); }

/* Oś dnia: pasek + znaczniki kaw nad nim. */
.dzien-os {
  position: relative;
  padding-top: 22px; /* miejsce na ☕ nad paskiem */
}

.dzien-pasek {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}

.dzien-wypelnienie {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  transition: clip-path 0.6s ease;
}

.dzien-teraz {
  position: absolute;
  bottom: -3px;
  width: 2px;
  height: 18px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--ink);
}
.dzien-teraz[hidden] { display: none; }

.dzien-kawy {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Kropka na pasku z obwódką w kolorze tła + ☕ nad nią. Hit-target większy niż znak. */
.dzien-kawa {
  position: absolute;
  bottom: 0;
  width: 24px;
  height: 36px;
  margin-left: -12px;
  pointer-events: auto;
  cursor: help;
}
.dzien-kawa::before {
  content: "☕";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  line-height: 1;
}
.dzien-kawa::after {
  content: "";
  position: absolute;
  bottom: 1px;
  left: 50%;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 2px var(--card);
}

.dzien-godziny {
  position: relative;
  height: 18px;
  margin-top: 4px;
  font-size: 0.7rem;
  color: var(--muted);
}
.dzien-godziny span {
  position: absolute;
  transform: translateX(-50%);
}
.dzien-godziny span:first-child { transform: none; }
.dzien-godziny span:last-child { transform: translateX(-100%); }

.dzien-staty {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--track);
}
.stat-liczba {
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.stat-opis {
  font-size: 0.72rem;
  line-height: 1.3;
  color: var(--muted);
}

.historia { margin-top: 14px; }
.historia[hidden] { display: none; }
.historia summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}
.historia table {
  width: 100%;
  margin-top: 8px;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}
.historia th,
.historia td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--track);
  text-align: right;
}
.historia th:first-child,
.historia td:first-child { text-align: left; }
.historia th {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}

@media (max-width: 420px) {
  .dzien-staty { gap: 6px; }
  .stat { padding: 8px; }
  .stat-liczba { font-size: 1rem; }
}

.comment {
  margin: 20px auto 0;
  padding: 12px 16px;
  max-width: 44ch;
  border-left: 4px solid var(--level, var(--muted));
  background: var(--track);
  border-radius: 8px;
  text-align: left;
  font-style: italic;
}

.meta {
  margin: 16px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

footer {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

/* ---------- Pasek jak w TV ---------- */

:root { --pasek-h: 44px; }

.pasek {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  height: var(--pasek-h);
  background: #0d0f12;
  color: #fff;
  border-top: 3px solid var(--level, #e0412f);
  font-weight: 600;
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.35);
}
.pasek[hidden] { display: none; }

.pasek-etykieta {
  flex: none;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--level, #e0412f);
  color: #111;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pasek-okno {
  flex: 1;
  display: flex;
  align-items: center;
  overflow: hidden;
}

.pasek-tor {
  display: flex;
  width: max-content;
  animation: przewijanie 30s linear infinite;
}

.pasek-polowa { display: flex; }

.pasek-wpis { white-space: nowrap; }
.pasek-wpis::after {
  content: "●";
  margin: 0 28px;
  color: var(--level, #e0412f);
  font-size: 0.7em;
  vertical-align: middle;
}

@keyframes przewijanie {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

body.ma-pasek { padding-bottom: calc(32px + var(--pasek-h)); }

/* Szeroki ekran (komputer): karta przy lewej krawędzi, żeby GIF w tle był lepiej widoczny.
   Telefon i wąskie okna: karta na środku jak dotąd. */
@media (min-width: 1000px) {
  body {
    align-items: flex-start;
    padding-left: 48px;
    padding-right: 48px;
  }
  .card,
  footer {
    width: 560px;
  }

  /* Pełnoekranowe tło rozmyte, a obok karty cały GIF w dużym rozmiarze. */
  .ma-tlo .tlo {
    filter: blur(24px) brightness(0.55);
    transform: scale(1.1);
  }
  .ma-tlo .tlo-duzy {
    display: block;
    position: fixed;
    z-index: 0;
    top: 48px;
    left: 656px;              /* 48px marginesu + 560px karty + 48px odstępu */
    width: calc(100vw - 704px);
    height: calc(100vh - 96px);
    object-fit: contain;
    filter: drop-shadow(0 12px 32px rgba(0, 0, 0, 0.5));
  }
  .ma-tlo.ma-pasek .tlo-duzy { height: calc(100vh - 96px - var(--pasek-h)); }

  /* Duży GIF jest po prawej, więc mały w karcie byłby powtórzeniem; statystyki dnia wchodzą wyżej. */
  .ma-tlo .gif { display: none; }
}

.tlo-duzy { display: none; }
.tlo-duzy[hidden] { display: none !important; }

/* Powyżej 100% liczba na czerwono (kołysanie wskazówki robi app.js). */
.overload .value { color: var(--z5); }

/* ---------- Tryb alarmowy (> 100%) ---------- */

.alarm,
.kogut { display: none; }

.alarm-on .alarm { display: block; }

/* GIF poziomu na całym ekranie (pod kartą). */
.tlo {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  background: #000;
}
.tlo[hidden] { display: none; }

/* Czerwona poświata od krawędzi ekranu; ok. 1 błysk na sekundę (bezpieczne dla oczu). */
.alarm-flash {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 35%, rgba(255, 0, 0, 0.6) 100%);
  animation: flash 1s ease-in-out infinite alternate;
}

@keyframes flash {
  from { opacity: 0.15; }
  to   { opacity: 1; }
}

.card, footer { position: relative; z-index: 1; }

.alarm-on main.card { margin-top: 36px; }
.ma-tlo footer span {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--card);
}

/* Kogut na górnej krawędzi karty. */
.alarm-on .kogut {
  display: block;
  position: absolute;
  top: -52px;
  left: 50%;
  width: 76px;
  transform: translateX(-50%);
}

.kogut-klosz {
  position: relative;
  overflow: hidden;
  width: 56px;
  height: 46px;
  margin: 0 auto;
  border-radius: 28px 28px 6px 6px;
  background: radial-gradient(circle at 50% 70%, #ff8a80 0%, #e53935 45%, #8e0000 100%);
  animation: glow 0.5s ease-in-out infinite alternate;
}

/* Obracający się snop światła w kloszu. */
.kogut-klosz::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 70%;
  width: 160px;
  height: 160px;
  margin: -80px 0 0 -80px;
  background: conic-gradient(from 0deg, transparent 0deg, rgba(255, 255, 255, 0.85) 25deg, transparent 50deg, transparent 180deg, rgba(255, 255, 255, 0.85) 205deg, transparent 230deg);
  animation: spin 0.8s linear infinite;
}

.kogut-podstawa {
  height: 10px;
  border-radius: 3px;
  background: #2b2f36;
}

@keyframes glow {
  from { box-shadow: 0 0 8px 2px rgba(255, 30, 30, 0.5); }
  to   { box-shadow: 0 0 40px 16px rgba(255, 30, 30, 0.9); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .alarm-flash { animation: none; opacity: 0.6; }
  .kogut-klosz, .kogut-klosz::after { animation: none; }
  .pasek-tor { animation: none; }
}
