/*
 * Gustav Timer PWA – vzhled 1:1 podle iOS TimerView.
 * Barvy a fonty odpovídají balíčku GustavUI (GustavUICore).
 */

@font-face {
    font-family: 'Martian Mono';
    src: url('/fonts/MartianMono-Bold.ttf') format('truetype');
    font-weight: 700;
    font-display: block;
}
@font-face {
    font-family: 'Martian Grotesk';
    src: url('/fonts/MartianGrotesk-StdRg.ttf') format('truetype');
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: 'Martian Grotesk';
    src: url('/fonts/MartianGrotesk-StdMd.ttf') format('truetype');
    font-weight: 500;
    font-display: swap;
}
@font-face {
    font-family: 'Martian Grotesk Cn';
    src: url('/fonts/MartianGrotesk-CnRg.ttf') format('truetype');
    font-weight: 400;
    font-display: swap;
}

:root {
    color-scheme: dark;

    /* GustavUI: StartColor / StopColor / ResetColor / LightColor */
    --volt: #CBFF73;
    --pink: #FF5A95;
    --neutral: #616E79;
    --light: #AAB2B6;

    /* GustavLayout */
    --control-height: 100px;
    --pad: 16px;

    /* Responzivní limity – na telefonu bez omezení, viz breakpointy dole */
    --content-max-width: none;
    --counter-max-width: none;

    /* Okraj kolem číslic počítadla (přičítá se k vlastním okrajům glyfů) */
    --counter-inset: 28px;

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

    --font-grotesk: 'Martian Grotesk', system-ui, -apple-system, 'Helvetica Neue', sans-serif;
    --font-grotesk-cn: 'Martian Grotesk Cn', 'Martian Grotesk', system-ui, sans-serif;
    --font-mono: 'Martian Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: #000;
    color: var(--volt);
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    font-family: var(--font-grotesk);
}

/* BackgroundImageView: scaledToFill + grayscale + černý overlay 30 % */
.bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: #222 url('/img/gym.jpg') center / cover no-repeat;
    filter: grayscale(1);

}
.bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
}
/* iOS 26 web app (status bar `black`) vzorkuje barvu status baru z horních ~10 px stránky.
   Fotka je tam tmavě šedá → pruh by byl šedý; černý přechod na pozadí ho drží čistě černý
   a do fotky se rozpustí dřív, než začne UI (progress bar je na 16 px). */
.bg::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 48px;
    z-index: 1;
    background: linear-gradient(to bottom, #000 0, #000 12px, rgba(0, 0, 0, 0) 48px);
}

/* ---------- Layout (portraitTimerView) ---------- */

.timer {
    position: fixed;
    inset: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    padding-top: calc(var(--safe-top) + var(--pad));
    /* iOS TimerView ignoruje spodní safe area – tlačítka sedí 16 pt nad hranou displeje */
    padding-bottom: var(--pad);
    padding-left: max(var(--pad), var(--safe-left));
    padding-right: max(var(--pad), var(--safe-right));
}

/* ProgressArrayView: segmenty podle poměru délek, mezera 5, výška 6 */
.progress {
    display: flex;
    gap: 5px;
    height: 6px;
    flex: none;
}
.progress-segment {
    position: relative;
    height: 100%;
    min-width: 6px;
    border-radius: 20px;
    background: var(--neutral);
    overflow: hidden;
}
.progress-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: 0;
    border-radius: 20px;
    background: var(--volt);
    will-change: width;
}

/* headerSection: font headUpDisplay (StdRg 15) */
.hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 8px;
    min-height: 24px;
    font-size: 15px;
    line-height: 24px;
    font-weight: 400;
    color: var(--volt);
}
.hud-info {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.2s ease-in-out;
}
.hud-info.is-hidden { opacity: 0; }
.hud-info.is-muted { opacity: 0.5; }
.hud-icons {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: none;
    height: 20px;
}
.hud-icon {
    width: 20px;
    height: 20px;
    display: block;
}
.hud-icon[hidden] { display: none; }

/* counterDisplay: MartianMono-Bold, minimumScaleFactor → font-size počítá JS.
   V iOS nemá počítadlo horizontální padding (má ho jen HUD a progress bar),
   proto přesahuje padding rodiče až k okrajům displeje. */
.counter-wrap {
    flex: 1;
    min-height: 0;
    align-self: center;
    width: calc(100% + max(var(--pad), var(--safe-left)) + max(var(--pad), var(--safe-right)));
    max-width: var(--counter-max-width);
    padding: 0 var(--counter-inset);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.counter {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 40vw;
    line-height: 1;
    letter-spacing: -0.03em;
    white-space: nowrap;
    color: var(--volt);
    font-variant-numeric: tabular-nums;
}

/* horizontalControlButtons: spacing 16, výška 100, sekundární šířka 100 */
.controls {
    display: flex;
    gap: 16px;
    flex: none;
    margin-top: var(--pad);
}
.control {
    appearance: none;
    border: 0;
    margin: 0;
    padding: 0;
    height: var(--control-height);
    border-radius: calc(var(--control-height) / 2);
    font: inherit;
    color: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.35s ease-in-out, color 0.35s ease-in-out, transform 0.12s ease-out, opacity 0.2s;
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
}
.control:active { transform: scale(0.97); }
.control:disabled { opacity: 0.35; cursor: default; }
.control:disabled:active { transform: none; }
.control:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }

