:root {
  color-scheme: dark;
  --ink: #061310;
  --panel: #0b211b;
  --line: #295448;
  --text: #f4f7f1;
  --muted: #a5b8b0;
  --green: #36c98f;
  --blue: #2e9ed9;
  --red: #ed5c56;
  --yellow: #f4c34f;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
}

body {
  color: var(--text);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  letter-spacing: 0;
  touch-action: none;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
  font: inherit;
}

.game-app {
  display: grid;
  width: 100vw;
  height: 100dvh;
  grid-template-rows: 68px minmax(0, 1fr);
}

.topbar {
  z-index: 5;
  display: grid;
  min-width: 0;
  grid-template-columns: 44px minmax(140px, 1fr) auto minmax(168px, 1fr);
  align-items: center;
  gap: 16px;
  padding: 0 clamp(12px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: #081a16;
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid #315f53;
  border-radius: 6px;
  color: var(--text);
  background: #102b24;
  cursor: pointer;
}

.icon-button svg {
  width: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.header-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: end;
  gap: 8px;
}

.coin-counter,
.shop-balance {
  display: flex;
  height: 40px;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid #315f53;
  border-radius: 6px;
  background: #102b24;
  font-variant-numeric: tabular-nums;
}

.coin-counter span,
.shop-balance span {
  display: grid;
  width: 21px;
  height: 21px;
  place-items: center;
  border: 2px solid #fff2b9;
  border-radius: 50%;
  color: #4a3510;
  background: var(--yellow);
  font-size: 11px;
  font-weight: 1000;
}

.coin-counter strong {
  color: #ffe090;
  font-size: 14px;
}

.mute-line {
  display: none;
}

.icon-button.is-muted .sound-wave {
  display: none;
}

.icon-button.is-muted .mute-line {
  display: block;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.brand > span:last-child {
  display: grid;
}

.brand strong {
  overflow: hidden;
  font-size: 16px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
}

.brand-ball {
  width: 31px;
  height: 31px;
  flex: 0 0 auto;
  border: 4px solid #f5f7f2;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 48%, #16201d 0 20%, transparent 21%),
    conic-gradient(from 10deg, #f5f7f2, #cbd6d1, #f5f7f2);
  box-shadow: 0 0 0 2px #183f34;
}

.scoreboard {
  display: grid;
  min-width: 240px;
  grid-template-columns: 1fr 72px 1fr;
  align-items: center;
  border: 1px solid #326052;
  border-radius: 6px;
  background: #102b24;
}

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

.scoreboard strong {
  font-size: 23px;
  font-variant-numeric: tabular-nums;
}

.scoreboard small {
  color: var(--muted);
  font-size: 11px;
}

.scoreboard > span {
  padding: 8px 7px;
  border-right: 1px solid #326052;
  border-left: 1px solid #326052;
  color: var(--yellow);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.arena {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #167449;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.status-pill {
  position: absolute;
  top: 18px;
  left: 50%;
  z-index: 2;
  min-width: 78px;
  padding: 7px 14px;
  transform: translateX(-50%) translateY(-12px);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 5px;
  opacity: 0;
  color: #11241e;
  background: rgba(245, 247, 242, 0.94);
  font-size: 13px;
  font-weight: 900;
  text-align: center;
  transition: 180ms ease;
  pointer-events: none;
}

.status-pill.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.screen-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 16, 12, 0.76);
  backdrop-filter: blur(4px);
  transition: opacity 180ms ease;
}

.screen-layer.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.screen-content {
  width: min(570px, 100%);
  text-align: center;
}

.screen-content > p:first-child {
  margin: 0 0 10px;
  color: var(--yellow);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.screen-content h1 {
  margin: 0;
  font-size: clamp(40px, 8vw, 76px);
  line-height: 1;
}

.screen-content > p:nth-of-type(2) {
  margin: 14px 0 22px;
  color: #d5e1dc;
  font-size: 15px;
}

.key-guide {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
}

.key-guide span {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid #477a6b;
  border-radius: 5px;
  color: #d9e4df;
  background: rgba(8, 32, 25, 0.8);
  font-size: 12px;
}

kbd {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid #83b6a6;
  border-radius: 4px;
  color: #092119;
  background: #e9f1ed;
  font-family: inherit;
  font-weight: 900;
}

.primary-button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 22px;
  border: 0;
  border-radius: 6px;
  color: #071b15;
  background: var(--green);
  box-shadow: 0 5px 0 #177c55;
  font-weight: 900;
  cursor: pointer;
}

.primary-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #177c55;
}

.primary-button svg {
  width: 19px;
  fill: currentColor;
}

.match-result {
  display: flex;
  justify-content: center;
  gap: 34px;
  margin: 0 0 22px;
}

.match-result div {
  display: grid;
  gap: 3px;
}

.match-result small {
  color: var(--muted);
  font-size: 11px;
}

.match-result strong {
  font-size: 24px;
}

.result-coins {
  color: var(--yellow);
}

.shop-layer {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(2, 12, 9, 0.8);
  backdrop-filter: blur(5px);
}

.shop-layer[hidden] {
  display: none;
}

.shop-panel {
  display: grid;
  width: min(820px, 100%);
  max-height: min(720px, calc(100dvh - 110px));
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid #44786a;
  border-radius: 7px;
  background: #0a211b;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.42);
}

.shop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 17px 18px;
  border-bottom: 1px solid #31584e;
  background: #102b24;
}

