:root {
  --bg-deep: #0c192c;
  --panel-bg: rgba(15, 23, 42, 0.88);
  --border-glass: rgba(255, 255, 255, 0.14);
  --left-accent: #38bdf8;
  --right-accent: #fb7185;
  --gold: #facc15;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Noto Sans TC", "PingFang HK", "Microsoft JhengHei", system-ui, sans-serif;
  background: radial-gradient(circle at top, #0369a1 0%, #0f172a 75%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
}

.app-shell {
  width: 100%;
  max-width: 1220px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Scoreboard */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  background: var(--panel-bg);
  border: 1px solid var(--border-glass);
  border-radius: 14px;
  padding: 10px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.team-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.team-panel.right {
  align-items: flex-end;
}

.team-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
}

.team-badge {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.5px;
}

.team-badge.player {
  background: rgba(56, 189, 248, 0.2);
  color: var(--left-accent);
  border: 1px solid rgba(56, 189, 248, 0.45);
}

.team-badge.cpu {
  background: rgba(251, 113, 133, 0.2);
  color: var(--right-accent);
  border: 1px solid rgba(251, 113, 133, 0.45);
}

.touch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.touch-badges {
  display: flex;
  gap: 6px;
}

.touch-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.touch-pill.active {
  background: var(--gold);
  color: #422006;
  box-shadow: 0 0 10px rgba(250, 204, 21, 0.55);
}

.special-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.special-bar {
  width: 110px;
  height: 9px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  overflow: hidden;
}

.special-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #38bdf8, #a855f7);
  transition: width 0.2s ease;
}

.special-fill.ready {
  background: linear-gradient(90deg, #facc15, #f97316, #ec4899);
  box-shadow: 0 0 12px #facc15;
}

.power-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #38bdf8, #facc15, #f97316);
  transition: width 0.05s linear;
}

.power-fill.green {
  background: linear-gradient(90deg, #22c55e, #4ade80);
  box-shadow: 0 0 10px #4ade80;
}

.stamina-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #22c55e, #4ade80);
  transition: width 0.12s ease;
}

.stamina-fill.low {
  background: linear-gradient(90deg, #ef4444, #f97316);
}

.wind-badge {
  font-size: 11px;
  font-weight: 700;
  color: #7dd3fc;
  margin-top: 2px;
}

.special-text {
  font-size: 11px;
  font-weight: 700;
  color: #e2e8f0;
}

.score-center {
  text-align: center;
  padding: 0 10px;
}

.score-digits {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 32px;
  font-weight: 900;
  line-height: 1;
}

.score-num.left { color: var(--left-accent); }
.score-num.right { color: var(--right-accent); }
.score-sep { color: var(--text-muted); font-size: 24px; }

.match-rule {
  font-size: 11px;
  color: var(--gold);
  font-weight: 700;
  margin-top: 3px;
}

.toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.toolbar select,
.toolbar button {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.toolbar select option {
  background: #0f172a;
  color: #f8fafc;
}

.toolbar button:hover,
.toolbar select:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Canvas Stage */
.stage-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1200 / 700;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.45);
  background: #fde68a;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

.serve-prompt {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.88);
  color: var(--gold);
  border: 2px solid var(--gold);
  padding: 8px 20px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 800;
  pointer-events: none;
  animation: pulseBadge 1.1s infinite ease-in-out;
}

@keyframes pulseBadge {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.06); }
}

.hidden {
  display: none !important;
}

/* Overlay Modal */
.overlay-modal {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 10;
}

.modal-card {
  width: 100%;
  max-width: 960px;
  max-height: 100%;
  overflow-y: auto;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  padding: 20px 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.modal-header-row {
  display: grid;
  grid-template-columns: 80px 1fr 80px;
  align-items: center;
  gap: 8px;
}

.btn-lang-pill {
  justify-self: end;
  background: rgba(56, 189, 248, 0.18);
  color: #e0f2fe;
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.btn-lang-pill:hover {
  background: rgba(56, 189, 248, 0.32);
}

.modal-card h1 {
  text-align: center;
  font-size: 26px;
  font-weight: 900;
  color: var(--gold);
}

.subtitle {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin: 4px 0 14px;
}

.team-selectors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.selector-group {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.selector-group.left { border-left: 4px solid var(--left-accent); }
.selector-group.right { border-left: 4px solid var(--right-accent); }

.selector-group h3 {
  font-size: 13px;
  margin-bottom: 8px;
}

.selector-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: #cbd5e1;
  margin-bottom: 6px;
}

.selector-group select {
  flex: 1;
  max-width: 220px;
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
}

.roster-title {
  font-size: 12px;
  font-weight: 700;
  color: #cbd5e1;
  margin-bottom: 8px;
}

.roster-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.char-card {
  display: flex;
  align-items: center;
  gap: 9px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.char-card:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.11);
}

.char-card.selected {
  border-color: var(--gold);
  background: rgba(250, 204, 21, 0.1);
}

.char-badge {
  width: 60px;
  height: 78px;
  border-radius: 10px;
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #e0f2fe 0%, #fef3c7 100%);
}

.char-badge img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}

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

