/* Telegram hands the page its theme as --tg-theme-* variables; the fallbacks are for opening it in a browser. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --sub: var(--tg-theme-subtitle-text-color, var(--hint));
  --link: var(--tg-theme-link-color, #2f80ed);
  --accent: var(--tg-theme-button-color, #2f80ed);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --header: var(--tg-theme-section-header-text-color, var(--hint));
  --sep: var(--tg-theme-section-separator-color, rgba(60, 60, 67, 0.16));
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --nav-bg: var(--tg-theme-bottom-bar-bg-color, var(--card));
  --soft: color-mix(in srgb, var(--text) 6%, transparent);
  --ok: #30a46c;

  --trading: #30a46c;
  --cp: #8e4ec6;
  --ad: #f76b15;
  --gym: #2f80ed;
  --notes: #d1a000;
  --listen: #12a594;

  --top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
  --nav-h: 56px;
  --r: 14px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #ffffff;
    --hint: #8e8e93;
    --sep: rgba(84, 84, 88, 0.45);
    --link: #4c9bff;
    --accent: #4c9bff;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#screen {
  padding: calc(var(--top) + 8px) 16px calc(var(--nav-h) + var(--bottom) + 24px);
  max-width: 640px;
  margin: 0 auto;
  animation: fade 0.18s ease;
}
@keyframes fade { from { opacity: 0; } }

/* ---- headers and sections */
.head { padding: 12px 4px 4px; }
.head h1 { margin: 0; font-size: 30px; line-height: 36px; font-weight: 700; letter-spacing: -0.02em; }
.head .sub { margin: 2px 0 0; color: var(--hint); font-size: 15px; }
.back { color: var(--link); font-size: 16px; margin: 0 0 6px -2px; display: inline-flex; align-items: center; gap: 2px; min-height: 32px; }
.section { margin-top: 22px; }
.section > h2 { margin: 0 16px 7px; font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.02em; color: var(--header); }
.section > .foot { margin: 7px 16px 0; font-size: 13px; color: var(--hint); }
.card { background: var(--card); border-radius: var(--r); overflow: hidden; }
.notice { margin-top: 16px; padding: 12px 12px 12px 16px; border-radius: var(--r); background: var(--card); color: var(--sub); font-size: 15px; display: flex; align-items: center; gap: 12px; }
.notice p { margin: 0; flex: 1; min-height: 36px; display: flex; align-items: center; }
.notice .btn { flex: none; }

/* ---- the "now" card */
.focus {
  margin-top: 16px;
  padding: 16px;
  border-radius: 18px;
  background: var(--card);
  position: relative;
  overflow: hidden;
}
.focus::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 16%, transparent), transparent 70%);
  pointer-events: none;
}
.focus > * { position: relative; }
.focus .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 30px; }
.focus .kicker { font-size: 13px; font-weight: 600; color: var(--c); text-transform: uppercase; letter-spacing: 0.03em; }
.chip-link {
  height: 30px; padding: 0 12px; border-radius: 15px; flex: none;
  background: color-mix(in srgb, var(--link) 12%, transparent); color: var(--link); font-size: 14px; font-weight: 600;
}
.chip-link:active { opacity: 0.7; }
.progress { margin-top: 12px; }
.progress .bar { margin-top: 0; height: 5px; }
.progress .live { margin-top: 8px; }
.focus .what { margin-top: 4px; font-size: 20px; font-weight: 650; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.focus .what .w { font-weight: 400; color: var(--hint); font-size: 17px; }
.focus .title { margin-top: 4px; font-size: 17px; }
.focus .meta { margin-top: 4px; color: var(--sub); font-size: 14px; }
.focus .live { margin-top: 10px; display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--sub); }
.focus .live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
.actions { margin-top: 14px; display: grid; gap: 8px; }
.actions .pair { display: flex; gap: 8px; }
.actions .pair > * { flex: 1; }

