/* 偷閒遊戲室：深色街機風，手機優先 */
:root {
  --bg: #0f131c;
  --surface: #181e2b;
  --surface-2: #212938;
  --line: #2c3547;
  --ink: #e8ecf3;
  --muted: #8e9ab0;
  --accent: #f1c40f;
  --primary: #3498db;
  --primary-dark: #21618c;
  --danger: #e74c3c;
  --ok: #2ecc71;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: #7fc4f5; }
h1, h2 { line-height: 1.25; }
[hidden] { display: none !important; }

.container { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }
.container.game-main { padding-top: 10px; }

/* ─── 頁首 ─────────────────────────────────── */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: #0a0d14;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  white-space: nowrap;
}
.nav { display: flex; gap: 4px; overflow-x: auto; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  font-size: .95rem;
}
.nav a:hover { color: var(--ink); background: var(--surface); }

/* ─── 共用元件 ─────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 10px; font-size: 1.15rem; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; justify-content: center; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .25);
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn-primary { background: var(--primary); border-color: var(--primary-dark); color: #fff; box-shadow: inset 0 -4px 0 var(--primary-dark); }
.btn-ghost { background: transparent; box-shadow: none; }
.btn-lg { padding: 12px 24px; font-size: 1.05rem; }

.icon-btn {
  width: 38px; height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 1.05rem;
  cursor: pointer;
}

input[type=text], input:not([type]), select {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0d1119;
  color: var(--ink);
  font: inherit;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 0; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 17px; height: 17px; }
label { display: block; font-weight: 600; font-size: .92rem; }
output { color: var(--accent); font-weight: 800; margin-left: 4px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.row input { flex: 1; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.two-col > .card { margin-bottom: 0; }
.two-col + * { margin-top: 16px; }

.alert {
  padding: 12px 16px;
  border-radius: 10px;
  background: rgba(231, 76, 60, .12);
  border: 1px solid rgba(231, 76, 60, .4);
  color: #ffb4ab;
  margin-bottom: 16px;
}
.alert p { margin: 0; }

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
  vertical-align: 2px;
}
.badge-me { background: rgba(52, 152, 219, .2); color: #7fc4f5; }
.badge-gold { background: rgba(241, 196, 15, .18); color: var(--accent); margin: 0; }

/* 提示放在上方：放底部會蓋住板子那一帶，打到一半看不到球 */
.toasts {
  position: fixed;
  left: 50%;
  top: 64px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  pointer-events: none;
  width: min(92vw, 420px);
}
.toast {
  padding: 10px 14px;
  border-radius: 10px;
  background: #273043;
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
  text-align: center;
  transition: opacity .4s, transform .4s;
}
.toast.out { opacity: 0; transform: translateY(-8px); }
.toast-error { border-color: rgba(231, 76, 60, .6); color: #ffb4ab; }
.toast-warn { border-color: rgba(241, 196, 15, .6); color: #ffe08a; }
.toast-ok { border-color: rgba(46, 204, 113, .6); color: #a6f0c4; }

/* ─── 首頁 ─────────────────────────────────── */
.hero { text-align: center; padding: 18px 0 6px; }
.hero h1 { font-size: clamp(2rem, 6vw, 3rem); margin: 0 0 8px; letter-spacing: .04em; }
.lead { color: var(--muted); margin: 0 auto 22px; max-width: 620px; }

.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; margin-bottom: 20px; }
.mode {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
  transition: transform .12s, border-color .12s;
}
.mode:hover { transform: translateY(-2px); border-color: var(--primary); }
.mode h2 { margin: 0; font-size: 1.25rem; }
.mode p { margin: 0 0 6px; color: var(--muted); flex: 1; }
.mode .btn { align-self: flex-start; }
.mode-icon { font-size: 1.9rem; }
.mode-play { border-top: 4px solid var(--accent); }
.mode-versus { border-top: 4px solid var(--danger); }
.mode-custom { border-top: 4px solid var(--ok); }

.mini-board { margin: 0; padding-left: 22px; }
.mini-board li { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--line); }
.mini-board .score { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }

.rules ul { margin: 0; padding-left: 20px; color: var(--muted); }
.rules li { margin-bottom: 6px; }
.rules b { color: var(--ink); }

/* ─── 遊戲畫面 ─────────────────────────────── */
.hud {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 480px;
  margin: 0 auto 8px;
  font-variant-numeric: tabular-nums;
}
.hud-item { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.hud-item b { font-size: 1.2rem; }
.hud-label { font-size: .72rem; color: var(--muted); }
.hud-level span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.lives { color: #ff6b9d; letter-spacing: 1px; }
.hud-buttons { margin-left: auto; display: flex; gap: 6px; }

.game-wrap { position: relative; display: flex; justify-content: center; }
#game {
  display: block;
  border-radius: 10px;
  border: 1px solid var(--line);
  touch-action: none;        /* 手指拖曳控制板子，不要讓頁面跟著捲動或縮放 */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.controls-hint { text-align: center; color: var(--muted); font-size: .8rem; margin: 8px 0 0; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 10, 16, .72);
  border-radius: 10px;
  z-index: 5;
}
.panel {
  width: min(100%, 380px);
  padding: 22px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
}
.panel h2 { margin: 0 0 8px; }
.big-score { font-size: 2.6rem; font-weight: 900; color: var(--accent); font-variant-numeric: tabular-nums; }
.score-form { text-align: left; margin-top: 12px; }
.form-msg { min-height: 1.4em; margin: 8px 0 0; }
.form-msg.ok { color: var(--ok); }
.form-msg.error { color: #ffb4ab; }

.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 5rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 24px rgba(0, 0, 0, .8);
  pointer-events: none;
  z-index: 4;
}

/* ─── 自訂圖片 ─────────────────────────────── */
.setup { max-width: 560px; margin: 0 auto; }
.setup h1 { font-size: 1.4rem; margin: 0 0 6px; }
.file-pick { display: inline-block; margin: 10px 0; }
.file-pick input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-pick:focus-within .btn { outline: 2px solid var(--primary); }
.preview { width: 100%; height: auto; display: block; border-radius: 8px; border: 1px solid var(--line); margin: 8px 0; }
.sliders { display: grid; gap: 10px; margin: 12px 0; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }

/* ─── 對戰 ─────────────────────────────────── */
.room-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.room-code { font-size: 2.2rem; font-weight: 900; letter-spacing: .25em; color: var(--accent); font-variant-numeric: tabular-nums; }
.code-input { text-transform: uppercase; letter-spacing: .2em; font-weight: 800; max-width: 180px; }
.players { list-style: none; margin: 0 0 8px; padding: 0; }
.players li { padding: 8px 10px; border-radius: 8px; background: var(--surface-2); margin-bottom: 6px; font-weight: 700; }
#host-controls select { width: 100%; margin: 4px 0 10px; }
#start-btn { width: 100%; margin-top: 10px; }

.versus-layout { display: flex; gap: 14px; justify-content: center; align-items: flex-start; }
.opponents { display: flex; flex-direction: column; gap: 10px; width: 150px; flex: none; }
.opponent { padding: 8px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); }
.opponent canvas { width: 100%; height: auto; display: block; border-radius: 4px; }
.opponent.is-out { opacity: .45; }
.opp-name { font-weight: 800; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opp-stats { font-size: .75rem; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.ranking { text-align: left; padding-left: 0; list-style: none; margin: 12px 0 16px; }
.ranking li { padding: 8px 10px; border-radius: 8px; background: var(--surface-2); margin-bottom: 6px; }
.ranking li.me { outline: 2px solid var(--primary); }

/* ─── 排行榜 ───────────────────────────────── */
.board { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.board th, .board td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.board th { color: var(--muted); font-size: .8rem; font-weight: 600; }
.board .num { text-align: right; font-weight: 800; color: var(--accent); }
.board .name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board tr.me td { background: rgba(52, 152, 219, .16); }

.empty-state { max-width: 520px; margin: 30px auto; text-align: center; }

@media (max-width: 720px) {
  .container { padding: 12px 10px 32px; }
  .site-header { padding: 8px 10px; }
  .brand span { display: none; }
  .nav a { padding: 6px 8px; font-size: .9rem; }
  .hud { gap: 10px; }
  .hud-best { display: none; }
  /* 手機上對手縮成一排放在場地上方 */
  .versus-layout { flex-direction: column; align-items: stretch; gap: 8px; }
  .opponents { flex-direction: row; width: auto; overflow-x: auto; }
  .opponent { flex: 0 0 112px; padding: 5px; }
  .opponent canvas { max-height: 46px; object-fit: contain; }
  .room-code { font-size: 1.8rem; }
}
