/* PiPPiPii — unlisted multiplayer block game.
   Self-contained (no index.css dependency); palette mirrors the main site. */

@font-face {
    font-family: 'PxPlusVGA';
    src: url('/fonts/Web437_IBM_VGA_8x16.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

:root {
    --color-bg: #000000;
    --color-bg-alt: #001a1a;
    --color-primary: #00ffff;
    --color-accent: #ffff00;
    --color-positive: #00ff00;
    --color-negative: #ff0000;
    --color-hover: #ff00ff;
    --color-muted: #808080;
    --border: 2px solid var(--color-primary);
    /* Every board, yours or not, is drawn at this height (see .pp-boards[data-count]). */
    --board-height: min(68vh, 560px);
    /* Space reserved under the match for the touch pad (0 unless .pp-touch). */
    --tp-height: 0px;
    --color-gold: #ffb800;
    --chat-height: 220px;
    --chat-height-match: 120px;
    --logo-small-height: 40px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    background-color: var(--color-bg);
}

body {
    min-height: 100vh;
    /* Transparent so the sea canvas (z-index -1) shows; html stays black. */
    /* No double-tap zoom: quick taps on the touch pad must stay game input. */
    touch-action: manipulation;
    background-color: transparent;
    color: var(--color-primary);
    font-family: 'PxPlusVGA', 'Courier New', monospace;
    font-size: 16px;
    line-height: 1.4;
    -webkit-text-size-adjust: 100%;
}

[hidden] {
    display: none !important;
}

.pp-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

/* ---- background sea (js/sea.js) ---- */

.pp-sea {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    pointer-events: none;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    opacity: 0.85;
}

/* ---- top bar ---- */

.pp-topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    padding: 10px 16px;
    border-bottom: var(--border);
    background-color: var(--color-bg-alt);
}

.pp-logo {
    display: flex;
    align-items: center;
    line-height: 0;
    min-height: var(--logo-small-height);
}

/* Small logo in the top bar during the lobby and matches. */
.pp-logo-small {
    height: var(--logo-small-height);
    width: auto;
}

/* On the menu screens the big logo takes over, so the small one steps aside. */
body[data-screen="name"] .pp-logo-small,
body[data-screen="browse"] .pp-logo-small {
    visibility: hidden;
}

.pp-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 8px 0 24px;
}

/* ---- review score under the logo (js/acclaim.js) ---- */

.pp-acclaim {
    /* Stacked and centered under the logo, so it stays put whatever the quote's length. */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: min(560px, 100%);
    margin: 10px 0 0;
    text-align: center;
}

.pp-acclaim-score {
    display: flex;
    align-items: baseline;
    justify-content: center;
    min-width: 92px;
    padding: 8px 10px;
    background-color: var(--color-accent);
    color: var(--color-bg);
    border: 3px solid var(--color-bg);
    outline: 2px solid var(--color-accent);
}

.pp-acclaim-number {
    font-size: 36px;
    line-height: 1;
}

.pp-acclaim-out {
    font-size: 12px;
}

.pp-acclaim-source {
    font-size: 11px;
    color: var(--color-accent);
}

.pp-acclaim-quote {
    margin: 4px 0 0;
    font-size: 14px;
    line-height: 1.3;
    color: var(--color-primary);
    min-height: 2.6em; /* two lines, so the layout doesn't jump between quotes */
    transition: opacity 250ms;
}

.pp-acclaim-who {
    font-size: 11px;
    color: var(--color-muted);
    transition: opacity 250ms;
}

.pp-acclaim-fading .pp-acclaim-quote,
.pp-acclaim-fading .pp-acclaim-who {
    opacity: 0;
}

.pp-logo-big {
    width: min(560px, 100%);
    height: auto;
}

.pp-topbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.pp-net-status {
    color: var(--color-positive);
}

.pp-net-status.pp-offline {
    color: var(--color-negative);
    animation: pp-blink 1s steps(2) infinite;
}

@keyframes pp-blink {
    50% { opacity: 0; }
}

.pp-main {
    padding: 16px;
    max-width: 1400px;
    margin: 0 auto;
}

/* ---- generic bits ---- */

.pp-heading {
    font-size: 24px;
    font-weight: normal;
    color: var(--color-accent);
    margin-bottom: 12px;
}

