:root {
  --bg: #0e1013;
  --panel: #171a1f;
  --panel-2: #1e2229;
  --line: #2a2f38;
  --text: #e8eaed;
  --muted: #8b929e;
  --accent: #e2554f;
  --accent-2: #5b8def;
  --ok: #3fbf7f;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 1.2rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
button:hover { background: #262b33; }
button:active { transform: scale(0.98); }
button.ghost { background: transparent; }
button.ghost:hover { background: var(--panel-2); }
button.danger { background: #3a1d1c; border-color: #6b2a27; color: #ff9d97; }
button.danger:hover { background: #4a2321; }
button.small { padding: 0.4rem 0.8rem; font-size: 0.85rem; }
button:disabled { opacity: 0.4; cursor: default; }

/* ---------- header ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: 0.02em; font-size: 1.15rem; }
.brand span { color: var(--accent); }
.conn { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.9rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #666; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.off { background: var(--accent); }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ---------- panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; }
h2 { font-size: 1rem; margin: 0 0 0.8rem; font-weight: 600; }

/* ---------- ftp ---------- */
.ftp-panel { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: center; justify-content: space-between; }
.ftp-set { display: flex; align-items: center; gap: 0.75rem; }
.ftp-set > label { color: var(--muted); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.08em; }
.ftp-input { display: flex; align-items: baseline; gap: 0.35rem; }
.ftp-input input {
  width: 110px;
  font-size: 1.8rem;
  font-weight: 700;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--line);
  color: var(--text);
  padding: 0.1rem 0;
  outline: none;
}
.ftp-input input:focus { border-color: var(--accent); }
.ftp-input span { color: var(--muted); }
.zone-table { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.zone-chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  font-size: 0.78rem;
  color: var(--muted);
  min-width: 84px;
}
.zone-chip b { display: block; color: var(--text); font-size: 0.9rem; }

/* ---------- filters ---------- */
.filters { display: flex; flex-direction: column; gap: 0.6rem; }
.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }

/* ---------- workout cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.9rem; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  transition: border-color 0.15s, transform 0.1s;
}
.card:hover { border-color: #3d434e; transform: translateY(-2px); }
.card.selected { border-color: var(--accent); }
.card-top { display: flex; justify-content: space-between; align-items: center; }
.card h3 { margin: 0; font-size: 1.02rem; }
.card .desc { color: var(--muted); font-size: 0.85rem; line-height: 1.35; min-height: 2.2em; }
.card .meta { display: flex; gap: 0.8rem; color: var(--muted); font-size: 0.8rem; }
.zone-tag { font-size: 0.72rem; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 6px; }
.card-graph { height: 46px; width: 100%; }
.card-graph svg { width: 100%; height: 100%; display: block; }

/* ---------- history ---------- */
.history { display: flex; flex-direction: column; gap: 0.4rem; }
.history-row {
  display: grid;
  grid-template-columns: 1.6fr 1fr repeat(4, 0.7fr);
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  font-size: 0.88rem;
  align-items: center;
}
.history-row:nth-child(odd) { background: var(--panel-2); }
.history-row .muted { color: var(--muted); font-size: 0.8rem; }
.history-row.head { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.empty { color: var(--muted); font-size: 0.9rem; }

/* ---------- player ---------- */
#player { gap: 1rem; }
.player-top { display: flex; justify-content: space-between; align-items: baseline; }
.interval-name { font-size: 1.6rem; font-weight: 700; }
.interval-time { font-size: 1.6rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.graph { width: 100%; height: 170px; }
.graph svg { width: 100%; height: 100%; display: block; }

.power-row { display: flex; justify-content: center; gap: 4rem; align-items: baseline; }
.big { text-align: center; }
.big-value { font-size: clamp(4rem, 18vw, 11rem); font-weight: 800; line-height: 0.9; font-variant-numeric: tabular-nums; }
.big-label { color: var(--muted); text-transform: uppercase; letter-spacing: 0.15em; font-size: 0.8rem; margin-top: 0.4rem; }
.target .big-value { color: var(--muted); font-size: clamp(2.5rem, 9vw, 5rem); }
.target .big-label { margin-top: 0.2rem; }

.metrics { display: flex; justify-content: center; gap: 2.2rem; flex-wrap: wrap; }
.metric { text-align: center; min-width: 72px; }
.metric .value { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric .label { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }

.progress { height: 5px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.4s linear; }
.total-time { text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }

.controls { display: flex; justify-content: center; gap: 0.75rem; flex-wrap: wrap; }

/* ---------- overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 50;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: min(520px, 100%);
}
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin: 1rem 0; }
.summary-grid .metric .value { font-size: 1.8rem; }
.ftp-suggestion { background: var(--panel-2); border-radius: 10px; padding: 0.9rem 1rem; margin-bottom: 1rem; font-size: 0.92rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; }

@media (max-width: 640px) {
  .power-row { gap: 1.5rem; }
  .history-row { grid-template-columns: 1.4fr repeat(3, 1fr); }
  .history-row .hide-sm { display: none; }
}
