:root {
  color-scheme: light;
  --grass: #5fb86f;
  --chalk: #f5f1df;
  --ink: #202022;
  --panel: #252824;
  --panel-border: #11140f;
  --accent: #e5c34f;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.14) 0 2px, transparent 2px 76px),
    linear-gradient(135deg, #2f7f48, #6bbd68 48%, #2f7f48);
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
}

#game-shell {
  position: relative;
  width: min(1100px, 100vw);
  aspect-ratio: 1100 / 720;
  max-height: 100vh;
  background: var(--grass);
  border: 10px solid rgba(21,52,28,0.45);
  box-shadow: 0 22px 60px rgba(0,0,0,0.38), inset 0 0 80px rgba(255,255,255,0.12);
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--grass);
}

#hud {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  pointer-events: none;
}

.brand,
.stat,
#pause-button,
#scoreboard {
  border: 2px solid var(--panel-border);
  background: var(--panel);
  color: #fff;
  font-weight: 700;
  box-shadow: 2px 3px 0 rgba(0,0,0,0.28);
}

.brand {
  padding: 9px 12px;
  font-size: 18px;
}

.stat {
  display: flex;
  gap: 7px;
  align-items: center;
  padding: 7px 10px;
  font-size: 13px;
}

.stat strong {
  min-width: 28px;
  text-align: center;
}

#timer,
#best-score {
  min-width: 52px;
}

#pause-button,
#message button {
  margin-left: auto;
  padding: 8px 12px;
  cursor: pointer;
  pointer-events: auto;
  font: inherit;
}

#pause-button {
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
}

#scoreboard {
  position: absolute;
  top: 66px;
  right: 12px;
  width: 190px;
  padding: 8px 10px 9px;
  pointer-events: none;
}

#scoreboard h2 {
  margin: 0 0 5px;
  font-size: 13px;
  line-height: 1;
}

#scoreboard ol {
  margin: 0;
  padding-left: 22px;
  font-size: 12px;
  line-height: 1.35;
}

#scoreboard li {
  white-space: nowrap;
}

#scoreboard .empty {
  list-style: none;
  margin-left: -22px;
  opacity: 0.78;
}

#message {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  text-align: center;
  background: rgba(245,241,223,0.86);
}

#message[hidden],
#score-form[hidden],
#home-panel[hidden],
#help-panel[hidden],
#pause-panel[hidden],
#analytics-consent[hidden],
#ad-home[hidden],
#ad-post-match[hidden],
#quick-rematch[hidden] {
  display: none;
}

#message h1 {
  margin: 0;
  font-size: clamp(36px, 6vw, 64px);
}

#message p {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

#score-form {
  display: grid;
  gap: 8px;
  justify-items: center;
  font-weight: 700;
}

#home-panel,
#help-panel {
  display: grid;
  gap: 8px;
  justify-items: stretch;
  width: min(360px, 86vw);
  margin: 0 auto;
  text-align: left;
  font-weight: 700;
}

#home-panel label {
  font-size: 13px;
  text-transform: uppercase;
}

.ad-placement {
  width: min(360px, 86vw);
  min-height: 58px;
  margin: 4px auto 0;
  padding-top: 13px;
  position: relative;
  border-top: 1px solid rgba(32,32,34,0.4);
}

.ad-label {
  position: absolute;
  top: 1px;
  left: 0;
  color: rgba(32,32,34,0.72);
  font: 700 9px/1 Arial, Helvetica, sans-serif;
  text-transform: uppercase;
}

.ad-mount {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 50px;
  overflow: hidden;
}

#home-panel select {
  width: 100%;
  border: 2px solid var(--panel-border);
  background: #fffdf0;
  color: var(--ink);
  padding: 7px 9px;
  font: inherit;
  font-weight: 700;
  box-shadow: 2px 3px 0 rgba(0,0,0,0.18);
}

#home-panel label[for="pitch-select"],
#pitch-select {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#pitch-previews {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

#message .pitch-preview {
  position: relative;
  min-width: 0;
  aspect-ratio: 1.2;
  padding: 0;
  overflow: hidden;
  border: 3px solid #242724;
  border-radius: 5px;
  background: #64b96f;
  box-shadow: none;
  cursor: pointer;
  width: 100%;
  margin: 0;
}

#message .pitch-preview::before {
  content: "";
  position: absolute;
  inset: 10% 25%;
  border: 2px solid rgba(255,255,255,0.82);
}

