:root {
  --app-height: 100dvh;
  --app-width: 100vw;
  --game-vw: 1vw;
  --runtime-safe-top: 0px;
  --runtime-safe-right: 0px;
  --runtime-safe-bottom: 0px;
  --runtime-safe-left: 0px;
  --inset-top: max(env(safe-area-inset-top, 0px), var(--runtime-safe-top), calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)));
  --inset-right: max(env(safe-area-inset-right, 0px), var(--runtime-safe-right), calc(var(--tg-safe-area-inset-right, 0px) + var(--tg-content-safe-area-inset-right, 0px)));
  --inset-bottom: max(env(safe-area-inset-bottom, 0px), var(--runtime-safe-bottom), calc(var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px)));
  --inset-left: max(env(safe-area-inset-left, 0px), var(--runtime-safe-left), calc(var(--tg-safe-area-inset-left, 0px) + var(--tg-content-safe-area-inset-left, 0px)));
  --safe-top: var(--inset-top);
  --safe-right: var(--inset-right);
  --safe-bottom: var(--inset-bottom);
  --safe-left: var(--inset-left);
  color: #f8e7bd;
  background: #100a08;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body,
.shell {
  position: relative;
  width: 100%;
  height: 100%;
  height: var(--app-height);
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  background: #100a08;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}

button {
  appearance: none;
  border: 0;
  color: inherit;
  font: inherit;
  touch-action: none;
  cursor: pointer;
}

.shell {
  display: grid;
  place-items: center;
  padding: 0;
  background:
    radial-gradient(circle at 50% 35%, rgba(139, 65, 28, 0.22), transparent 50%),
    #100a08;
}

.stage {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: var(--stage-width, min(100vw, calc(100dvh * 2.164)));
  aspect-ratio: 844 / 390;
  overflow: hidden;
  background: #25140f;
  border: 1px solid #60401f;
}

.is-portrait .stage {
  transform: translate(-50%, -50%) rotate(90deg);
  --safe-top: var(--inset-right);
  --safe-right: var(--inset-bottom);
  --safe-bottom: var(--inset-left);
  --safe-left: var(--inset-top);
}

#arena {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hud {
  position: absolute;
  z-index: 4;
  top: calc(var(--safe-top) + 8px);
  right: calc(var(--safe-right) + 12px);
  left: calc(var(--safe-left) + 12px);
  display: grid;
  grid-template-columns: minmax(92px, 1fr) auto minmax(92px, 1fr);
  gap: clamp(8px, calc(var(--game-vw) * 2), 18px);
  align-items: flex-start;
  pointer-events: none;
}

.fight-status {
  display: grid;
  gap: 1px;
  min-width: 92px;
  text-align: center;
  filter: drop-shadow(0 2px 0 #130b08);
}

.eyebrow {
  color: #d5a653;
  font-size: clamp(8px, calc(var(--game-vw) * 1.5), 11px);
  font-weight: 800;
  letter-spacing: 0.12em;
}

#action-name {
  font-size: clamp(11px, calc(var(--game-vw) * 2), 18px);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

#combo-meter {
  position: absolute;
  top: clamp(65px, calc(var(--game-vw) * 11), 78px);
  left: 50%;
  transform: translateX(-50%);
  justify-self: center;
  padding: 1px 6px;
  border: 1px solid rgba(242, 198, 110, 0.7);
  border-radius: 999px;
  background: rgba(78, 30, 18, 0.86);
  color: #ffe19a;
  font-size: clamp(8px, calc(var(--game-vw) * 1.3), 10px);
  font-weight: 900;
  letter-spacing: 0.07em;
}

#combo-meter[hidden] {
  display: none;
}

