:root {
  --bg: #101418;
  --panel: rgba(12, 16, 20, 0.72);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #eef2f0;
  --muted: #9fb0aa;
  --accent: #f2c14e;
  --gutter: max(10px, env(safe-area-inset-left));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none; /* all gestures are handled in JS */
}

/* The overlay itself lets pointer events through to the canvas. */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button, #help, #gameover .card { pointer-events: auto; }

/* ---- top bar ---- */
#topbar {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: var(--gutter);
  right: var(--gutter);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.player {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 6px 10px;
  max-width: 300px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.player.right { justify-self: end; text-align: right; }
.player.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 18px rgba(242, 193, 78, 0.25); }
.pname { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.player.right .pname { justify-content: flex-end; }
.player.active .name::before { content: "\25B6\00a0"; color: var(--accent); font-size: 0.8em; }
.wins {
  min-width: 1.6em;
  padding: 0 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.group { color: var(--muted); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.player.right .chips { justify-content: flex-end; }
.chips:empty { display: none; }

.chip {
  --c: #888;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  color: #111;
  background: radial-gradient(circle at 50% 50%, #fff 0 34%, transparent 36%), var(--c);
  box-shadow: inset -2px -3px 4px rgba(0, 0, 0, 0.35);
}
.chip.stripe {
  background: radial-gradient(circle at 50% 50%, #fff 0 34%, transparent 36%),
    linear-gradient(#f4f1e8 0 24%, var(--c) 24% 76%, #f4f1e8 76%);
}
.chip.down { opacity: 0.25; filter: grayscale(0.6); }

#status {
  align-self: center;
  max-width: 42vw;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  text-align: center;
  font-weight: 600;
}
#status:empty { display: none; }

/* ---- power bar ---- */
#power {
  position: absolute;
  left: var(--gutter);
  top: 50%;
  width: 18px;
  height: 160px;
  margin-top: -80px;
  border-radius: 9px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.15s;
}
#power.visible { opacity: 1; }
#power-fill {
  position: absolute;
  inset: 0;
  transform-origin: bottom;
  transform: scaleY(0);
  background: linear-gradient(to top, #4cc36b, #f2c14e 55%, #e2483d);
}
#power span {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.8);
}

/* ---- controls ---- */
#controls {
  position: absolute;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: var(--gutter);
  right: var(--gutter);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
#controls .sep { width: 8px; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  min-width: 40px;
  min-height: 38px;
  padding: 6px 12px;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover { border-color: rgba(255, 255, 255, 0.35); }
button:active { background: rgba(255, 255, 255, 0.15); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button[data-action="aim-left"], button[data-action="aim-right"],
button[data-action="cam-left"], button[data-action="cam-right"] { font-size: 18px; line-height: 1; }

/* ---- help ---- */
#help {
  position: absolute;
  left: 50%;
  bottom: calc(max(10px, env(safe-area-inset-bottom)) + 52px);
  transform: translateX(-50%);
  width: min(460px, calc(100% - 2 * var(--gutter)));
  max-height: 60vh;
  overflow: auto;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(12, 16, 20, 0.88);
  border: 1px solid var(--panel-border);
}
#help[hidden] { display: none; }
#help h2 { margin: 0 0 6px; font-size: 16px; }
#help ul { margin: 0 0 10px; padding-left: 18px; }
#help li { margin: 3px 0; }
#help button { width: 100%; }

/* ---- game over ---- */
#gameover {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.35);
  pointer-events: auto;
}
#gameover[hidden] { display: none; }
#gameover .card {
  min-width: 260px;
  max-width: calc(100% - 32px);
  padding: 20px 24px;
  border-radius: 14px;
  text-align: center;
  background: rgba(12, 16, 20, 0.92);
  border: 1px solid var(--accent);
}
#gameover h2 { margin: 0 0 8px; color: var(--accent); }
#gameover p { margin: 4px 0; }
#gameover button { margin-top: 12px; }

/* ---- small screens ---- */
@media (max-width: 640px) {
  body { font-size: 13px; }
  #topbar { grid-template-columns: 1fr 1fr; }
  #status { grid-column: 1 / -1; grid-row: 2; max-width: none; justify-self: center; font-size: 12px; }
  .player { padding: 4px 8px; }
  .chip { width: 16px; height: 16px; font-size: 8px; }
  button { min-height: 34px; min-width: 36px; padding: 4px 9px; }
  #controls { gap: 4px; }
  #controls .sep { width: 2px; }
  #power { height: 120px; margin-top: -60px; }
}
