:root {
  --green: #1b7f3b;
  --green-dark: #14602c;
  --bg: #f5f7f5;
  --card: #ffffff;
  --text: #1c1f1c;
  --muted: #667066;
  --line: #dde3dd;
  --accent: #ffd54d;
  --danger: #c62828;
  --nav-h: 58px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.25rem; margin: 0 0 12px; }
h3 { font-size: 1.05rem; margin: 0; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }

label { font-size: 0.9rem; font-weight: 600; }
.hint { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.msg { color: var(--danger); font-size: 0.9rem; min-height: 1.2em; margin: 8px 0 0; }
.sub { color: var(--muted); margin: 0 0 20px; }

input {
  font-size: 1.05rem;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 100%;
  background: var(--card);
}
input:focus { outline: 2px solid var(--green); border-color: var(--green); }

.btn {
  font-size: 1rem;
  font-weight: 600;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  width: 100%;
  cursor: pointer;
  touch-action: manipulation;
}
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:active { background: var(--green-dark); }
.btn.big { font-size: 1.15rem; padding: 16px; }
.btn:disabled { opacity: 0.45; }

.iconbtn {
  border: none;
  background: none;
  font-size: 1.4rem;
  color: var(--green);
  cursor: pointer;
  padding: 4px 10px;
}

.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

/* ---------- setup ---------- */
#view-setup {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.setup-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  text-align: center;
}
.setup-card .stack { text-align: left; }
.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 22px 0 4px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- roster ---------- */
.page { padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); max-width: 480px; margin: 0 auto; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  font-size: 1.05rem;
  text-align: left;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.list-item:active { background: #eaf3ea; }
.add-row { margin-top: 20px; }
.confirm {
  margin-top: 16px;
  background: #fff8e1;
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.confirm p { margin: 0 0 4px; font-weight: 600; }

/* ---------- app shell ---------- */
#view-app main {
  padding: 18px 16px calc(var(--nav-h) + 20px + env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
}
.screen-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.screen-head h2 { margin: 0; }

#bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
}
#bottomnav button {
  flex: 1;
  border: none;
  background: none;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  position: relative;
}
#bottomnav button.active { color: var(--green); }
#bottomnav button.dot::after {
  content: "";
  position: absolute;
  top: 10px;
  right: 24%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

/* ---------- today ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
}
.card p { margin: 8px 0 0; color: var(--text); font-size: 0.95rem; }
.card a { display: inline-block; margin-top: 10px; color: var(--green); font-weight: 600; text-decoration: none; }
.dur { color: var(--muted); font-size: 0.85rem; font-weight: 400; white-space: nowrap; }

/* ---------- live shared drill ---------- */
.live-drill {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
}
.ld-row { display: flex; gap: 8px; }
.ld-row input { flex: 1; }
.ld-row .btn { width: auto; white-space: nowrap; }
.btn.small { width: auto; padding: 8px 14px; font-size: 0.9rem; }
.ld-active-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.ld-join { text-align: left; }
.ld-head { display: flex; justify-content: space-between; align-items: center; }
.ld-title { font-size: 1.05rem; }
#ld-live-dot { color: #e53935; animation: ldpulse 1.4s ease-in-out infinite; }
@keyframes ldpulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
.lap.readonly { cursor: default; }
.ld-mode { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; font-size: 0.9rem; }
.ld-mode label { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.ld-mode .hint { font-weight: 400; }
.ld-laps { flex-direction: row; align-items: center; gap: 8px; }
.ld-laps input { width: 60px; padding: 6px 8px; font-size: 1rem; border: 1px solid var(--line); border-radius: 8px; }
.heat-select { flex: 1; font-size: 1rem; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }

/* ---------- per-athlete lanes ---------- */
.lane-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.lane {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  cursor: pointer;
  text-align: left;
  min-height: 64px;
}
.lane-name { font-weight: 600; font-size: 0.95rem; }
.lane-time { font-variant-numeric: tabular-nums; font-size: 1.15rem; color: var(--muted); }
.lane-waiting { border-style: dashed; }
.lane-running { background: #eaf3ea; border-color: var(--green); }
.lane-running .lane-time { color: var(--green); font-weight: 700; }
.lane-done { background: #f4f7f4; }
.lane-done .lane-time { color: var(--text); font-weight: 700; }

/* ---------- timer ---------- */
#time-display {
  font-size: 3.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  margin: 18px 0 10px;
}
.timer-btns { display: flex; gap: 8px; margin-bottom: 14px; }
.timer-btns .btn { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 0.9rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
}
.chip.armed { background: var(--green); border-color: var(--green); color: #fff; }
.lap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  width: 100%;
}
.lap.selected { border-color: var(--green); outline: 2px solid var(--green); }
.lap.assigned .lap-who { color: var(--green); font-weight: 700; }
.lap-who { color: var(--muted); font-size: 0.9rem; }
#btn-save-times { margin-top: 14px; }

/* ---------- drill rotation ---------- */
.rotation {
  background: var(--card);
  border: 1px solid var(--green);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.rot-now { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.rot-next { margin: 2px 0 10px; }
.rot-btns { display: flex; gap: 8px; }
.rot-btns .btn.primary { flex: 1; }

/* ---------- heat banner ---------- */
.heat-banner {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-weight: 600;
  font-size: 0.95rem;
}
.heat-banner.heat-danger { background: var(--danger); color: #fff; }
.heat-banner.heat-warn { background: #fff3cd; color: #7a5b00; border: 1px solid #ffe08a; }

/* ---------- practice & heat timer ---------- */
.practice-timer {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-top: 14px;
}
.practice-timer h3 { margin: 0 0 10px; }
.pt-wbgt { display: flex; align-items: flex-end; gap: 8px; }
.pt-wbgt label { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.pt-wbgt input { width: 100%; }
.pt-wbgt .btn { width: auto; white-space: nowrap; }
.pt-tier { margin: 10px 0; font-weight: 600; color: var(--text); }
.pt-tier.pt-warn { color: #b26a00; }
.pt-tier.pt-danger { color: #fff; background: var(--danger); padding: 10px; border-radius: 10px; text-align: center; }
.pt-display { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; margin: 6px 0; }
.pt-status { text-align: center; font-size: 1rem; color: var(--muted); min-height: 1.3em; margin: 0 0 10px; }
.pt-status.pt-break { color: #fff; background: var(--green); padding: 8px; border-radius: 8px; font-weight: 700; }
.pt-status.pt-cap { color: var(--danger); font-weight: 700; }
.pt-btns { display: flex; gap: 8px; }
.pt-btns .btn.primary { flex: 1; }

/* ---------- log ---------- */
input[type="range"] { padding: 0; height: 34px; accent-color: var(--green); }
.rpe-scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.75rem; margin-top: -6px; }
.badge {
  margin-top: 16px;
  background: #fff8e1;
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
}
a { color: var(--green); }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #263238;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.95rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  max-width: 90vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
