:root {
  color-scheme: dark;
  font-family: "Segoe UI", "Microsoft JhengHei", sans-serif;
  color: #eef0df;
  background: #111b20;
  --lime: #d9ef84;
  --edge: #486463;
  --panel: #15272bec;
  --orange-team: #ffae89;
  --blue-team: #89dcf2;
  --display: "Bahnschrift", "Microsoft JhengHei", "Arial Black", sans-serif;
  --hud-gap: 16px;
  --hud-top: max(var(--hud-gap), calc(env(safe-area-inset-top) + 8px));
  --hud-right: max(var(--hud-gap), calc(env(safe-area-inset-right) + 8px));
  --hud-bottom: max(var(--hud-gap), calc(env(safe-area-inset-bottom) + 8px));
  --hud-left: max(var(--hud-gap), calc(env(safe-area-inset-left) + 8px));
}

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

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

p, h2, dl, dd {
  margin: 0;
}

button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--edge);
  border-radius: 7px;
  color: inherit;
  background: var(--panel);
  font: inherit;
  cursor: pointer;
}

button:hover {
  border-color: #789076;
  background: #23383a;
}

button:focus-visible, canvas:focus-visible {
  outline: 2px solid var(--lime);
  outline-offset: 3px;
}

.game {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
}

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(ellipse at 50% 25%, #4c625f 0%, #30484a 45%, #1a2d36 76%, #14252e 100%);
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, #e5eed04d .6px, transparent .9px) 1px 1px / 22px 22px;
  opacity: .25;
  pointer-events: none;
}

canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
}

canvas[data-mouselook="true"] {
  cursor: none;
}

canvas:focus-visible {
  outline-offset: -4px;
}

.match-hud {
  position: absolute;
  top: var(--hud-top);
  left: 50%;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 6px;
  transform: translateX(-50%);
  pointer-events: none;
}

.stats {
  display: flex;
  overflow: hidden;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 6px 22px #0b1a2280;
}

.stats > div {
  display: flex;
  min-width: clamp(65px, 7.7vw, 103px);
  align-items: baseline;
  justify-content: center;
  gap: clamp(6px, 1.05vw, 14px);
  padding: 9px clamp(7px, 1.3vw, 15px);
  border-top: 3px solid var(--team);
  color: var(--team);
}

.stats > div + div {
  border-left: 1px solid var(--edge);
}

.stats dt {
  font-size: .82rem;
  font-weight: 700;
  white-space: nowrap;
}

.stats dd {
  font: 800 clamp(1.2rem, 3.4vw, 1.75rem)/1 var(--display);
  font-variant-numeric: tabular-nums;
}

.stats .score-clock {
  --team: #e9efd9;
  min-width: clamp(55px, 6.3vw, 84px);
  align-items: center;
}

.score-clock dd {
  font-size: clamp(.94rem, 2.7vw, 1.4rem);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.match-badges {
  display: flex;
  gap: 6px;
}

.match-badge {
  padding: 4px 9px;
  border: 1px solid #78948b;
  border-radius: 5px;
  color: #e9efd9;
  background: var(--panel);
  font-size: .8rem;
  font-weight: 700;
  white-space: nowrap;
}

.match-badge.golden-ball {
  border-color: #a98436;
  color: #ffe59b;
}

.score-home {
  --team: var(--orange-team);
}

.score-away {
  --team: var(--blue-team);
}

.hud-button {
  position: absolute;
  top: var(--hud-top);
  z-index: 2;
  display: grid;
  min-width: 48px;
  place-content: center;
  gap: 2px;
  padding: 4px 8px;
  font-size: .77rem;
}

.reset {
  left: var(--hud-left);
}

.camera-reset {
  right: var(--hud-right);
}

.reset-icon, .camera-arrow {
  color: var(--lime);
  line-height: 1;
}

.reset-icon {
  font-size: 1.15rem;
}

.camera-arrow {
  transform: rotate(var(--camera-angle, 0rad));
}

.stamina-ring {
  --stamina-color: #66f0ff;
  --stamina-fill: 100%;
  --stamina-stroke: 7px;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  width: clamp(37px, 4.2vw, 51px);
  aspect-ratio: 1;
  border: 2px solid #102a35;
  border-radius: 50%;
  filter: drop-shadow(0 2px 3px #071824c4);
  pointer-events: none;
}

.stamina-ring::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: conic-gradient(var(--stamina-color) var(--stamina-fill), #122b35f2 0);
  mask: radial-gradient(
    circle farthest-side,
    transparent calc(100% - var(--stamina-stroke)),
    #000 calc(100% - var(--stamina-stroke) + 1px)
  );
}

.stamina-ring[data-state="sprinting"] {
  --stamina-color: #c5fbff;
}

.stamina-ring[data-state="tired"] {
  --stamina-color: #faa867;
}

.feedback {
  position: absolute;
  bottom: var(--hud-bottom);
  left: 50%;
  z-index: 1;
  max-width: min(calc(100% - 28px), 350px);
  padding: 6px 10px;
  border: 1px solid var(--edge);
  border-radius: 5px;
  color: #eef0df;
  background: var(--panel);
  font-size: .84rem;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.feedback:empty, #goal-detail:empty, #match-summary:empty {
  display: none;
}

.feedback[data-kind="hit"] {
  color: var(--lime);
}

.goal-banner, .match-overlay {
  --goal-color: var(--lime);
}

[data-team="home"] {
  --goal-color: var(--orange-team);
}

[data-team="away"] {
  --goal-color: var(--blue-team);
}

[data-team="draw"] {
  --goal-color: #e9efd9;
}

.goal-banner, .match-overlay[data-team] .match-card {
  gap: 9px;
  padding: clamp(16px, 4vw, 34px) clamp(18px, 6vw, 58px);
  border: 1px solid var(--edge);
  border-top: 4px solid var(--goal-color);
  border-radius: 9px;
  background: linear-gradient(160deg, #22393bee 0%, #101d26f5 85%);
  box-shadow: 0 18px 62px #071722aa;
  text-align: center;
}

.goal-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  display: grid;
  width: max-content;
  max-width: calc(100% - var(--hud-left) - var(--hud-right));
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: goal-appear .17s ease-out;
}

.goal-banner strong, .match-card h2 {
  color: var(--goal-color);
  font: 900 clamp(2rem, 8vw, 4.4rem)/1.08 var(--display);
  text-wrap: balance;
  text-shadow: 0 4px 0 #0b1822;
}

#goal-detail, #match-summary {
  color: #e8eee0;
  font-size: clamp(.88rem, 2.5vw, 1.06rem);
  font-weight: 600;
}

@keyframes goal-appear {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(.90);
  }
}