.char-name {
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.char-name span {
  display: block;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
}

.char-role {
  font-size: 10px;
  color: #7dd3fc;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.char-stats {
  font-size: 10px;
  color: #cbd5e1;
  margin-top: 1px;
}

.modal-actions {
  display: flex;
  justify-content: center;
}

.btn-primary {
  background: linear-gradient(135deg, #facc15, #f97316);
  color: #1e1b4b;
  border: none;
  border-radius: 999px;
  padding: 11px 36px;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(249, 115, 22, 0.45);
  transition: transform 0.12s ease;
}

.btn-primary:hover {
  transform: scale(1.04);
}

.pause-card {
  width: 100%;
  max-width: 440px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 18px;
  padding: 26px 28px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.pause-card h2 {
  font-size: 24px;
  font-weight: 900;
  color: var(--gold);
  margin-bottom: 4px;
}

.pause-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.pause-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.2);
}

.pause-tips {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: #cbd5e1;
}

/* Bottom Controls Bar */
.controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--panel-bg);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  padding: 8px 16px;
  font-size: 12px;
}

.keys-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  color: #cbd5e1;
}

kbd {
  display: inline-block;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 5px;
  padding: 1px 6px;
  font-family: inherit;
  font-weight: 700;
  font-size: 11px;
  color: #ffffff;
  margin: 0 2px;
}

.action-hint {
  font-weight: 700;
  color: var(--gold);
}

/* Mobile Touch Controls & Landscape Layout */
.touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

.joy-base {
  position: absolute;
  left: 22px;
  bottom: 22px;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.38);
  border: 2px solid rgba(255, 255, 255, 0.38);
  backdrop-filter: blur(4px);
  pointer-events: auto;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.joy-stick {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #7dd3fc, #0284c7);
  border: 2px solid #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  transform: translate(0, 0);
  pointer-events: none;
}

.touch-buttons-right {
  position: absolute;
  right: 22px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: auto;
  touch-action: none;
}

.touch-sub-btns {
  display: flex;
  gap: 8px;
}

.touch-mini-btn {
  background: rgba(15, 23, 42, 0.65);
  color: #f8fafc;
  border: 1.5px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 800;
  touch-action: none;
  user-select: none;
}

.touch-mini-btn.spec {
  border-color: var(--gold);
  color: var(--gold);
}

.touch-hit-btn {
  width: 102px;
  height: 102px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fde047, #f97316);
  color: #1e1b4b;
  border: 3px solid #ffffff;
  font-size: 14px;
  font-weight: 900;
  box-shadow: 0 8px 24px rgba(249, 115, 22, 0.5);
  touch-action: none;
  user-select: none;
}

.touch-hit-btn:active {
  transform: scale(0.94);
}

.stage-full-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 8;
  background: rgba(15, 23, 42, 0.72);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  backdrop-filter: blur(6px);
  touch-action: manipulation;
  user-select: none;
}

.stage-full-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(15, 23, 42, 0.88);
}

.rotate-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 25, 44, 0.94);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.rotate-card {
  max-width: 340px;
  text-align: center;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 18px;
  padding: 24px;
}

.rotate-icon {
  font-size: 42px;
  margin-bottom: 10px;
}

.rotate-card h2 {
  font-size: 18px;
  color: var(--gold);
  margin-bottom: 8px;
}

.rotate-card p {
  font-size: 13px;
  color: #cbd5e1;
  margin-bottom: 16px;
}

@media (max-height: 540px) and (orientation: landscape), (pointer: coarse) and (orientation: landscape) {
  body {
    padding: 4px 8px;
    height: 100dvh;
    overflow: hidden;
  }
  .app-shell {
    height: 100%;
    gap: 4px;
    justify-content: space-between;
  }
  .scoreboard {
    padding: 4px 10px;
    gap: 8px;
    border-radius: 10px;
  }
  .team-meta {
    font-size: 11px;
  }
  .special-bar {
    width: 68px;
    height: 7px;
  }
  .score-digits {
    font-size: 22px;
  }
  .toolbar select,
  .toolbar button {
    padding: 3px 7px;
    font-size: 11px;
  }
  .stage-wrap {
    flex: 1;
    width: auto;
    height: 100%;
    max-width: 100%;
    margin: 0 auto;
    border-radius: 10px;
  }
  .controls-bar {
    display: none;
  }
}

@media (max-width: 900px) and (orientation: portrait) {
  .scoreboard {
    grid-template-columns: 1fr;
    text-align: center;
  }
  .team-panel, .team-panel.right {
    align-items: center;
  }
  .roster-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .team-selectors {
    grid-template-columns: 1fr;
  }
}
