:root {
  --bg: #07130d;
  --panel: #102018ee;
  --gold: #ffd166;
  --mint: #87f5b5;
  --line: #dfffe9;
  --danger: #ef476f;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at top, #173b29, #07130d 60%);
  color: #f2fff6;
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  background: #1f8f57;
  color: white;
  font-weight: 900;
  letter-spacing: .04em;
  box-shadow: 0 4px 0 #0a4d2c;
  cursor: pointer;
}

button:hover,
button:focus { filter: brightness(1.12); }
button.secondary { background: #29443a; box-shadow: 0 4px 0 #14251f; }
button.danger { background: #b83255; box-shadow: 0 4px 0 #63172b; }
.smallBtn { min-height: 44px; padding: 8px 12px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; max-width: 1160px; margin: 0 auto; background: linear-gradient(180deg, #0b2118dd, #07130d55); border-bottom: 1px solid #7bf0a533; }
.topbar > div:first-child { position: relative; padding-left: 60px; }
.topbar > div:first-child::before { content: '⚽'; position: absolute; left: 0; top: 50%; width: 46px; height: 46px; transform: translateY(-50%); display: grid; place-items: center; border-radius: 14px; background: radial-gradient(circle at 60% 35%, #fff, #7bf0a5 38%, #0b2a1d 40%); border: 1px solid #89f5b566; box-shadow: inset 0 0 18px #0008, 0 8px 20px #0008; }
.topbar strong { font-size: clamp(18px, 3vw, 30px); text-shadow: 0 2px 0 #000; }
.topbar span { display: block; color: #9bd9b7; font-size: 14px; font-weight: 700; }
.topActions { display: flex; gap: 8px; align-items: center; }
.topActions button { background: linear-gradient(180deg, #16392a, #0b2118); border: 1px solid #89f5b555; box-shadow: inset 0 1px 0 #ffffff22, 0 4px 0 #06130d; }
#gameShell { min-height: 100%; display: flex; flex-direction: column; }

#stage {
  position: relative;
  width: min(100vw, 1160px);
  margin: 0 auto;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}

canvas {
  width: 100%;
  max-height: calc(100vh - 74px);
  aspect-ratio: 16 / 9;
  background: #165f33;
  border: 3px solid #dfffe9;
  border-radius: 18px;
  box-shadow: 0 18px 60px #0008;
  display: block;
}

#uiLayer {
  position: absolute;
  inset: 16px;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card {
  pointer-events: auto;
  max-width: 960px;
  max-height: calc(100vh - 110px);
  overflow: auto;
  background: linear-gradient(180deg, #14251fee, #0b1712f5);
  border: 2px solid #3da86d;
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 14px 50px #000b;
  user-select: text;
}

.title { font-size: clamp(30px, 6vw, 66px); margin: 0; color: var(--gold); text-shadow: 3px 3px #000; }
.subtitle { margin-top: 0; color: #b8dcc8; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.team,
.upgrade,
.statBox { background: #183528; border: 1px solid #3b8b60; border-radius: 16px; padding: 14px; }
.team h3,
.upgrade h3 { margin: .1rem 0; color: var(--mint); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.menuBtns { display: grid; gap: 12px; max-width: 380px; }
.pill { display: inline-block; padding: 4px 9px; border-radius: 999px; background: #254b3a; color: #c8ffe0; margin: 2px; }
.scoreHud { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); min-width: min(620px, calc(100vw - 130px)); background: linear-gradient(180deg, #061610ee, #091f17e8); border: 1px solid #9cffbd66; border-radius: 20px; padding: 10px 16px; font-weight: 900; text-align: center; box-shadow: inset 0 1px 0 #ffffff1c, 0 12px 34px #0009; backdrop-filter: blur(8px); }
.scoreMain { display: grid; grid-template-columns: 42px 1fr auto 1fr 42px; gap: 10px; align-items: center; }
.teamCrest { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; font-size: 9px; color: #fff; text-shadow: 0 1px 2px #000; border: 2px solid #fff8; background: linear-gradient(135deg, var(--crest-a), var(--crest-b)); box-shadow: inset 0 0 0 2px #0005; }
.teamCode { font-size: 24px; letter-spacing: .05em; }
.scoreText { min-width: 118px; font-size: 42px; line-height: 1; color: white; text-shadow: 0 3px 0 #000; }
.scoreMeta { display: flex; justify-content: center; gap: 14px; padding-top: 8px; margin-top: 8px; border-top: 1px solid #cfffff22; color: #d8ffea; font-size: 12px; text-transform: uppercase; }
.scoreConditions { margin-top: 4px; color: #9ccdb0; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pauseBtn { pointer-events: auto; position: absolute; top: 10px; right: 10px; display: grid; gap: 2px; place-items: center; min-width: 86px; min-height: 76px; background: linear-gradient(180deg, #2fc96c, #0d623a); border: 1px solid #a6ffc4aa; border-radius: 22px; box-shadow: inset 0 2px 0 #ffffff35, 0 6px 0 #06361f, 0 16px 34px #0008; text-transform: uppercase; }
.pauseIcon { font-size: 30px; line-height: .8; }
.floatLog { position: absolute; left: 20px; bottom: 20px; display: grid; gap: 0; width: min(390px, 45vw); pointer-events: none; border: 1px solid #63e89b55; border-radius: 16px; overflow: hidden; background: #061610d9; box-shadow: 0 14px 34px #0008; }
.logRow { display: grid; grid-template-columns: 54px 28px 1fr 42px; gap: 8px; align-items: center; padding: 8px 10px; border-bottom: 1px solid #ffffff12; font-weight: 800; }
.logRow:last-child { border-bottom: 0; }
.logTime { color: #8ff0af; font-variant-numeric: tabular-nums; }
.logIcon { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: #ffffff12; color: #fff; }
.logText { color: #f1fff7; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logSide { color: #b48cff; font-size: 11px; }
.logRow.goal .logIcon { background: #ffffff; color: #09130d; }
.logRow.card .logIcon, .logRow.foul .logIcon { background: #ef476f; }


#touchControls { display: none; position: absolute; inset: 0; pointer-events: none; touch-action: none; }
#stick { position: absolute; left: 28px; bottom: 28px; width: 158px; height: 158px; border-radius: 50%; background: radial-gradient(circle, #102920 0 32%, #0b1a17cc 33% 70%, #152c36ee); border: 2px solid #cfffff33; pointer-events: auto; touch-action: none; box-shadow: inset 0 0 24px #000c, 0 12px 34px #000a; }
#stick::before { content: '▲  ◀  ▶  ▼'; position: absolute; inset: 18px; display: grid; place-items: center; color: #8ff0af; font-size: 21px; letter-spacing: 14px; opacity: .85; }
#stickKnob { position: absolute; left: 51px; top: 51px; width: 56px; height: 56px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #caffdf, #42c783 62%, #188653); border: 2px solid #baffd2; box-shadow: inset 0 -6px 10px #0003, 0 7px 18px #000b; }
#touchButtons { position: absolute; right: 22px; bottom: 22px; width: min(340px, 42vw); display: grid; grid-template-columns: 1fr; gap: 16px; pointer-events: auto; touch-action: none; }
#touchButtons button { min-height: 86px; border-radius: 24px; font-size: 22px; background: linear-gradient(180deg, #2d94ff, #075aac); border: 2px solid #91d7ff; box-shadow: inset 0 3px 0 #ffffff40, inset 0 -8px 18px #001c4a55, 0 6px 0 #03305d, 0 16px 30px #0008; text-shadow: 0 2px 0 #001d36; }
#touchButtons button:active { transform: translateY(4px); box-shadow: inset 0 2px 0 #ffffff30, 0 2px 0 #03305d, 0 8px 18px #0008; }
#touchButtons #contextBtn { background: linear-gradient(180deg, #ff4e77, #b5143f); border-color: #ffb3c5; box-shadow: inset 0 3px 0 #ffffff40, inset 0 -8px 18px #51001955, 0 6px 0 #6a0825, 0 16px 30px #0008; }


@media (pointer: coarse), (max-width: 800px) {
  #touchControls.playing { display: block; }
  .topbar { padding: 6px 10px; }
  #stage { padding: 2px; align-items: flex-start; }
  #stage.playing { padding-top: 122px; }
  #stage.playing canvas { max-height: calc(58vh - 86px); }
  canvas { max-height: 56vh; border-radius: 12px; }
  .card { max-height: calc(100vh - 80px); padding: 16px; }
  .scoreHud { min-width: min(430px, calc(100vw - 102px)); padding: 8px 10px; top: 6px; }
  .teamCode { font-size: 15px; } .scoreText { min-width: 72px; font-size: 28px; } .teamCrest { width: 30px; height: 30px; }
  .scoreMeta { gap: 7px; font-size: 10px; flex-wrap: wrap; } .scoreConditions { display: none; }
  .pauseBtn { right: 6px; top: 6px; min-width: 74px; min-height: 70px; border-radius: 18px; }
  .floatLog { left: 10px; bottom: 184px; width: min(350px, 46vw); font-size: 11px; } .logRow { grid-template-columns: 42px 22px 1fr; padding: 6px 8px; } .logSide { display: none; }
  #stick { left: 14px; bottom: 14px; width: 134px; height: 134px; }
  #stickKnob { left: 42px; top: 42px; width: 50px; height: 50px; }
  #touchButtons { width: min(260px, 42vw); right: 10px; bottom: 10px; } #touchButtons button { min-height: 76px; font-size: 17px; }
  .grid { grid-template-columns: 1fr; }
}

@media (orientation: landscape) and (pointer: coarse) {
  #stage.playing { padding-top: 60px; }
  #stage.playing canvas { max-height: calc(100vh - 118px); height: calc(100vh - 124px); }
  canvas { max-height: calc(100vh - 52px); width: auto; height: calc(100vh - 58px); }
  #touchButtons { width: 220px; }
  #stick { bottom: 18px; }
  .floatLog { bottom: 20px; }
}

.penalty { text-align: center; }
.aimBar { position: relative; height: 34px; border-radius: 999px; background: linear-gradient(90deg,#ef476f,#ffd166 35%,#87f5b5 46%,#87f5b5 54%,#ffd166 65%,#ef476f); border: 2px solid #fff; margin: 14px 0; }
.aimBar span { position: absolute; top: -8px; width: 5px; height: 48px; background: #07130d; border: 1px solid white; transform: translateX(-50%); }
.aimBar b { position: absolute; inset: 8px 46%; border: 2px solid #07130d; border-radius: 999px; }
body.high-contrast { --bg: #000; --panel: #000; --gold: #fff000; --mint: #00ff99; --line: #fff; background: #000; color: #fff; }
body.high-contrast canvas { border-color: #fff; filter: contrast(1.25) saturate(1.25); }
body.high-contrast .card, body.high-contrast .statBox, body.high-contrast .team, body.high-contrast .upgrade, body.high-contrast .scoreHud, body.high-contrast .floatLog { background: #020202f5; border-color: #fff; color: #fff; }
body.large-controls #stick { width: 184px; height: 184px; }
body.large-controls #stickKnob { left: 60px; top: 60px; width: 64px; height: 64px; }
body.large-controls #touchButtons { width: min(380px, 52vw); gap: 18px; }
body.large-controls #touchButtons button { min-height: 100px; font-size: 24px; }
body.reduced-motion *, body.reduced-motion *::before, body.reduced-motion *::after { scroll-behavior: auto !important; }