.btn {
  min-height: 46px; padding: 0 14px; border-radius: 12px;
  background: var(--soft); color: var(--text); font-size: 16px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform 0.12s var(--ease), opacity 0.12s;
}
.btn:active:not(:disabled) { transform: scale(0.97); opacity: 0.85; }
.btn.primary { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.quiet { background: none; color: var(--link); }
.btn.danger { background: none; color: var(--danger); }
.btn.sm { min-height: 36px; font-size: 15px; border-radius: 10px; }
.link { color: var(--link); display: flex; width: fit-content; align-items: center; gap: 4px; font-size: 15px; margin-top: 8px; min-height: 32px; }
.empty { margin: 0; padding: 16px; color: var(--hint); font-size: 15px; }

/* ---- timeline rows */
.tl { list-style: none; margin: 0; padding: 4px 0; }
.tl li { position: relative; }
.tl .item {
  width: 100%; text-align: left; display: grid; grid-template-columns: 62px 14px 1fr auto; align-items: start;
  gap: 0 8px; padding: 10px 14px 10px 12px; min-height: 52px;
}
.tl .item:active { background: var(--soft); }
.tl .t { color: var(--hint); font-size: 14px; font-variant-numeric: tabular-nums; padding-top: 2px; text-align: right; }
.tl .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--hint)); margin-top: 6px; justify-self: center; position: relative; z-index: 1; }
.tl li + li .item::before {
  content: ""; position: absolute; left: 89px; top: 0; height: 16px; width: 2px; border-radius: 1px; background: var(--sep); transform: translateX(-1px);
}
.tl li:not(:last-child) .item::after {
  content: ""; position: absolute; left: 89px; top: 26px; bottom: 0; width: 2px; border-radius: 1px; background: var(--sep); transform: translateX(-1px);
}
.tl .main { min-width: 0; }
.tl .name { font-size: 16px; font-weight: 550; }
.tl .name small { font-weight: 400; color: var(--hint); font-size: 14px; }
.tl .detail { color: var(--sub); font-size: 14px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl .marker .name { font-weight: 400; color: var(--hint); font-size: 15px; }
.tl .marker .dot { width: 6px; height: 6px; margin-top: 8px; background: var(--hint); opacity: 0.6; }
.tl .marker.work .dot { width: 10px; height: 10px; margin-top: 6px; background: none; border: 2px solid var(--hint); opacity: 1; }
.tl .faded { opacity: 0.5; }
.tl .nowline .item { min-height: 26px; padding-top: 2px; padding-bottom: 2px; align-items: center; }
.tl .nowline .t { color: var(--accent); font-weight: 600; font-size: 13px; padding-top: 0; }
.tl .nowline .dot { width: 9px; height: 9px; margin-top: 0; background: var(--accent); opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.tl .nowline .main { height: 2px; border-radius: 1px; background: var(--accent); opacity: 0.55; }
.tl .faded .name { text-decoration: none; }

.pill {
  display: inline-flex; align-items: center; gap: 3px; height: 22px; padding: 0 8px; border-radius: 11px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--soft); color: var(--sub); margin-top: 1px;
}
.pill.done { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill.now { background: var(--accent); color: var(--on-accent); }
.pill.wait { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

/* ---- week */
.seg { display: flex; background: var(--soft); border-radius: 10px; padding: 2px; margin-top: 14px; }
.seg button { flex: 1; min-height: 32px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--sub); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.stat { padding: 14px 16px; }
.stat .big { font-size: 22px; font-weight: 700; }
.stat .big small { font-size: 15px; font-weight: 400; color: var(--hint); }
.bar { height: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; margin-top: 10px; }
.bar > span { display: block; height: 100%; border-radius: 3px; background: var(--c, var(--accent)); transform-origin: left; transition: transform 0.4s var(--ease); }
.stat .tracks { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 14px; color: var(--sub); }

.days { list-style: none; margin: 0; padding: 0; }
.days li { position: relative; }
.days li + li::before { content: ""; position: absolute; top: 0; left: 80px; right: 0; border-top: 0.5px solid var(--sep); }
.day { width: 100%; display: grid; grid-template-columns: 52px 1fr 12px; gap: 12px; align-items: center; padding: 10px 14px 10px 16px; text-align: left; min-height: 60px; }
.day:active { background: var(--soft); }
.day .date { text-align: center; }
.day .date b { display: block; font-size: 20px; font-weight: 650; line-height: 1.1; }
.day .date span { font-size: 12px; color: var(--hint); text-transform: uppercase; font-weight: 600; }
.day.today .date b { color: var(--accent); }
.day.today .date span { color: var(--accent); }
.day.past { opacity: 0.6; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 8px; border-radius: 8px; font-size: 13px;
  background: color-mix(in srgb, var(--c, var(--hint)) 13%, transparent); color: var(--text); white-space: nowrap;
}
.chip.off { opacity: 0.5; }
.chip .mark { font-size: 11px; color: var(--sub); }
.chip.ok .mark { color: var(--ok); }
.chev { color: var(--hint); opacity: 0.6; font-size: 20px; }
.free { color: var(--hint); font-size: 15px; }

/* ---- progress */
.track { padding: 14px 16px 6px; }
.track + .track { border-top: 0.5px solid var(--sep); }
.track .top { display: flex; align-items: center; gap: 10px; }
.icon { width: 34px; height: 34px; flex: none; border-radius: 10px; display: grid; place-items: center; font-size: 18px; background: color-mix(in srgb, var(--c) 16%, transparent); }
.track .top .n { font-weight: 600; font-size: 17px; flex: 1; display: flex; align-items: center; gap: 8px; }
.tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; padding: 3px 7px; border-radius: 6px; background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--c); }
.track .count { font-variant-numeric: tabular-nums; color: var(--sub); font-size: 15px; }
.track .meta { color: var(--sub); font-size: 14px; margin-top: 8px; }
.track .nx { width: 100%; text-align: left; margin-top: 10px; padding: 10px 0 2px; display: flex; gap: 10px; align-items: baseline; border-top: 0.5px solid var(--sep); }
.track button.nx:active { opacity: 0.6; }
.track .nx .k { flex: none; width: 40px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--c); }
.track .nx .tt { flex: 1; min-width: 0; }
.track .nx .tt div:first-child { font-size: 15px; }
.track .nx .tt div + div { font-size: 13px; color: var(--hint); margin-top: 1px; }
.track .nx .go { color: var(--link); }
.track .then { padding: 4px 0 10px 50px; font-size: 13px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track.off .icon, .track.off .bar > span { filter: grayscale(0.7); opacity: 0.7; }

/* ---- settings */
.rows { list-style: none; margin: 0; padding: 0; }
.rows > li { position: relative; }
.rows > li + li::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 0.5px solid var(--sep); }
.row { width: 100%; min-height: 48px; padding: 10px 16px; display: flex; align-items: center; gap: 12px; text-align: left; }
button.row:active { background: var(--soft); }
.row .l { flex: 1; font-size: 16px; }
.row .v { color: var(--hint); font-size: 16px; font-variant-numeric: tabular-nums; }
.row .v::after { content: "›"; margin-left: 8px; opacity: 0.6; font-size: 20px; vertical-align: -1px; }
.row.static .v::after { content: none; }
.dows { display: flex; gap: 6px; padding: 10px 14px 12px; }
.dows button {
  flex: 1; height: 38px; border-radius: 10px; font-size: 14px; font-weight: 600; background: var(--soft); color: var(--sub);
  transition: background 0.15s, color 0.15s;
}
.dows button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.pick { padding: 10px 14px 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.pick .btn { flex: 1; }
.pick.two { display: grid; grid-template-columns: 1fr 1fr; }

/* ---- sheet */
#sheet { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#sheet .scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.36); opacity: 0; transition: opacity 0.22s ease; }
#sheet .panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 86vh; overflow-y: auto; overscroll-behavior: contain;
  max-width: 640px; margin: 0 auto;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 6px 18px calc(var(--bottom) + 18px);
  transform: translateY(105%); visibility: hidden; transition: transform 0.26s var(--ease), visibility 0s 0.26s;
}
#sheet.open { pointer-events: auto; }
#sheet.open .panel { visibility: visible; transition: transform 0.26s var(--ease); }
#sheet.open .scrim { opacity: 1; }
#sheet.open .panel { transform: none; }
.grab { width: 36px; height: 5px; border-radius: 3px; background: var(--sep); margin: 4px auto 10px; }
.sh-head { display: flex; gap: 12px; align-items: center; }
.sh-head .n { font-size: 19px; font-weight: 650; }
.sh-head .w { color: var(--hint); font-size: 14px; }
.sh-item { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--soft); }
.sh-item .title { font-size: 17px; font-weight: 600; }
.sh-item .meta { color: var(--sub); font-size: 14px; margin-top: 3px; }
.sh-item .note { color: var(--sub); font-size: 14px; margin-top: 6px; font-style: italic; }
.sh-status { margin-top: 12px; color: var(--sub); font-size: 15px; }
.times { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.times .btn { min-height: 44px; font-variant-numeric: tabular-nums; }
.times .btn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }

/* ---- nav */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--nav-bg) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
  border-top: 0.5px solid var(--sep);
  padding-bottom: var(--bottom);
}
#nav button {
  flex: 1; max-width: 160px; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--hint); font-size: 11px; font-weight: 500;
}
#nav button[aria-current="page"] { color: var(--accent); }
#nav svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- toast */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--bottom) + 14px); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  transition: transform 0.22s var(--ease), opacity 0.22s;
  width: max-content; max-width: calc(100vw - 32px);
  display: flex; align-items: center; gap: 14px;
  padding: 11px 16px; border-radius: 14px;
  background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--bg); font-size: 15px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}
#toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
#toast button { color: var(--accent); font-weight: 650; filter: brightness(1.25); }

/* ---- loading */
.sk { background: var(--card); border-radius: var(--r); height: 72px; margin-top: 16px; position: relative; overflow: hidden; }
.sk.tall { height: 260px; }
.sk::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, var(--soft), transparent); animation: shimmer 1.2s infinite; transform: translateX(-100%); }
@keyframes shimmer { to { transform: translateX(100%); } }

[data-c="trading"] { --c: var(--trading); }
[data-c="cp"] { --c: var(--cp); }
[data-c="ad"] { --c: var(--ad); }
[data-c="gym"] { --c: var(--gym); }
[data-c="notes"] { --c: var(--notes); }
[data-c="listen"] { --c: var(--listen); }
[data-c="ok"] { --c: var(--ok); }

/* Small phones: a little less padding and type, so the plan shows under the card. */
@media (max-width: 360px) {
  #screen { padding-left: 12px; padding-right: 12px; }
  .head h1 { font-size: 26px; line-height: 32px; }
  .focus { padding: 14px; }
  .focus .what { font-size: 18px; }
  .focus .title { font-size: 16px; }
  .btn { min-height: 44px; font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