#message .pitch-preview::after {
  content: attr(data-short-name);
  position: absolute;
  inset: auto 0 0;
  padding: 3px 2px;
  background: rgba(30,32,30,0.82);
  color: #fff;
  font-size: 9px;
  text-transform: none;
}

#message .pitch-preview[data-pitch="canoe-lake"] {
  background: linear-gradient(90deg, #4384bd 0 22%, #b8ad97 22% 31%, #64b96f 31%);
}

#message .pitch-preview[data-pitch="southsea-beach"] {
  background: linear-gradient(90deg, #666b6e 0 16%, #d4c39f 16% 84%, #3c91bf 84%);
}

#message .pitch-preview[data-pitch="albert-road"] {
  background: linear-gradient(90deg, #9f6759 0 15%, #b5b5af 15% 23%, #686c6f 23% 77%, #b5b5af 77% 85%, #9f6759 85%);
}

#message .pitch-preview[data-pitch="school-playground"] {
  background:
    linear-gradient(90deg, transparent 46%, #d65a4a 46% 48%, #e1a943 48% 50%, #58a980 50% 52%, #4c83ae 52% 54%, transparent 54%),
    repeating-linear-gradient(0deg, transparent 0 17px, rgba(239, 235, 219, 0.45) 17px 18px),
    #777570;
}

#message .pitch-preview.is-selected {
  border-color: #f2cf36;
  box-shadow: 0 0 0 2px #202022, inset 0 0 0 2px #f2cf36;
}

.pitch-selected-icon {
  position: absolute;
  z-index: 2;
  top: 3px;
  right: 3px;
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border: 2px solid #202022;
  border-radius: 50%;
  background: #f2cf36;
  color: #202022;
  font: 900 13px/1 Arial, sans-serif;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 100ms ease, transform 100ms ease;
}

.pitch-preview.is-selected .pitch-selected-icon {
  opacity: 1;
  transform: scale(1);
}

.check-row {
  display: flex;
  gap: 9px;
  align-items: center;
  text-transform: none;
}

.check-row input {
  width: 20px;
  height: 20px;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  padding: 6px 8px;
  border: 2px solid rgba(32,32,34,0.35);
  background: rgba(255,253,240,0.58);
}

.option-grid label {
  display: grid;
  gap: 4px;
  align-content: center;
  font-size: 11px;
}

.option-grid .check-row {
  display: flex;
}

.option-grid select {
  padding: 5px 6px;
}

.option-grid input[type="range"] {
  width: 100%;
  accent-color: #235ed0;
}

.option-grid output {
  float: right;
}

.menu-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 4px;
}

.policy-links {
  display: flex;
  gap: 14px;
  justify-content: center;
  font-size: 12px;
  text-transform: none;
}

.policy-links a {
  color: #174f80;
  font-weight: 800;
}

#help-panel {
  width: min(680px, 92vw);
  gap: 12px;
}

.help-players {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.control-card {
  display: grid;
  grid-template-columns: 106px minmax(0, 1fr);
  gap: 12px 16px;
  align-items: center;
  margin: 0;
  padding: 14px;
  border: 2px solid var(--panel-border);
  border-radius: 6px;
  background: rgba(255, 253, 240, 0.96);
  box-shadow: 3px 4px 0 rgba(0,0,0,0.2);
}

.control-card h2 {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 17px;
  text-transform: uppercase;
}

.team-dot {
  width: 14px;
  height: 14px;
  border: 2px solid var(--ink);
  border-radius: 50%;
}

.team-dot-home {
  background: #2f6fd0;
}

.team-dot-away {
  background: #d84a4a;
}

.control-move {
  display: grid;
  gap: 5px;
  justify-items: center;
  font-size: 12px;
  text-transform: uppercase;
}

.key-cluster {
  display: grid;
  grid-template-columns: repeat(3, 30px);
  grid-template-rows: repeat(2, 30px);
  gap: 3px;
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border: 2px solid #181a17;
  border-bottom-width: 4px;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font: 800 14px/1 Arial, Helvetica, sans-serif;
  box-shadow: 0 1px 0 rgba(0,0,0,0.15);
}

.key-up {
  grid-column: 2;
}

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

.key-down {
  grid-column: 2;
  grid-row: 2;
}

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

.control-actions {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.control-actions li {
  display: grid;
  grid-template-columns: 22px 32px minmax(0, 1fr);
  gap: 7px;
  align-items: center;
  font-size: 13px;
}

.action-icon {
  font-size: 21px;
  line-height: 1;
  text-align: center;
}

.action-icon-target {
  font-size: 24px;
}

.help-tip {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 14px;
}

.help-tip > span {
  font-size: 22px;
}

@media (max-width: 620px), (max-height: 590px) {
  #help-panel {
    width: min(380px, 92vw);
  }

  .help-players {
    grid-template-columns: 1fr;
  }

  .control-card {
    grid-template-columns: 92px minmax(0, 1fr);
    padding: 9px 11px;
    gap: 7px 12px;
  }

  .key-cluster {
    grid-template-columns: repeat(3, 26px);
    grid-template-rows: repeat(2, 26px);
  }

  kbd {
    min-width: 26px;
    height: 26px;
    font-size: 12px;
  }
}

.name-row {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

#score-name {
  width: min(220px, 68vw);
  border: 2px solid var(--panel-border);
  background: #fffdf0;
  color: var(--ink);
  padding: 9px 10px;
  font: inherit;
  font-weight: 700;
  text-align: center;
  box-shadow: 2px 3px 0 rgba(0,0,0,0.18);
}

#message button {
  margin: 0 auto;
  border: 2px solid var(--panel-border);
  background: var(--panel);
  color: #fff;
  box-shadow: 2px 3px 0 rgba(0,0,0,0.24);
}