.pp-subheading {
    font-size: 18px;
    font-weight: normal;
    color: var(--color-accent);
    margin-bottom: 8px;
}

.pp-muted {
    color: var(--color-muted);
}

.pp-panel {
    border: var(--border);
    background-color: var(--color-bg-alt);
    padding: 12px;
    margin-bottom: 16px;
}

.pp-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.pp-field-label {
    color: var(--color-muted);
    font-size: 14px;
}

.pp-input {
    font: inherit;
    color: var(--color-accent);
    background-color: var(--color-bg);
    border: 2px solid var(--color-muted);
    border-radius: 0;
    padding: 4px 8px;
    min-width: 0;
}

.pp-input:focus {
    outline: none;
    border-color: var(--color-accent);
}

.pp-input:disabled {
    color: var(--color-muted);
}

.pp-input-small {
    width: auto;
    max-width: 9em;
}

.pp-button {
    font: inherit;
    color: var(--color-bg);
    background-color: var(--color-primary);
    border: 2px solid var(--color-primary);
    border-radius: 0;
    padding: 4px 12px;
    cursor: pointer;
}

.pp-button:hover,
.pp-button:focus-visible {
    background-color: var(--color-hover);
    border-color: var(--color-hover);
    outline: none;
}

.pp-button:disabled {
    background-color: var(--color-bg);
    color: var(--color-muted);
    border-color: var(--color-muted);
    cursor: not-allowed;
}

.pp-button-small {
    padding: 2px 8px;
    font-size: 14px;
}

.pp-button-big {
    font-size: 22px;
    padding: 8px 24px;
    background-color: var(--color-positive);
    border-color: var(--color-positive);
}

.pp-button-danger {
    background-color: var(--color-bg);
    color: var(--color-negative);
    border-color: var(--color-negative);
}

.pp-button-danger:hover,
.pp-button-danger:focus-visible {
    background-color: var(--color-negative);
    border-color: var(--color-negative);
    color: var(--color-bg);
}

.pp-tag {
    font-size: 12px;
    color: var(--color-bg);
    background-color: var(--color-accent);
    padding: 0 4px;
    margin-left: 8px;
}

.pp-tag-you {
    background-color: var(--color-positive);
}

.pp-tag-ai {
    background-color: #c080ff;
}

/* ---- menu: name + browse ---- */

.pp-menu {
    max-width: 800px;
    margin: 0 auto;
}

.pp-name-form {
    max-width: 420px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    text-align: center;
}

.pp-name-form .pp-heading {
    margin-bottom: 0;
}

.pp-input-big {
    font-size: 24px;
    padding: 8px 12px;
    text-align: center;
}

.pp-whoami {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    color: var(--color-muted);
    margin-bottom: 16px;
}

.pp-whoami-name {
    color: var(--color-positive);
}

.pp-browse-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.pp-browse-head .pp-heading {
    margin-bottom: 0;
}

.pp-lobby-table {
    width: 100%;
    border-collapse: collapse;
}

.pp-lobby-table th {
    text-align: left;
    color: var(--color-muted);
    font-weight: normal;
    border-bottom: 1px solid var(--color-muted);
    padding: 4px 6px;
}

.pp-lobby-table td {
    padding: 6px;
    border-bottom: 1px dashed #004040;
    overflow-wrap: anywhere;
}

.pp-lobby-table td:last-child {
    text-align: right;
}

.pp-empty {
    color: var(--color-muted);
    padding: 12px 6px;
}

/* ---- lobby ---- */

.pp-lobby-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.pp-lobby-grid {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    gap: 16px;
}

@media (max-width: 800px) {
    .pp-lobby-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

.pp-players {
    list-style: none;
}

.pp-player {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px dashed #004040;
}

.pp-player-mine .pp-player-name {
    color: var(--color-positive);
}

.pp-player-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
}

.pp-mini-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pp-mini-field .pp-input-small {
    width: 6em;
}

.pp-mini-field select.pp-input-small {
    width: 9em;
}

.pp-add-local {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

/* The name box keeps a usable width; the buttons wrap below it on phones. */
.pp-add-local .pp-input {
    flex: 1 1 160px;
}

.pp-rules {
    border: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0 12px;
}

.pp-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.pp-check input {
    accent-color: var(--color-accent);
    width: 18px;
    height: 18px;
}

.pp-start-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
}

