:root {
  --bg: #0f1020;
  --bg-2: #181a35;
  --card: #1e2148;
  --accent: #ff5a3c;
  --accent-2: #ffb03c;
  --work: #ff5a3c;
  --rest: #2dd4bf;
  --ready: #ffb03c;
  --text: #f4f5ff;
  --muted: #9ea3d0;
  --radius: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: radial-gradient(circle at 50% 0%, var(--bg-2), var(--bg));
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- Loading screen ---------- */
.loader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: radial-gradient(circle at 50% 30%, var(--bg-2), var(--bg));
  z-index: 100;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}
.loader.fade { opacity: 0; visibility: hidden; }
.drop {
  font-size: 80px;
  animation: bounce 1.4s ease-in-out infinite;
}
.drop.big { font-size: 90px; animation: pop 0.6s ease; }
.logo {
  font-size: 52px;
  letter-spacing: 10px;
  font-weight: 800;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { color: var(--muted); letter-spacing: 4px; text-transform: uppercase; font-size: 13px; }
.loader-bar {
  margin-top: 16px;
  width: 180px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.1);
  overflow: hidden;
}
.loader-bar span {
  display: block;
  height: 100%;
  width: 40%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  animation: slide 1.1s ease-in-out infinite;
}

@keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-18px); } }
@keyframes pop { 0% { transform: scale(0.4); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }
@keyframes slide { 0% { transform: translateX(-120%); } 100% { transform: translateX(320%); } }

/* ---------- Layout ---------- */
.screen { min-height: 100%; }
main.screen, .done {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 18px 120px;
  padding-top: max(18px, env(safe-area-inset-top));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.brand { font-size: 24px; letter-spacing: 3px; font-weight: 800; }
.link {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
}
.link:active { background: rgba(255,255,255,0.14); }

.panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
}
.panel h2 { font-size: 18px; margin-bottom: 4px; }
.hint { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.loading-text { color: var(--muted); font-size: 14px; }

/* ---------- Exercise grid ---------- */
.exercise-groups { display: flex; flex-direction: column; gap: 6px; }
.cat-heading {
  font-size: 13px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 14px 2px 8px;
}
.cat-heading:first-child { margin-top: 0; }
.exercise-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.ex-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  padding: 14px;
  border-radius: 14px;
  border: 2px solid transparent;
  background: rgba(255,255,255,0.05);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}
.ex-card:active { transform: scale(0.97); }
.ex-card .emoji { font-size: 26px; }
.ex-card .ex-name { font-weight: 700; font-size: 15px; }
.ex-card .ex-desc { color: var(--muted); font-size: 12px; line-height: 1.3; }
.ex-card.selected {
  border-color: var(--accent);
  background: rgba(255,90,60,0.16);
}
.ex-card .badge {
  align-self: flex-start;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  opacity: 0;
}
.ex-card.selected .badge { opacity: 1; }

/* ---------- Settings ---------- */
.settings { display: flex; flex-direction: column; gap: 18px; }
.setting span {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin-bottom: 8px;
}
.setting small { color: var(--accent-2); font-weight: 700; }
input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
  outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
input[type=range]::-moz-range-thumb {
  width: 24px; height: 24px; border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  cursor: pointer;
}
.summary { margin-top: 16px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- Spotify ---------- */
.spotify-block { display: flex; flex-direction: column; }
.spotify-btn {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  border: none;
  border-radius: 999px;
  background: #1db954; /* Spotify green */
  cursor: pointer;
}
.spotify-btn::before { content: '🎧'; }
.spotify-btn:active { transform: scale(0.97); }
.spotify-status { font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.spotify-status strong { color: var(--text); }
.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
  text-decoration: underline;
}

/* ---------- Custom dropdown (playlist picker) ---------- */
.dropdown { position: relative; width: 100%; }
.dropdown-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  text-align: left;
  color: var(--text);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  cursor: pointer;
}
.dropdown-toggle:focus { outline: none; border-color: var(--accent); }
.dropdown-toggle #playlist-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dropdown-toggle .caret { color: var(--muted); flex-shrink: 0; transition: transform 0.15s ease; }
.dropdown.open .caret { transform: rotate(180deg); }
.dropdown-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 260px;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 6px;
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(0,0,0,0.5);
  z-index: 30;
}
.dropdown-menu li {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.dropdown-menu li small { color: var(--muted); }
.dropdown-menu li:hover { background: rgba(255,255,255,0.08); }
.dropdown-menu li.active { background: rgba(255,90,60,0.18); color: var(--text); }

/* ---------- Sweat button ---------- */
.sweat-btn {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(524px, calc(100% - 36px));
  padding: 18px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #fff;
  border: none;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 30px rgba(255,90,60,0.4);
  cursor: pointer;
  z-index: 20;
}
.sweat-btn:disabled { opacity: 0.4; box-shadow: none; cursor: not-allowed; }
.sweat-btn:not(:disabled):active { transform: translateX(-50%) scale(0.98); }

.done .sweat-btn { position: static; transform: none; margin-top: 24px; width: min(360px, 100%); }
.done .sweat-btn:not(:disabled):active { transform: scale(0.98); }
.done { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; min-height: 100vh; gap: 8px; }
.done h1 { font-size: 30px; }

/* ---------- Timer screen ---------- */
.timer {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.4s ease;
  z-index: 40;
}
.timer.phase-ready { background: radial-gradient(circle at 50% 40%, #3a2c12, var(--bg)); }
.timer.phase-work  { background: radial-gradient(circle at 50% 40%, #4a1a14, var(--bg)); }
.timer.phase-rest  { background: radial-gradient(circle at 50% 40%, #103b38, var(--bg)); }
.timer-inner { text-align: center; padding: 24px; width: 100%; max-width: 460px; }
.phase-label {
  font-size: 20px;
  letter-spacing: 6px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--accent-2);
}
.phase-work .phase-label, .timer.phase-work .phase-label { color: var(--work); }
.timer.phase-rest .phase-label { color: var(--rest); }
.exercise-name { font-size: 30px; font-weight: 800; margin: 6px 0 18px; min-height: 38px; }

.ring-wrap { position: relative; width: 280px; height: 280px; margin: 0 auto; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: rgba(255,255,255,0.1); stroke-width: 8; }
.ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 339.292;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.25s linear, stroke 0.3s ease;
}
.timer.phase-rest .ring-progress { stroke: var(--rest); }
.timer.phase-ready .ring-progress { stroke: var(--ready); }
.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 88px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.countdown.pulse { animation: tick 0.4s ease; }
@keyframes tick { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }

.up-next { margin-top: 22px; color: var(--muted); font-size: 15px; min-height: 20px; }
.progress-text { margin-top: 6px; color: var(--muted); font-size: 13px; letter-spacing: 1px; }

.timer-controls { margin-top: 26px; display: flex; gap: 12px; justify-content: center; }
.ctrl {
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  background: rgba(255,255,255,0.12);
  color: var(--text);
  cursor: pointer;
}
.ctrl.ghost { background: transparent; border: 1px solid rgba(255,255,255,0.2); }
.ctrl.danger { background: var(--accent); color: #fff; }
.ctrl:active { transform: scale(0.97); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(3px);
  animation: fade-in 0.15s ease;
}
.modal {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  animation: pop 0.2s ease;
}
.modal h2 { font-size: 20px; margin-bottom: 8px; }
.modal .hint { margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .ctrl { flex: 1; padding: 13px; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Admin ---------- */
.admin-form { display: flex; flex-direction: column; gap: 14px; }
.field-row { display: flex; gap: 12px; }
.field-row .field:first-child { flex: 0 0 90px; }
.field-row .field:last-child { flex: 1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field select {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  font-family: inherit;
}
.field select:focus { outline: none; border-color: var(--accent); }
.field select option {
  background: var(--card);
  color: var(--text);
}
.cat-heading { font-size: 13px; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); margin: 16px 2px 4px; }
.field span { font-size: 13px; color: var(--muted); }
.field input, .field textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  font-family: inherit;
  resize: vertical;
}
.field input:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-error { color: var(--accent); font-size: 13px; min-height: 16px; }
.form-actions { display: flex; align-items: center; gap: 12px; }
.sweat-btn.inline {
  position: static;
  transform: none;
  width: auto;
  flex: 1;
  padding: 14px;
  font-size: 17px;
  letter-spacing: 1px;
}
.sweat-btn.inline:active { transform: scale(0.98); }

.admin-list { display: flex; flex-direction: column; gap: 10px; }
.admin-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255,255,255,0.05);
}
.admin-emoji { font-size: 26px; }
.admin-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.admin-text strong { font-size: 15px; }
.admin-text small { color: var(--muted); font-size: 12px; }
.admin-actions { display: flex; gap: 6px; }
.icon-btn {
  border: none;
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 16px;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.92); }