#message #score-submit {
  margin: 0;
}

#message #quick-rematch {
  margin-top: -4px;
  background: #e5c34f;
  color: #202022;
}

#pause-panel {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-content: center;
  gap: 20px;
  background: rgba(22,24,21,0.84);
  color: #fff;
  text-align: center;
}

#pause-panel h1 {
  margin: 0;
  font-size: 54px;
}

.pause-actions {
  display: flex;
  gap: 10px;
}

.pause-actions button {
  border: 2px solid #11140f;
  background: #fffdf0;
  color: #202022;
  padding: 11px 16px;
  font: 700 16px Arial, Helvetica, sans-serif;
  box-shadow: 3px 4px 0 rgba(0,0,0,0.32);
  cursor: pointer;
}

#analytics-consent {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(22,24,21,0.84);
}

.consent-dialog {
  width: min(520px, 92vw);
  padding: 20px;
  border: 3px solid var(--panel-border);
  border-radius: 6px;
  background: #fffdf0;
  box-shadow: 5px 7px 0 rgba(0,0,0,0.34);
}

.consent-dialog h1 {
  margin: 0 0 10px;
  font-size: 28px;
}

.consent-dialog p {
  margin: 8px 0;
  line-height: 1.35;
}

#analytics-consent-status {
  font-weight: 800;
}

.consent-dialog ul {
  margin: 12px 0 16px;
  padding-left: 22px;
  line-height: 1.45;
}

.consent-dialog .policy-links {
  justify-content: flex-start;
  margin: 0 0 16px;
  font-size: 14px;
}

.consent-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.consent-actions button {
  min-height: 42px;
  padding: 9px 13px;
  border: 2px solid var(--panel-border);
  background: var(--panel);
  color: #fff;
  font: 700 14px Arial, Helvetica, sans-serif;
  box-shadow: 2px 3px 0 rgba(0,0,0,0.24);
  cursor: pointer;
}

#analytics-reject {
  background: #fff;
  color: var(--ink);
}

#analytics-close {
  margin-left: auto;
  background: #e5c34f;
  color: var(--ink);
}

#touch-controls,
#fullscreen-toggle {
  display: none;
}

#game-shell:fullscreen,
#game-shell:-webkit-full-screen {
  width: 100vw;
  height: 100dvh;
  max-height: none;
  border: 0;
  aspect-ratio: auto;
}

body.viewport-play-mode {
  overflow: hidden;
}

body.viewport-play-mode #game-shell {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  max-height: none;
  border: 0;
  aspect-ratio: auto;
  box-shadow: none;
}