/* ---- controls legend (lobby, under each local player's input picker) ---- */

.pp-player-legend {
    flex-basis: 100%;
}

.pp-legend {
    border-collapse: collapse;
    font-size: 12px;
    color: var(--color-muted);
}

.pp-legend th,
.pp-legend td {
    text-align: left;
    font-weight: normal;
    padding: 1px 10px 1px 0;
    white-space: nowrap;
}

.pp-legend-scheme {
    color: var(--color-muted);
}

.pp-legend-keys {
    color: var(--color-primary);
}

.pp-legend-off {
    color: var(--color-muted);
    text-decoration: line-through;
}

/* ---- accounts (optional) ---- */

.pp-form-error {
    color: var(--color-negative);
    min-height: 1.4em;
    font-size: 14px;
}

.pp-account-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 13px;
}

.pp-star {
    color: var(--color-accent);
    font-size: 13px;
}

.pp-recovery-row {
    display: flex;
    gap: 8px;
    margin: 12px 0 4px;
}

.pp-recovery-row .pp-input {
    flex: 1;
    font-size: 13px;
    color: var(--color-positive);
}

.pp-dialog p {
    margin-bottom: 8px;
}

.pp-account-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
    margin: 8px 0 12px;
}

.pp-auth-switch {
    margin-right: auto;
    background-color: var(--color-bg);
    color: var(--color-primary);
}

/* ---- stats (registered players) ---- */

.pp-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px 16px;
    margin-bottom: 4px;
}

.pp-stat-cell {
    display: flex;
    flex-direction: column;
}

.pp-stat-cell-label {
    color: var(--color-muted);
    font-size: 12px;
}

.pp-stat-cell-value {
    color: var(--color-accent);
    font-size: 18px;
}

.pp-stats-hint {
    font-size: 13px;
    margin-bottom: 12px;
}

.pp-name-link {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    text-decoration: underline dotted;
    text-underline-offset: 3px;
}

.pp-name-link:hover,
.pp-name-link:focus-visible {
    color: var(--color-hover);
    outline: none;
}

#pp-stats-dialog {
    min-width: min(480px, calc(100vw - 32px));
}

/* ---- front screen menu, solo play, leaderboards ---- */

.pp-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--color-primary);
}

.pp-tab {
    font: inherit;
    font-size: 18px;
    padding: 6px 18px;
    background-color: var(--color-bg);
    color: var(--color-muted);
    border: 2px solid var(--color-muted);
    border-bottom: none;
    border-radius: 0;
    cursor: pointer;
    margin-right: 6px;
}

.pp-tab[aria-selected="true"] {
    color: var(--color-bg);
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

.pp-tab:focus-visible {
    outline: 2px solid var(--color-hover);
}

.pp-browse-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pp-button-solo {
    background-color: var(--color-accent);
    border-color: var(--color-accent);
}

.pp-button-vsai {
    background-color: #c080ff;
    border-color: #c080ff;
}

.pp-results-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

body.pp-solo #pp-match-chat-slot,
body.pp-solo .pp-chat-hint {
    display: none;
}

.pp-leaders-note {
    font-size: 13px;
    margin-bottom: 12px;
}

.pp-leaderboards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}

.pp-board-card {
    margin-bottom: 0;
}

.pp-leader-list {
    list-style: none;
}

.pp-leader-row {
    display: grid;
    grid-template-columns: 2.2em 1fr auto;
    gap: 6px;
    padding: 2px 0;
    font-size: 14px;
    align-items: baseline;
}

.pp-leader-empty {
    font-size: 14px;
    padding: 2px 0;
}

.pp-leader-rank {
    color: var(--color-muted);
}

.pp-leader-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

.pp-leader-value {
    color: var(--color-accent);
}

