/* Active Health Tracker. Standalone like /gkr/ and /loadout/: the homepage's style.css is not loaded.
   Fonts and colours match the homepage. When HP or SP drops under 9 the <body> gets .low and the
   whole page turns red: the bar, the map tint, the frames and the text. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

:root {
  --font-display: "Segoe UI Variable Display Light", "Segoe UI Variable Display", "Segoe UI Light", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-button: "Liberation Sans", Arial, Helvetica, sans-serif;
  --font-mono: "Liberation Mono", "Courier New", Courier, monospace;

  --blue: #7f90ff;           /* bar, normal */
  --red: #f26b6b;            /* bar, low health */
  --ink: #000a2e;            /* text on the bar */
  --white: #ffffff;
  --text: #b9c3ff;           /* muted text */
  --hp: #e8151b;
  --sp: #1e8fff;
  --log: #ffd400;
  --revive: #19e01f;
  --panel: rgba(0, 3, 24, 0.72);
  --frame: var(--white);
  --bar: var(--blue);
  --bar-h: clamp(32px, 5.4vh, 48px);
  --tint: rgba(0, 0, 0, 0);
}

body.low {
  --bar: var(--red);
  --text: #ffc2c2;
  --panel: rgba(30, 0, 0, 0.72);
  --tint: rgba(140, 0, 0, 0.55);
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--white);
  font-family: var(--font-mono);
  background-color: #000318;
  background-image: url("../images/background.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  transition: background-color 0.4s ease-out;
}

body.low {
  background-color: #1a0000;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

input,
textarea {
  font: inherit;
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- blue grid that follows the cursor (same as the homepage) ---- */
.grid {
  position: fixed;
  inset: -120px;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(90, 120, 255, 0.16) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(90, 120, 255, 0.16) 1px, transparent 1px);
  background-size: 180px 180px;
  transform: translate3d(var(--gx, 0px), var(--gy, 0px), 0);
  transition: transform 0.25s ease-out;
  will-change: transform;
}

body.low .grid {
  background-image:
    linear-gradient(to right, rgba(255, 90, 90, 0.16) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 90, 90, 0.16) 1px, transparent 1px);
}

/* red wash over the map when health is low; invisible otherwise */
.tint {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255, 40, 40, 0.28), transparent 70%),
    var(--tint);
  opacity: 0;
  transition: opacity 0.4s ease-out;
}

body.low .tint {
  opacity: 1;
}

/* ---- title bar across the top (same as /gkr/ and /loadout/) ---- */
.bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  height: var(--bar-h);
  background: var(--bar);
  color: var(--ink);
  transition: background 0.4s ease-out;
}

.bar-title {
  flex: 1 1 auto;
  margin: 0;
  padding: 0 calc(var(--bar-h) + 1vw);
  text-align: center;
  font-family: var(--font-button);
  font-weight: 700;
  font-size: clamp(13px, 1.6vw, 24px);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.back {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(var(--bar-h) * 1.2);
  height: var(--bar-h);
  color: var(--ink);
  transition: transform 0.18s ease-out;
}

.back svg {
  width: 62%;
  height: 62%;
  fill: currentColor;
}

.back:hover,
.back:focus-visible {
  transform: translateX(-4px);
}

.back:focus-visible,
.turn-next:focus-visible,
.turn-undo:focus-visible,
.reset-btn:focus-visible,
.check input:focus-visible + .check-box {
  outline: 2px solid var(--white);
  outline-offset: 2px;
}

.page {
  position: relative;
  z-index: 1;
  padding-top: var(--bar-h);
  min-height: 100vh;
}

/* ---- three columns: vitals, log, graph ---- */
.tracker {
  display: grid;
  grid-template-columns: 27vw 19vw minmax(0, 1fr);
  gap: 0 3vw;
  min-height: calc(100vh - var(--bar-h));
  padding: 3vh 2vw 4vh 2.6vw;
}

/* ---- turn counter ---- */
.turn-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.6vh;
}

.turn-box {
  display: flex;
  align-items: stretch;
  border: 3px solid var(--frame);
  background: var(--panel);
}

.turn-label {
  display: flex;
  align-items: center;
  padding: 0.1em 0.5em 0.1em 0.5em;
  font-family: var(--font-button);
  font-weight: 700;
  font-size: clamp(22px, 2.8vw, 44px);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.turn-label #turn {
  display: inline-block;
  min-width: 1.1em;
  text-align: center;
}

.turn-next {
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(40px, 3.8vw, 60px);
  border-left: 3px solid var(--frame);
  color: var(--white);
  transition: background 0.15s ease-out;
}

.turn-next svg {
  width: 55%;
  height: 55%;
  fill: currentColor;
}

.turn-next:hover,
.turn-next:focus-visible {
  background: rgba(255, 255, 255, 0.16);
}

.turn-undo {
  align-self: flex-end;
  margin-right: 1.4vw;
  width: 1.6em;
  height: 1.6em;
  color: var(--white);
  opacity: 0.85;
  transition: opacity 0.15s ease-out, transform 0.15s ease-out;
}

