:root {
  --color-text-light: #e0d5c4;
  --color-text-dark: #2a1a3a;
  --color-text-muted-light: #b0a594;
  --color-text-muted-dark: #5a4630;
  --color-bg-dark-primary: #1a0e2a;
  --color-bg-dark-secondary: #1f122e;
  --color-border-themed: #5a4630;

  /* Best Practice: Define sprite properties as variables for maintainability */
  --sprite-url: url('/textures/border-image.png');
  --sprite-grid-size: 140px; /* Each grid cell is 140x140 */
  --sprite-total-width: 420px;
  --sprite-total-height: 420px;
  
  /* Y-positions for rows in the 3x3 sprite sheet */
  --sprite-footer-row-y: 0px; /* Top row */
  --sprite-header-row-y: -280px; /* Bottom row (2 * 140px) */

  /* X-positions for columns */
  --sprite-left-col-x: 0px;
  --sprite-middle-col-x: -140px;
  --sprite-right-col-x: -280px;

  /* --- Background & Star Effects Configuration --- */
  /* Controls the 'wobble' displacement of the main background. Increase for a more intense effect. */
  --wobble-strength: 0.1%;
  /* Controls the speed of the wobble. Decrease for a faster effect. */
  --wobble-duration: 25s;
  /* Controls the tiling size of the stars texture. Smaller values = denser starfield. */
  --stars-background-size: 256px;
  /* The overall opacity of the star layer. */
  --stars-base-opacity: 0.8;
  /* Controls the speed of the shimmering noise effect. Lower is faster. */
  --stars-shimmer-duration: 20s;
}
@font-face {
  font-family: 'BBT';
  src: url('/fonts/bbt.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
}
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden; /* Body doesn't scroll; .ui-layer does */
}
body {
  font-family: 'BBT', serif;
  background-color: var(--color-bg-dark-primary);
  display: flex;
  flex-direction: column;
}

@keyframes heat-wobble {
  0%   { background-position: 50% 50%; }
  25%  { background-position: calc(50% + var(--wobble-strength)) calc(50% - var(--wobble-strength)); }
  50%  { background-position: calc(50% - var(--wobble-strength)) calc(50% + var(--wobble-strength)); }
  75%  { background-position: calc(50% + var(--wobble-strength)) calc(50% + var(--wobble-strength)); }
  100% { background-position: 50% 50%; }
}

@keyframes scroll-mask {
  from { mask-position: 0 0; -webkit-mask-position: 0 0; }
  to   { mask-position: -512px -512px; -webkit-mask-position: -512px -512px; }
}

@keyframes pulse {
  50% {
    opacity: 0.5;
  }
}

.background-layer {
  background-image: url('/textures/background.png');
  background-repeat: repeat;
  animation: heat-wobble var(--wobble-duration) ease-in-out infinite;
  position: fixed;
  inset: 0;
  z-index: 0;
  will-change: transform; /* Performance hint for parallax */
}

.background-stars-layer {
  /* This is the visible layer of stars */
  background-image: url('/textures/background_stars.png');
  background-repeat: repeat;
  background-size: var(--stars-background-size) var(--stars-background-size);

  /* --- Procedural Shimmer using a MASK --- */
  /* The noise texture is used as a mask, not a visible background.
     Its brightness values control the opacity of the star layer. */
  mask-image: url('/textures/noise_texture.png');
  mask-mode: luminance; /* Use the brightness of the mask */
  mask-repeat: repeat;
  mask-size: 512px;

  /* Prefixes for full browser compatibility */
  -webkit-mask-image: url('/textures/noise_texture.png');
  -webkit-mask-mode: luminance;
  -webkit-mask-repeat: repeat;
  -webkit-mask-size: 512px;

  /* Animate the MASK's position to create the shimmer effect */
  animation: scroll-mask var(--stars-shimmer-duration) linear infinite;
  
  /* Use opacity to control the overall intensity of the final masked layer */
  opacity: var(--stars-base-opacity);
  
  /* --- Positioning & Parallax --- */
  position: fixed;
  inset: 0;
  z-index: 1; /* Sits on top of main background */
  will-change: transform; /* Performance hint for parallax */
}

.ui-layer {
  position: absolute;
  inset: 0;
  z-index: 3; /* Sits above background and stars */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on mobile */
}

