:root {
  --bg: #0f1115;
  --bg-elev: #1a1d24;
  --bg-elev-2: #242832;
  --text: #f5f7fa;
  --text-dim: #9aa3b2;
  --accent: #ff6b35;
  --accent-dim: #b8431e;
  --danger: #e0432c;
  --ok: #2ec27e;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}
input { user-select: text; -webkit-user-select: text; }

#app { height: 100%; position: relative; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; padding-top: var(--safe-top); padding-bottom: var(--safe-bottom); }
.screen.active { display: flex; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; gap: 8px;
  border-bottom: 1px solid #232732;
  min-height: 56px;
}
.topbar h1 { font-size: 18px; font-weight: 600; margin: 0; flex: 1; text-align: center; }
.icon-btn {
  background: var(--accent); color: white; border: none; border-radius: 50%;
  width: 40px; height: 40px; font-size: 24px; font-weight: 300; line-height: 1;
  cursor: pointer;
}
.icon-btn:active { background: var(--accent-dim); }
.text-btn {
  background: none; border: none; color: var(--text-dim);
  font-size: 16px; padding: 8px 4px; min-width: 64px; cursor: pointer;
}
.text-btn.primary { color: var(--accent); font-weight: 600; }
.text-btn:active { opacity: 0.6; }

/* Workout List */
.workout-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.workout-list li {
  background: var(--bg-elev);
  border-radius: var(--radius);
  margin-bottom: 10px;
  padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
}
.workout-list .play {
  background: var(--accent); color: white; border: none; border-radius: 50%;
  width: 44px; height: 44px; font-size: 18px; flex-shrink: 0; cursor: pointer;
}
.workout-list .info { flex: 1; min-width: 0; }
.workout-list .info .name { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.workout-list .info .meta { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.workout-list .actions { display: flex; gap: 4px; }
.workout-list .actions button {
  background: var(--bg-elev-2); color: var(--text-dim); border: none; border-radius: 8px;
  width: 36px; height: 36px; font-size: 16px; cursor: pointer;
}
.workout-list .actions .del:active { background: var(--danger); color: white; }
.empty-msg { color: var(--text-dim); text-align: center; padding: 32px 24px; display: none; }
.empty-msg.show { display: block; }

/* Editor */
.editor-body { flex: 1; overflow-y: auto; padding: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 20px; }
.field span { color: var(--text-dim); font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; }
.field input, .interval-row input {
  background: var(--bg-elev); border: 1px solid #2a2f3a; color: var(--text);
  padding: 12px 14px; border-radius: 10px; font-size: 16px; font-family: inherit;
}
.field input:focus, .interval-row input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.section-title { font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; margin: 16px 0 8px; }
.interval-list { list-style: none; padding: 0; margin: 0; }
.interval-row {
  background: var(--bg-elev); border-radius: var(--radius); padding: 10px;
  margin-bottom: 8px; display: grid;
  grid-template-columns: auto 1fr 90px auto; gap: 8px; align-items: center;
}
.interval-row .handle {
  display: flex; flex-direction: column; gap: 2px;
}
.interval-row .handle button {
  background: var(--bg-elev-2); border: none; color: var(--text-dim);
  width: 28px; height: 22px; border-radius: 6px; font-size: 12px; cursor: pointer;
}
.interval-row .handle button:disabled { opacity: 0.3; }
.interval-row input[type="text"] { width: 100%; }
.interval-row input[type="number"] { width: 100%; text-align: center; }
.interval-row .del {
  background: none; border: none; color: var(--text-dim); width: 36px; height: 36px;
  font-size: 18px; cursor: pointer;
}
.interval-row .del:active { color: var(--danger); }
.add-btn {
  background: var(--bg-elev); color: var(--accent); border: 1px dashed var(--accent-dim);
  width: 100%; padding: 14px; border-radius: var(--radius); font-size: 16px;
  font-weight: 600; cursor: pointer; margin-top: 8px;
}
.add-btn:active { background: var(--bg-elev-2); }

/* Timer */
.timer-body {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: space-around; padding: 24px 16px; gap: 8px;
}
.cycle-label { color: var(--text-dim); font-size: 14px; text-transform: uppercase; letter-spacing: 0.1em; }
.interval-name {
  font-size: 32px; font-weight: 700; text-align: center;
  max-width: 100%; word-wrap: break-word; padding: 0 8px;
}
.progress-ring-wrap { position: relative; width: 280px; max-width: 80vw; aspect-ratio: 1; }
.progress-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.progress-ring-bg { fill: none; stroke: var(--bg-elev); stroke-width: 6; }
.progress-ring-fg {
  fill: none; stroke: var(--accent); stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 339.292;
  stroke-dashoffset: 339.292;
  transition: stroke-dashoffset 0.1s linear, stroke 0.2s;
}
.progress-ring-fg.warning { stroke: #ffb547; }
.progress-ring-fg.last { stroke: var(--danger); }
.progress-ring-wrap .countdown {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 88px; font-weight: 200; font-variant-numeric: tabular-nums;
}
.interval-count { color: var(--text-dim); font-size: 14px; }
.sound-test {
  background: var(--bg-elev); color: var(--text-dim); border: 1px solid #2a2f3a;
  border-radius: 999px; padding: 8px 14px; font-size: 12px; cursor: pointer;
  font-family: inherit;
}
.sound-test:active { background: var(--bg-elev-2); color: var(--text); }
.controls { display: flex; gap: 20px; align-items: center; margin-top: 8px; }
.ctrl-btn {
  background: var(--bg-elev); color: var(--text); border: none; border-radius: 50%;
  width: 64px; height: 64px; font-size: 24px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.ctrl-btn.big { width: 88px; height: 88px; font-size: 36px; }
.ctrl-btn.primary { background: var(--accent); color: white; }
.ctrl-btn:active { transform: scale(0.94); }
