* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at center, #3b2414 0%, #1b0f07 100%);
  color: #f3ead8;
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }

header {
  display: grid;
  grid-template-columns: 1fr minmax(0, 2fr) 1fr;
  grid-template-areas: "p0 c p1";
  gap: 8px;
  padding: 8px 10px 4px;
  align-items: stretch;
}
#p0 { grid-area: p0; }
#p1 { grid-area: p1; }
.center { grid-area: c; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 6px; }

.player {
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 6px 10px;
  transition: border-color .2s, box-shadow .2s;
  min-width: 0;
}
.player.turn { border-color: #f2c014; box-shadow: 0 0 12px rgba(242, 192, 20, 0.45); }
.player.winner { border-color: #4ade80; box-shadow: 0 0 14px rgba(74, 222, 128, 0.6); }
.pname { font-weight: 700; font-size: 15px; }
.player.turn .pname::after { content: " ◀ 輪到你"; color: #f2c014; font-size: 12px; }
.pgroup { font-size: 12px; opacity: .8; margin: 2px 0 4px; }
.pballs { display: flex; flex-wrap: wrap; gap: 3px; min-height: 20px; }
.mini {
  width: 20px; height: 20px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; color: #111;
  background: radial-gradient(circle at center, #fbf8ef 0 36%, var(--c) 37%);
  box-shadow: inset -2px -2px 3px rgba(0,0,0,.35);
}
.mini.stripe { background: radial-gradient(circle at center, #fbf8ef 0 36%, transparent 37%), linear-gradient(#f6f1e3 0 22%, var(--c) 22% 78%, #f6f1e3 78%); }
.mini.gone { opacity: .2; }

#msg {
  text-align: center;
  font-size: 15px;
  line-height: 1.35;
  min-height: 2.7em;
  display: flex; align-items: center; justify-content: center;
}
.btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
button {
  font: inherit;
  font-size: 13px;
  color: #f3ead8;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 5px 10px;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover { background: rgba(255, 255, 255, 0.18); }
button.primary { background: #f2c014; color: #2a170b; font-weight: 700; border: none; padding: 10px 22px; font-size: 16px; }

#stage { flex: 1; min-height: 0; position: relative; }
#table { position: absolute; inset: 0; touch-action: none; display: block; }

footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 10px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}
.fine { width: 48px; height: 48px; font-size: 22px; flex: none; border-radius: 50%; padding: 0; touch-action: none; }
#power {
  flex: 1;
  height: 48px;
  position: relative;
  border-radius: 24px;
  background: rgba(0, 0, 0, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.2);
  overflow: hidden;
  touch-action: none;
  cursor: ew-resize;
}
#power.active { border-color: #f2c014; }
#power.disabled { opacity: .45; cursor: default; }
#powerFill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0;
  background: linear-gradient(90deg, #4ade80, #f2c014 55%, #ef4444);
}
#powerLabel {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; text-align: center; padding: 0 12px;
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
}

.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 10;
}
.card {
  background: #2a170b;
  border: 2px solid #7a4a22;
  border-radius: 14px;
  padding: 18px 22px;
  max-width: 520px;
  max-height: 100%;
  overflow: auto;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
.card h2 { margin: 0 0 10px; }
.card ul { text-align: left; padding-left: 18px; line-height: 1.5; font-size: 14px; }
.card li { margin-bottom: 5px; }

@media (max-width: 700px) {
  header {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "p0 p1" "c c";
    gap: 6px;
    padding: 6px 8px 2px;
  }
  .player { padding: 4px 8px; }
  .pname { font-size: 14px; }
  .mini { width: 16px; height: 16px; font-size: 8px; }
  #msg { font-size: 14px; min-height: 2.6em; }
  button { font-size: 12px; padding: 4px 8px; }
  .fine { width: 44px; height: 44px; }
  #power { height: 44px; }
  #powerLabel { font-size: 12px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  header { padding: 4px 8px 0; }
  .pgroup { display: none; }
  #msg { min-height: 0; font-size: 13px; }
  footer { padding: 4px 10px 6px; }
  .fine { width: 40px; height: 40px; }
  #power { height: 40px; }
}