/* HiRMU, the eternal number one. */
.pp-leader-legend {
    color: var(--color-gold, #ffb800);
    text-shadow: 0 0 6px rgba(255, 184, 0, 0.6);
}

.pp-leader-legend .pp-leader-rank,
.pp-leader-legend .pp-leader-value {
    color: var(--color-gold, #ffb800);
}

/* ---- voice controls ---- */

.pp-voice-toggle {
    background-color: var(--color-bg);
    color: var(--color-muted);
    border-color: var(--color-muted);
}

.pp-voice-toggle.pp-on {
    background-color: var(--color-accent);
    color: var(--color-bg);
    border-color: var(--color-accent);
}

.pp-voice-note {
    margin-top: 6px;
}

.pp-legend-note p {
    margin-bottom: 2px;
}

.pp-voice-status,
.pp-match-voice {
    color: var(--color-accent);
    font-size: 12px;
}

.pp-match-voice {
    border: 1px solid var(--color-accent);
    padding: 1px 6px;
    max-width: 50vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- chat ---- */

.pp-chat {
    display: flex;
    flex-direction: column;
}

.pp-chat-log {
    list-style: none;
    height: var(--chat-height);
    overflow-y: auto;
    border: 1px solid #004040;
    background-color: var(--color-bg);
    padding: 6px;
    margin-bottom: 8px;
    overflow-wrap: anywhere;
}

#pp-match-chat-slot .pp-chat-log {
    height: var(--chat-height-match);
}

.pp-chat-line {
    color: #c0ffff;
}

.pp-chat-from {
    color: var(--color-accent);
}

.pp-chat-system {
    color: var(--color-muted);
}

.pp-chat-form {
    display: flex;
    gap: 8px;
}

.pp-chat-form .pp-input {
    flex: 1;
}

/* ---- match ---- */

.pp-match-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.pp-match-clock {
    color: var(--color-accent);
    font-size: 20px;
}

.pp-boards {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}

/* All boards share one size, which shrinks as more boards share the row and
   with the window width so the row doesn't wrap. ~110px per board is the
   header/side-panel/padding overhead; 320/170 is the canvas aspect. */
.pp-boards[data-count="2"] {
    --board-height: max(160px, min(68vh, 560px, calc((100vw - 32px - 2 * 110px - 1 * 16px) / 2 * 320 / 170)));
}

.pp-boards[data-count="3"] {
    --board-height: max(160px, min(58vh, 480px, calc((100vw - 32px - 3 * 110px - 2 * 16px) / 3 * 320 / 170)));
}

/* The 160px floors stop boards collapsing to nothing in a narrow window;
   they wrap onto more rows instead. */
.pp-boards[data-count="4"] {
    --board-height: max(160px, min(52vh, 440px, calc((100vw - 32px - 4 * 110px - 3 * 16px) / 4 * 320 / 170)));
}

.pp-board {
    border: var(--border);
    background-color: var(--color-bg-alt);
    padding: 6px;
}

.pp-board-local {
    border-color: var(--color-gold);
    box-shadow: 0 0 12px rgba(255, 184, 0, 0.45);
}

.pp-board-header {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.pp-board-name {
    color: var(--color-accent);
}

.pp-board-device {
    color: var(--color-muted);
    font-size: 12px;
}

.pp-board-status {
    height: 14px;
    line-height: 14px;
    overflow: hidden;
    white-space: nowrap;
    font-size: 11px;
    color: #c080ff;
    margin-bottom: 2px;
}

.pp-board-shielded .pp-board-well {
    box-shadow: 0 0 10px 2px #40ffff;
}

.pp-board-powers {
    font-size: 11px;
    min-height: 2.6em;
    margin-bottom: 6px;
    color: var(--color-muted);
}

.pp-board-power {
    line-height: 1.3;
}

.pp-board-body {
    display: flex;
    gap: 6px;
}

.pp-board-well {
    position: relative;
}

.pp-board-canvas {
    display: block;
    height: var(--board-height);
    aspect-ratio: 170 / 320; /* canvas size from render.js */
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.pp-board-side {
    display: flex;
    flex-direction: column;
    min-width: 64px;
}

.pp-board-preview {
    width: 64px;
    image-rendering: pixelated;
    border: 1px solid #004040;
    margin-bottom: 8px;
}

.pp-stat-label {
    color: var(--color-muted);
    font-size: 12px;
}

.pp-stat-value {
    color: var(--color-primary);
    margin-bottom: 6px;
}

.pp-board-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    color: var(--color-accent);
    text-shadow: 3px 3px 0 var(--color-bg), -1px -1px 0 var(--color-bg);
    background-color: rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

.pp-board-overlay.pp-visible {
    display: flex;
}

.pp-board-meter-flash {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    opacity: 0;
    pointer-events: none;
}

.pp-board-meter-flash.pp-visible {
    animation: pp-meter-flash 0.5s steps(5) forwards;
}

@keyframes pp-meter-flash {
    0% { opacity: 1; box-shadow: 0 0 12px 4px currentColor; }
    100% { opacity: 0; }
}

/* Full-viewport layer for the crap-flinging particles. */
.pp-fx-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 400;
}

/* ---- results ---- */

.pp-results {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 500;
    padding: 16px;
}

.pp-results-box {
    border: 2px solid var(--color-accent);
    background-color: var(--color-bg-alt);
    padding: 20px;
    min-width: min(420px, 100%);
}

.pp-results-list {
    margin: 12px 0 20px 1.6em;
}

.pp-results-list li {
    padding: 4px 0;
}

.pp-results-winner {
    color: var(--color-accent);
}

/* ---- dialogs + toast ---- */

.pp-dialog {
    margin: auto;
    border: 2px solid var(--color-accent);
    background-color: var(--color-bg-alt);
    color: var(--color-primary);
    padding: 20px;
    max-width: min(640px, calc(100vw - 32px));
}

.pp-dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.7);
}

.pp-dialog .pp-input {
    width: 100%;
}

.pp-dialog-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

.pp-controls-dialog {
    max-width: min(760px, calc(100vw - 32px));
}

.pp-controls-dialog .pp-muted {
    margin-bottom: 8px;
    font-size: 14px;
}

.pp-controls-table {
    width: 100%;
    border-collapse: collapse;
}

.pp-controls-table th,
.pp-controls-table td {
    text-align: left;
    vertical-align: middle;
    padding: 4px;
    font-weight: normal;
}

.pp-controls-table thead th {
    color: var(--color-muted);
}

.pp-bind-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.pp-bind-add {
    background-color: var(--color-bg);
    color: var(--color-primary);
}

.pp-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    background-color: var(--color-negative);
    color: var(--color-bg);
    padding: 8px 16px;
    z-index: 900;
    display: none;
}