.control-primary {
    flex: 1;
    min-width: 0;
    gap: 8px;
    padding: 0 24px;
    background: var(--volt);
    color: var(--neutral);
}
.is-running .control-primary {
    background: var(--pink);
    color: var(--volt);
}
.control-label {
    font-family: var(--font-grotesk);
    font-weight: 500;
    font-size: 20px;
    letter-spacing: 0.01em;
}
.control-desc {
    font-family: var(--font-grotesk-cn);
    font-weight: 400;
    font-size: 20px;
    text-transform: uppercase;
    opacity: 0.5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.control-desc:empty { display: none; }
.is-running .control-desc { display: none; }

/* Odpočet 3-2-1 (_cd=1): nahradí label/desc velkou číslicí, viz engine.isCountingDown */
.control-countdown {
    display: none;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 32px;
    line-height: 1;
}
.is-counting-down .control-label,
.is-counting-down .control-desc { display: none; }
.is-counting-down .control-countdown { display: block; }

@keyframes countdown-pulse {
    0% { transform: scale(1.4); opacity: 0.35; }
    100% { transform: scale(1); opacity: 1; }
}
.control-countdown.pulse { animation: countdown-pulse 0.35s ease-out; }

.control-secondary {
    flex: none;
    width: var(--control-height);
    background: rgba(97, 110, 121, 0.82);
    color: var(--volt);
    position: relative;
}
.control-icon {
    position: absolute;
    inset: 24px;
    width: calc(100% - 48px);
    height: calc(100% - 48px);
    transition: opacity 0.25s ease-in-out, transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.control-icon-skip { opacity: 0; transform: rotate(-30deg) scale(0.8); }
.control-icon-reset { opacity: 1; transform: none; }
.is-running .control-icon-skip { opacity: 1; transform: none; }
.is-running .control-icon-reset { opacity: 0; transform: rotate(30deg) scale(0.8); }

/* ---------- Responzivita (mobile first) ---------- */

/* Nízký displej na výšku (malý telefon v prohlížeči s lištami): nižší tlačítka */
@media (max-height: 640px) and (orientation: portrait) {
    :root { --control-height: 80px; }
    .control-icon { inset: 18px; width: calc(100% - 36px); height: calc(100% - 36px); }
    .control-label, .control-desc { font-size: 18px; }
    .control-countdown { font-size: 26px; }
}

/* Tablet a širší: ovládání a HUD se drží čitelné šířky uprostřed, pozadí zůstává na celou plochu */
@media (min-width: 600px) {
    :root {
        --pad: 24px;
        --content-max-width: 720px;
        --counter-max-width: 900px;
        --counter-inset: 36px;
    }
    .progress, .hud, .controls {
        width: 100%;
        max-width: var(--content-max-width);
        margin-left: auto;
        margin-right: auto;
    }
    .hud { font-size: 17px; }
    .hud-icon { width: 22px; height: 22px; }
}

/* Desktop: větší typografie ovládání, počítadlo omezené výškou ne šířkou */
@media (min-width: 1024px) and (min-height: 700px) {
    :root {
        --pad: 32px;
        --control-height: 112px;
        --content-max-width: 820px;
        --counter-max-width: 1200px;
        --counter-inset: 48px;
    }
    .hud { font-size: 18px; }
    .control-label, .control-desc { font-size: 22px; }
    .control-countdown { font-size: 40px; }
}

/* Myš: jemná odezva na hover, na dotyku se neuplatní */
@media (hover: hover) and (pointer: fine) {
    .control:not(:disabled):hover { filter: brightness(1.06); }
}

/* ---------- Landscape (telefon): jen počítadlo, tap = start/stop ---------- */

.is-landscape .progress,
.is-landscape .hud,
.is-landscape .controls {
    display: none;
}
.is-landscape .timer {
    padding: var(--pad);
    padding-left: max(var(--pad), var(--safe-left));
    padding-right: max(var(--pad), var(--safe-right));
    cursor: pointer;
}
/* V landscape iOS safe area respektuje – číslice nesmí pod Dynamic Island */
.is-landscape .counter-wrap {
    width: 100%;
}

@media (prefers-reduced-motion: reduce) {
    .control, .control-icon, .hud-info { transition: none; }
    .control-countdown.pulse { animation: none; }
}

/* Zvýšený kontrast: pevnější pozadí sekundárního tlačítka */
@media (prefers-contrast: more) {
    .control-secondary { background: var(--neutral); }
}
