/* Everything is authored at 1x and scaled up by the root zoom. Integer scales keep pixel art crisp. */
:root {
  --site-scale: 2;
  --site-viewport-width: calc(100vw / var(--site-scale));
  --site-viewport-height: calc(100dvh / var(--site-scale));
  --button-normal: url("../assets/textures/godot-theme/button-normal.png");
  --button-focus: url("../assets/textures/godot-theme/button-focus.png");
  --button-pressed: url("../assets/textures/godot-theme/button-pressed.png");
  --round-rect: url("../assets/textures/round_rect.png");
  /* Rectangle with two-pixel stepped corners, matching the panel artwork. */
  --stepped-corners: polygon(
    2px 0, calc(100% - 2px) 0, calc(100% - 2px) 1px, calc(100% - 1px) 1px,
    calc(100% - 1px) 2px, 100% 2px, 100% calc(100% - 2px), calc(100% - 1px) calc(100% - 2px),
    calc(100% - 1px) calc(100% - 1px), calc(100% - 2px) calc(100% - 1px), calc(100% - 2px) 100%, 2px 100%,
    2px calc(100% - 1px), 1px calc(100% - 1px), 1px calc(100% - 2px), 0 calc(100% - 2px),
    0 2px, 1px 2px, 1px 1px, 2px 1px);
  zoom: var(--site-scale);
  color-scheme: dark;
  font-family: "m5x7", "Mona", monospace;
  font-size: 8px;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
  image-rendering: pixelated;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  min-height: var(--site-viewport-height);
  font-size: 16px;
  color: #ffffff;
  background: #ffffff;
  isolation: isolate;
  cursor: url("../assets/textures/cursor.png") 6 2, auto;
}

/* Background doodles */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: url("../assets/textures/doodle_pattern.png") center / 1024px;
  filter: invert(1);
  opacity: 0.06;
  pointer-events: none;
}

a {
  -webkit-tap-highlight-color: transparent;
  color: inherit;
}

h1 {
  font-family: "1980 P02", "Mona", monospace;
  font-size: 2rem;
  font-weight: 400;
  line-height: 1;
  color: #ffffff;
}

h2 {
  font-family: "1980 P04", "Mona", monospace;
  font-size: 2rem;
  color: #e6e6e6;
}

p {
  margin-bottom: 8px;
}

::selection {
  background: white;
  color: black;
}

/* Panels and buttons draw their 9-slice artwork from --surface. */
.panel,
.pixel-button {
  border: calc(var(--edge-width) * 1px) solid transparent;
  border-image: var(--surface) var(--edge-width) fill;
}

.panel {
  --edge-width: 4;
  --surface: var(--button-normal);
  width: round(down, 100%, 1px);
  min-width: 0;
}

.panel header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 4px;
  min-height: 19px;
  padding: 1px 4px;
  border-bottom: 1px solid #303034;
  font-family: "m3x6", "Mona", monospace;
  color: #a6a6ae;
  overflow-wrap: anywhere;
}

.panel header > span {
  line-height: 1;
}

.panel section:has(figure) header {
  border-bottom: 0;
}

.pixel-button {
  --edge-width: 3;
  --surface: var(--button-normal);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 40px;
  min-height: 14px;
  padding: 0 6px;
  font-family: "1980 P03", "Mona", monospace;
  line-height: 8px;
  white-space: nowrap;
  text-decoration: none;
}

.solid-button {
  --surface: var(--round-rect);
  color: #000000;
}

.solid-button > span {
  transform: translateY(-2px);
}

/* Blue fill behind the text on hover, masked to the button's rounded shape. */
@media (hover: hover) {
  .solid-button:not([data-live]):hover {
    position: relative;
    isolation: isolate;
    color: #ffffff;
  }

  .solid-button:not([data-live]):hover::before {
    content: "";
    position: absolute;
    inset: -3px;
    z-index: -1;
    background: blue;
    -webkit-mask-box-image: var(--round-rect) 3 fill / 3px / 0 stretch;
    mask-border: var(--round-rect) 3 fill / 3px / 0 stretch;
  }
}

.solid-button[data-live] {
  --surface: var(--button-focus);
  color: #ffffff;
}

.solid-button[data-live]:is(:hover, :focus-visible) {
  --surface: var(--button-pressed);
  color: #000000;
}

/* Page layout: content on the left, sidebar on the right. Stacked on narrow screens. */
.site {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 320px) 136px;
  grid-template-areas: "content sidebar";
  align-items: start;
  gap: 8px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 40px 8px 32px;
}

.site > aside {
  grid-area: sidebar;
  display: grid;
  gap: 4px;
}

.site > main {
  grid-area: content;
}

@media (max-width: 767px) {
  .site {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "sidebar" "content";
    max-width: min(336px, calc(var(--site-viewport-width) - 4px));
    padding-inline: 2px;
  }
}

/* Main content */
.panel figure {
  width: calc(100% + 6px);
  height: 75px;
  margin-inline: -3px;
  overflow: hidden;
  animation: image-reveal 500ms ease-out both;
}

@keyframes image-reveal {
  from { clip-path: inset(49% 0 49%); }
  to { clip-path: inset(0); }
}

.panel figure img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.panel article {
  min-height: 152px;
  padding: 8px 6px;
  font-family: "PixelCode", "Mona", monospace;
  font-size: 9px;
  color: #a6a6ae;
  overflow-wrap: anywhere;
}

.panel article > :last-child {
  margin-bottom: 0;
}

article a:hover {
  color: white;
}

img.emote {
  height: 1em;
  vertical-align: -0.15em;
}

img.char-icon {
  height: 1em;
  vertical-align: -0.1em;
  zoom: 2;
  margin: -0.2em -0.1em;
}

.friend-buttons img {
  zoom: 0.5;
}

body > footer {
  display: grid;
  place-items: center;
  min-height: 96px;
  padding: 24px 8px;
  background: black;
  font-family: "m3x6", "Mona", monospace;
  color: #a6a6ae;
  text-align: center;
}

body > footer a:hover {
  color: #ffffff;
}

@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after {
    animation: none !important;
    transition: none !important;
  }
}

/* Firefox: zoom breaks custom cursor size and border-image sampling (Mozilla bug 2021775),
   so draw those at zoom 1 with sizes scaled by hand. */
@supports (-moz-appearance: none) {
  body {
    cursor: image-set(url("../assets/textures/cursor.png") calc(var(--site-scale) * 1dppx)) 6 2, auto;
  }

  .panel,
  .pixel-button {
    position: relative;
    isolation: isolate;
    border-image: none;
  }

  .panel::after,
  .pixel-button::after {
    content: "";
    position: absolute;
    zoom: calc(1 / var(--site-scale));
    inset: calc(var(--edge-width) * var(--site-scale) * -1px);
    z-index: -2;
    border: calc(var(--edge-width) * var(--site-scale) * 1px) solid transparent;
    border-image: var(--surface) var(--edge-width) fill;
    pointer-events: none;
  }

  .solid-button:not([data-live]):hover::before {
    clip-path: var(--stepped-corners);
  }
}
