@font-face {
  font-family: "Mallory";
  src: url("../fonts/Mallory-Book.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Mallory";
  src: url("../fonts/Mallory-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Mallory MP";
  src: url("../fonts/MalloryMP-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

:root {
  --river-ink: #172127;
  --river-paper: #f8f9f5;
  --river-panel: #fffdf2;
  --river-blue: #216f91;
  --river-deep: #174f76;
  --river-foam: #d6f7f0;
  --river-grass: #5d854b;
  --river-bank: #d9be76;
  --river-red: #e8462e;
  --river-yellow: #f4cb4d;
  --river-line: #16313a;
}

* {
  box-sizing: border-box;
}

body.river-runner-page {
  min-height: 100vh;
  margin: 0;
  color: var(--river-ink);
  background:
    linear-gradient(90deg, rgba(93, 133, 75, 0.2) 0 1px, transparent 1px 34px),
    linear-gradient(0deg, rgba(23, 79, 118, 0.08) 0 1px, transparent 1px 34px),
    var(--river-paper);
  font-family: "Mallory", "Avenir Next", sans-serif;
}

button {
  font: inherit;
}

.river-shell {
  width: min(1240px, calc(100vw - 32px));
  margin: 0 auto;
  padding: clamp(24px, 4vw, 54px) 0 48px;
}

.river-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  gap: 28px;
  align-items: end;
  margin-bottom: 22px;
}

.river-kicker,
.river-stats span,
.overlay-label,
.metric-line span {
  font-family: "Mallory MP", "Mallory", sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.river-kicker {
  margin: 0 0 8px;
  color: var(--river-red);
}

.river-head h1 {
  margin: 0;
  font-size: clamp(54px, 9vw, 118px);
  font-weight: 700;
  line-height: 0.86;
}

.river-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border: 2px solid var(--river-line);
  border-radius: 8px;
  background: var(--river-panel);
  box-shadow: 8px 8px 0 rgba(23, 33, 39, 0.12);
  overflow: hidden;
}

.river-stats div {
  min-width: 0;
  padding: 16px 12px 14px;
  text-align: center;
}

.river-stats div + div {
  border-left: 2px solid var(--river-line);
}

.river-stats span {
  display: block;
  color: var(--river-deep);
}

.river-stats strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 0.9;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(210px, 280px);
  gap: 18px;
  align-items: stretch;
}

.river-stage {
  position: relative;
  min-height: 0;
  border: 2px solid var(--river-line);
  border-radius: 8px;
  background: var(--river-deep);
  box-shadow: 8px 8px 0 rgba(23, 33, 39, 0.14);
  overflow: hidden;
}

.health-hud {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 3;
  width: min(260px, calc(100% - 28px));
  padding: 10px 12px 12px;
  border: 2px solid var(--river-line);
  border-radius: 8px;
  background: rgba(255, 253, 242, 0.92);
  box-shadow: 5px 5px 0 rgba(23, 33, 39, 0.16);
  pointer-events: none;
}

.health-hud-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.health-hud-row span {
  color: var(--river-deep);
  font-family: "Mallory MP", "Mallory", sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.health-hud-row strong {
  font-size: 18px;
  line-height: 1;
}

.health-track {
  position: relative;
  height: 18px;
  border: 2px solid var(--river-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  overflow: hidden;
}

.health-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #e8462e, #f4cb4d);
  transition: width 180ms ease;
}

.health-track i {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--river-line);
  opacity: 0.75;
}

.health-track i:nth-of-type(1) {
  left: 33.333%;
}

.health-track i:nth-of-type(2) {
  left: 66.666%;
}

#riverCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  min-height: 360px;
  max-height: min(68vh, 720px);
  background: var(--river-deep);
}

.game-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 24px;
  background: rgba(248, 249, 245, 0.78);
  text-align: center;
}

.game-overlay[hidden] {
  display: none;
}

.overlay-label {
  margin: 0;
  color: var(--river-red);
}

.overlay-title {
  margin: 0;
  font-size: clamp(44px, 9vw, 96px);
  font-weight: 700;
  line-height: 0.88;
}

.primary-game-button,
.secondary-game-button,
.control-button {
  border: 2px solid var(--river-line);
  border-radius: 8px;
  color: var(--river-ink);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.primary-game-button:hover,
.secondary-game-button:hover,
.control-button:hover,
.primary-game-button:focus-visible,
.secondary-game-button:focus-visible,
.control-button:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.primary-game-button {
  min-width: 144px;
  min-height: 52px;
  padding: 12px 24px;
  background: var(--river-yellow);
  box-shadow: 5px 5px 0 rgba(23, 33, 39, 0.2);
  font-weight: 700;
}

.secondary-game-button {
  width: 100%;
  min-height: 46px;
  padding: 10px 16px;
  background: #ffffff;
  box-shadow: 4px 4px 0 rgba(23, 33, 39, 0.12);
  font-weight: 700;
}

.river-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  border: 2px solid var(--river-line);
  border-radius: 8px;
  padding: 14px;
  background: var(--river-panel);
  box-shadow: 8px 8px 0 rgba(23, 33, 39, 0.12);
}

.panel-block {
  display: grid;
  gap: 12px;
}

.metric-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.metric-line span {
  color: var(--river-deep);
}

.metric-line strong {
  font-size: 30px;
  line-height: 1;
}

.meter {
  height: 14px;
  border: 2px solid var(--river-line);
  border-radius: 999px;
  background: #ffffff;
  overflow: hidden;
}

.meter span {
  display: block;
  width: 20%;
  height: 100%;
  background: linear-gradient(90deg, var(--river-yellow), var(--river-red));
}

.touch-controls {
  display: grid;
  grid-template-columns: repeat(3, 62px);
  grid-template-rows: repeat(3, 56px);
  justify-content: center;
  gap: 8px;
  padding-top: 6px;
}

.control-button {
  display: grid;
  width: 62px;
  height: 56px;
  place-items: center;
  background: #ffffff;
  box-shadow: 4px 4px 0 rgba(23, 33, 39, 0.12);
  font-size: 24px;
  line-height: 1;
  touch-action: none;
}

.control-button.is-active {
  background: var(--river-yellow);
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 rgba(23, 33, 39, 0.16);
}

.control-up {
  grid-column: 2;
  grid-row: 1;
}

.control-left {
  grid-column: 1;
  grid-row: 2;
}

.control-right {
  grid-column: 3;
  grid-row: 2;
}

.control-down {
  grid-column: 2;
  grid-row: 3;
}

@media screen and (max-width: 900px) {
  .river-head,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .river-panel {
    grid-template-columns: minmax(0, 1fr) minmax(170px, auto) minmax(210px, auto);
    align-items: center;
  }

  .touch-controls {
    padding-top: 0;
  }
}

@media screen and (max-width: 640px) {
  .river-shell {
    width: min(100vw - 20px, 1240px);
    padding-top: 18px;
  }

  .river-head {
    gap: 16px;
    margin-bottom: 14px;
  }

  .river-head h1 {
    font-size: clamp(38px, 12.5vw, 52px);
    line-height: 0.92;
  }

  .river-head h1 br {
    display: none;
  }

  .river-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .river-stats div {
    padding: 12px 6px 10px;
  }

  .river-stats strong {
    font-size: 30px;
  }

  #riverCanvas {
    min-height: 420px;
    aspect-ratio: 5 / 7;
    max-height: 62vh;
  }

  .river-panel {
    grid-template-columns: 1fr;
  }

  .panel-block {
    grid-template-columns: 1fr 1fr;
  }

  .panel-block:first-child {
    grid-template-columns: 1fr;
  }
}
