/* Political Wars. Mobile first: the page never scrolls or zooms while playing, the
   controls stay clear of the notch and the home bar, and menus use the whole screen. */
:root {
  --pw-bg: #0b1020;
  --pw-panel: rgba(8, 13, 30, 0.9);
  --pw-line: rgba(255, 255, 255, 0.85);
  --pw-accent: #0090c1;
  --pw-yellow: #fde047;
  --pw-red: #f87171;
  --vh: 100vh;
  --controls-h: 240px;
  --btn: 84px; /* control size; shrinks on narrow phones so four fit side by side */
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--pw-bg);
  overflow: hidden;
  overscroll-behavior: none;
}

#hpg-game {
  position: relative;
  box-sizing: border-box; /* the notch padding sits inside the screen height, not on top of it */
  height: var(--vh);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: "Press Start 2P", ui-monospace, monospace;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#hpg-game * { box-sizing: border-box; }
#hpg-game [hidden] { display: none !important; }

.pw-stage {
  position: relative;
  flex: none;
  touch-action: none;
}
.pw-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}

/* Portrait phone: the stage at the top, controls in their own panel below. */
#hpg-game.is-portrait { justify-content: flex-start; padding-top: env(safe-area-inset-top); }
#hpg-game.is-portrait .pw-controls {
  position: relative;
  width: 100%;
  height: var(--controls-h);
  margin-top: auto;
  padding: 12px 16px calc(18px + env(safe-area-inset-bottom));
  background: linear-gradient(#141b33, #0b1020);
  border-top: 3px solid #1f2a4d;
  align-items: center;
}

/* Landscape phone: controls float over the bottom corners of the stage. */
#hpg-game.is-landscape .pw-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 calc(14px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  pointer-events: none;
  opacity: 0.82;
}
#hpg-game.is-landscape .pw-controls > * { pointer-events: auto; }

.pw-controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  touch-action: none;
}