@media (hover: none), (pointer: coarse) {
  html,
  body,
  #game-shell,
  #game {
    touch-action: none;
  }

  html,
  body {
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body {
    display: block;
    background: var(--grass);
  }

  #game-shell {
    width: 100vw;
    height: 100dvh;
    max-height: none;
    border: 0;
    aspect-ratio: auto;
    box-shadow: none;
  }

  #scoreboard {
    display: none;
  }

  #fullscreen-toggle {
    position: absolute;
    top: calc(64px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    z-index: 5;
    display: block;
    min-width: 64px;
    height: 42px;
    border: 2px solid rgba(17,20,15,0.82);
    background: rgba(37,40,36,0.72);
    color: #fff;
    font: 900 16px Arial, Helvetica, sans-serif;
    box-shadow: 2px 3px 0 rgba(0,0,0,0.26);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  #touch-controls {
    position: absolute;
    inset: auto calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
    z-index: 5;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
  }

  .touch-pad {
    pointer-events: auto;
  }

  .touch-pad-left {
    width: 184px;
    height: 184px;
    display: grid;
    place-items: center;
  }

  .touch-joystick {
    position: relative;
    width: 172px;
    height: 172px;
    padding: 0;
    box-sizing: border-box;
    border: 4px solid rgba(17,20,15,0.82);
    border-radius: 50%;
    background: rgba(37,40,36,0.62);
    box-shadow: 4px 6px 0 rgba(0,0,0,0.28), inset 0 0 0 3px rgba(255,255,255,0.12);
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .touch-joystick.is-active {
    cursor: grabbing;
    border-color: rgba(242,207,54,0.94);
  }

  .touch-joystick-guide {
    position: absolute;
    inset: 28px;
    border: 2px solid rgba(255,255,255,0.18);
    border-radius: 50%;
    pointer-events: none;
  }

  .touch-joystick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 72px;
    height: 72px;
    margin: -36px 0 0 -36px;
    border: 3px solid rgba(17,20,15,0.9);
    border-radius: 50%;
    box-sizing: border-box;
    background: rgba(239,240,231,0.92);
    box-shadow: 3px 4px 0 rgba(0,0,0,0.3), inset 0 0 0 7px rgba(37,40,36,0.14);
    transform: translate(var(--stick-x, 0px), var(--stick-y, 0px));
    transition: transform 90ms ease-out;
    will-change: transform;
    pointer-events: none;
  }

  .touch-joystick.is-active .touch-joystick-knob {
    background: rgba(242,207,54,0.96);
    transition: none;
  }

  .touch-pad-right {
    display: grid;
    grid-template-columns: repeat(2, 82px);
    grid-template-rows: 50px 72px;
    gap: 9px;
    justify-items: center;
  }

  .touch-pad-right .touch-button-small {
    grid-column: 1 / -1;
  }

  .touch-button {
    width: 66px;
    height: 58px;
    border: 3px solid rgba(17,20,15,0.82);
    background: rgba(37,40,36,0.68);
    color: #fff;
    font: 900 26px Arial, Helvetica, sans-serif;
    box-shadow: 3px 4px 0 rgba(0,0,0,0.26);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .touch-button:active,
  .touch-button.is-pressed {
    transform: translate(2px, 3px);
    box-shadow: 1px 1px 0 rgba(0,0,0,0.28);
    background: rgba(229,195,79,0.76);
  }

  .touch-button-small {
    width: 58px;
    height: 50px;
    font-size: 22px;
  }

  .touch-button-action {
    width: 82px;
    height: 70px;
    font-size: 17px;
  }

  #message {
    z-index: 6;
  }

  #pause-button {
    pointer-events: auto;
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  #touch-controls {
    inset-inline: calc(8px + env(safe-area-inset-left)) calc(8px + env(safe-area-inset-right));
  }

  .touch-pad-left {
    width: 154px;
    height: 154px;
  }

  .touch-joystick {
    width: 146px;
    height: 146px;
  }

  .touch-joystick-guide {
    inset: 24px;
  }

  .touch-joystick-knob {
    width: 64px;
    height: 64px;
    margin: -32px 0 0 -32px;
  }

  .touch-button {
    width: 56px;
    height: 52px;
  }

  .touch-pad-right {
    grid-template-columns: repeat(2, 70px);
  }

  .touch-button-action {
    width: 70px;
  }
}

@media (pointer: coarse) and (max-width: 380px) {
  #touch-controls {
    inset-inline: calc(6px + env(safe-area-inset-left)) calc(6px + env(safe-area-inset-right));
  }

  .touch-pad-left {
    width: 138px;
    height: 138px;
  }

  .touch-joystick {
    width: 132px;
    height: 132px;
  }

  .touch-joystick-guide {
    inset: 22px;
  }

  .touch-joystick-knob {
    width: 58px;
    height: 58px;
    margin: -29px 0 0 -29px;
  }

  .touch-pad-right {
    grid-template-columns: repeat(2, 64px);
    gap: 7px;
  }

  .touch-button-action {
    width: 64px;
    font-size: 15px;
  }
}

@media (max-width: 720px) {
  #hud {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .brand {
    font-size: 15px;
  }

  #scoreboard {
    top: auto;
    bottom: 12px;
    width: 160px;
  }
}
