/*
  PTHS Tracker — visual pass (Ulric, K-UID).
  Logic in app.js and structure in index.html do not depend on any of these
  class names having a particular look, only on them existing and toggling
  [hidden] / .done / .active / .complete as documented in app.js.

  ---------------------------------------------------------------------------
  Design direction: "iron & chalk", not generic dark-SaaS.
  This is a solo gymnastics-strength tracker used mid-set, one-handed, sweaty,
  phone propped up and read at a small distance. Everything is tuned for that:
  big tap targets, high-contrast glanceable state, zero network dependency
  (system fonts only — gym wifi is not guaranteed), motion that carries real
  status (timer ring, section fill) rather than decoration.

  Token roles:
    bg/surface   — matte iron, warm near-black (not blue-black SaaS default)
    text/dim     — chalk white / chalk dust
    accent       — hazard amber: "working" / primary action / hold phase
    rest         — teal: rest phase (must read as calm, opposite of accent)
    done         — chalk-lime: completed (distinct from both, satisfying pop)
    warn         — amber-yellow: gate / caution notes
    danger       — for sync failure only
  ---------------------------------------------------------------------------
*/

:root {
  --bg: #14120d;
  --surface: #211d16;
  --surface-2: #2b251c;
  --surface-3: #362f23;
  --border: rgba(246, 242, 232, 0.09);
  --border-strong: rgba(246, 242, 232, 0.16);

  --text: #f6f2e8;
  --text-dim: #b8ab97;
  --text-faint: #8a7d6b;

  --accent: #ff6a1a;
  --accent-ink: #1c0d02;
  --rest: #33c9a3;
  --rest-ink: #062a21;
  --done: #8fd44e;
  --done-ink: #10230a;
  --warn: #f2c14e;
  --danger: #ff5c4d;

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 26px;
  --tap-min: 56px;

  --font-display: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "SFMono-Regular", "Roboto Mono", Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

* { box-sizing: border-box; }

/* Author `display` rules (e.g. .timer-overlay{display:flex}) beat the UA
   stylesheet's [hidden]{display:none} regardless of selector specificity,
   since author origin always wins over UA origin. Without this, elements
   toggled via the `hidden` DOM property (app.js does exactly this for the
   timer overlay and the banners) stay visible. This one rule keeps every
   [hidden] element actually hidden. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  padding-bottom: 3rem;
}

/* Visible keyboard focus everywhere — dark UI default outlines are near-invisible. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

/* ---------------------------------------------------------------------- */
/* Progress strip — sticky "what's done / where am I" readout             */
/* ---------------------------------------------------------------------- */

.progress-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(var(--bg) 82%, transparent);
  padding: 0.75rem 0 0.6rem;
  margin: 0 -1rem;
  padding-left: 1rem;
  padding-right: 1rem;
}

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin-bottom: 0.6rem;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--rest), var(--done));
  border-radius: 999px;
  transition: width 0.35s var(--ease);
}

.section-rail {
  display: flex;
  gap: 0.5rem;
}

.rail-pill {
  --pct: 0;
  flex: 1 1 0;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.rail-pill::before {
  content: "";
  position: absolute;
  inset: 0;
  width: var(--pct, 0%);
  background: var(--surface-3);
  z-index: -1;
  transition: width 0.3s var(--ease);
}

.rail-pill-num {
  position: relative;
}

.rail-pill.active {
  color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.rail-pill.complete {
  color: var(--done-ink);
}

.rail-pill.complete::before {
  background: var(--done);
  width: 100%;
}

.rail-pill.complete.active {
  box-shadow: inset 0 0 0 2px var(--done);
}

/* ---------------------------------------------------------------------- */
/* Header                                                                  */
/* ---------------------------------------------------------------------- */

.app-header {
  padding-top: 0.25rem;
}

.app-header h1 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: 0 0 0.35rem;
}

.meta {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0;
}

.banner {
  background: var(--surface-2);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin: 1rem 0;
  font-size: 0.95rem;
  line-height: 1.45;
}

.safety {
  background: var(--surface-2);
  border-left: 4px solid var(--warn);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin: 1.5rem 0 1rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-dim);
}

/* Fatigue calibration block — additive, functional-only styling (Mack).
   Reuses the existing .banner shell + token system so it doesn't clash;
   Ulric owns further visual polish on top of this if he wants it. */
.fatigue-cal-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
}

.fatigue-cal-intro {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 0.6rem;
}

