:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --card: #1e293b;
  --card2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #22c55e;
  --primary-d: #16a34a;
  --secondary: #3b82f6;
  --danger: #ef4444;
  --work: #22c55e;
  --rest: #3b82f6;
  --roundrest: #a855f7;
  --prepare: #f59e0b;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

.screen { min-height: 100dvh; display: none; }
.screen:not([hidden]) { display: block; }
#screen-login.screen:not([hidden]),
#screen-player.screen:not([hidden]) { display: flex; }

.muted { color: var(--muted); }
.spacer { flex: 1; }
.error { color: var(--danger); font-size: .95rem; margin: 4px 0 0; }

/* Buttons */
.btn {
  appearance: none; border: 0; border-radius: 12px;
  padding: 12px 16px; font-size: 1rem; font-weight: 600;
  color: #fff; background: var(--card2); cursor: pointer;
  transition: transform .05s ease, filter .15s ease;
  touch-action: manipulation; user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); color: #06250f; }
.btn-secondary { background: var(--secondary); }
.btn-danger { background: var(--danger); }
.btn-ghost { background: transparent; color: var(--muted); padding: 8px 10px; }
.btn-sm { padding: 8px 12px; font-size: .9rem; }
.btn-block { display: block; width: 100%; margin-top: 10px; }
.btn-big { padding: 16px 28px; font-size: 1.15rem; min-width: 150px; }

/* Inputs */
label { display: block; font-size: .85rem; color: var(--muted); margin-top: 12px; font-weight: 600; }
input {
  width: 100%; margin-top: 5px; padding: 12px 14px; font-size: 1.05rem;
  background: var(--bg); color: var(--text);
  border: 1px solid #334155; border-radius: 10px; outline: none;
}
input:focus { border-color: var(--secondary); }

/* Login */
#screen-login { align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card h1 { font-size: 1.4rem; margin: 6px 0 2px; }
.login-card label { text-align: left; }
.login-card .btn-primary { margin-top: 18px; }
.logo { font-size: 3rem; }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow);
}

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; background: var(--bg2);
  position: sticky; top: 0; z-index: 5;
  border-bottom: 1px solid #334155;
  padding-top: max(14px, env(safe-area-inset-top));
}
.brand { font-weight: 700; }

.view { padding: 16px; max-width: 720px; margin: 0 auto; padding-bottom: 40px; }
.list-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.list-head h2 { margin: 0; font-size: 1.25rem; flex: 1; }

/* Workout list */
.workout-list { display: flex; flex-direction: column; gap: 12px; }
.wcard {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px;
}
.wcard .wmain { flex: 1; min-width: 0; }
.wcard h3 { margin: 0 0 4px; font-size: 1.1rem; }
.wcard .wsub { color: var(--muted); font-size: .85rem; }
.wcard .wactions { display: flex; gap: 8px; }
.empty { text-align: center; margin-top: 40px; }
.save-state { text-align: center; color: var(--muted); font-size: .8rem; min-height: 1em; margin-top: 14px; }

/* Editor */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-grid label:last-child { grid-column: 1 / -1; }
h3 { margin: 22px 0 8px; }
.ex-list { display: flex; flex-direction: column; gap: 8px; }
.ex-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: 10px; padding: 8px 8px 8px 12px;
}
.ex-row .ex-idx { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 1.5em; }
.ex-row .ex-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ex-row input.ex-name { background: var(--bg); border: 1px solid #334155; }
.ex-row .icon-btn {
  background: var(--card2); border: 0; color: var(--text);
  width: 36px; height: 36px; border-radius: 8px; font-size: 1rem; cursor: pointer;
}
.ex-row .icon-btn:active { transform: scale(.95); }
.ex-row .icon-btn.danger { color: var(--danger); }
.add-row { display: flex; gap: 8px; margin-top: 10px; }
.add-row input { margin-top: 0; }
.add-row .btn { white-space: nowrap; }
.editor-summary { margin-top: 16px; color: var(--muted); font-size: .9rem; background: var(--card); border-radius: 10px; padding: 12px; }
.editor-actions { margin-top: 18px; }

/* Player */
#screen-player {
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  transition: background-color .4s ease;
}
.player-top { display: flex; align-items: center; gap: 10px; }
.player-top .muted { flex: 1; text-align: center; }
.stage {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 14px; padding: 10px 0;
}
.phase-label {
  text-transform: uppercase; letter-spacing: .12em; font-weight: 800;
  font-size: 1.1rem; opacity: .9;
}
.exercise-name {
  font-size: clamp(1.6rem, 7vw, 2.6rem); font-weight: 800; line-height: 1.1;
  max-width: 92%;
}
.timer-wrap { position: relative; width: min(62vw, 280px); aspect-ratio: 1; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(255,255,255,.12); stroke-width: 6; }
.ring-fg {
  fill: none; stroke: #fff; stroke-width: 6; stroke-linecap: round;
  stroke-dasharray: 339.292; stroke-dashoffset: 0;
  transition: stroke-dashoffset .25s linear, stroke .3s ease;
}
.timer {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: clamp(3rem, 16vw, 6rem); font-weight: 800; font-variant-numeric: tabular-nums;
}
.next-up { color: rgba(255,255,255,.85); font-size: 1.05rem; min-height: 1.4em; }
.next-up b { font-weight: 800; }

.player-meta { display: flex; justify-content: space-around; gap: 8px; padding: 12px 0; }
.meta-item { display: flex; flex-direction: column; align-items: center; }
.meta-num { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.meta-cap { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; opacity: .8; }

.player-controls { display: flex; align-items: center; justify-content: center; gap: 14px; padding-top: 6px; }

/* Phase background tints on the player screen */
#screen-player.ph-prepare { background: linear-gradient(160deg, #3b2c08, var(--bg)); }
#screen-player.ph-work    { background: linear-gradient(160deg, #07351a, var(--bg)); }
#screen-player.ph-rest    { background: linear-gradient(160deg, #0b2a52, var(--bg)); }
#screen-player.ph-roundrest { background: linear-gradient(160deg, #2e1149, var(--bg)); }
#screen-player.ph-done    { background: linear-gradient(160deg, #07351a, var(--bg)); }
#screen-player.pulse .timer { animation: pulse .5s ease; }
@keyframes pulse { 0%{transform:scale(1);} 40%{transform:scale(1.18);} 100%{transform:scale(1);} }

@media (min-width: 560px) {
  .timer-wrap { width: 300px; }
}
