:root {
  color-scheme: dark;
  --bg: #070914;
  --panel: #101624;
  --panel-2: #151d2e;
  --line: #263754;
  --text: #edf7ff;
  --muted: #9db3c7;
  --cyan: #2df7ff;
  --green: #6dff8f;
  --pink: #ff4dd8;
  --amber: #ffd166;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Arial, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background:
    radial-gradient(circle at 18% 18%, rgba(45, 247, 255, 0.18), transparent 24rem),
    radial-gradient(circle at 88% 74%, rgba(255, 77, 216, 0.14), transparent 22rem),
    linear-gradient(145deg, #050711 0%, #0a1021 55%, #07121a 100%);
  color: var(--text);
  overflow-x: hidden;
}

button,
a {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

a {
  text-decoration: none;
}

.app-shell {
  width: min(1100px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(300px, 720px);
  gap: 24px;
  justify-content: center;
  align-items: center;
  padding: 28px 0;
}

.game-panel {
  border: 1px solid rgba(45, 247, 255, 0.25);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(16, 22, 36, 0.94), rgba(8, 13, 24, 0.96));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45), inset 0 0 36px rgba(45, 247, 255, 0.05);
  padding: clamp(16px, 3vw, 24px);
}

.game-nav {
  margin-bottom: 18px;
}

.game-nav a {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid rgba(45, 247, 255, 0.25);
  border-radius: 8px;
  color: var(--cyan);
  background: rgba(7, 12, 22, 0.72);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--cyan);
  font-size: 0.78rem;
  letter-spacing: 0;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.2rem);
  line-height: 0.95;
}

.stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stats div {
  min-width: 76px;
  padding: 10px 12px;
  border: 1px solid rgba(109, 255, 143, 0.28);
  border-radius: 8px;
  background: rgba(7, 12, 22, 0.8);
}

.stats span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.stats strong {
  color: var(--green);
  font-size: 1.4rem;
}

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid rgba(45, 247, 255, 0.4);
  border-radius: 8px;
  overflow: hidden;
  background: #060a12;
  box-shadow: inset 0 0 42px rgba(45, 247, 255, 0.12), 0 0 30px rgba(45, 247, 255, 0.12);
  touch-action: none;
}

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

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 16px;
  text-align: center;
  background: rgba(3, 8, 15, 0.58);
  backdrop-filter: blur(5px);
}

.overlay.is-hidden {
  display: none;
}

.overlay p {
  margin: 0;
  font-size: clamp(1.6rem, 6vw, 3.8rem);
  font-weight: 800;
  color: var(--text);
  text-shadow: 0 0 18px rgba(45, 247, 255, 0.7);
}

#startButton,
.command {
  min-height: 44px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--cyan), #4f8cff);
  color: #03101a;
  font-weight: 800;
  box-shadow: 0 0 20px rgba(45, 247, 255, 0.26);
}

#startButton {
  padding: 0 28px;
}

.controls-row {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.command {
  flex: 1;
  padding: 0 18px;
}

.command:nth-child(2) {
  background: linear-gradient(135deg, var(--pink), var(--amber));
}

.touch-pad {
  align-self: center;
  display: grid;
  grid-template-columns: repeat(4, minmax(58px, 78px));
  grid-auto-rows: 56px;
  gap: 10px;
  justify-content: center;
  width: min(380px, 100%);
  margin: 0 auto;
  padding: 12px;
  border: 1px solid rgba(255, 77, 216, 0.25);
  border-radius: 8px;
  background: rgba(10, 16, 31, 0.74);
}

.pad-btn {
  border: 1px solid rgba(45, 247, 255, 0.35);
  border-radius: 8px;
  background: rgba(21, 29, 46, 0.92);
  color: var(--cyan);
  font-size: 1.5rem;
  font-weight: 800;
  box-shadow: inset 0 0 18px rgba(45, 247, 255, 0.08);
}

.pad-btn:active,
.command:active,
#startButton:active {
  transform: translateY(1px);
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    align-content: start;
    width: min(100vw - 16px, 680px);
    gap: 12px;
    padding: 10px 0 16px;
  }

  .game-panel {
    padding: 12px;
  }

  .game-nav {
    margin-bottom: 10px;
  }

  .topbar {
    align-items: start;
    margin-bottom: 12px;
  }

  .touch-pad {
    position: sticky;
    bottom: 8px;
    grid-template-columns: repeat(4, minmax(54px, 1fr));
    grid-auto-rows: 50px;
  }
}

@media (max-width: 520px) {
  .topbar {
    display: grid;
  }

  .stats {
    justify-content: stretch;
  }

  .stats div {
    flex: 1 1 76px;
  }

  .controls-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .board-wrap {
    width: min(100%, calc(100vh - 265px));
    min-width: min(100%, 330px);
    margin: 0 auto;
  }

  .pad-btn {
    font-size: 1.22rem;
  }
}
