/* css/style.css
   Stage 1: static session screen. Black field, white numbers, coloured border band.
   No fonts are loaded from the network. System fonts only. */

/* --------------------------------------------------------------------------
   Tokens
   -------------------------------------------------------------------------- */
:root {
  --bg:          #000000;
  --fg:          #FFFFFF;

  /* Border band colours (spec 3.5) */
  --blue:        #2979FF;   /* warm-up, rest, cooldown */
  --green:       #00C853;   /* work, in zone */
  --red:         #D50000;   /* work, out of zone */
  --grey:        #616161;   /* work, no HR data */
  --amber:       #FFAB00;   /* paused */

  --band-width:  24px;
  --band-color:  var(--blue);

  /* Dead space reserved at the bottom of the screen so nothing lands under the
     Android gesture bar. 10% of screen height, or the OS-reported safe area if
     that happens to be larger. Nothing interactive is ever drawn in here. */
  --gesture-safe: 10vh;

  /* Vertical stretch applied to the big HR digits.
     1 = undistorted. Raise toward ~1.6 to trade shape for height. See README. */
  --hr-stretch:  1;
}

/* --------------------------------------------------------------------------
   Reset / page
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* .screen sets display:flex, which would otherwise beat the browser's default
   rule for the hidden attribute. Keep this above the layout rules. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;              /* single screen, never scrolls */
  overscroll-behavior: none;
}

body {
  font-family: Roboto, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  font-variant-numeric: tabular-nums lining-nums;   /* digits keep a fixed width */
  font-feature-settings: "tnum" 1, "lnum" 1;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;    /* kills the double-tap-to-zoom delay */
  -webkit-user-select: none;
  user-select: none;
}

/* --------------------------------------------------------------------------
   Border band
   A fixed overlay so the band never pushes the layout around when it changes.
   -------------------------------------------------------------------------- */
.band {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;          /* clicks pass straight through to the buttons */
  border: var(--band-width) solid var(--band-color);
  transition: border-color 150ms linear;
}

.band[data-band="blue"]  { --band-color: var(--blue);  }
.band[data-band="green"] { --band-color: var(--green); }
.band[data-band="red"]   { --band-color: var(--red);   }
.band[data-band="grey"]  { --band-color: var(--grey);  }
.band[data-band="amber"] {
  --band-color: var(--amber);
  animation: band-pulse 1.6s ease-in-out infinite;
}

@keyframes band-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.2; }
}

@media (prefers-reduced-motion: reduce) {
  .band { transition: none; }
  .band[data-band="amber"] { animation: none; }
}

/* --------------------------------------------------------------------------
   Session screen
   -------------------------------------------------------------------------- */
.screen {
  position: fixed;
  inset: 0;
  padding-top:    calc(var(--band-width) + 10px);
  padding-left:   calc(var(--band-width) + 8px);
  padding-right:  calc(var(--band-width) + 8px);
  padding-bottom: calc(var(--band-width) + max(var(--gesture-safe), env(safe-area-inset-bottom, 0px)));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  text-align: center;
}

/* 1. Heart rate — the dominant element. Takes all leftover height. */
.hr {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
}

.hr__value {
  /* Width-bound, not height-bound: three digits have to fit across a portrait
     screen. min() takes whichever limit bites first. */
  font-size: min(58vh, 52vw);
  line-height: 0.80;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--fg);
  transform: scaleY(var(--hr-stretch));
  transform-origin: center;
}

.hr__unit {
  font-size: 3.2vh;
  font-weight: 500;
  letter-spacing: 0.30em;
  color: #9E9E9E;
  margin-top: 1.2vh;
}

