:root {
  --bg: #14161c;
  --card: #1e212b;
  --card-2: #262a37;
  --text: #f0f1f5;
  --muted: #9aa0ae;
  --accent: #2dd4bf;
  --accent-dark: #14b8a6;
  --danger: #f87171;
  --rest: #facc15;
  --border: #333747;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  max-width: 640px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(48px, env(safe-area-inset-bottom));
}

.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; }

h1 { font-size: 22px; }
h2 { font-size: 14px; margin: 0 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Buttons and inputs */
button {
  background: var(--accent);
  color: #06201c;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
button:hover { background: var(--accent-dark); }
button.secondary { background: var(--card-2); color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { background: var(--border); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button.danger:hover { background: rgba(248, 113, 113, 0.1); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
.link-btn {
  background: none;
  border: none;
  padding: 4px;
  color: var(--muted);
  text-decoration: underline;
  font-size: 14px;
  font-weight: 400;
}
.link-btn:hover { background: none; color: var(--text); }

input, textarea, select {
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
}
textarea { width: 100%; resize: vertical; margin-top: 10px; }
input.small-num { width: 64px; padding: 6px 8px; font-size: 15px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row input[type="text"] { flex: 1; min-width: 140px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 16px;
}

/* Login */
#login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--card);
  padding: 32px;
  border-radius: 16px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  border: 1px solid var(--border);
}
.login-card input { width: 100%; margin: 16px 0; font-size: 18px; text-align: center; }
.login-card button { width: 100%; }

/* Header */
.topbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.routine-select { flex: 1; min-width: 0; font-weight: 600; padding: 12px; }
.mode-btn { padding: 12px 16px; }

/* ---------- Workout mode ---------- */
.player {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px 18px 16px;
  text-align: center;
  margin-bottom: 16px;
}
.player-section {
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  min-height: 18px;
}
.player-name {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  margin: 8px 0 6px;
  overflow-wrap: anywhere;
}
.player-name.is-rest { color: var(--rest); }
.player-target { color: var(--muted); font-size: 15px; min-height: 20px; line-height: 1.4; }
.player-clock {
  font-size: 84px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin: 18px 0 14px;
}
.player-clock.is-countdown { color: var(--accent); }
.progress { height: 6px; background: var(--card-2); border-radius: 3px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.3s linear; }
.player-next { color: var(--muted); font-size: 15px; margin-top: 12px; min-height: 20px; }
.player-video {
  display: inline-block;
  margin-top: 10px;
  color: var(--accent);
  font-size: 15px;
  text-decoration: none;
  padding: 6px 12px;
  border: 1px solid var(--accent);
  border-radius: 999px;
}
.player-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  margin: 20px 0 12px;
}
.round-btn { width: 60px; height: 60px; border-radius: 50%; padding: 0; font-size: 20px; }
.start-btn { width: 120px; height: 72px; border-radius: 36px; font-size: 22px; }
.start-btn.is-running { background: var(--card-2); color: var(--text); border: 2px solid var(--accent); }
.player-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}
.player-footer strong { color: var(--text); font-variant-numeric: tabular-nums; }

.routine-notes {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
  white-space: pre-wrap;
}

.overview { display: flex; flex-direction: column; gap: 12px; }
.ov-block { border: 1px solid var(--border); border-radius: 12px; padding: 8px; }
.ov-block.circuit { border-left: 4px solid var(--rest); }
.ov-title { font-size: 13px; color: var(--muted); font-weight: 600; padding: 4px 6px 8px; }
.ov-block.circuit .ov-title { color: var(--rest); }
.ov-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 8px;
  font-size: 15px;
  font-weight: 500;
  text-align: left;
}
.ov-item:hover { background: var(--card-2); }
.ov-item.rest { color: var(--rest); font-size: 13px; padding: 4px 8px; opacity: 0.8; }
.ov-item.active { background: rgba(45, 212, 191, 0.12); border-color: var(--accent); }
.ov-item.ov-transition { border: 1px dashed rgba(250, 204, 21, 0.5); padding: 8px; font-size: 14px; opacity: 1; }
.ov-dur { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; flex-shrink: 0; }

/* ---------- Edit mode ---------- */
.editor { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.block {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.block.circuit { border-left: 4px solid var(--rest); }
.block-header, .block-footer { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.block-name { flex: 1; min-width: 140px; font-weight: 600; padding: 8px 10px; font-size: 15px; }
.block-rounds { color: var(--rest); font-size: 14px; font-weight: 600; }
.block-footer button { padding: 8px 12px; font-size: 14px; }
.add-block-btn { width: 100%; }
.inserter { display: flex; justify-content: center; gap: 16px; margin: -6px 0; }
.inserter .link-btn { font-size: 13px; color: var(--muted); text-decoration: none; padding: 2px 6px; }
.inserter .link-btn:hover { color: var(--accent); }
.transition {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  border: 1px dashed var(--rest);
  border-radius: 12px;
  padding: 8px 10px;
  background: rgba(250, 204, 21, 0.06);
}
.transition-label { color: var(--rest); font-weight: 600; flex: 1; }

.item {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.item-main { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.item-name { font-weight: 600; flex: 1; min-width: 120px; }
.item-duration { color: var(--muted); font-size: 13px; }
.item-target { font-size: 13px; }
.item-sets { font-size: 12px; color: var(--rest); }
.item-notes { font-size: 13px; color: var(--muted); font-style: italic; }
.item-video { color: var(--accent); font-size: 13px; }
.item-controls { display: flex; gap: 6px; flex-shrink: 0; }
.item-controls button { padding: 6px 10px; font-size: 13px; }
.rest-item { background: rgba(250, 204, 21, 0.08); border-color: rgba(250, 204, 21, 0.35); }
.rest-item .item-name { color: var(--rest); }
.rest-badge { background: var(--rest); color: #1a1400; border-radius: 6px; padding: 2px 6px; font-size: 13px; }

.edit-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.edit-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.edit-field input { width: 100%; }

/* Import preview */
#import-preview { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.preview-item {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--rest);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.preview-name { font-weight: 600; font-size: 14px; }
.preview-meta { font-size: 12px; color: var(--muted); }
.preview-fields { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.preview-field { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 2px; }
