/* Match the page colour so no white shows when iOS bounces past the edges. */
body.health-tracker-page {
  background-color: #1b1b1f;
}

/* Pin the page to the screen: no scrolling, no bounce, and no site menu button on top. */
html:has(body.health-tracker-page),
body.health-tracker-page {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body.health-tracker-page .mobile-nav-toggle {
  display: none;
}

/*
 * Both screens are their own full-screen layers, so the tracker can fill the device. Fixed layers
 * on iOS are sized with dvh, so the browser toolbars do not cut off the bottom buttons.
 */
.health-tracker-menu,
.health-tracker-play {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  color: #f4f1ea;
  background-color: #1b1b1f;
}

/* The setup screen is centred and sized to fit, so it never scrolls. */
.health-tracker-menu {
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  padding: 1rem 0;
  text-align: center;
}

.health-tracker-menu .container {
  flex: 0 1 auto;
}

.health-tracker-play {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* Leave room for the site sidebar on desktop. */
@media (min-width: 1200px) {
  .health-tracker-menu,
  .health-tracker-play {
    left: 300px;
  }
}

.health-tracker-menu[hidden],
.health-tracker-play[hidden],
.health-tracker-button[hidden],
.health-tracker-panel[hidden] {
  display: none;
}

.health-tracker-nav {
  display: flex;
  justify-content: flex-start;
  max-width: 640px;
  margin: 0 auto 1.5rem auto;
}

.health-tracker-nav-button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 1rem;
  font-weight: 600;
  color: #f4f1ea;
  text-decoration: none;
  background: rgba(0, 0, 0, 0.6);
  border: 2px solid #f4f1ea;
  border-radius: 8px;
  box-shadow: 2px 2px 0 #000;
  transition: background 0.2s ease;
}

.health-tracker-nav-button:hover,
.health-tracker-nav-button:focus {
  color: #fff;
  background: #3a3a42;
}

.health-tracker-title {
  color: #f4f1ea;
  font-size: 2.2rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-shadow: 2px 2px 0 #000;
  margin-bottom: 0.5rem;
}

.health-tracker-subtitle {
  max-width: 640px;
  margin: 0 auto 1.5rem auto;
  color: #f4f1ea;
  text-shadow: 1px 1px 0 #000;
}

.health-tracker-group {
  max-width: 640px;
  margin: 0 auto 1.5rem auto;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 12px;
}

.health-tracker-group h5 {
  color: #ffd166;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.75rem;
}

.health-tracker-buttons,
.health-tracker-choice {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.health-tracker-button {
  flex: 1 1 160px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.9rem 1rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: #f4f1ea;
  background: #3a3a42;
  border: 2px solid #f4f1ea;
  border-radius: 8px;
  box-shadow: 2px 2px 0 #000;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.2s ease, transform 0.1s ease;
}

.health-tracker-button:hover,
.health-tracker-button:focus {
  color: #fff;
  background: #52525c;
}

.health-tracker-button:active {
  transform: translateY(2px);
}

.health-tracker-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.health-tracker-button.is-selected {
  background: #b3261e;
  border-color: #ffd166;
}

.health-tracker-button-primary {
  background: #b3261e;
  border-color: #ffd166;
}

.health-tracker-button-primary:hover,
.health-tracker-button-primary:focus {
  background: #d1362d;
}

/* Setup */

.health-tracker-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.health-tracker-stepper .health-tracker-button {
  flex: 0 0 auto;
  min-width: 56px;
}

.health-tracker-start {
  width: 8rem;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 700;
}

.health-tracker-presets {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.health-tracker-preset {
  min-width: 3.5rem;
  padding: 0.4rem 0.8rem;
  font-weight: 600;
  color: #f4f1ea;
  background: transparent;
  border: 2px solid #8a8a96;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.health-tracker-preset:hover,
.health-tracker-preset:focus {
  border-color: #ffd166;
}

.health-tracker-names {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.5rem;
}

.health-tracker-input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 1.1rem;
  color: #f4f1ea;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid #8a8a96;
  border-radius: 8px;
}

.health-tracker-input:focus {
  outline: none;
  border-color: #ffd166;
}

.health-tracker-input::placeholder {
  color: #9a9aa6;
}

/* Play */

.health-tracker-play {
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* A single player gets the whole screen, with the bar at the top. */
.health-tracker-play.is-single {
  grid-template-rows: auto 1fr;
}

.health-tracker-play.is-single .health-tracker-panel-1 {
  display: none;
}

.health-tracker-play.is-single .health-tracker-bar {
  grid-row: 1;
}

.health-tracker-play.is-single .health-tracker-panel-0 {
  grid-row: 2;
}

.health-tracker-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0.5rem 0.75rem 0.75rem 0.75rem;
  text-align: center;
  transition: background 0.3s ease;
}

.health-tracker-panel-0 {
  background: #1f3f66;
}

.health-tracker-panel-1 {
  background: #6b2430;
  transform: rotate(180deg);
}

.health-tracker-panel.is-defeated {
  background: #2a2a2e;
}

.health-tracker-name {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #ffd166;
  overflow-wrap: anywhere;
}

.health-tracker-score {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.health-tracker-value {
  font-size: clamp(4rem, 22vmin, 11rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5);
}

/* Shown instead of the value when a player reaches 0. */
.health-tracker-skull {
  height: clamp(4rem, 22vmin, 11rem);
  width: auto;
  color: #e53935;
  filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.5));
}

.health-tracker-skull[hidden],
.health-tracker-value[hidden] {
  display: none;
}

/* Shows the running total of recent taps, e.g. -7, on both sides of the health, then fades away. */
.health-tracker-delta {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: clamp(2.5rem, 11vmin, 5.5rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.health-tracker-delta-left {
  left: 0.25rem;
}

.health-tracker-delta-right {
  right: 0.25rem;
}

.health-tracker-delta.is-visible {
  opacity: 1;
}

.health-tracker-delta.is-down {
  color: #ff8a80;
}

.health-tracker-delta.is-up {
  color: #8be28b;
}

.health-tracker-steps {
  display: grid;
  grid-template-columns: 1fr 1fr 1.5fr 1.5fr 1fr 1fr;
  gap: 0.4rem;
  height: clamp(3.5rem, 16vmin, 6.5rem);
}

.health-tracker-step {
  padding: 0;
  font-size: clamp(1.1rem, 4.5vmin, 2rem);
  font-weight: 700;
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease, filter 0.1s ease;
}

.health-tracker-step-down {
  background: rgba(150, 25, 25, 0.75);
}

.health-tracker-step-up {
  background: rgba(30, 120, 50, 0.75);
}

.health-tracker-step-one {
  font-size: clamp(1.4rem, 6vmin, 2.6rem);
}

.health-tracker-step:active {
  transform: scale(0.94);
  filter: brightness(1.4);
}

.health-tracker-bar {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  padding: 0.3rem;
  background: #000;
}

.health-tracker-bar-button {
  min-width: 3.5rem;
  padding: 0.3rem 0.8rem;
  font-size: 1.2rem;
  color: #f4f1ea;
  background: #3a3a42;
  border: 2px solid #8a8a96;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.health-tracker-bar-button:hover,
.health-tracker-bar-button:focus {
  border-color: #ffd166;
}

@media (max-width: 575px) {
  .health-tracker-title {
    font-size: 1.7rem;
  }

  /* Bigger tap targets on phones. */
  .health-tracker-steps {
    height: clamp(4.5rem, 21vmin, 6.5rem);
    gap: 0.35rem;
  }

  .health-tracker-step {
    font-size: clamp(1.3rem, 5.5vmin, 2rem);
  }

  .health-tracker-step-one {
    font-size: clamp(1.7rem, 7.5vmin, 2.6rem);
  }
}

/* Short screens: tighten the setup screen so everything still fits without scrolling. */
@media (max-height: 760px) {
  .health-tracker-subtitle {
    display: none;
  }

  .health-tracker-nav {
    margin-bottom: 0.5rem;
  }

  .health-tracker-title {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
  }

  .health-tracker-group {
    margin-bottom: 0.6rem;
    padding: 0.6rem 1rem;
  }

  .health-tracker-group h5 {
    margin-bottom: 0.4rem;
    font-size: 1rem;
  }

  .health-tracker-button {
    padding: 0.55rem 1rem;
  }

  .health-tracker-stepper {
    margin-bottom: 0.5rem;
  }
}

/* Phone held sideways: keep the buttons from eating the whole panel. */
@media (max-height: 500px) {
  .health-tracker-name,
  .health-tracker-title {
    display: none;
  }

  .health-tracker-names {
    grid-template-columns: 1fr 1fr;
  }
}

@supports (height: 100dvh) {
  .health-tracker-menu,
  .health-tracker-play {
    height: 100dvh;
    bottom: auto;
  }
}