.shop-header small {
  color: var(--yellow);
  font-size: 10px;
  font-weight: 900;
}

.shop-header h2 {
  margin: 2px 0 0;
  font-size: 22px;
}

.shop-tools {
  display: flex;
  align-items: center;
  gap: 9px;
}

.shop-balance {
  height: 38px;
}

.shop-balance strong {
  min-width: 28px;
  color: #ffe090;
  text-align: right;
}

.close-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid #477468;
  border-radius: 6px;
  color: #e8f0ec;
  background: #173930;
  cursor: pointer;
}

.close-button svg {
  width: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.shop-copy {
  margin: 0;
  padding: 12px 18px;
  border-bottom: 1px solid #294d43;
  color: var(--muted);
  font-size: 12px;
}

.keeper-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 11px;
  overflow: auto;
  padding: 14px;
}

.keeper-card {
  position: relative;
  display: grid;
  min-width: 0;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid #315c50;
  border-radius: 7px;
  background: #102a23;
}

.keeper-card.is-selected {
  border-color: var(--yellow);
  box-shadow: inset 0 0 0 1px rgba(244, 195, 79, 0.45);
}

.keeper-avatar {
  position: relative;
  display: grid;
  width: 54px;
  height: 64px;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  background: var(--keeper-color);
}

.keeper-avatar::before {
  position: absolute;
  top: 8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #e7ad86;
  content: "";
}

.keeper-avatar::after {
  position: absolute;
  right: 8px;
  bottom: -8px;
  left: 8px;
  height: 39px;
  border-radius: 8px 8px 0 0;
  background: rgba(7, 26, 21, 0.48);
  content: "";
}

.keeper-avatar strong {
  z-index: 1;
  margin-top: 27px;
  color: #fff;
  font-size: 14px;
}

.keeper-info {
  min-width: 0;
}

.keeper-info h3 {
  overflow: hidden;
  margin: 1px 0 2px;
  font-size: 14px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.keeper-info > span {
  color: var(--muted);
  font-size: 10px;
}

.keeper-stats {
  display: grid;
  gap: 4px;
  margin-top: 8px;
}

.keeper-stat {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 22px;
  align-items: center;
  gap: 5px;
  color: #b8c9c2;
  font-size: 9px;
}

.keeper-stat i {
  height: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: #29483f;
}

.keeper-stat i::after {
  display: block;
  width: var(--stat-value);
  height: 100%;
  background: var(--green);
  content: "";
}

.keeper-action {
  grid-column: 1 / -1;
  min-height: 34px;
  margin-top: 2px;
  border: 1px solid #497d6e;
  border-radius: 5px;
  color: #092119;
  background: var(--green);
  font-size: 11px;
  font-weight: 900;
  cursor: pointer;
}

.keeper-action.is-owned {
  color: #eff5f2;
  background: #1c4b3f;
}

.keeper-action:disabled {
  border-color: #5e6b67;
  color: #9eaaa6;
  background: #283632;
  cursor: default;
}

.mobile-controls {
  position: absolute;
  right: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 0;
  z-index: 2;
  display: flex;
  align-items: end;
  justify-content: space-between;
  padding: 0 clamp(14px, 4vw, 46px);
  pointer-events: none;
}

.direction-pad,
.action-pad {
  pointer-events: auto;
}

.direction-pad {
  position: relative;
  width: 152px;
  height: 152px;
}

.move-button,
.action-button {
  position: absolute;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.38);
  color: #fff;
  background: rgba(5, 28, 21, 0.68);
  backdrop-filter: blur(3px);
  cursor: pointer;
  user-select: none;
}