#root {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  /* position: relative;  <- This was causing the background to scroll with the content. Removing it fixes the issue. */
}
/* Ensure form elements inherit the global font */
input, button, textarea, select {
  font-family: inherit;
}
img {
  /* Prevent users from dragging or selecting images */
  -webkit-user-drag: none;
  user-drag: none;
  user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
}
.nine-slice-button {
  /* Slicing the image */
  border-image-source: url('/textures/button_idle.png');
  border-image-slice: 38 fill; /* 'fill' makes the center piece visible */
  border-image-width: 19px; /* Scaled down border */
  border-image-repeat: round;

  /* Basic styling */
  border-style: solid;
  background-color: transparent; /* Center piece from image is background */
  padding: 0 1.5rem; /* Horizontal padding */
  height: 48px; /* Vertical padding is controlled by border-width and height */
  
  /* Text styling */
  color: var(--color-text-light);
  font-family: 'BBT', serif;
  font-size: 1.125rem; /* 18px */
  text-decoration: none; /* for links */

  /* Layout */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  
  /* Transitions and interaction */
  transition: all 0.2s ease-in-out;
  cursor: pointer;
  position: relative; /* For pseudo-elements or child positioning */
}

.nine-slice-button:hover:not(:disabled) {
  border-image-source: url('/textures/button_hover.png');
  color: #ffffff;
  transform: translateY(-2px);
}

.nine-slice-button:active:not(:disabled) {
  transform: translateY(0px);
  filter: brightness(0.95);
}

.nine-slice-button:disabled {
  filter: grayscale(80%) brightness(0.7);
  cursor: not-allowed;
  transform: none;
}

.nine-slice-button > span {
  position: relative;
  top: -2px; /* Manual vertical adjustment for custom font */
}

.nine-slice-button-square {
  /* Slicing based on user request: 36px slice */
  border-image-source: url('/textures/buttonsquare_idle.png');
  border-image-slice: 36 fill;
  border-image-width: 18px; /* Half of slice for good scaling */
  border-image-repeat: round;

  /* Basic styling */
  border-style: solid;
  background-color: transparent; /* Center piece from image is background */
  padding: 0 1.5rem; /* Horizontal padding */
  height: 48px;
  
  /* Text styling */
  color: var(--color-text-light);
  font-family: 'BBT', serif;
  font-size: 1.125rem; /* 18px */
  text-decoration: none;

  /* Layout */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.75rem; /* For spacing icon and text */
  
  /* Transitions and interaction */
  transition: all 0.2s ease-in-out;
  cursor: pointer;
  position: relative;

  /* Sizing from previous login button */
  width: 100%;
  max-width: 320px;
}

.nine-slice-button-square:hover:not(:disabled) {
  border-image-source: url('/textures/buttonsquare_hover.png');
  color: #ffffff;
  transform: translateY(-2px);
}

.nine-slice-button-square:active:not(:disabled) {
  transform: translateY(0px);
  filter: brightness(0.95);
}

.nine-slice-button-square:disabled {
  filter: grayscale(80%) brightness(0.7);
  cursor: not-allowed;
  transform: none;
}

/* Apply manual font alignment to both icon and text */
.nine-slice-button-square > span, 
.nine-slice-button-square > svg {
  position: relative;
  top: -2px;
}

.nine-slice-card {
  /* Slicing the image */
  border-image-source: url('/textures/card_normal.png');
  border-image-slice: 140 fill; /* 'fill' makes the center piece visible */
  border-image-width: 70px;
  border-image-repeat: round;

  /* Basic styling */
  border-style: solid;
  background-color: transparent; /* Center piece from image is background */
  padding: 2.5rem; /* Generous padding to complement the thick border */
  
  /* Set text color to light yellow for readability on textured background */
  color: var(--color-text-light);
}

.nine-slice-item-box {
  /* Slicing the image */
  border-image-source: url('/textures/card_normal.png');
  border-image-slice: 140 fill;
  border-image-width: 15px;
  border-image-repeat: round;

  /* Basic styling */
  border-style: solid;
  background-color: transparent; /* Center piece from image is background */
  padding: 0.5rem;
}

/* Common setup for header and footer background frames */
.site-header, .site-footer {
  position: relative;
  height: var(--sprite-grid-size);
  background-image: var(--sprite-url);
  background-repeat: repeat-x;
  background-size: var(--sprite-total-width) var(--sprite-total-height);
  border-style: none;
  padding: 0; /* Padding is handled by the inner content container now */
}

/* Corner pseudo-elements */
.site-header::before, .site-header::after,
.site-footer::before, .site-footer::after {
  content: '';
  position: absolute;
  top: 0;
  width: var(--sprite-grid-size);
  height: var(--sprite-grid-size);
  background-image: var(--sprite-url);
  background-repeat: no-repeat;
  background-size: var(--sprite-total-width) var(--sprite-total-height);
  z-index: 1; /* Place corners above repeating background */
}