.turn-undo svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.turn-undo:hover,
.turn-undo:focus-visible {
  opacity: 1;
  transform: translateX(-3px);
}

.turn-undo:disabled {
  opacity: 0.25;
  cursor: default;
  transform: none;
}

/* ---- HP / SP ---- */
.stat {
  margin-top: 2.4vh;
}

.stat-head {
  margin-left: 2.2vw;
  font-family: var(--font-button);
  font-weight: 700;
  font-size: clamp(15px, 1.5vw, 24px);
}

.stat-body {
  display: flex;
  align-items: center;
  gap: 1.2vw;
  margin-top: 0.4vh;
}

.stat-icon {
  flex: 0 0 auto;
  width: clamp(44px, 5.6vw, 88px);
  height: clamp(44px, 5.6vw, 88px);
  color: var(--white);
  transition: color 0.3s ease-out;
}

.field {
  display: inline-block;
}

.value {
  width: 2.3em;
  padding: 0 0 0.05em;
  text-align: center;
  font-family: var(--font-button);
  font-weight: 300;
  font-size: clamp(24px, 2.6vw, 40px);
  line-height: 1.1;
  background: none;
  border: 0;
  border-bottom: 3px solid var(--white);
  outline: 0;
  -moz-appearance: textfield;
  appearance: textfield;
}

.value::-webkit-outer-spin-button,
.value::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.value::placeholder,
.count::placeholder {
  color: transparent;
}

.value:focus {
  border-bottom-color: var(--text);
}

.slash {
  font-family: var(--font-button);
  font-weight: 700;
  font-size: clamp(26px, 2.8vw, 44px);
  line-height: 1;
}

/* current value turns red when it is under 9 */
.stat.low .value:first-of-type,
.stat.low .stat-icon,
.stat.low .stat-head {
  color: #ff5a5a;
}

.stat.low .stat-body .field:first-of-type .value {
  color: #ff5a5a;
  border-bottom-color: #ff5a5a;
}

/* ---- revive / autoinjectors ---- */
.consumables {
  display: flex;
  gap: 2.4vw;
  margin-top: 7vh;
}

.consumable-label {
  text-align: center;
  font-size: clamp(9px, 0.72vw, 12px);
  font-weight: 700;
  line-height: 1.15;
}

.consumable-body {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.4vw;
  margin-top: 0.8vh;
}

.consumable-icon {
  width: clamp(40px, 4.4vw, 68px);
  height: clamp(40px, 4.4vw, 68px);
  color: var(--white);
}

.check {
  position: relative;
  display: inline-block;
  cursor: pointer;
}

.check input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.check-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(22px, 2vw, 32px);
  height: clamp(22px, 2vw, 32px);
  border: 2px solid var(--white);
  background: var(--panel);
  font-family: var(--font-button);
  font-weight: 700;
  font-size: clamp(14px, 1.3vw, 22px);
  color: var(--hp);
  transition: border-color 0.15s ease-out;
}

.check-mark {
  opacity: 0;
}

.check input:checked + .check-box .check-mark {
  opacity: 1;
}

.check.done {
  cursor: default;
}

.check.done .check-box {
  border-color: rgba(255, 255, 255, 0.6);
}

.count {
  width: clamp(22px, 2vw, 32px);
  height: clamp(22px, 2vw, 32px);
  padding: 0;
  text-align: center;
  font-family: var(--font-button);
  font-weight: 700;
  font-size: clamp(14px, 1.3vw, 22px);
  color: var(--hp);
  background: var(--panel);
  border: 2px solid var(--white);
  outline: 0;
  -moz-appearance: textfield;
  appearance: textfield;
}

.count::-webkit-outer-spin-button,
.count::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.count:focus {
  border-color: var(--text);
}

/* ---- log ---- */
.log {
  display: flex;
  flex-direction: column;
  align-self: start;
  margin-top: 22vh;
}

.log-title {
  position: absolute;
  margin: 1.2vh 0 0 0.6vw;
  font-weight: 700;
  font-size: clamp(11px, 0.95vw, 15px);
  pointer-events: none;
}

#log {
  width: 100%;
  min-height: 36vh;
  padding: 4vh 0.6vw 1vh;
  resize: vertical;
  background: var(--panel);
  border: 2px solid var(--white);
  outline: 0;
  font-size: clamp(11px, 0.9vw, 14px);
  line-height: 1.4;
  color: var(--white);
}

#log::placeholder {
  color: var(--white);
  opacity: 0.9;
}

#log:focus {
  border-color: var(--text);
}

.log-hint {
  margin: 0.8vh 0 0;
  font-size: clamp(9px, 0.7vw, 12px);
  color: var(--text);
  opacity: 0.8;
}

/* ---- graph ---- */
.graph-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 0;
  padding-top: 3vh;
}

.graph {
  position: relative;
  width: min(100%, 78vh);
  border: 2px solid var(--white);
  background: var(--panel);
}

