/* Reset, page shell, typography, and the two primitives everything else is
 * composed from: the gold-framed notched panel, and the pixel button. */

/* Not on Google Fonts, so vendored rather than linked -- same reasoning as
 * Press Start 2P, but this is the only copy that exists (no CDN fallback).
 * Free for personal use (dafont); a commercial licence exists from the
 * author but isn't purchased here -- fine for this non-monetised, five
 * -friends project, but don't reuse this file in anything sold or
 * monetised without buying one (see README.md). The url() here is relative
 * to this file's own location, not the document's -- build.py swaps it for
 * an inlined data URI in the bundled output, where that distinction doesn't
 * survive being pasted into one file. */
@font-face {
  font-family: 'Pixelmax';
  src: url('../assets/fonts/pixelmax.otf') format('opentype');
  font-display: swap;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

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

body {
  min-height: 100vh;
  background-color: var(--bg);
  /* A dot grid so large dark areas still read as pixel art, over a very slight
   * cold bloom from the top so the page is not a flat field of black. */
  background-image:
    radial-gradient(rgba(196, 214, 255, 0.045) 1px, transparent 0),
    radial-gradient(120% 70% at 50% 0%, rgba(70, 92, 150, 0.16), transparent 70%);
  background-size: 4px 4px, auto;
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 10px;
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
}

img {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

/* All pixel art scales with hard edges, never smoothed. */
.sprite,
.portrait__img {
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

/* Sprites carry width/height attributes. Once `max-width: 100%` starts shrinking
 * one in a narrow column, a fixed height would stretch the art, so height is
 * always derived from the width. */
.sprite {
  height: auto;
}

:focus-visible {
  outline: var(--fw) solid var(--gold);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- type */

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: 0.02em;
}

.micro-label {
  display: block;
  font-family: var(--font-display);
  font-size: 8px;
  line-height: 1.4;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}

.muted-note {
  color: var(--ink-faint);
  font-size: 9px;
  line-height: 1.8;
}

/* ---------------------------------------------------------------- shell */

#app {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.view {
  width: 100%;
  max-width: var(--shell);
  margin: 0 auto;
  padding: var(--s6) var(--s5) var(--s8);
  flex: 1;
}

.page {
  display: flex;
  flex-direction: column;
  gap: var(--s6);
}

.section {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}

/* ---------------------------------------------------------------- panel */

/* Two nested elements: the outer paints the gold frame, the inner the stone
 * surface. Both are clipped to the same notched polygon, which yields bevelled
 * pixel corners that a border-radius cannot produce. The frame carries a
 * top-to-bottom gradient so the gold reads as lit from above. */
.panel {
  --notch: 7px;
  position: relative;
  padding: var(--fw);
  background: linear-gradient(var(--edge-bright), var(--edge) 38%, var(--edge-dim));
  clip-path: polygon(
    var(--notch) 0,
    calc(100% - var(--notch)) 0,
    100% var(--notch),
    100% calc(100% - var(--notch)),
    calc(100% - var(--notch)) 100%,
    var(--notch) 100%,
    0 calc(100% - var(--notch)),
    0 var(--notch)
  );
}

.panel__in {
  position: relative;
  height: 100%;
  padding: var(--s4);
  background: linear-gradient(var(--panel-2), var(--panel) 42%);
  /* Top-inner light line and bottom-inner shadow: the classic window bevel. */
  box-shadow:
    inset 0 2px 0 var(--bevel),
    inset 0 -2px 0 var(--bevel-dim);
  clip-path: polygon(
    var(--notch-sm) 0,
    calc(100% - var(--notch-sm)) 0,
    100% var(--notch-sm),
    100% calc(100% - var(--notch-sm)),
    calc(100% - var(--notch-sm)) 100%,
    var(--notch-sm) 100%,
    0 calc(100% - var(--notch-sm)),
    0 var(--notch-sm)
  );
}

/* Corner filigree on every panel.
 *
 * Four background layers, one per corner, from CSS custom properties that
 * src/ui/sprite.js fills in at startup: it renders one hand-drawn ornament and
 * mirrors it for the other three corners. Doing it as backgrounds rather than
 * elements means any panel gets all four for free without touching its markup.
 */
.panel__in::after {
  content: '';
  position: absolute;
  inset: 2px;
  pointer-events: none;
  background-image: var(--corner-tl), var(--corner-tr), var(--corner-bl), var(--corner-br);
  background-position: left top, right top, left bottom, right bottom;
  background-size: 13px 13px;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  opacity: 0.85;
  transition: opacity 160ms var(--ease);
}

/* Dense list rows carry a smaller, quieter ornament, so ninety history rows read
 * as texture rather than as ninety competing decorations. */
.match-card > .panel__in::after {
  inset: 1px;
  background-size: 8px 8px;
  opacity: 0.55;
}

/* The leaderboard's own rows go without: the curl sat close enough to the
 * WINS/PLAYED/WIN RATE figures that on the champion row (which used to
 * amplify its own corners further still) it landed on top of the text. */
.ladder-row > .panel__in::after {
  display: none;
}

/* ---------------------------------------------------------------- button */

.pixel-btn {
  --btn-face: var(--panel-2);
  --btn-edge: var(--edge);
  --btn-ink: var(--ink);
  --btn-bevel: var(--bevel);
  --btn-shade: var(--bevel-dim);
  display: inline-block;
  padding: var(--fw);
  background: linear-gradient(var(--edge-bright), var(--btn-edge) 40%, var(--edge-dim));
  clip-path: polygon(
    5px 0, calc(100% - 5px) 0, 100% 5px, 100% calc(100% - 5px),
    calc(100% - 5px) 100%, 5px 100%, 0 calc(100% - 5px), 0 5px
  );
  transition: transform 90ms var(--ease);
}

.pixel-btn__face {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  padding: 9px var(--s4);
  background: var(--btn-face);
  color: var(--btn-ink);
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.06em;
  white-space: nowrap;
  box-shadow:
    inset 0 2px 0 var(--btn-bevel),
    inset 0 -2px 0 var(--btn-shade);
  clip-path: polygon(
    3px 0, calc(100% - 3px) 0, 100% 3px, 100% calc(100% - 3px),
    calc(100% - 3px) 100%, 3px 100%, 0 calc(100% - 3px), 0 3px
  );
}

.pixel-btn:hover .pixel-btn__face {
  filter: brightness(1.16);
}

/* Press moves the whole button down a pixel: cheap, tactile, no layout shift. */
.pixel-btn:active {
  transform: translateY(2px);
}

/* A primary action: set apart from the default button by weight as well as
 * hue -- a heavier frame, a doubled inner border, and the same corner
 * filigree the panels use, scaled down. */
.pixel-btn--primary {
  --btn-face: var(--cta);
  --btn-ink: var(--cta-ink);
  --btn-bevel: var(--cta-bright);
  --btn-shade: var(--cta-deep);
  padding: 4px;
  background: linear-gradient(#ffeec0, var(--edge) 45%, var(--edge-dim));
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.4);
}

.pixel-btn--primary .pixel-btn__face {
  position: relative;
  box-shadow:
    inset 0 0 0 2px var(--cta-deep),
    inset 0 3px 0 var(--btn-bevel),
    inset 0 -3px 0 var(--cta-deep);
}

/* Corner filigree, same ornament as the panels. */
.pixel-btn--primary .pixel-btn__face::after {
  content: '';
  position: absolute;
  inset: 2px;
  pointer-events: none;
  background-image: var(--corner-tl), var(--corner-tr), var(--corner-bl), var(--corner-br);
  background-position: left top, right top, left bottom, right bottom;
  background-size: 7px 7px;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  opacity: 0.55;
  mix-blend-mode: multiply;
}

.pixel-btn--primary:hover .pixel-btn__face::after {
  opacity: 0.8;
}

/* LOG GAME only: an extra modifier layered on top of --primary (keeps its
 * frame, padding and corner filigree) that swaps just the face colour to
 * gold and adds a slow pulse, so this one button reads as the loudest thing
 * on screen -- everywhere else that shares --primary stays on the blue
 * accent. Re-declares the two rules above that hardcode --cta-deep rather
 * than reading the --btn-* custom properties, since those need the hero
 * tokens specifically. */
.pixel-btn--hero {
  --btn-face: var(--hero);
  --btn-ink: var(--hero-ink);
  --btn-bevel: var(--hero-bright);
  --btn-shade: var(--hero-deep);
  animation: cta-pulse 2.6s ease-in-out infinite;
}

.pixel-btn--hero .pixel-btn__face {
  box-shadow:
    inset 0 0 0 2px var(--hero-deep),
    inset 0 3px 0 var(--hero-bright),
    inset 0 -3px 0 var(--hero-deep);
}

@keyframes cta-pulse {
  0%, 100% { filter: drop-shadow(0 0 5px rgba(240, 194, 70, 0.4)); }
  50% { filter: drop-shadow(0 0 15px rgba(240, 194, 70, 0.8)); }
}

@media (prefers-reduced-motion: reduce) {
  .pixel-btn--hero {
    animation: none;
    filter: drop-shadow(0 0 8px rgba(240, 194, 70, 0.5));
  }
}

.pixel-btn--ghost {
  --btn-face: transparent;
  --btn-edge: var(--edge-dim);
  --btn-ink: var(--ink-dim);
  --btn-bevel: transparent;
  --btn-shade: transparent;
  background: var(--edge-dim);
}

.pixel-btn--ghost .pixel-btn__face {
  box-shadow: none;
}

.pixel-btn--ghost:hover .pixel-btn__face {
  background: var(--panel-2);
  color: var(--ink);
  filter: none;
}

.pixel-btn--lg .pixel-btn__face {
  padding: 12px var(--s5);
  font-size: 10px;
}

.pixel-btn--wide {
  width: 100%;
}

.pixel-btn--wide .pixel-btn__face {
  width: 100%;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  color: var(--ink-faint);
  font-size: 17px;
  line-height: 1;
  background: var(--well);
  transition: color 120ms, background 120ms;
}

.icon-btn:hover {
  color: var(--loss);
  background: var(--panel-3);
}

.icon-btn--lg {
  width: 32px;
  height: 32px;
  font-size: 22px;
}