.site-header::before, .site-footer::before {
  left: 0;
}

.site-header::after, .site-footer::after {
  right: 0;
}

/* Ensure content is visible above the background frame */
.site-header > *, .site-footer > * {
  position: relative;
  z-index: 2;
  height: 100%; /* Ensure content container fills the bar */
}

/* === Header specific styles (uses BOTTOM row of sprite) === */
.site-header {
  background-position: var(--sprite-middle-col-x) var(--sprite-header-row-y);
}
.site-header::before {
  background-position: var(--sprite-left-col-x) var(--sprite-header-row-y);
}
.site-header::after {
  background-position: var(--sprite-right-col-x) var(--sprite-header-row-y);
}

/* === Footer specific styles (uses TOP row of sprite) === */
.site-footer {
  display: flex; /* Re-apply for content centering */
  justify-content: center;
  background-position: var(--sprite-middle-col-x) var(--sprite-footer-row-y);
  padding-top: 48px; /* Position content correctly inside the frame */
  box-sizing: border-box; /* Ensure padding is included in height */
}
.site-footer::before {
  background-position: var(--sprite-left-col-x) var(--sprite-footer-row-y);
}
.site-footer::after {
  background-position: var(--sprite-right-col-x) var(--sprite-footer-row-y);
}

.textured-underline {
  display: inline-block;
  padding-bottom: 4px; /* Space between text and underline */
  text-decoration: none !important;
  border-style: solid;
  border-width: 0 16px 16px 16px;
  border-color: transparent;
  border-image-source: url('/textures/underline.png');
  border-image-slice: 0 33 33;
  border-image-repeat: round;
}