#chart {
  display: block;
  width: 100%;
  height: auto;
  font-family: var(--font-mono);
  font-weight: 700;
}

#chart .axis {
  stroke: var(--white);
  stroke-width: 1.5;
  fill: none;
}

#chart .arrow {
  fill: var(--white);
}

#chart .gridline {
  stroke: rgba(255, 255, 255, 0.7);
  stroke-width: 1;
  stroke-dasharray: 3 4;
}

#chart .tick,
#chart .axis-label,
#chart .legend-text {
  fill: var(--white);
  font-size: 11px;
}

#chart .axis-label {
  font-size: 12px;
}

#chart .legend-text {
  font-size: 10px;
}

#chart .line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

#chart .line.hp,
#chart .legend-swatch.hp,
#chart .legend-text.hp {
  stroke: var(--hp);
}

#chart .line.sp,
#chart .legend-swatch.sp,
#chart .legend-text.sp {
  stroke: var(--sp);
}

#chart .legend-swatch {
  stroke: none;
}

#chart .legend-swatch.hp { fill: var(--hp); }
#chart .legend-swatch.sp { fill: var(--sp); }
#chart .legend-swatch.log { fill: var(--log); }
#chart .legend-text.hp { fill: var(--hp); stroke: none; }
#chart .legend-text.sp { fill: var(--sp); stroke: none; }
#chart .legend-text.log { fill: var(--log); }

/* the turn being typed now, not registered yet */
#chart .line.live {
  stroke-dasharray: 4 4;
  opacity: 0.55;
}

#chart .live-dot {
  opacity: 0.55;
}

#chart .live-dot.hp { fill: var(--hp); }
#chart .live-dot.sp { fill: var(--sp); }

#chart .marker {
  fill: var(--log);
  cursor: help;
  transition: transform 0.12s ease-out;
  transform-box: fill-box;
  transform-origin: center;
}

#chart .marker:hover,
#chart .marker:focus {
  transform: scale(1.35);
  outline: 0;
}

#chart .marker-text {
  fill: var(--log);
  font-size: 8px;
  text-anchor: middle;
  pointer-events: none;
}

#chart .revive {
  fill: var(--revive);
}

#chart .empty {
  fill: var(--text);
  font-size: 11px;
  font-weight: 400;
  text-anchor: middle;
}

.tooltip {
  position: absolute;
  z-index: 3;
  max-width: 46%;
  padding: 0.5em 0.7em;
  border: 1.5px solid var(--log);
  background: rgba(0, 3, 24, 0.95);
  color: var(--white);
  font-size: clamp(10px, 0.78vw, 13px);
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  pointer-events: none;
}

.tooltip[hidden] {
  display: none;
}

.tooltip .tooltip-turn {
  display: block;
  margin-bottom: 0.2em;
  color: var(--log);
  font-weight: 700;
}

.resets {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.4vh;
  margin-top: 3.5vh;
  margin-right: 1vw;
}

.reset-btn {
  display: flex;
  align-items: center;
  gap: 0.7em;
  font-weight: 700;
  font-size: clamp(11px, 0.95vw, 15px);
  text-transform: uppercase;
  transition: opacity 0.15s ease-out;
}

.reset-btn::before {
  content: "";
  width: 0.75em;
  height: 0.75em;
  background: var(--white);
  transform: rotate(45deg);
  transition: background 0.15s ease-out;
}

.reset-btn:hover::before,
.reset-btn:focus-visible::before {
  background: var(--text);
}

.reset-btn:hover,
.reset-btn:focus-visible {
  opacity: 0.85;
}

/* ---- small screens: stack everything ---- */
@media (max-width: 900px) {
  .bar-title {
    padding: 0 var(--bar-h);
    white-space: normal;
    font-size: 13px;
  }

  .tracker {
    grid-template-columns: 1fr;
    gap: 28px;
    padding: 20px 16px 40px;
  }

  .turn-label {
    font-size: 28px;
  }

  .turn-next {
    width: 44px;
  }

  .stat-head {
    margin-left: 12px;
  }

  .stat-icon {
    width: 52px;
    height: 52px;
  }

  .value {
    font-size: 28px;
  }

  .consumables {
    margin-top: 28px;
    gap: 28px;
  }

  .consumable-label,
  .log-hint {
    font-size: 11px;
  }

  .log {
    margin-top: 0;
  }

  .log-title {
    position: static;
    margin: 0 0 6px;
    font-size: 13px;
  }

  #log {
    min-height: 160px;
    padding: 10px;
    font-size: 13px;
  }

  .graph-wrap {
    padding-top: 0;
    align-items: stretch;
  }

  .resets {
    margin: 24px 0 0;
    gap: 14px;
  }

  .reset-btn {
    font-size: 12px;
    text-align: left;
  }

  .tooltip {
    max-width: 70%;
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .grid,
  .tint,
  .bar,
  .back,
  .turn-next,
  .turn-undo,
  #chart .marker {
    transition: none;
  }
}