.move-button {
  width: 52px;
  height: 52px;
  border-radius: 7px;
}

.move-button svg {
  width: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.move-button.up {
  top: 0;
  left: 50px;
}

.move-button.left {
  top: 50px;
  left: 0;
}

.move-button.down {
  top: 100px;
  left: 50px;
}

.move-button.right {
  top: 50px;
  left: 100px;
}

.action-pad {
  position: relative;
  width: 184px;
  height: 164px;
}

.action-button {
  width: 66px;
  height: 66px;
  align-content: center;
  border-radius: 50%;
}

.action-button strong,
.action-button small {
  display: block;
  line-height: 1;
}

.action-button strong {
  font-size: 20px;
}

.action-button small {
  margin-top: 4px;
  font-size: 9px;
  font-weight: 800;
}

.action-button.shoot {
  top: 0;
  right: 0;
  background: rgba(231, 79, 72, 0.82);
}

.action-button.dribble {
  right: 76px;
  bottom: 0;
  background: rgba(45, 151, 211, 0.82);
}

.action-button.skill {
  top: 16px;
  left: 0;
  background: rgba(232, 172, 52, 0.85);
}

.action-button.tackle {
  right: 0;
  bottom: 0;
  background: rgba(36, 155, 109, 0.86);
}

.move-button.is-active,
.action-button.is-active {
  transform: scale(0.91);
  filter: brightness(1.3);
}

@media (hover: hover) and (pointer: fine) {
  .mobile-controls {
    opacity: 0.38;
  }

  .mobile-controls:hover {
    opacity: 1;
  }
}

@media (max-width: 680px) {
  .game-app {
    grid-template-rows: 58px minmax(0, 1fr);
  }

  .topbar {
    grid-template-columns: 38px minmax(60px, 1fr) auto minmax(84px, 1fr);
    gap: 7px;
    padding: 0 8px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .brand-ball,
  .brand small {
    display: none;
  }

  .brand strong {
    font-size: 13px;
  }

  .header-actions {
    gap: 5px;
  }

  .header-actions .icon-button {
    width: 34px;
  }

  .coin-counter {
    height: 36px;
    gap: 4px;
    padding: 0 7px;
  }

  .coin-counter span {
    width: 18px;
    height: 18px;
    font-size: 9px;
  }

  .coin-counter strong {
    font-size: 11px;
  }

  .scoreboard {
    min-width: 164px;
    grid-template-columns: 1fr 55px 1fr;
  }

  .scoreboard small {
    display: none;
  }

  .scoreboard strong {
    font-size: 19px;
  }

  .scoreboard > span {
    padding: 7px 3px;
    font-size: 11px;
  }

  .mobile-controls {
    padding: 0 10px;
  }

  .direction-pad {
    width: 130px;
    height: 130px;
  }

  .move-button {
    width: 46px;
    height: 46px;
  }

  .move-button.up {
    left: 42px;
  }

  .move-button.left {
    top: 42px;
  }

  .move-button.down {
    top: 84px;
    left: 42px;
  }

  .move-button.right {
    top: 42px;
    left: 84px;
  }

  .action-pad {
    width: 150px;
    height: 136px;
  }

  .action-button {
    width: 57px;
    height: 57px;
  }

  .action-button.dribble {
    right: 62px;
  }

  .action-button strong {
    font-size: 17px;
  }

  .shop-layer {
    padding: 8px;
  }

  .shop-panel {
    max-height: calc(100dvh - 72px);
  }

  .shop-header {
    padding: 11px 12px;
  }

  .shop-header h2 {
    font-size: 18px;
  }

  .shop-copy {
    padding: 8px 12px;
    font-size: 10px;
  }

  .keeper-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 9px;
  }
}

@media (max-height: 580px) {
  .mobile-controls {
    bottom: 8px;
  }

  .direction-pad {
    transform: scale(0.82);
    transform-origin: left bottom;
  }

  .action-pad {
    transform: scale(0.82);
    transform-origin: right bottom;
  }

  .screen-content h1 {
    font-size: 39px;
  }

  .screen-content > p:nth-of-type(2) {
    margin: 8px 0 12px;
  }

  .key-guide {
    margin-bottom: 15px;
  }

  .shop-panel {
    max-height: calc(100dvh - 76px);
  }

  .keeper-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .keeper-card {
    grid-template-columns: 42px minmax(0, 1fr);
    padding: 8px;
  }

  .keeper-avatar {
    width: 42px;
    height: 54px;
  }
}
