/* #region Fonts */
@font-face {
  font-family: "TinyPixel";
  src: url("assets/fonts/tinypixel.otf") format("opentype");
  font-display: swap;
}

@font-face {
  font-family: "Antapani";
  src: url("assets/fonts/Antapani-ExtraBold.otf") format("opentype");
  font-weight: 800;
  font-display: swap;
}

@font-face {
  font-family: "PixelCode";
  src: url("assets/fonts/PixelCode/PixelCode.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "PixelCode";
  src: url("assets/fonts/PixelCode/PixelCode-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

@font-face {
  font-family: "PixelCode";
  src: url("assets/fonts/PixelCode/PixelCode-Italic.ttf") format("truetype");
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "PixelCode";
  src: url("assets/fonts/PixelCode/PixelCode-Bold-Italic.ttf") format("truetype");
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "m5x7";
  src: url("assets/fonts/m5x7.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "m3x6";
  src: url("assets/fonts/m3x6.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "1980 P02";
  src: url("assets/fonts/1980v23P02.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "1980 P03";
  src: url("assets/fonts/1980v23P03.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "1980 P04";
  src: url("assets/fonts/1980v23P04.ttf") format("truetype");
  font-display: swap;
}

/* Fallback for emoji and other characters missing from the primary fonts. */
@font-face {
  font-family: "Mona";
  src: url("assets/fonts/Mona/MonaS12.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "Mona";
  src: url("assets/fonts/Mona/MonaS12-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

/* #endregion */

/* #region Theme & Base Styles */
:root {
  /* Default scale */
  --site-scale: 2;
  --site-viewport-width: calc(100vw / var(--site-scale));
  --site-viewport-height: calc(100dvh / var(--site-scale));
  --godot-button-normal: url("assets/textures/godot-theme/button-normal.png");
  --godot-button-focus: url("assets/textures/godot-theme/button-focus.png");
  --godot-button-hover: url("assets/textures/godot-theme/button-hover.png");
  --godot-button-pressed: url("assets/textures/godot-theme/button-pressed.png");
  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;
  cursor: url("assets/textures/cursor.png") 6 2, auto;
}

/* Gecko scales custom cursors with CSS zoom. Keep the native 32px cursor
   by cancelling that scale through the image resolution. */
@supports (-moz-appearance: none) {
  body {
    cursor: image-set(url("assets/textures/cursor.png") calc(var(--site-scale) * 1dppx)) 6 2, auto;
  }
}

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;
}

article a:hover {
  color: white;
}

/* #endregion */

/* #region Shared Components */
.panel header, .top-bar-controls, .world-clock {
  display: flex;
  align-items: center;
}

.panel header, body > footer {
  font-family: "m3x6", "Mona", monospace;
  color: #a6a6ae;
}

.panel,
.pixel-button {
  border: calc(var(--edge-width) * 1px) solid transparent;
  border-image: var(--surface) var(--edge-width) fill;
}

/* Firefox corrupts border-image sampling under zoom (Mozilla bug 2021775).
   Paint the artwork at effective zoom 1, with explicitly scaled borders. */
@supports (-moz-appearance: none) {
  .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);
    border: calc(var(--edge-width) * var(--site-scale) * 1px) solid transparent;
    border-image: var(--surface) var(--edge-width) fill;
    z-index: -2;
    pointer-events: none;
  }
}

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

.panel header {
  flex-wrap: wrap;
  gap: 2px 4px;
  min-height: 19px;
  padding: 1px 4px;
  border-bottom: 1px solid #303034;
  overflow-wrap: anywhere;
}

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

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

/* #endregion */

/* #region Pixel Buttons */
.pixel-button {
  --edge-width: 4;
  --surface: var(--godot-button-normal);
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 0 4px;
  font-family: "1980 P02", "Mona", monospace;
  line-height: 12px;
  text-decoration: none;
  color: #ffffff;
}

.pixel-button:focus-visible {
  --surface: var(--godot-button-focus);
  color: #ffffff;
}

.pixel-button:active {
  --surface: var(--godot-button-pressed);
  color: #000000;
}

.pixel-button > img {
  filter: brightness(0) invert(1);
}

.pixel-button:active > img {
  filter: brightness(0);
}

@media (hover: hover) {
  .pixel-button:hover {
    --surface: var(--godot-button-hover);
    color: #ffffff;
  }

  .pixel-button:hover:active {
    --surface: var(--godot-button-hover);
    color: #000000;
  }
}

/* #endregion */

/* #endregion */

/* #region Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  position: fixed;
  inset: 0 0 auto;
  height: 20px;
  background: black;
  z-index: 100;
  line-height: 1;
  font-family: "m3x6", "Mona", monospace;
}

.top-bar-navigation {
  display: flex;
  position: relative;
  align-items: center;
  flex: 1 1 auto;
  gap: 2px;
  min-width: 0;
  height: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}

.navigation-selector {
  position: absolute;
  z-index: 1;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border: 3px solid transparent;
  border-image: url("assets/textures/round_rect.png") 3 fill;
  image-rendering: pixelated;
  mix-blend-mode: difference;
  pointer-events: none;
  will-change: transform, width, height;
}

/* Firefox samples border-image incorrectly under root zoom. Render the
   selector artwork at effective zoom 1, like the panel surfaces above. */
@supports (-moz-appearance: none) {
  .navigation-selector {
    border-image: none;
  }

  .navigation-selector::after {
    content: "";
    position: absolute;
    zoom: calc(1 / var(--site-scale));
    inset: calc(3 * var(--site-scale) * -1px);
    border: calc(3 * var(--site-scale) * 1px) solid transparent;
    border-image: url("assets/textures/round_rect.png") 3 fill;
    pointer-events: none;
  }
}

.top-bar-brand {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  text-decoration: none;
}

.top-bar-brand canvas {
  display: block;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

.top-bar-navigation::-webkit-scrollbar {
  display: none;
}

.top-bar-navigation > a {
  flex: 0 0 auto;
  --edge-width: 3;
  justify-content: center;
  gap: 4px;
  min-width: 40px;
  min-height: 14px;
  padding-inline: 6px;
  font-family: "1980 P03", "Mona", monospace;
  font-size: inherit;
  line-height: 8px;
  white-space: nowrap;
  overflow-wrap: normal;
}

.top-bar-navigation > a > span {
  transform: translateY(-1px);
}

.top-bar-navigation img {
  width: 8px;
  height: 8px;
  flex-shrink: 0;
}

.top-bar .server-status-label,
.top-bar .world-clock > span {
  /* Align these pixel-font labels within the fixed-height top bar. */
  transform: translateY(-1px);
}

/* #region World Clock */
.world-clock {
  flex-shrink: 0;
  gap: 4px;
  padding-inline: 4px;
}

.world-clock > img {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  image-rendering: pixelated;
}

.world-clock > span {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* #endregion */

/* #region Controls */
.top-bar-controls {
  flex-shrink: 0;
  gap: 6px;
  padding-inline: 4px;
}

.lite-icon {
  width: 8px;
  height: 8px;
}

@media (max-width: 767px) {
  .top-bar .top-bar-navigation {
    display: none;
  }

  .mobile-navigation-slot {
    padding: 4px;
  }

  .mobile-navigation-slot .top-bar-navigation {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    width: 100%;
    height: auto;
    overflow: visible;
  }

  .mobile-navigation-slot .top-bar-navigation > a {
    flex: 0 0 auto;
    justify-content: flex-start;
    min-width: 0;
    min-height: 18px;
    width: 100%;
  }

  .top-bar-controls {
    margin-left: auto;
  }

  .top-bar-controls > .solid-button {
    min-height: 18px;
  }

  .top-bar .world-clock,
  .top-bar .server-status {
    display: none;
  }
}

/* #endregion */

/* #region Server Status */
.server-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.server-status::before {
  content: "";
  flex-shrink: 0;
  width: 4px;
  height: 4px;
  background: var(--status-color, #a6a6ae);
}

.server-status[data-status="online"] {
  --signal-icon: url("assets/textures/icons/signal_icon.png");
}

.server-status[data-status="offline"] {
  --signal-icon: url("assets/textures/icons/signal_offline_icon.png");
}

.server-status[data-status="online"] [data-server-status-word],
.server-status[data-status="offline"] [data-server-status-word] {
  font-family: "1980 P02", "Mona", monospace;
}

.server-status[data-status="online"] [data-server-status-word] {
  color: #78d957;
}

.server-status[data-status="online"][data-admission="closed"] [data-server-status-word] {
  color: #ee6b6b;
}

.server-status[data-status="online"][data-admission="full"] [data-server-status-word] {
  color: #eabf4b;
}

.server-status[data-status="offline"] [data-server-status-word] {
  color: #ee6b6b;
}

.server-status[data-status="online"],
.server-status[data-status="offline"] {
  align-items: flex-end;
}

.server-status[data-status="online"]::before,
.server-status[data-status="offline"]::before {
  width: 16px;
  height: 16px;
  background: var(--signal-icon) center / 16px 16px no-repeat;
  image-rendering: pixelated;
}

.top-bar .server-status[data-status="online"]::before {
  transform: translateY(0.3333px);
}

.top-bar .server-status[data-status="offline"]::before {
  transform: translateY(-0.6667px);
}

.server-status[data-status="unknown"] {
  --status-color: #eabf4b;
}

/* #endregion */

/* #region Solid Buttons */
.solid-button {
  --edge-width: 3;
  --surface: url("assets/textures/round_rect.png");
  justify-content: center;
  gap: 4px;
  min-width: 40px;
  min-height: 14px;
  padding-inline: 6px;
  font-family: "1980 P03", "Mona", monospace;
  line-height: 8px;
  white-space: nowrap;
  color: #000000;
}

.solid-button > span {
  /* hard coded align */
  transform: translateY(-0.125em);
}

.solid-button > img {
  filter: none;
}

.solid-button:focus-visible,
.solid-button:active {
  --surface: url("assets/textures/round_rect.png");
  color: #000000;
}

.solid-button:active > img {
  filter: none;
}

@media (hover: hover) {
  .solid-button:not([data-live]):hover {
    position: relative;
    isolation: isolate;
    --surface: url("assets/textures/round_rect.png");
    color: #ffffff;
  }

  .solid-button:not([data-live]):hover:active {
    --surface: url("assets/textures/round_rect.png");
    color: #ffffff;
  }

  .solid-button:not([data-live]):hover::before {
    content: "";
    position: absolute;
    inset: -3px;
    z-index: -1;
    background: blue;
    pointer-events: none;
    -webkit-mask-box-image: url("assets/textures/round_rect.png") 3 fill / 3px / 0 stretch;
    mask-border: url("assets/textures/round_rect.png") 3 fill / 3px / 0 stretch;
  }
}

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

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

/* #endregion */

/* #endregion */

/* #region Page Layout */
.site {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 320px) 136px;
  grid-template-areas: "content sidebar";
  gap: 8px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 40px 8px 32px;
  align-content: start;
  align-items: start;
}

.site > aside {
  grid-area: sidebar;
}

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

.mobile-navigation-panel {
  display: none;
}

@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;
  }

  .mobile-navigation-panel {
    display: block;
  }
}

/* #endregion */

/* #region Sidebar */

/* #region Top Bar Navigation State */

.top-bar-navigation a[data-current] {
  --surface: var(--godot-button-focus);
  color: #ffffff;
}

.top-bar-navigation a:not([data-current]):hover {
  --surface: var(--godot-button-focus);
  color: #ffffff;
}

.top-bar-navigation a:not([data-current]):hover:active {
  --surface: var(--godot-button-pressed);
  color: #000000;
}

.top-bar-navigation a[data-current] img {
  filter: brightness(0) invert(1);
}

.top-bar-navigation a[data-current]:focus-visible {
  --surface: var(--godot-button-focus);
  color: #ffffff;
}

.top-bar-navigation a[data-current]:focus-visible img {
  filter: brightness(0) invert(1);
}

.top-bar-navigation a[data-current]:hover:active {
  --surface: var(--godot-button-focus);
  color: #ffffff;
}

/* #endregion */

/* #region Status Content */
.status-content {
  display: grid;
  gap: 2px;
  padding: 4px;
}

.twitch-status {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: start;
  gap: 4px;
}

.twitch-picture {
  position: relative;
}

.twitch-picture img {
  display: block;
  width: 100%;
  /* Match the panel's two-pixel stepped corners without an image mask. */
  clip-path: 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
  );
}

.twitch-details {
  min-width: 0;
  font-family: "TinyPixel", "Mona", monospace;
  /* TinyPixel's native grid is 7px; the shared site zoom scales its pixels. */
  font-size: 7px;
  line-height: 10px;
  overflow-wrap: anywhere;
}

.twitch-details > strong,
.twitch-details > span {
  display: block;
}

.twitch-details > strong {
  font-weight: 400;
  color: #a6a6ae;
}

.twitch-details > span {
  color: #c5c5cd;
}

.twitch-title {
  min-width: 0;
  color: #c5c5cd;
  overflow: hidden;
}

.twitch-title-track {
  display: flex;
  width: max-content;
}

.twitch-title-segment {
  display: block;
  flex: 0 0 auto;
  padding-right: 12px;
}

.twitch-title-segment > span {
  display: block;
  white-space: nowrap;
}

.twitch-title:not([data-scrolling]) [aria-hidden="true"] {
  display: none;
}

.twitch-title[data-scrolling] .twitch-title-track {
  animation: stream-title-scroll 18s linear infinite;
}

@keyframes stream-title-scroll {
  to { transform: translateX(-50%); }
}

.twitch-status:not([data-status="live"]) [data-stream-duration],
.twitch-status:not([data-status="live"]) [data-stream-viewers] {
  display: none;
}

.twitch-status[data-status="live"] .twitch-picture::after {
  content: "";
  position: absolute;
  inset: 0;
  border: calc(var(--edge-width) * 1px) solid transparent;
  border-image: url("assets/textures/panel_outline.png") var(--edge-width) fill;
  filter: brightness(0) saturate(100%) invert(19%) sepia(100%) saturate(6500%) hue-rotate(350deg) brightness(110%) contrast(125%);
  animation: twitch-outline-pulse 1.8s ease-in-out infinite;
  pointer-events: none;
}

@supports (-moz-appearance: none) {
  .twitch-status[data-status="live"] .twitch-picture::after {
    zoom: calc(1 / var(--site-scale));
    border-width: calc(var(--edge-width) * var(--site-scale) * 1px);
  }

  .solid-button:not([data-live]):hover::before {
    clip-path: 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);
  }
}

@keyframes twitch-outline-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@media (prefers-reduced-motion: reduce) {
  .twitch-title[data-scrolling] .twitch-title-track,
  .twitch-status[data-status="live"] .twitch-picture::after,
  .panel > section:not([hidden]) > figure {
    animation: none;
  }
}

.twitch-status[data-status="live"] [data-stream-status] {
  color: #ff1744;
}

.twitch-status[data-status="unknown"] [data-stream-status] {
  color: #eabf4b;
}

/* #endregion */

/* #region Social Links */
.filter-definitions {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.social-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-evenly;
  gap: 2px;
  padding: 2px 0;
}

.social-links a {
  filter: grayscale(1);
  opacity: 0.7;
}

.social-links img {
  display: block;
  width: 12px;
  height: 12px;
}

.social-links a:hover {
  filter: none;
  opacity: 1;
}

.social-links a:hover img {
  filter: url("#social-icon-outline");
}

/* #endregion */

/* #endregion */

/* #region Main Content */
/* #region Inline Images */
img.emote {
  height: 1em;
  vertical-align: -0.15em;
}

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

/* #endregion */

.panel figure {
  width: calc(100% + 6px);
  height: 75px;
  margin-inline: -3px;
  overflow: hidden;
}

.panel > section:not([hidden]) > figure {
  clip-path: inset(0);
  animation: content-image-reveal 500ms ease-out both;
}

@keyframes content-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 {
  font-family: "PixelCode", "Mona", monospace;
  font-size: 9px;
  padding: 8px 6px;
  min-height: 152px;
  color: #a6a6ae;
  overflow-wrap: anywhere;
}

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

/* #region Friend Buttons */
.friend-buttons img {
  zoom: 0.5;
}

/* #endregion */

/* #endregion */

/* #region Footer */
body > footer {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  min-height: 96px;
  padding: 24px 8px;
  background: black;
  text-align: center;
}

body > footer small {
  font-size: inherit;
}

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

/* #endregion */