.pp-toast.pp-visible {
    display: block;
}

/* ---- touch pad (touch devices, during a match) ---- */

.pp-touchpad {
    display: none;
}

body.pp-touch {
    --tp-height: 210px;
}

body.pp-touch[data-screen="match"] .pp-main {
    /* The pad is fixed over the bottom; keep content clear of it. */
    padding-bottom: var(--tp-height);
}

body.pp-touch[data-screen="match"] .pp-touchpad {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--tp-height) + env(safe-area-inset-bottom));
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--color-bg-alt);
    border-top: 2px solid var(--color-primary);
    z-index: 300;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* Keyboard-only hints make no sense on a touch screen. */
body.pp-touch .pp-chat-hint,
body.pp-touch[data-screen="match"] #pp-controls-button {
    display: none;
}

.pp-touchpad button {
    font: inherit;
    border-radius: 0;
    padding: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.pp-touchpad svg {
    width: 55%;
    height: 55%;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
    stroke-linecap: square;
    pointer-events: none;
}

.pp-touchpad svg .pp-tp-fill {
    fill: currentColor;
    stroke: none;
}

/* D-pad: a plus shape on a 3x3 grid. */
.pp-tp-dpad {
    --cell: min(60px, 16vw);
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, var(--cell));
    grid-template-rows: repeat(3, var(--cell));
}