.fatigue-cal-list {
  margin: 0;
  padding-left: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.fatigue-cal-item {
  font-size: 0.85rem;
  line-height: 1.45;
}

.fatigue-cal-label {
  color: var(--text);
}

.fatigue-cal-action {
  color: var(--text-dim);
}

/* ---------------------------------------------------------------------- */
/* Sections                                                                */
/* ---------------------------------------------------------------------- */

.section {
  margin: 1.75rem 0;
  scroll-margin-top: 5.5rem; /* keep header clear of sticky progress strip */
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.6rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.section-header-label {
  min-width: 0;
}

.section-header-count {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-faint);
}

.section-header-count.complete {
  color: var(--done);
}

.section-note {
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.4;
  margin: -0.2rem 0 0.7rem;
}

/* ---------------------------------------------------------------------- */
/* Items — the core glanceable, thumb-driven unit                         */
/* ---------------------------------------------------------------------- */

.item {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 0.9rem;
  margin-bottom: 0.6rem;
  cursor: pointer;
  transition: background-color 0.2s var(--ease), border-color 0.2s var(--ease);
}

.item:active {
  background: var(--surface-2);
}

.item.done {
  background: rgba(143, 212, 78, 0.1);
  border-color: rgba(143, 212, 78, 0.35);
}

.item-check {
  flex: 0 0 auto;
  width: var(--tap-min);
  height: var(--tap-min);
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.item-check::after {
  content: "\2713";
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--done-ink);
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.18s var(--ease), transform 0.18s var(--ease);
}

.item.done .item-check {
  border-color: var(--done);
  background: var(--done);
}

.item.done .item-check::after {
  opacity: 1;
  transform: scale(1);
}

.item-body {
  flex: 1 1 auto;
  min-width: 0;
  padding-top: 0.15rem;
}

.item-name {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.35;
}

.item.done .item-name {
  color: var(--text-dim);
  text-decoration: line-through;
  text-decoration-color: var(--done);
  text-decoration-thickness: 2px;
}

.item-params {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.item-cue {
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-dim);
  margin-top: 0.4rem;
  border-top: 1px dashed var(--border);
  padding-top: 0.4rem;
}

/* "Jak na to" — optional longer how-to, collapsed by default so the
   checklist stays scannable. Native <details>/<summary>: free keyboard/tap
   support, no JS toggle state to get wrong (see the timer-overlay [hidden]
   bug for why that matters). Functional styling only (Mack); Ulric owns
   further polish. */
.item-details {
  margin-top: 0.5rem;
}

.item-details-summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.4rem 0.1rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
}

.item-details-summary::-webkit-details-marker {
  display: none;
}

.item-details-summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 0.15s var(--ease);
}

.item-details[open] .item-details-summary::before {
  transform: rotate(90deg);
}

.item-details-body {
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text-dim);
  padding: 0.2rem 0.1rem 0.3rem;
  white-space: pre-line;
}

.item-gate {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--warn);
  margin-top: 0.4rem;
}

.item-actions {
  margin-top: 0.6rem;
}

/* ---------------------------------------------------------------------- */
/* Buttons                                                                 */
/* ---------------------------------------------------------------------- */

.btn {
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  padding: 0.5rem 1.25rem;
  border-radius: 999px;
  border: none;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s var(--ease), background-color 0.15s var(--ease);
}

.btn:active {
  transform: scale(0.96);
}

.btn-timer {
  background: var(--surface-2);
  color: var(--accent);
  border: 2px solid var(--accent);
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-secondary {
  background: var(--surface-3);
  color: var(--text);
}

/* ---------------------------------------------------------------------- */
/* Footer                                                                  */
/* ---------------------------------------------------------------------- */

.app-footer {
  text-align: center;
  margin-top: 2rem;
}

.sync-status {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-faint);
}

.sync-status.error {
  color: var(--danger);
  font-weight: 700;
}

/* ---------------------------------------------------------------------- */
/* Timer overlay — full-screen, one-hand operable, readable at arm's reach */
/* ---------------------------------------------------------------------- */

.timer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 9, 6, 0.97);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.timer-box {
  width: 100%;
  height: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 2.5rem 1.5rem calc(1.75rem + env(safe-area-inset-bottom, 0px));
  text-align: center;
}

.timer-item-name {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-dim);
}

/* Draining ring: --progress (0-100, set from app.js each tick) is the
   fraction of the current phase remaining. It reads at a glance even
   from across the room, no need to read the digits. */
.timer-ring {
  --progress: 100;
  --phase-color: var(--accent);
  width: min(72vw, 280px);
  height: min(72vw, 280px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: conic-gradient(
    var(--phase-color) calc(var(--progress) * 1%),
    var(--surface-2) 0
  );
  transition: background 0.9s linear;
}

.timer-ring.rest {
  --phase-color: var(--rest);
}

.timer-ring-face {
  width: calc(100% - 22px);
  height: calc(100% - 22px);
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.timer-phase {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

.timer-phase.hold { color: var(--accent); }
.timer-phase.rest { color: var(--rest); }

.timer-display {
  font-family: var(--font-mono);
  font-size: clamp(3.5rem, 18vw, 5rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.timer-set-progress {
  font-family: var(--font-mono);
  color: var(--text-dim);
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 1.25rem;
}

.timer-controls {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}

.timer-controls .btn {
  flex: 1 1 auto;
}

/* ---------------------------------------------------------------------- */
/* Small screens: tighten a little further                                */
/* ---------------------------------------------------------------------- */

@media (max-width: 360px) {
  .rail-pill { height: 36px; font-size: 0.8rem; }
  .timer-display { font-size: clamp(3rem, 20vw, 4rem); }
}

/* ---------------------------------------------------------------------- */
/* Accessibility: respect reduced motion globally                         */
/* ---------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