.pw-dpad {
  position: relative;
  display: flex;
  gap: 10px;
  touch-action: none;
}
.pw-dpad span {
  width: var(--btn);
  height: var(--btn);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  border: 3px solid var(--pw-line);
  border-radius: 18px;
  background: rgba(40, 52, 90, 0.85);
  box-shadow: 0 5px 0 #000;
}
.pw-dpad span.is-on { background: var(--pw-accent); transform: translateY(3px); box-shadow: 0 2px 0 #000; }

.pw-actions {
  display: grid;
  grid-template-columns: repeat(2, auto);
  grid-template-areas: ". punch" "block kick";
  gap: 10px 12px;
  align-items: end;
  touch-action: none;
}
.pw-btn {
  width: var(--btn);
  height: var(--btn);
  border-radius: 50%;
  border: 3px solid var(--pw-line);
  color: #fff;
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.02em;
  box-shadow: 0 5px 0 #000;
  touch-action: none;
  cursor: pointer;
}
.pw-punch { grid-area: punch; background: #c2410c; }
.pw-kick { grid-area: kick; background: #b91c1c; }
.pw-block { grid-area: block; background: #1d4ed8; }
.pw-btn.is-on { transform: translateY(3px); box-shadow: 0 2px 0 #000; filter: brightness(1.25); }

#hpg-game.is-landscape { --btn: min(74px, 17vh); }
.pw-btn { font-size: calc(var(--btn) * 0.13); }

.pw-keys {
  margin-top: 12px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
  text-align: center;
  line-height: 1.8;
  padding: 0 12px;
}

.pw-pause-btn {
  position: absolute;
  left: 50%;
  top: 11%;
  transform: translateX(-50%);
  width: 44px;
  height: 44px;
  border: 2px solid var(--pw-line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font: inherit;
  font-size: 10px;
  cursor: pointer;
  z-index: 3;
}

.pw-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 10px;
  background: #111827;
  border: 2px solid var(--pw-line);
  font-size: 11px;
  z-index: 20;
}

/* Menus cover the whole screen (the stage alone is too small on a phone held upright). */
.pw-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  background: rgba(5, 9, 22, 0.72);
  overflow-y: auto;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}
.pw-title { background: radial-gradient(circle at 50% 30%, rgba(0, 144, 193, 0.35), rgba(5, 9, 22, 0.94) 70%); }

.pw-panel {
  width: min(520px, 100%);
  margin: auto;
  padding: 22px 18px;
  border: 3px solid var(--pw-line);
  border-radius: 14px;
  background: var(--pw-panel);
  text-align: center;
  box-shadow: 0 8px 0 #000;
}
.pw-panel-wide { width: min(760px, 100%); }
.pw-logo { height: 34px; margin-bottom: 10px; }
.pw-h1 {
  margin: 0 0 10px;
  font-size: clamp(22px, 7vw, 40px);
  line-height: 1.25;
  color: var(--pw-yellow);
  text-shadow: 3px 3px 0 #000;
}
.pw-h2 {
  margin: 0 0 14px;
  font-size: clamp(15px, 4.6vw, 24px);
  line-height: 1.4;
  text-shadow: 2px 2px 0 #000;
}
.pw-h2.is-win { color: var(--pw-yellow); }
.pw-h2.is-lose { color: var(--pw-red); }
.pw-tagline { margin: 0 0 18px; font-size: 11px; line-height: 1.7; color: #bae6fd; }
.pw-winline { margin: 0 0 18px; font-size: 12px; line-height: 1.8; }
.pw-note { font-size: 10px; line-height: 1.7; color: rgba(255, 255, 255, 0.75); }
.pw-disclaimer { margin: 16px 0 0; font-size: 8px; line-height: 1.7; color: rgba(255, 255, 255, 0.55); }
.pw-label { font-size: 10px; color: rgba(255, 255, 255, 0.75); }

.pw-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.pw-cta {
  min-width: 200px;
  padding: 18px 26px;
  border: 3px solid #fff;
  border-radius: 12px;
  background: #16a34a;
  color: #fff;
  font: inherit;
  font-size: 18px;
  box-shadow: 0 6px 0 #000;
  cursor: pointer;
}
.pw-cta:active { transform: translateY(3px); box-shadow: 0 3px 0 #000; }

.pw-chip {
  display: inline-block;
  padding: 10px 12px;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font: inherit;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
}
.pw-chip.is-on { background: var(--pw-accent); border-color: #fff; }

#hpg-game button:focus-visible, #hpg-game a:focus-visible { outline: 3px solid var(--pw-yellow); outline-offset: 3px; }

.pw-loading {
  height: 16px;
  margin: 8px auto;
  width: 80%;
  border: 2px solid #fff;
  border-radius: 6px;
  overflow: hidden;
}
.pw-loading span { display: block; height: 100%; background: var(--pw-accent); transition: width 0.2s; }

.pw-how { margin-top: 16px; text-align: left; font-size: 9px; line-height: 1.9; }
.pw-how summary { cursor: pointer; text-align: center; color: #bae6fd; }
.pw-how p { margin: 8px 0 0; }

/* Candidate tiles: two across on phones, up to four on wide screens. */
.pw-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 10px;
}
.pw-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 6px 10px;
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font: inherit;
  cursor: pointer;
}
.pw-tile:hover:not(:disabled), .pw-tile:focus-visible { border-color: #22d3ee; box-shadow: 0 0 14px rgba(34, 211, 238, 0.5); }
.pw-tile.is-selected { border-color: var(--pw-yellow); }
.pw-tile:disabled { opacity: 0.45; cursor: default; }
.pw-tile-art {
  width: 100%;
  height: 132px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-size: 44px;
}
.pw-tile-art img { height: 100%; width: auto; image-rendering: pixelated; }
.pw-tile-name { margin-top: 8px; font-size: 12px; line-height: 1.5; }
.pw-tile-random .pw-tile-art { color: var(--pw-yellow); align-items: center; }

@media (prefers-reduced-motion: reduce) {
  .pw-loading span { transition: none; }
}

/* Leaderboard: the score form after a win and the board screen. */
#hpg-game input, #hpg-game select { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
.pw-input {
  font: inherit;
  font-size: 16px; /* 16px or more, or iPhones zoom in when the box is tapped */
  padding: 10px 10px;
  border: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}
.pw-input:focus { outline: 3px solid var(--pw-yellow); outline-offset: 2px; }
.pw-initials { width: 6.2em; text-align: center; text-transform: uppercase; letter-spacing: 0.12em; }
.pw-town { max-width: 100%; font-size: 12px; min-height: 44px; }
@supports (-webkit-touch-callout: none) { .pw-town { font-size: 16px; } }
.pw-town option { color: #111; }
.pw-score { margin: 4px 0 12px; font-size: 12px; }
.pw-score strong { font-size: 20px; color: var(--pw-yellow); text-shadow: 2px 2px 0 #000; }
.pw-rank { margin: 0 0 6px; font-size: 13px; line-height: 1.6; color: #86efac; }
.pw-post { margin: 6px 0 4px; padding-top: 12px; border-top: 2px dashed rgba(255, 255, 255, 0.25); }
.pw-post .pw-note { margin: 0; }
.pw-post-msg:empty { display: none; }
.pw-post-msg { margin-top: 8px !important; color: #fca5a5; }
.pw-fine { margin: 10px 0 0; font-size: 8px; line-height: 1.7; color: rgba(255, 255, 255, 0.55); }
.pw-h3 { margin: 16px 0 6px; font-size: 11px; color: #bae6fd; }
.pw-cta-small { min-width: 150px; padding: 12px 18px; font-size: 14px; }
.pw-board { list-style: none; margin: 12px 0 4px; padding: 0; text-align: left; font-size: 10px; }
.pw-board li {
  display: grid;
  grid-template-columns: 2.6em 3.6em minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  padding: 8px 8px;
  border-radius: 8px;
  line-height: 1.4;
}
.pw-board li:nth-child(odd) { background: rgba(255, 255, 255, 0.06); }
.pw-board li.is-me { background: rgba(253, 224, 71, 0.18); box-shadow: inset 0 0 0 2px var(--pw-yellow); }
.pw-board-town { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: rgba(255, 255, 255, 0.85); }
.pw-board-pts { text-align: right; color: var(--pw-yellow); }
.pw-board-towns li { grid-template-columns: 2.6em minmax(0, 1fr) auto; }

/* Mobile pass (1.6.5). Every button is at least 44 px tall, the size a thumb needs. On a phone held
   sideways (a short screen) the title packs up so PLAY shows without scrolling: the big picture shrinks
   and the long words go (they are in How to play too). */
#hpg-game .pw-chip { min-height: 44px; }
#hpg-game .pw-cta { min-height: 48px; }
@media (orientation: landscape) and (max-height: 500px) {
  #hpg-game [data-screen="title"] .pw-hero { max-height: 48px; width: auto; margin-top: 0; margin-bottom: 4px; }
  #hpg-game [data-screen="title"] .pw-lead, #hpg-game [data-screen="title"] .pw-fine { display: none; }
  #hpg-game [data-screen="title"] .pw-h1 { font-size: clamp(24px, 9vh, 40px); margin-bottom: 2px; }
  #hpg-game [data-screen="title"] .pw-tagline { margin-bottom: 4px; }
  #hpg-game [data-screen="title"] .pw-cta { margin-top: 4px; margin-bottom: 6px; padding-top: 6px; padding-bottom: 6px; }
  #hpg-game .pw-panel { padding-top: 12px; padding-bottom: 12px; }
  #hpg-game .pw-tile-art { height: min(132px, 30vh); }
  #hpg-game .pw-grid { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
  #hpg-game .pw-h2 { margin-top: 0; margin-bottom: 6px; }
}
/* How to play: a summary a thumb can hit. */
#hpg-game summary { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; }
#hpg-game .pw-how { font-size: 11px; }
#hpg-game .pw-how summary { font-size: 12px; }
#hpg-game .pw-pause-btn { font-size: 12px; }
#hpg-game .pw-label { font-size: 12px; }
#hpg-game .pw-fine { font-size: 10px; line-height: 1.6; }
#hpg-game .pw-disclaimer { font-size: 10px; line-height: 1.6; color: rgba(255, 255, 255, 0.7); }
@media (orientation: landscape) and (max-height: 500px) { #hpg-game [data-screen="title"] .pw-disclaimer, #hpg-game [data-screen="title"] .pw-how { margin-top: 6px; } }
/* Two quick taps on a menu button are two taps, never a zoom (iPhones zoom on a double tap otherwise). */
#hpg-game button, #hpg-game a, #hpg-game summary, #hpg-game select, #hpg-game input { touch-action: manipulation; }
/* The hint on the pause screen for the secret move. */
.pw-secret { margin: 0 0 14px; font-size: 10px; line-height: 1.8; color: #fde047; max-width: 34em; }