.match-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: var(--hud-top) var(--hud-right) var(--hud-bottom) var(--hud-left);
  pointer-events: none;
}

.match-card {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.match-card button, .mouse-resume {
  padding: 9px 20px;
  border-color: var(--lime);
  color: #14252a;
  background: var(--lime);
  font-weight: 800;
  box-shadow: 0 6px 23px #09111470;
  pointer-events: auto;
}

.match-card button:hover, .mouse-resume:hover {
  background: #e7f6a9;
}

.mouse-resume {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 5;
  transform: translate(-50%, -50%);
}

.goal-banner:not([hidden]) ~ .mouse-resume {
  top: calc(50% + clamp(76px, 11vw, 120px));
}

.load-error {
  position: absolute;
  inset: 25% 12%;
  z-index: 5;
  align-content: center;
  line-height: 1.6;
  text-align: center;
}

.touch-controls {
  position: absolute;
  right: var(--hud-right);
  bottom: var(--hud-bottom);
  left: var(--hud-left);
  z-index: 2;
  display: none;
  align-items: end;
  justify-content: space-between;
  gap: 4px;
  pointer-events: none;
}

.stage[data-cutscene] .camera-reset,
.stage[data-cutscene] .touch-controls {
  display: none;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(2, 44px);
  gap: 4px;
}

.dpad button:nth-child(1) { grid-area: 1 / 2; }
.dpad button:nth-child(2) { grid-area: 2 / 1; }
.dpad button:nth-child(3) { grid-area: 2 / 2; }
.dpad button:nth-child(4) { grid-area: 2 / 3; }

.touch-actions {
  display: grid;
  justify-items: end;
  gap: 4px;
}

.touch-action-row {
  display: flex;
  gap: 4px;
}

.dpad button, .touch-actions button {
  padding: 3px;
  font-size: .78rem;
  font-weight: 700;
  touch-action: none;
  user-select: none;
  pointer-events: auto;
}

.dpad button:active, #touch-sprint:active {
  border-color: var(--lime);
  background: #41574a;
}

#touch-pass {
  color: var(--lime);
}

#touch-dive {
  color: #9deef5;
}

#touch-kick {
  border-color: var(--lime);
  color: #1c2b23;
  background: var(--lime);
}

@media (pointer: coarse), (max-width: 690px) {
  :root {
    --hud-gap: 9px;
  }

  .touch-controls {
    display: flex;
  }

  .feedback {
    bottom: calc(var(--hud-bottom) + 103px);
  }
}

@media (max-width: 318px) {
  :root {
    --hud-gap: 8px;
  }
}

@media (max-width: 299px) {
  .stats > div {
    min-width: 54px;
    gap: 4px;
    padding-inline: 5px;
  }

  .stats .score-clock {
    min-width: 46px;
  }

  .touch-controls {
    flex-wrap: wrap;
  }

  .touch-actions {
    margin-inline-start: auto;
  }

  .feedback {
    bottom: calc(var(--hud-bottom) + 195px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .goal-banner {
    animation: none;
  }
}