/* 2. Interval countdown — second largest. */
.countdown {
  font-size: min(17vh, 26vw);
  line-height: 0.90;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* 3. Block label */
.block-label {
  font-size: 5vh;
  font-weight: 700;
  letter-spacing: 0.14em;
  margin-top: 0.6vh;
}

/* 4. Round indicator */
.round {
  font-size: 3.6vh;
  font-weight: 500;
  letter-spacing: 0.10em;
  color: #BDBDBD;
  margin-top: 0.4vh;
}

.round[hidden] { display: none; }

/* 5. Total elapsed — smallest readout */
.elapsed {
  font-size: 2.6vh;
  font-weight: 400;
  letter-spacing: 0.10em;
  color: #757575;
  margin-top: 1vh;
}

/* 6. Controls — deliberately small and low. */
.controls {
  display: flex;
  gap: 14px;
  margin-top: 1.6vh;
  width: 100%;
  justify-content: center;
}

.btn {
  font: inherit;
  font-size: 1.9vh;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: #BDBDBD;
  background: transparent;
  border: 1px solid #424242;
  border-radius: 6px;
  padding: 1.1vh 5vw;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { background: #1A1A1A; }

.btn--danger { color: #9E6060; border-color: #4A2A2A; }
.btn--quiet  { color: #757575; border-color: transparent; }
.btn--wide   { width: 100%; padding: 2.2vh 0; font-size: 2.4vh; }

/* --------------------------------------------------------------------------
   Home screen
   -------------------------------------------------------------------------- */
.screen--home {
  justify-content: center;
  gap: 1.2vh;
  overflow-y: auto;              /* safety net on very short screens only */
}

.home__title {
  font-size: 2.8vh;
  font-weight: 700;
  letter-spacing: 0.30em;
  color: #9E9E9E;
}

.home__phases {
  display: flex;
  flex-direction: column;
  gap: 1.8vh;
  width: 100%;
}

.phase {
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6vh;
  width: 100%;
  padding: 2.1vh 0;
  color: var(--fg);
  background: transparent;
  border: 2px solid #2E2E2E;
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.phase:active { background: #141414; border-color: var(--blue); }

.phase__name {
  font-size: 4vh;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.phase__detail {
  font-size: 2vh;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: #757575;
}

/* Bluetooth block on the home screen */
.home__ble {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1vh;
  width: 100%;
}

.ble__status {
  font-size: 1.9vh;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: #9E9E9E;
  text-align: center;
  /* A long strap name ("COROS HEART RATE 747EF8") would wrap to a second line
     and push the home screen past one screenful. Keep it to one line. */
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ble__note {
  font-size: 1.6vh;
  color: #616161;
  text-align: center;
}

/* Wake-lock warning — normally absent, so it costs no height */
.home__warn {
  font-size: 1.7vh;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: 0.04em;
  color: #FFAB00;
  text-align: center;
}

.home__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.home__zone {
  font-size: 2vh;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: #616161;
}

.home__footbtns { display: flex; align-items: center; gap: 1vw; }

/* --------------------------------------------------------------------------
   History (spec 3.8)
   This screen is a list, so it is allowed to scroll. The session screen is not.
   -------------------------------------------------------------------------- */
.screen--history {
  justify-content: flex-start;
  gap: 1.4vh;
}

.hist__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.hist__title {
  font-size: 2.2vh;
  font-weight: 700;
  letter-spacing: 0.24em;
  color: #9E9E9E;
}

.hist__list {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  overflow-y: auto;
  text-align: left;
}

.hist__empty {
  padding: 6vh 0;
  font-size: 2vh;
  color: #616161;
  text-align: center;
}

.sess {
  border: 1px solid #2E2E2E;
  border-radius: 8px;
  margin-bottom: 1.2vh;
  background: #0A0A0A;
}

.sess__head {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.4vh;
  padding: 1.6vh 9vw 1.6vh 3vw;   /* right padding leaves room for the chevron */
  cursor: pointer;
  list-style: none;
}

.sess__head::-webkit-details-marker { display: none; }

/* The default marker is hidden, so give the row its own "tap to open" hint. */
.sess__head::after {
  content: '⌄';
  position: absolute;
  right: 4vw;
  top: 1.4vh;
  font-size: 2.4vh;
  line-height: 1;
  color: #616161;
  transition: transform 150ms ease;
}

.sess[open] .sess__head::after { transform: rotate(180deg); }

.sess__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2vw;
}

.sess__date  { font-size: 1.9vh; font-weight: 600; color: var(--fg); }
.sess__phase { font-size: 1.6vh; font-weight: 700; letter-spacing: 0.12em; color: #2979FF; }
.sess__meta  { font-size: 1.6vh; color: #757575; }

.sess__partial {
  font-size: 1.4vh;
  font-weight: 700;
  letter-spacing: 0.10em;
  color: #FFAB00;
}

.sess__tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 1.6vh;
  font-variant-numeric: tabular-nums;
}

.sess__tbl th {
  padding: 0.8vh 3vw;
  text-align: right;
  font-weight: 600;
  color: #616161;
  border-top: 1px solid #2E2E2E;
}

.sess__tbl th:first-child, .sess__tbl td:first-child { text-align: left; }

.sess__tbl td {
  padding: 0.7vh 3vw;
  color: #BDBDBD;
  text-align: right;
}

.sess__tbl tr td.good { color: var(--green); font-weight: 600; }

.hist__actions {
  display: flex;
  gap: 3vw;
  width: 100%;
}

.hist__actions .btn { flex: 1 1 0; }

.dialog__note {
  font-size: 1.8vh;
  color: #757575;
  margin-top: -1vh;
}

/* --------------------------------------------------------------------------
   Unsupported-browser message (spec 6)
   -------------------------------------------------------------------------- */
.screen--msg { justify-content: center; gap: 3vh; }

.msg__title {
  font-size: 4.4vh;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.10em;
  color: var(--red);
}

.msg__body {
  font-size: 2.2vh;
  line-height: 1.5;
  color: #BDBDBD;
  max-width: 34ch;
}

.msg__body--dim { color: #757575; }

/* --------------------------------------------------------------------------
   Disconnected banner (session screen)
   -------------------------------------------------------------------------- */
.banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3vw;
  width: 100%;
  padding: 0.9vh 2vw;
  background: #2A0000;
  border: 1px solid #5A1F1F;
  border-radius: 6px;
}

.banner__text {
  font-size: 1.9vh;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #FF6E6E;
}

.banner__btn {
  font: inherit;
  font-size: 1.7vh;
  font-weight: 600;
  letter-spacing: 0.10em;
  color: #FFCDD2;
  background: transparent;
  border: 1px solid #7A2A2A;
  border-radius: 4px;
  padding: 0.6vh 3vw;
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   Complete screen
   -------------------------------------------------------------------------- */
.screen--done { justify-content: center; gap: 4vh; }

.done__title {
  font-size: 6.5vh;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.12em;
}

.done__detail {
  font-size: 2.6vh;
  letter-spacing: 0.14em;
  color: #757575;
}

/* --------------------------------------------------------------------------
   Test-HR strip — STAGE 3 ONLY, removed when ble.js lands in Stage 5
   -------------------------------------------------------------------------- */
.testhr {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: 1.4vh;
  opacity: 0.55;
}

.testhr__label {
  font-size: 1.5vh;
  letter-spacing: 0.14em;
  color: #616161;
  white-space: nowrap;
}

.testhr__range { flex: 1 1 auto; min-width: 0; accent-color: #616161; }

.testhr__drop {
  font: inherit;
  font-size: 1.5vh;
  letter-spacing: 0.12em;
  color: #9E9E9E;
  background: transparent;
  border: 1px solid #424242;
  border-radius: 4px;
  padding: 0.6vh 2.4vw;
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   Abort dialog
   -------------------------------------------------------------------------- */
.dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8vw;
  background: rgba(0, 0, 0, 0.88);
}

.dialog__box {
  display: flex;
  flex-direction: column;
  gap: 2.4vh;
  width: 100%;
  padding: 4vh 5vw;
  background: #0A0A0A;
  border: 1px solid #333;
  border-radius: 12px;
  text-align: center;
}

.dialog__q {
  font-size: 3vh;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.dialog__row { display: flex; gap: 12px; }
.dialog__row .btn { flex: 1 1 0; font-size: 2.2vh; padding: 1.8vh 0; }
