:root {
  --bg: #121820;
  --panel: #1e2a38;
  --text: #eef3f8;
  --muted: #9aabbd;
  --accent: #f0c040;
  --line: #2c3c4f;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body, #app {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  height: 100%;
  height: 100dvh;
}
html, body {
  background: var(--bg); color: var(--text);
  overflow: hidden; touch-action: none;
}
#app {
  display: flex; flex-direction: column;
  /* 桌面略收，避免寬螢幕把球場壓成細長條；高度主導 */
  max-width: min(560px, 100vw); margin: 0 auto;
}
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0; z-index: 5;
}
#topbar h1 {
  margin: 0; font-size: 1.1rem; color: var(--accent); letter-spacing: 0.06em;
}
#top-actions { display: flex; gap: 0.35rem; }
#main {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
}
#hud {
  padding: 0.4rem 0.75rem 0.15rem;
  text-align: center; flex-shrink: 0;
  background: #161d27;
  border-bottom: 1px solid var(--line);
}
#hud.hidden { display: none; }
#hud .score {
  font-size: 1.35rem; font-weight: 800; color: var(--accent);
}
#hud .sub { font-size: 0.8rem; color: var(--muted); margin-top: 0.1rem; }

#game-wrap {
  flex: 1; min-height: 0; background: #0d1218;
  display: flex; flex-direction: column;
}
#court-stage {
  flex: 1 1 auto; min-height: 200px; position: relative; width: 100%;
  display: flex; align-items: stretch; justify-content: center;
  background: #0d1218;
  overflow: hidden;
  contain: layout paint;
}
#court {
  display: block; width: 100%; height: 100%;
  max-width: 100%;
  touch-action: none;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  backface-visibility: hidden;
}

#toast {
  position: absolute; left: 50%; top: 10%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.75); color: #fff;
  padding: 0.4rem 0.85rem; border-radius: 999px;
  font-size: 0.88rem; opacity: 0; pointer-events: none;
  transition: opacity 0.2s; z-index: 3; white-space: nowrap;
}
#toast.show { opacity: 1; }

button {
  font: inherit; border: 1px solid var(--line);
  background: #243040; color: var(--text);
  border-radius: 8px; padding: 0.45rem 0.75rem; cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:hover { filter: brightness(1.08); }
button.primary {
  background: var(--accent); color: #1a1508;
  border-color: transparent; font-weight: 700;
}
button.ghost { background: transparent; }
button.wide { width: 100%; margin-top: 0.45rem; }

.overlay {
  position: fixed; inset: 0;
  background: rgba(8,12,18,0.8);
  display: flex; align-items: center; justify-content: center;
  z-index: 20; padding: 1rem;
  touch-action: manipulation;
}
.overlay.hidden, .hidden { display: none !important; }
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 1.25rem 1.4rem;
  width: min(360px, 100%);
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
}
.panel.wide-panel { width: min(440px, 100%); }
.panel h2 { margin: 0 0 0.25rem; color: var(--accent); }
.tagline { margin: 0 0 0.9rem; color: var(--muted); font-size: 0.88rem; }
.panel label {
  display: block; margin-bottom: 0.65rem;
  font-size: 0.85rem; color: var(--muted);
}
.panel select {
  display: block; width: 100%; margin-top: 0.25rem;
  padding: 0.45rem; border-radius: 8px;
  border: 1px solid var(--line); background: #16202c;
  color: var(--text); font: inherit;
}
.hint { margin: 0.75rem 0 0; font-size: 0.78rem; color: var(--muted); text-align: center; }
.panel ul { padding-left: 1.1rem; font-size: 0.88rem; line-height: 1.55; }

.abil-cols {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 0.75rem 0 1rem;
}
.abil-cols h3 { margin: 0 0 0.4rem; font-size: 0.95rem; }
.abil {
  display: grid; grid-template-columns: 2.5rem 1fr 1.8rem;
  align-items: center; gap: 0.35rem;
  font-size: 0.78rem; margin-bottom: 0.35rem; color: var(--muted);
}
.abil-bar {
  height: 8px; background: #2a3544; border-radius: 4px; overflow: hidden;
}
.abil-bar i {
  display: block; height: 100%;
  background: linear-gradient(90deg, #7bc96f, var(--accent));
}
.abil em { font-style: normal; color: var(--text); text-align: right; }

/* Touch bar: own row under canvas (does not cover court) */
#touch-controls {
  display: none;
  flex-shrink: 0;
  padding: 0.45rem 0.75rem 0.65rem;
  justify-content: space-between; align-items: center;
  background: #161d27;
  border-top: 1px solid var(--line);
  z-index: 4;
  gap: 0.75rem;
}
#dpad {
  display: grid;
  grid-template-columns: 3rem 3rem 3rem;
  grid-template-rows: 2.7rem 2.7rem 2.7rem;
  gap: 0.22rem;
  justify-items: center;
  align-items: center;
}
#pad-up { grid-column: 2; grid-row: 1; }
#pad-left { grid-column: 1; grid-row: 2; }
#pad-right { grid-column: 3; grid-row: 2; }
#pad-down { grid-column: 2; grid-row: 3; }
.pad {
  width: 3rem; height: 2.7rem; font-size: 1rem;
  border-radius: 10px; user-select: none;
  touch-action: manipulation;
  -webkit-user-select: none;
}
.hit {
  width: 5.8rem; height: 5.8rem; border-radius: 50%;
  font-size: 1.05rem; user-select: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  flex-shrink: 0;
}

@media (max-width: 820px), (pointer: coarse) {
  #touch-controls {
    display: flex;
    max-height: 24vh;
    overflow: hidden;
    padding: 0.3rem 0.6rem 0.45rem;
  }
  #court-stage { min-height: 55%; }
  #dpad {
    grid-template-columns: 2.6rem 2.6rem 2.6rem;
    grid-template-rows: 2.3rem 2.3rem 2.3rem;
  }
  .pad { width: 2.6rem; height: 2.3rem; }
  .hit { width: 5rem; height: 5rem; }
}
@media (max-width: 420px) {
  #hud .score { font-size: 1.15rem; }
  .hit { width: 5.2rem; height: 5.2rem; }
  #dpad {
    grid-template-columns: 2.7rem 2.7rem 2.7rem;
    grid-template-rows: 2.45rem 2.45rem 2.45rem;
  }
  .pad { width: 2.7rem; height: 2.45rem; }
}

/* 寬螢幕：收窄 app，球場以高度主導、比例自然 */
@media (min-width: 900px) and (pointer: fine) {
  #app {
    max-width: 460px;
    height: 100dvh;
  }
  #court-stage {
    min-height: 0;
  }
}
