:root {
  --bg: #0f172a;
  --bg-soft: #111827;
  --card: rgba(255, 255, 255, 0.08);
  --card-strong: rgba(255, 255, 255, 0.13);
  --text: #f8fafc;
  --muted: #cbd5e1;
  --muted-2: #94a3b8;
  --line: rgba(255, 255, 255, 0.14);
  --primary: #22c55e;
  --primary-strong: #16a34a;
  --orange: #f97316;
  --red: #ef4444;
  --blue: #38bdf8;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(34, 197, 94, 0.25), transparent 34rem),
    radial-gradient(circle at top right, rgba(56, 189, 248, 0.16), transparent 26rem),
    var(--bg);
  color: var(--text);
}

body.light {
  --bg: #f3f4f6;
  --bg-soft: #ffffff;
  --card: rgba(255, 255, 255, 0.9);
  --card-strong: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --muted-2: #64748b;
  --line: rgba(15, 23, 42, 0.12);
  --shadow: 0 16px 38px rgba(15, 23, 42, 0.10);
  background:
    radial-gradient(circle at top left, rgba(34, 197, 94, 0.18), transparent 30rem),
    radial-gradient(circle at top right, rgba(56, 189, 248, 0.14), transparent 26rem),
    var(--bg);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

#app-shell {
  max-width: 780px;
  min-height: 100vh;
  margin: 0 auto;
  padding-bottom: calc(96px + var(--safe-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.15rem 1rem .75rem;
  background: linear-gradient(to bottom, rgba(15, 23, 42, .96), rgba(15, 23, 42, .78), transparent);
  backdrop-filter: blur(14px);
}

body.light .topbar { background: linear-gradient(to bottom, rgba(243, 244, 246, .98), rgba(243, 244, 246, .82), transparent); }

.eyebrow {
  margin: 0 0 .25rem;
  color: var(--primary);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin: 0; font-size: 1.7rem; letter-spacing: -.04em; }
h2 { margin-bottom: .6rem; font-size: 1.55rem; letter-spacing: -.035em; }
h3 { margin-bottom: .45rem; font-size: 1.1rem; }
p { color: var(--muted); line-height: 1.45; }

.app-content { padding: .4rem 1rem 1rem; }

.card, .hero, .loading-card, .modal-card {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.card { padding: 1rem; margin: .85rem 0; }
.hero { padding: 1.15rem; margin: .6rem 0 1rem; overflow: hidden; position: relative; }
.hero::after {
  content: "";
  position: absolute;
  right: -3rem;
  top: -3rem;
  width: 9rem;
  height: 9rem;
  border-radius: 999px;
  background: rgba(34, 197, 94, .18);
}

.loading-card { text-align: center; padding: 2.5rem 1.2rem; }
.loader {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,.18);
  border-top-color: var(--primary);
  margin: 0 auto 1rem;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.grid { display: grid; gap: .75rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.stat-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .65rem; margin-top: .9rem; }
.stat {
  padding: .75rem;
  border-radius: 18px;
  background: rgba(255,255,255,.08);
  border: 1px solid var(--line);
}
.stat strong { display: block; font-size: 1.05rem; color: var(--text); }
.stat span { display: block; margin-top: .2rem; color: var(--muted-2); font-size: .78rem; }

.badges { display: flex; flex-wrap: wrap; gap: .45rem; margin: .6rem 0; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .34rem .58rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.07);
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}
.badge.good { color: #bbf7d0; background: rgba(34,197,94,.16); border-color: rgba(34,197,94,.28); }
.badge.warn { color: #fed7aa; background: rgba(249,115,22,.17); border-color: rgba(249,115,22,.32); }
.badge.danger { color: #fecaca; background: rgba(239,68,68,.16); border-color: rgba(239,68,68,.3); }
.badge.info { color: #bae6fd; background: rgba(56,189,248,.15); border-color: rgba(56,189,248,.26); }
body.light .badge.good { color: #166534; }
body.light .badge.warn { color: #9a3412; }
body.light .badge.danger { color: #991b1b; }
body.light .badge.info { color: #075985; }

.actions { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: .9rem; }
.actions.vertical { flex-direction: column; }

button.primary, button.secondary, button.ghost, button.danger {
  min-height: 46px;
  border: 0;
  border-radius: 16px;
  padding: .8rem 1rem;
  font-weight: 900;
  color: var(--text);
}
button.primary { background: linear-gradient(135deg, var(--primary), var(--primary-strong)); color: #052e16; }
button.secondary { background: rgba(255,255,255,.12); border: 1px solid var(--line); }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
button.danger { background: rgba(239, 68, 68, .18); border: 1px solid rgba(239,68,68,.36); color: #fecaca; }
button.small { min-height: 36px; border-radius: 999px; padding: .45rem .75rem; font-size: .82rem; }
body.light button.secondary, body.light button.ghost { color: var(--text); }
body.light button.danger { color: #991b1b; }

.list { display: grid; gap: .65rem; }
.list-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  width: 100%;
  padding: .9rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255,255,255,.075);
  color: inherit;
  text-align: left;
}
.list-item:active { transform: translateY(1px); }
.list-item .title { display: block; font-weight: 900; }
.list-item .meta { display: block; color: var(--muted-2); font-size: .86rem; margin-top: .22rem; }
.chevron { color: var(--muted-2); font-size: 1.25rem; padding-top: .1rem; }

.section-title { margin: 1.2rem 0 .5rem; color: var(--muted); font-size: .92rem; font-weight: 900; text-transform: uppercase; letter-spacing: .06em; }

.exercise-card {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: .8rem;
  padding: .85rem;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.075);
}
.exercise-card img, .step-image {
  width: 74px;
  height: 74px;
  object-fit: cover;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.08);
}
.exercise-card p { margin: .25rem 0 0; font-size: .9rem; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.08);
  color: var(--text);
  padding: .82rem .9rem;
  outline: none;
}
body.light input, body.light select, body.light textarea { background: #fff; }
label { display: block; margin: .75rem 0 .35rem; color: var(--muted); font-size: .86rem; font-weight: 800; }
textarea { min-height: 86px; resize: vertical; }

.timer-screen {
  min-height: calc(100vh - 160px);
  display: flex;
  flex-direction: column;
}
.timer-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1.1rem;
  margin: .3rem 0;
  border-radius: 34px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.13), rgba(255,255,255,.06)),
    var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.timer-phase { display: flex; justify-content: space-between; align-items: center; gap: .8rem; margin-bottom: .8rem; }
.timer-title { font-size: 1.55rem; letter-spacing: -.04em; margin-bottom: .35rem; }
.timer-instruction { min-height: 3.2em; font-size: 1rem; }
.timer-clock {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 150px;
  margin: .8rem 0;
  border-radius: 32px;
  background: rgba(0,0,0,.22);
  border: 1px solid var(--line);
  font-size: clamp(4rem, 22vw, 7.8rem);
  font-weight: 950;
  line-height: 1;
  letter-spacing: -.07em;
}
body.light .timer-clock { background: rgba(15,23,42,.05); }
.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  border: 1px solid var(--line);
}
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--primary), var(--blue)); border-radius: inherit; transition: width .2s linear; }
.timer-footer { display: grid; gap: .65rem; }
.next-step { color: var(--muted-2); font-size: .92rem; }
.timer-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .55rem; }
.timer-actions button { padding: .7rem .55rem; }
.step-visual { display: flex; gap: .75rem; align-items: center; }
.step-visual .step-image { width: 88px; height: 88px; flex: 0 0 auto; }

.week-card-header { display: flex; justify-content: space-between; gap: .75rem; align-items: flex-start; }
.week-card-header h3 { margin-bottom: .25rem; }
.week-sessions { margin-top: .75rem; display: grid; gap: .5rem; }
.session-mini { padding: .65rem; border-radius: 16px; background: rgba(255,255,255,.065); border: 1px solid var(--line); }

.summary-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .5rem;
}
.summary-bar .stat { text-align: center; padding: .7rem .45rem; }

.toast {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: calc(92px + var(--safe-bottom));
  z-index: 100;
  max-width: 720px;
  margin: 0 auto;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  padding: .85rem 1rem;
  border-radius: 18px;
  background: rgba(15, 23, 42, .96);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: var(--shadow);
}
.toast.visible { transform: translateY(0); opacity: 1; }

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .25rem;
  max-width: 780px;
  margin: 0 auto;
  padding: .55rem .55rem calc(.55rem + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(15,23,42,.92);
  backdrop-filter: blur(18px);
}
body.light .bottom-nav { background: rgba(255,255,255,.92); }
.nav-item {
  border: 0;
  border-radius: 16px;
  padding: .65rem .28rem;
  background: transparent;
  color: var(--muted-2);
  font-size: .73rem;
  font-weight: 900;
}
.nav-item.active { background: rgba(34,197,94,.18); color: var(--text); }

.hidden { display: none !important; }
.muted { color: var(--muted-2); }
.text-danger { color: #fecaca; }
body.light .text-danger { color: #991b1b; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }

@media (min-width: 720px) {
  .grid.two-desktop { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-content { padding-left: 1.25rem; padding-right: 1.25rem; }
}

@media (max-width: 390px) {
  .timer-clock { min-height: 128px; }
  .summary-bar { grid-template-columns: repeat(2, 1fr); }
  .stat-row { grid-template-columns: 1fr; }
  .timer-actions { grid-template-columns: 1fr; }
}