.search-wrapper {
  position: relative;
  display: inline-block;
}
.search-input-container {
  border-style: solid;
  border-width: 0 28px;
  border-image-source: url('/textures/searchbar.png');
  border-image-slice: 0 114 0 114 fill;
  border-image-repeat: stretch;
  height: 48px;
  display: flex;
  align-items: center;
  background-clip: padding-box;
  width: 280px;
}
.search-input {
  background: transparent;
  border: none;
  outline: none;
  width: 100%;
  height: 100%;
  color: var(--color-text-light);
  font-family: inherit;
  font-size: 1rem;
  padding: 0 10px;
  position: relative;
  top: -2px; /* Manual font alignment */
}
.search-input::placeholder {
  color: var(--color-text-muted-light);
  opacity: 0.7;
}
.search-results-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: -4px;
  background-color: var(--color-bg-dark-secondary);
  border: 2px solid var(--color-border-themed);
  border-top: none;
  border-radius: 0 0 8px 8px;
  z-index: 100;
  max-height: 300px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-themed) var(--color-bg-dark-primary);
}
.search-result-item {
  padding: 10px 16px;
  cursor: pointer;
  color: var(--color-text-light);
  transition: background-color 0.2s, color 0.2s;
  border-bottom: 1px solid var(--color-border-themed);
}
.search-result-item:last-child {
  border-bottom: none;
}
.search-result-item:hover {
  background-color: var(--color-border-themed);
  color: white;
}
.mobile-menu-button {
  color: var(--color-text-light);
  transition: color 0.2s;
}
.mobile-menu-button:hover {
  color: white;
}
@keyframes fade-in-down {
  from { opacity: 0; transform: translate(-50%, -20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.animate-fade-in-down {
  animation: fade-in-down 0.5s ease-out forwards;
}

/* --- Intro Animation Styles --- */
.intro-overlay {
  position: fixed;
  inset: 0;
  background-color: black;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease-in-out;
  pointer-events: none;
}
.animate-intro-logo {
  animation: intro-logo-anim 2s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.animate-intro-slogan {
  opacity: 0;
  animation: intro-slogan-anim 1s ease-out 1s forwards;
}
@keyframes intro-logo-anim {
  from {
    opacity: 0;
    filter: blur(12px);
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    filter: blur(0);
    transform: scale(1);
  }
}
@keyframes intro-slogan-anim {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.nine-slice-button.disconnect-button,
.nine-slice-button-square.disconnect-button {
  /* No new image, use filters on the existing ones */
  --disconnect-hue-rotate: 340deg; /* shifts yellow towards red */
  --disconnect-saturate: 1.5;
  --disconnect-brightness: 0.9;
  filter: hue-rotate(var(--disconnect-hue-rotate)) saturate(var(--disconnect-saturate)) brightness(var(--disconnect-brightness));
  /* Override the text color to ensure contrast */
  color: #ffdddd;
  text-shadow: 1px 1px 2px rgba(96, 12, 12, 0.7);
}

.nine-slice-button.disconnect-button:hover:not(:disabled),
.nine-slice-button-square.disconnect-button:hover:not(:disabled) {
  /* Keep the hover image but apply the same filter and increase brightness */
  filter: hue-rotate(var(--disconnect-hue-rotate)) saturate(var(--disconnect-saturate)) brightness(1.1);
  color: #ffffff;
}

/* Also need to reset default filter on disabled */
.nine-slice-button.disconnect-button:disabled,
.nine-slice-button-square.disconnect-button:disabled {
  filter: grayscale(80%) brightness(0.7);
  color: var(--color-text-light);
  text-shadow: none;
}

/* --- User Profile Styles --- */
.user-profile-button {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 4px;
  border-radius: 9999px; /* pill shape */
  background-color: rgba(0,0,0,0.25);
  transition: background-color 0.2s ease-in-out, transform 0.2s ease-in-out;
  cursor: pointer;
  border: 1px solid rgba(90, 70, 48, 0.5); /* var(--color-border-themed) with alpha */
  height: 48px;
  box-sizing: border-box;
}

.user-profile-button:hover {
  background-color: rgba(0,0,0,0.4);
  transform: translateY(-1px);
}

.user-profile-button .profile-name {
  color: var(--color-text-light);
  font-weight: bold;
  font-size: 1rem;
  padding-right: 12px;
  position: relative;
  top: -1px;
}

.profile-pic-container {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  background-image: url('/textures/profilepic_background.png');
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
  padding: 2px;
  box-sizing: border-box;
}

.profile-pic-image {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--color-bg-dark-primary);
}

/* --- Shooting Star Effect --- */
.shooting-star-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  overflow: hidden;
  z-index: 2; /* Sits on top of background layers, but behind UI */
}

.shooting-star {
  position: absolute;
  display: flex;
  align-items: center;
  /* Head is on the right, so pivot from there */
  transform-origin: right center;
  /* Puts head on the right of the container, tail on the left */
  flex-direction: row-reverse;

  /* Deceleration via 'ease-out'. Duration from --duration var. */
  transition:
    left var(--duration, 2s) ease-out,
    top var(--duration, 2s) ease-out,
    opacity 0.4s ease-in-out;
}

.shooting-star-head {
  height: 15px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(255, 255, 220, 0.9)) drop-shadow(0 0 12px rgba(255, 180, 80, 0.4));
  animation: star-flicker 1.5s infinite ease-in-out;
  
  /* Transition for the yellow color shift during burnout */
  transition: filter 0.6s ease-in;
}

.shooting-star-tail {
  /* Use CSS vars for dynamic sizing from React */
  height: var(--tail-width, 2px);
  width: var(--tail-length, 250px);
  
  /* Create a "hot core" effect, whiter in the middle and fading to yellow at the edges */
  background: linear-gradient(
    to left,
    rgba(255, 255, 220, 0.8), /* Bright head of the tail */
    rgba(255, 216, 138, 0.3) 70%, /* Fades to a warmer, more transparent color */
    transparent
  );

  /* Use a mask to create the tapered, fading shape instead of a hard rectangle */
  mask-image: linear-gradient(to left, black 50%, transparent 100%);
  -webkit-mask-image: linear-gradient(to left, black 50%, transparent 100%);

  /* Add a soft blur for a more ethereal, "glowy" effect */
  filter: blur(0.5px) drop-shadow(0 0 6px rgba(255, 255, 220, 0.7));

  /* Remove border-radius, as the tapered mask handles the shape */
  border-radius: 0; 

  /* Transition all the properties for a smooth animation */
  transition:
    width 0.6s ease-out,
    height 0.6s ease-out,
    background 0.6s ease-in,
    filter 0.6s ease-in;
}

/* --- Burnout Phase --- */
.shooting-star.is-burning-out .shooting-star-head {
  /* Shift hue towards yellow/orange and brighten */
  filter: drop-shadow(0 0 10px #fff8e1) drop-shadow(0 0 15px #ffc107) hue-rotate(-20deg) brightness(1.2);
}

.shooting-star.is-burning-out .shooting-star-tail {
  /* Change color to a more intense yellow/orange */
  background: linear-gradient(to left, #ffc107, transparent);
  filter: blur(0.5px) drop-shadow(0 0 8px #ffc107);
  /* Note: width and height are set via inline styles from React during burnout */
}

/* --- Explosion --- */
.star-explosion {
  /* Positioned at the pivot point (right center) of the parent */
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff8e1, #ffc107, rgba(255, 193, 7, 0));
  animation: star-explode-anim 0.5s ease-out forwards;
}

/* --- Star Animations --- */
@keyframes star-flicker {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.8); opacity: 0.7; }
}

@keyframes star-explode-anim {
  from {
    transform: scale(0);
    opacity: 1;
  }
  to {
    transform: scale(2.5);
    opacity: 0;
  }
}

/* --- News Markers --- */
@keyframes gentle-bob {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-2px); /* Reduced bobbing for smaller icon */
  }
}

.new-news-marker-menu {
  position: absolute;
  top: -10px;    /* Adjusted position for smaller size */
  right: -12px;   /* Adjusted position for smaller size */
  width: 22px;    /* Made ~3x smaller (from 64px) */
  height: 22px;   /* Made ~3x smaller (from 64px) */
  pointer-events: none; /* So it doesn't block clicks on the link */
  animation: gentle-bob 2.5s ease-in-out infinite;
}

.new-news-marker-menu-mobile {
    position: absolute;
    top: -6px;   /* Adjusted position for smaller size */
    right: -6px;  /* Adjusted position for smaller size */
    width: 16px; /* Made 3x smaller (from 48px) */
    height: 16px;/* Made 3x smaller (from 48px) */
    pointer-events: none;
    animation: gentle-bob 2.5s ease-in-out infinite;
}

.news-post-marker {
  position: absolute;
  top: -15px; /* Adjusted for smaller size */
  right: -15px; /* Adjusted for smaller size */
  width: 35px; /* Roughly 4x smaller than original 139px */
  height: auto;
  transform: rotate(10deg);
  pointer-events: none;
  filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.3)); /* Reduced shadow for smaller element */
}

