/*
 * Mini App styling.
 *
 * Colours come from two places. Chrome — background, text, buttons — follows the
 * theme Telegram hands us, so the app looks native in whichever theme the user
 * runs. The three level accents are the PDF's, so a glance at the phone and a
 * glance at the printout agree on what orange, blue and green mean.
 *
 * No framework. There is no shared state complex enough to justify one, and the
 * project has exactly two dependencies.
 */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #111827);
  --hint: var(--tg-theme-hint-color, #6b7280);
  --card: var(--tg-theme-secondary-bg-color, #f3f4f6);
  --accent: var(--tg-theme-button-color, #2563eb);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);

  /* The PDF's level colours, so phone and printout agree. */
  --full: #ea580c;
  --part: #2563eb;
  --fund: #16a34a;
  --delo: #7c3aed;

  /* For levels nobody has seen yet. */
  --spare-1: #d97706;
  --spare-2: #e11d48;
  --spare-3: #14b8a6;

  --gap: 12px;
  --radius: 10px;
}

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

body {
  margin: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ---------------------------------------------------------------- chrome --- */

.bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px var(--gap);
  background: var(--bg);
}

.week {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--fg);
  font-size: 15px;
  font-weight: 600;
}

.run {
  flex: none;
  padding: 10px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.run:disabled { opacity: 0.5; }

/* Day tabs stay reachable while scrolling a long session. */
.days {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 6px var(--gap);
  background: var(--bg);
  scrollbar-width: none;
}
.days::-webkit-scrollbar { display: none; }

.days button {
  flex: none;
  padding: 9px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--card);
  color: var(--fg);
  font-size: 14px;
  font-weight: 600;
}
.days button[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-fg);
}

.levels {
  display: flex;
  gap: 6px;
  padding: 4px var(--gap) 10px;
}

.levels button {
  flex: 1;
  padding: 9px 4px;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 8px 8px 0 0;
  background: var(--card);
  color: var(--hint);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
}
/* The colour arrives inline as --level, because the set of levels is not
   fixed: a deload week has DELOAD and CF4FUN, and a rule per known name would
   simply not match them. */
.levels button[aria-selected="true"] {
  color: var(--level, var(--accent));
  border-bottom-color: var(--level, var(--accent));
}

/* --------------------------------------------------------------- content --- */

.content { padding: 0 var(--gap) 32px; }

.session {
  margin: 18px 0 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--level, var(--accent));
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--level, var(--accent));
}

.block {
  margin: 14px 0 4px;
  font-size: 15px;
  font-weight: 800;
}

.subblock {
  margin: 10px 0 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--hint);
}

/* Whole row is the tap target: in a gym, with chalk on your hands, a 16px
   checkbox is not a real target. */
.item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  margin: 3px 0;
  padding: 11px 12px;
  border: 0;
  border-left: 3px solid var(--level, var(--accent));
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font-size: 15px;
  text-align: left;
}

.item .tick {
  flex: none;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  border: 2px solid var(--hint);
  border-radius: 6px;
  font-size: 15px;
  font-weight: 800;
  line-height: 19px;
  text-align: center;
  color: transparent;
}

.item[aria-pressed="true"] .tick {
  border-color: var(--level, var(--accent));
  background: var(--level, var(--accent));
  color: var(--accent-fg);
}
.item[aria-pressed="true"] .label {
  opacity: 0.45;
  text-decoration: line-through;
}

.note {
  margin: 6px 2px 12px;
  font-size: 13.5px;
  font-style: italic;
  color: var(--hint);
  overflow-wrap: anywhere;
}

.empty, .error {
  padding: 32px var(--gap);
  text-align: center;
  color: var(--hint);
}
.error { color: #dc2626; }

.progress {
  margin: 2px 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--hint);
}

/* ----------------------------------------------------------------- toast --- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 10;
  max-width: 88%;
  padding: 11px 18px;
  transform: translate(-50%, 20px);
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}
.toast[data-show="true"] { opacity: 0.95; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