.pp-tp-key,
.pp-tp-hub {
    background-color: #003838;
    border: 2px solid var(--color-primary);
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.pp-tp-hub {
    grid-area: 2 / 2;
    border-color: transparent;
}

.pp-tp-up { grid-area: 1 / 2; }
.pp-tp-left { grid-area: 2 / 1; }
.pp-tp-right { grid-area: 2 / 3; }
.pp-tp-down { grid-area: 3 / 2; }

.pp-tp-key.pp-pressed {
    background-color: var(--color-primary);
    color: var(--color-bg);
}

.pp-tp-label {
    position: absolute;
    font-size: 10px;
    color: var(--color-muted);
    white-space: nowrap;
    pointer-events: none;
}

.pp-tp-label-up {
    /* Beside the ↑ key, in the empty top-right corner of the plus. */
    left: calc(var(--cell) * 2 + 6px);
    top: calc(var(--cell) / 2);
    transform: translateY(-50%);
}

/* Rotate buttons on a diagonal, HOLD tucked in the corner. */
.pp-tp-actions {
    --round: min(76px, 20vw);
    position: relative;
    width: calc(var(--round) * 2 + 16px);
    height: calc(var(--round) * 2 + 10px);
}

.pp-tp-round {
    position: absolute;
    width: var(--round);
    height: var(--round);
    border-radius: 50% !important;
    background-color: #ff2a6d;
    border: 3px solid #ff9ab8;
    color: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.pp-tp-round.pp-pressed {
    background-color: #ff9ab8;
    transform: translateY(2px);
}

.pp-tp-ccw {
    left: 0;
    bottom: 12px;
}

.pp-tp-cw {
    right: 0;
    top: 0;
}

.pp-tp-label-ccw {
    left: calc(var(--round) / 2);
    bottom: -4px;
    transform: translateX(-50%);
}

.pp-tp-label-cw {
    right: calc(var(--round) / 2);
    top: calc(var(--round) + 2px);
    transform: translateX(50%);
}

.pp-tp-hold {
    position: absolute;
    right: 0;
    bottom: 0;
    height: 30px;
    padding: 0 12px !important;
    border: 2px solid var(--color-accent);
    color: var(--color-accent);
    background-color: #1a1a00;
    font-size: 12px !important;
}

.pp-tp-use {
    position: absolute;
    left: 0;
    top: 0;
    height: 30px;
    padding: 0 12px !important;
    border: 2px solid #c080ff;
    color: #c080ff;
    background-color: #1a0026;
    font-size: 12px !important;
}

.pp-tp-use.pp-pressed {
    background-color: #c080ff;
    color: var(--color-bg);
}

.pp-tp-hold.pp-pressed {
    background-color: var(--color-accent);
    color: var(--color-bg);
}

/* ---- phone layout: opponents small in a row on top, yours big below ---- */

@media (max-width: 700px) {
    body[data-screen="match"] .pp-main {
        padding-left: 6px;
        padding-right: 6px;
        padding-top: 6px;
    }

    body[data-screen="match"] .pp-topbar {
        padding: 4px 8px;
    }

    body[data-screen="match"] .pp-logo {
        --logo-small-height: 28px;
    }

    body[data-screen="match"] .pp-match-head {
        margin-bottom: 6px;
    }

    body[data-screen="match"] .pp-match-clock {
        font-size: 14px;
    }

    /* No room for chat during a match on a phone. */
    #pp-match-chat-slot {
        display: none;
    }

    body.pp-touch {
        --tp-height: 172px;
    }

    .pp-tp-dpad {
        --cell: min(50px, 14vw);
    }

    .pp-tp-actions {
        --round: min(62px, 17vw);
    }

    /* [data-count] matches the desktop per-count rules' specificity, and
       being later in the file, wins over them on phones. */
    .pp-boards,
    .pp-boards[data-count] {
        --opp-canvas: 80px;
        --opp-row: 118px;
        gap: 6px;
        margin-bottom: 0;
        /* Your board fills what's left under the opponents' row and above the
           pad: ~156px covers the top bar, the match header, your board's own
           header/frame and the gaps. */
        --board-height: max(150px, calc(100vh - var(--tp-height) - var(--opp-row) - 156px));
        --board-height: max(150px, calc(100dvh - var(--tp-height) - var(--opp-row) - 156px));
    }

    .pp-boards[data-count="1"] {
        --opp-row: 0px;
    }

    /* Opponents first, then a forced line break, then your board(s). */
    .pp-boards::before {
        content: '';
        order: 0;
        flex-basis: 100%;
        height: 0;
    }

    .pp-board:not(.pp-board-local) {
        order: -1;
        padding: 3px;
    }

    .pp-board-local {
        order: 1;
    }

    .pp-board:not(.pp-board-local) .pp-board-canvas {
        height: var(--opp-canvas);
    }

    .pp-board:not(.pp-board-local) .pp-board-header {
        font-size: 11px;
        margin-bottom: 2px;
    }

    .pp-board:not(.pp-board-local) .pp-board-side {
        min-width: 0;
        font-size: 10px;
    }

    .pp-board:not(.pp-board-local) .pp-preview-label,
    .pp-board:not(.pp-board-local) .pp-board-preview,
    .pp-board:not(.pp-board-local) .pp-stat-level {
        display: none;
    }

    .pp-board:not(.pp-board-local) .pp-stat-label,
    .pp-board:not(.pp-board-local) .pp-stat-value {
        font-size: 10px;
        margin-bottom: 0;
    }

    .pp-board:not(.pp-board-local) .pp-board-overlay {
        font-size: 18px;
    }
}

/* REVERSE power-up landing: the well flips over and back. */
.pp-board-well.pp-flip {
    animation: pp-flip 520ms ease-in-out;
}

@keyframes pp-flip {
    0% { transform: scaleX(1); }
    50% { transform: scaleX(-1); }
    100% { transform: scaleX(1); }
}

/* A collected power-up lands in the POWER box. */
.pp-board-powers.pp-pop {
    animation: pp-pop 360ms ease-out;
}

@keyframes pp-pop {
    0% { transform: scale(1); filter: brightness(1); }
    35% { transform: scale(1.35); filter: brightness(2.2); }
    100% { transform: scale(1); filter: brightness(1); }
}

@media (prefers-reduced-motion: reduce) {
    .pp-board-well.pp-flip,
    .pp-board-powers.pp-pop {
        animation: none;
    }
}

/* The logo after the 3-2-1: zooms in with the "PIPPIPII!" shout, then blows
   up past the screen edges and fades as play starts (match.js). */
.pp-intro {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 450;
    overflow: hidden;
}

.pp-intro img {
    width: min(80vw, 800px);
    height: auto;
    filter: drop-shadow(0 0 24px rgba(255, 64, 255, 0.6));
    animation: pp-intro-in 350ms cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

.pp-intro.pp-intro-out img {
    animation: pp-intro-out 600ms ease-in forwards;
}

@keyframes pp-intro-in {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes pp-intro-out {
    from { transform: scale(1); opacity: 1; }
    to { transform: scale(4); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .pp-intro img {
        animation-name: pp-intro-fade-in;
    }

    .pp-intro.pp-intro-out img {
        animation-name: pp-intro-fade-out;
    }

    @keyframes pp-intro-fade-in {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    @keyframes pp-intro-fade-out {
        from { opacity: 1; }
        to { opacity: 0; }
    }
}

/* ---- settings dialog ---- */

.pp-settings {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px 16px;
    margin: 12px 0;
}

.pp-setting-label {
    font-size: 14px;
}

.pp-toggle[aria-pressed="true"] {
    background-color: var(--color-positive);
    border-color: var(--color-positive);
}

.pp-fineprint {
    font-size: 9px;
}

/* ---- the announcer in the corner (js/avatar.js) ---- */

.pp-announcer {
    position: fixed;
    right: 12px;
    bottom: 12px;
    z-index: 300;
    display: flex;
    /* Subtitle to the left of the vet, in the strip below the boards. */
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
    pointer-events: none;
}

.pp-announcer-canvas {
    display: block;
    width: 216px; /* 72x48 sprite pixels at 3x */
    height: 144px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background-color: rgba(0, 0, 0, 0.65);
    border: 2px solid var(--color-primary);
}

.pp-caption {
    max-width: min(440px, 70vw);
    padding: 4px 8px;
    font-size: 14px;
    line-height: 1.35;
    color: #ffffff;
    background-color: rgba(0, 0, 0, 0.88);
    border: 2px solid var(--color-accent);
    text-align: right;
}

@media (max-width: 700px) {
    .pp-announcer {
        flex-direction: column;
    }

    .pp-announcer-canvas {
        width: 144px; /* 2x */
        height: 96px;
    }

    .pp-caption {
        font-size: 12px;
    }
}

/* Phones: sit above the touch pad. */
body.pp-touch[data-screen="match"] .pp-announcer {
    bottom: calc(var(--tp-height) + 8px);
}

body.pp-touch .pp-announcer-canvas {
    width: 108px; /* 1.5x */
    height: 72px;
}

/* Phones: subtitles go to the top, so they never cover the bottom of the well. */
body.pp-touch .pp-caption {
    position: fixed;
    top: 64px;
    left: 8px;
    right: 8px;
    max-width: none;
    text-align: center;
}

.pp-setting-note {
    grid-column: 1 / -1;
    margin: 0;
    font-size: 11px;
}