/* --- Custom text styles from user request --- */
.slogan-text {
  font-size: 2.25rem; /* 36px, Tailwind's text-4xl */
  line-height: 2.5rem;
  color: #f5eecf; /* A soft, pastel yellow */
  font-style: italic;
}

@media (min-width: 768px) { /* Corresponds to md: breakpoint */
  .slogan-text {
    font-size: 3rem; /* 48px, Tailwind's text-5xl */
    line-height: 1;
  }
}

.main-body-text {
  font-size: 19.5px;
  line-height: 1.5;
  color: var(--color-text-light); /* Keep existing text color */
}

/* --- Worlds Page Styles --- */
.nine-slice-world-card {
  border-style: solid;
  border-image-source: url('/textures/worldcard_card1.png');
  border-image-slice: 53 fill;
  border-image-width: 27px;
  border-image-repeat: round;
  background-color: transparent;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.world-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0;
  color: var(--color-text-light);
}

.world-card-title {
  font-size: 1.5rem; /* 24px */
  font-weight: bold;
}

.world-status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem; /* 8px */
  font-weight: bold;
  font-size: 1rem; /* 16px */
}

.world-status-indicator .dot {
  width: 12px;
  height: 12px;
  border-radius: 9999px;
}

.world-card-image-container {
  position: relative;
  aspect-ratio: 16 / 9;
  padding: 0;
  /* Add overflow hidden and border radius to clip the blurred background */
  overflow: hidden;
  border-radius: 6px;
}

/* NEW: Blurred background to fill empty space behind non-16:9 images */
.world-card-image-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(8px) brightness(0.6);
  transform: scale(1.1); /* Scale up to prevent blurred edges from showing */
}

.world-card-image {
  position: absolute;
  z-index: 1; /* Sit on top of the blurred background */
  /* Inset the image by 5px on each side to make it appear smaller than the border frame */
  top: 5px;
  left: 5px;
  right: 5px;
  bottom: 5px;
  /* Let the absolute positioning handle the size, overriding any explicit width/height */
  width: auto;
  height: auto;
  object-fit: contain; /* Keep contain to prevent cropping the main image */
  background-color: transparent; /* Remove black bars */
  display: block;
  /* The container now handles the radius */
  border-radius: 0;
}

.world-card-border-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-style: solid;
  border-width: 32px;
  border-image-source: url('/textures/worldcard_border1.png');
  border-image-slice: 64;
  border-image-repeat: round;
  pointer-events: none;
  z-index: 2; /* Ensure the border is on top of all images */
}

.world-card-content {
  padding: 0;
}

.world-card-description {
  color: var(--color-text-muted-light);
  font-size: 1rem;
  line-height: 1.5;
}