:root {
  --bg: #0b2416;
  --bg2: #133a24;
  --card: #fbf6ec;
  --ink: #2a1c10;
  --muted: #7a6a58;
  --accent: #c8862e;
  --accent2: #1f8a4c;
  --wood: #5c3317;
  --solid: #f2c12e;
  --danger: #c0392b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 50% 30%, var(--bg2), var(--bg) 70%);
  color: #f3ead8;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- game screen ---------- */
#game-screen { position: fixed; inset: 0; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.hud {
  display: grid; grid-template-columns: 1fr minmax(0, 1.4fr) 1fr auto; align-items: center; gap: 8px;
  padding: 6px 10px; background: rgba(0,0,0,.35); border-bottom: 1px solid rgba(255,255,255,.08);
  min-height: 52px;
}
.player { display: flex; flex-direction: column; gap: 2px; padding: 4px 10px; border-radius: 10px; border: 2px solid transparent; min-width: 0; transition: background .2s, border-color .2s; }
.player.right { align-items: flex-end; text-align: right; }
.player.active { background: rgba(255, 210, 63, .14); border-color: rgba(255, 210, 63, .7); }
.pname { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.pgroup { font-size: 12px; color: #cdbf9f; }
.pballs { display: flex; gap: 3px; flex-wrap: wrap; }
.player.right .pballs { justify-content: flex-end; }
.mini { width: 14px; height: 14px; border-radius: 50%; display: inline-block; position: relative; box-shadow: inset -2px -2px 3px rgba(0,0,0,.35); }
.mini.stripe { background: #f7f4ea !important; overflow: hidden; }
.mini.stripe::after { content: ""; position: absolute; left: 0; right: 0; top: 4px; height: 6px; background: var(--c); }
.mini.gone { opacity: .18; }
.hud-mid { text-align: center; min-width: 0; }
#msg { font-size: 14px; line-height: 1.3; color: #fff7e0; }
.icon-btn {
  background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.2);
  width: 40px; height: 40px; border-radius: 10px; font-size: 20px; display: grid; place-items: center; padding: 0;
}
.icon-btn:active { background: rgba(255,255,255,.25); }

.play { flex: 1; display: flex; min-height: 0; }
#table { flex: 1; min-width: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.side { width: 76px; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 6px; background: rgba(0,0,0,.2); }
.side-label { font-size: 13px; font-weight: 700; color: #f3ead8; }
.side-hint { font-size: 11px; color: #cdbf9f; text-align: center; line-height: 1.3; }
#power {
  position: relative; flex: 1; width: 34px; max-height: 340px; min-height: 120px; border-radius: 17px;
  background: linear-gradient(#3a2412, #1d1209); border: 2px solid #8a5a2b; overflow: hidden; touch-action: none; cursor: ns-resize;
}
#power-fill { position: absolute; left: 0; right: 0; top: 0; height: 0%; background: linear-gradient(#ffe066, #ff9f1c 50%, #e63946); }
#power-knob { position: absolute; left: 3px; right: 3px; height: 24px; top: 0; border-radius: 12px; background: #f1d9a8; box-shadow: 0 2px 4px rgba(0,0,0,.5); }
#power.disabled { opacity: .4; }
.fine { display: flex; gap: 6px; }
.fine .icon-btn { width: 30px; height: 36px; font-size: 18px; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: rgba(5, 20, 12, .82); z-index: 10; overflow-y: auto;
}
.overlay.see-through { background: rgba(5, 20, 12, .45); }
.card {
  background: var(--card); color: var(--ink); border-radius: 18px; padding: 24px 22px; width: min(420px, 100%);
  box-shadow: 0 20px 50px rgba(0,0,0,.5); border: 4px solid var(--wood); text-align: center;
  -webkit-user-select: text; user-select: text;
}
.card h1 { margin: 6px 0 12px; font-size: 28px; }
.card h2 { margin: 0 0 12px; font-size: 22px; }
.logo { display: grid; place-items: center; }
.ball8 {
  width: 64px; height: 64px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #555, #111 60%);
  display: grid; place-items: center; font-weight: 800; color: #111; font-size: 22px; position: relative;
}
.ball8::before { content: ""; position: absolute; width: 30px; height: 30px; border-radius: 50%; background: #fff; }
.ball8 { isolation: isolate; }
.ball8::before { z-index: -1; }
.buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.buttons button {
  border: 2px solid #d9c9a8; background: #fff; color: var(--ink); padding: 12px 14px; border-radius: 12px; font-size: 16px; font-weight: 600;
}
.buttons button:hover { background: #fff8e8; }
.buttons button.primary { background: var(--accent2); border-color: #146b39; color: #fff; }
.buttons button.primary.alt { background: var(--accent); border-color: #9e6820; }
.buttons button:focus-visible, .icon-btn:focus-visible, #power:focus-visible { outline: 3px solid #ffd23f; outline-offset: 2px; }
.note { font-size: 13px; color: var(--muted); margin: 12px 0 0; line-height: 1.5; }
.error { color: var(--danger); min-height: 1.2em; font-size: 14px; margin: 6px 0 0; }
label { display: block; text-align: left; font-size: 14px; font-weight: 600; margin-top: 10px; }
label input {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font-size: 16px; border-radius: 10px;
  border: 2px solid #d9c9a8; background: #fff; color: var(--ink);
}
label input:focus { outline: none; border-color: var(--accent2); }
#user-box { font-size: 15px; margin-bottom: 4px; }
#user-box .stats { color: var(--muted); font-size: 13px; }
#user-box .row { display: flex; gap: 8px; justify-content: center; margin-top: 8px; flex-wrap: wrap; }
#user-box button { border: 2px solid #d9c9a8; background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 10px; font-size: 14px; font-weight: 600; }
.board { width: 100%; border-collapse: collapse; font-size: 15px; }
.board th, .board td { padding: 7px 6px; border-bottom: 1px solid #eadfc8; }
.board th { color: var(--muted); font-size: 13px; font-weight: 600; }
.board td:nth-child(2) { text-align: left; font-weight: 600; }
.board th:nth-child(2) { text-align: left; }
.board tr.me td { background: #fff0c8; }
.help ul { text-align: left; padding-left: 18px; margin: 0; line-height: 1.6; font-size: 14px; }
.help li { margin-bottom: 6px; }
#over-title { font-size: 26px; }

#rotate-tip {
  position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.7); color: #fff;
  padding: 8px 14px; border-radius: 20px; font-size: 13px; z-index: 5; pointer-events: none;
}

@media (max-width: 640px), (max-height: 420px) {
  .hud { gap: 4px; padding: 4px 6px; min-height: 44px; }
  .pname { font-size: 13px; }
  .pgroup { display: none; }
  .mini { width: 10px; height: 10px; }
  .mini.stripe::after { top: 3px; height: 4px; }
  #msg { font-size: 12px; }
  .icon-btn { width: 34px; height: 34px; font-size: 17px; }
  .side { width: 62px; padding: 6px 4px; gap: 6px; }
  .side-hint { display: none; }
}
@media (orientation: portrait) {
  .hud { grid-template-columns: 1fr 1fr auto; }
  .hud-mid { grid-column: 1 / -1; grid-row: 2; }
}
