/* plan33.io game harness — shared conventions. Theme via :root vars.
 * Corewatch theme: dark space palette, teal core glow, amber danger accent. */

:root {
  --bg: #05070c;
  --fg: #e8ecf1;
  --muted: #8b95a5;
  --accent: #38e8c6;
  --accent2: #ffb454;
  --danger: #ff5c5c;
  --scrim: rgba(4, 6, 10, 0.82);
  --panel: rgba(14, 19, 28, 0.95);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  background: var(--bg);
}

/* ---------- corner chrome ---------- */
.chrome {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  z-index: 20;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg);
  font: 600 16px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.icon-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

/* ---------- touch controls (coarse pointers, while playing) ---------- */
/* Corewatch has no directional pad: dragging anywhere on the canvas aims the
   turret, so the only on-screen control needed is a single Fire button. */
.touchpad { display: none; }

@media (pointer: coarse) {
  body.state-playing .touchpad,
  body.state-paused .touchpad {
    display: block;
    position: fixed;
    right: calc(20px + env(safe-area-inset-right));
    bottom: calc(20px + env(safe-area-inset-bottom));
    z-index: 15;
  }
  .pad-btn-fire {
    width: 84px;
    height: 84px;
    border-radius: 50%;
    border: 2px solid rgba(255, 180, 84, 0.55);
    background: rgba(255, 180, 84, 0.14);
    color: var(--accent2);
    font-size: 30px;
    touch-action: none;
  }
  .pad-btn-fire:active { background: var(--accent2); color: #2a1600; }
}

/* ---------- overlays: visibility driven purely by body state class ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  z-index: 30;
}

body.state-menu     .overlay-menu,
body.state-paused   .overlay-paused,
body.state-gameover .overlay-gameover { display: grid; }

.panel {
  width: min(420px, 100%);
  padding: 28px 24px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: var(--panel);
  text-align: center;
  animation: pop 180ms ease-out;
}

@keyframes pop { from { transform: scale(0.96); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .panel { animation: none; } }

.panel h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: 0.5px; color: var(--accent); }
.panel h2 { margin: 0 0 14px; font-size: 24px; }
.tagline  { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.score    { margin: 0 0 4px; font-size: 20px; font-weight: 600; }
.hi       { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.hint     { margin: 14px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }

.btn {
  display: block;
  width: 100%;
  margin: 8px 0 0;
  padding: 14px 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #04241d;
  font: 700 16px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

/* ---------- crowd data: share button + popover (crowd.js) ---------- */
.btn-share { font-weight: 600; }

.share-popover {
  margin: 8px 0 0;
  display: grid;
  gap: 6px;
  text-align: left;
}
.share-popover.hidden { display: none; }

.share-option {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg);
  font: 600 14px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
  text-align: center;
}
.share-option:hover { background: rgba(255, 255, 255, 0.12); }

/* ---------- crowd data: like + leaderboard (opt-in per game) ---------- */
.like-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 12px 0 0;
}
.btn-like {
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg);
  font: 600 14px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
.btn-like[aria-pressed="true"] { color: #ff6b8a; border-color: #ff6b8a; }
.like-count { color: var(--muted); font-size: 13px; }

.leaderboard {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  font-size: 13px;
  text-align: left;
  max-height: 160px;
  overflow-y: auto;
}
.leaderboard li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--fg);
}
.leaderboard .lb-rank { color: var(--muted); width: 2em; }
.leaderboard .lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