.fighter-hud {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.fighter-meta {
  display: flex;
  justify-content: space-between;
  color: #f4d28e;
  font-size: clamp(8px, calc(var(--game-vw) * 1.35), 11px);
  letter-spacing: 0.06em;
  text-shadow: 0 2px #170c08;
}

.enemy-hud {
  text-align: right;
}

.health-track {
  height: clamp(7px, calc(var(--game-vw) * 1.6), 11px);
  overflow: hidden;
  border: 1px solid #d2a75e;
  background: rgba(20, 11, 8, 0.86);
  box-shadow: 0 2px 0 rgba(20, 9, 7, 0.8);
}

.health-track i {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(#e36b42, #a5201e);
  transform-origin: left center;
  transition: transform 180ms ease-out;
}

.enemy-hud .health-track i {
  background: linear-gradient(#d2bd63, #98762a);
  transform-origin: right center;
}

.stamina-track {
  height: clamp(3px, calc(var(--game-vw) * 0.65), 5px);
  overflow: hidden;
  border: 1px solid rgba(225, 195, 121, 0.46);
  background: rgba(20, 11, 8, 0.72);
}

.stamina-track i {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #78b8a2, #d6c56e);
  transform: scaleX(1);
  transform-origin: left center;
  transition: transform 100ms linear;
}

.enemy-hud .stamina-track i {
  transform-origin: right center;
}

.stage.phase-two .enemy-hud .fighter-meta strong {
  color: #ffc36c;
  text-shadow: 0 0 7px rgba(235, 87, 34, 0.8), 0 2px #170c08;
}

.stage.phase-two .enemy-hud .stamina-track i {
  background: linear-gradient(90deg, #d98336, #ffd06f);
}

.system-actions {
  position: absolute;
  top: clamp(27px, calc(var(--game-vw) * 6), 40px);
  left: 50%;
  display: flex;
  gap: 5px;
  transform: translateX(-50%);
  pointer-events: auto;
}

.system-actions button {
  width: clamp(27px, calc(var(--game-vw) * 5), 34px);
  aspect-ratio: 1;
  border: 1px solid rgba(230, 184, 97, 0.42);
  border-radius: 50%;
  background: rgba(27, 15, 12, 0.78);
  color: #dfbd79;
  font-size: clamp(11px, calc(var(--game-vw) * 2), 15px);
  font-weight: 900;
}

.controls {
  position: absolute;
  z-index: 3;
  right: calc(var(--safe-right) + 10px);
  bottom: calc(var(--safe-bottom) + 8px);
  left: calc(var(--safe-left) + 10px);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  pointer-events: none;
}

.tutorial-coach[hidden] {
  display: none;
}

.tutorial-coach {
  position: absolute;
  z-index: 8;
  bottom: calc(var(--safe-bottom) + 10px);
  left: 50%;
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: min(48%, 390px);
  padding: 5px 6px 5px 10px;
  border: 1px solid rgba(239, 196, 103, 0.68);
  border-radius: 999px;
  background: rgba(24, 13, 10, 0.9);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.34);
  transform: translateX(-50%);
  color: #f7d895;
  font-size: clamp(8px, calc(var(--game-vw) * 1.45), 11px);
  font-weight: 800;
  white-space: nowrap;
}

.tutorial-coach button {
  padding: 4px 7px;
  border: 1px solid rgba(239, 196, 103, 0.45);
  border-radius: 999px;
  background: #5c2819;
  color: #f8dea5;
  font-size: clamp(7px, calc(var(--game-vw) * 1.15), 9px);
  font-weight: 900;
}

.movement,
.combat {
  display: flex;
  align-items: flex-end;
  gap: clamp(7px, calc(var(--game-vw) * 1.8), 14px);
  pointer-events: auto;
}

.direction-grid {
  display: grid;
  grid-template-columns: repeat(2, clamp(58px, calc(var(--game-vw) * 11), 76px));
  grid-template-rows: repeat(2, clamp(58px, calc(var(--game-vw) * 11), 76px));
  gap: clamp(5px, calc(var(--game-vw) * 1), 8px);
}

.movement button {
  width: clamp(48px, calc(var(--game-vw) * 11), 74px);
  aspect-ratio: 1;
  border: 2px solid rgba(222, 178, 90, 0.55);
  border-radius: 50%;
  background: rgba(26, 18, 15, 0.74);
  box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.025), 0 6px 16px rgba(0, 0, 0, 0.34);
  font-size: clamp(17px, calc(var(--game-vw) * 3.2), 25px);
}

.combat button {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 2px solid rgba(237, 196, 110, 0.58);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #9a5524, #512518 64%, #26130f);
  box-shadow: inset 0 0 0 5px rgba(25, 12, 8, 0.34), 0 7px 18px rgba(0, 0, 0, 0.4);
}

.combat button.shield {
  background: radial-gradient(circle at 35% 28%, #545b61, #2a3036 64%, #151a1d);
}

.combat button.high {
  border-color: rgba(238, 207, 135, 0.72);
}

.combat button.low {
  background: radial-gradient(circle at 35% 28%, #b17427, #6d3219 64%, #2b150f);
}

.combat button.shield.low {
  background: radial-gradient(circle at 35% 28%, #44505b, #232a31 64%, #12171b);
}

.combat span {
  align-self: end;
  font-size: clamp(9px, calc(var(--game-vw) * 1.7), 13px);
  font-weight: 900;
  letter-spacing: 0.02em;
}

.combat small {
  align-self: start;
  color: rgba(255, 237, 196, 0.66);
  font-size: clamp(7px, calc(var(--game-vw) * 1.25), 9px);
  font-weight: 700;
}

.combat button.no-stamina {
  border-color: #766452;
  background: #30251e;
}

.combat button.counter-ready {
  border-color: #b9f3b3;
  box-shadow: inset 0 0 0 3px rgba(155, 219, 137, 0.3), 0 0 12px rgba(155, 219, 137, 0.3);
}

button.is-pressed,
button:active {
  filter: brightness(1.42);
  transform: translateY(2px) scale(0.97);
}

.combat button.action-active {
  border-color: #f4d28d;
  box-shadow: inset 0 0 0 2px rgba(244, 210, 141, 0.35);
}

.combat button.action-queued {
  border-style: dashed;
  border-color: #f4d28d;
}

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

.game-overlay {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: rgba(13, 7, 6, 0.78);
  text-align: center;
}

.game-overlay > strong {
  color: #f0c66f;
  font-size: clamp(25px, calc(var(--game-vw) * 7), 50px);
  letter-spacing: 0.08em;
  text-shadow: 0 3px #4d1713;
}

.game-overlay > span {
  color: #d8bea0;
  font-size: clamp(10px, calc(var(--game-vw) * 2), 14px);
  max-width: min(90%, 480px);
  line-height: 1.35;
}

.game-overlay > div {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.game-overlay button {
  min-width: 98px;
  min-height: 44px;
  padding: 9px 13px;
  border: 1px solid #bc8540;
  border-radius: 7px;
  background: #5c2819;
  color: #f4d28e;
  font-size: 10px;
  font-weight: 900;
}

.fight-result[hidden] {
  display: none;
}

.game-overlay.with-result {
  gap: 7px;
  background: rgba(13, 7, 6, 0.91);
}

.game-overlay.with-result > strong {
  font-size: clamp(22px, calc(var(--game-vw) * 4), 30px);
}

.fight-result {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 8px 14px;
  width: min(450px, calc(calc(var(--game-vw) * 100) - var(--safe-left) - var(--safe-right) - 32px));
  padding: 12px 14px 8px;
  border: 1px solid #75522e;
  border-radius: 9px;
  background: linear-gradient(135deg, #352114, #201410);
}

.rank-badge {
  display: grid;
  align-content: center;
  border-right: 1px solid #76512c;
  padding-right: 12px;
  color: #f4d28e;
}

.rank-badge > span {
  font-size: 9px;
  letter-spacing: 0.1em;
}

.rank-badge > strong {
  font-size: 52px;
  line-height: 1.1;
  color: #ffe09a;
  text-shadow: 0 3px #6f341c;
}

.result-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px 8px;
  margin: 0;
  align-content: center;
}

.result-metrics dt {
  font-size: 9px;
  color: #c6aa83;
}

.result-metrics dd {
  margin: 2px 0 0;
  font-size: 19px;
  font-weight: 800;
  color: #fff0cc;
}

#result-record {
  grid-column: 1 / -1;
  margin: 0;
  color: #d6b470;
  font-size: 9px;
  letter-spacing: 0.04em;
}

.compact-game .game-overlay.with-result { gap: 4px; }
.compact-game .fight-result { padding: 7px 10px; gap: 5px 10px; }
.compact-game .rank-badge > strong { font-size: 40px; }
.compact-game .result-metrics { gap: 5px; }
.compact-game .result-metrics dd { font-size: 16px; }
.compact-game .game-overlay > div { margin-top: 2px; }
.compact-game .game-overlay.with-result > span { font-size: 10px; line-height: 1.2; }

.narrow-game .tutorial-coach {
    /* Keep the coach in the free strip between movement and combat buttons. */
    width: calc(100% - var(--safe-left) - var(--safe-right) - 4 * clamp(58px, calc(var(--game-vw) * 11), 76px) - 50px);
    max-width: 390px;
    flex-direction: column;
    gap: 3px;
    padding: 5px 7px;
    border-radius: 8px;
    text-align: center;
    white-space: normal;
}
