@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

:root {
  /* Theme colors */
  --color-background: #d6f7d6;
  --color-text: #18594a;
  --color-accent: #6ba66b;
  --color-border: #18594a;
  --color-shadow: rgba(0, 0, 0, 0.2);
  
  /* Typography */
  --font-primary: 'Press Start 2P', monospace, system-ui, -apple-system, sans-serif;
  
  /* Layout */
  --gameboy-width: 420px;
  --gameboy-height: 340px;
  --gameboy-offset: 160px;
  --canvas-width: 380px;
  --canvas-height: 320px;
}

/* Base Styles */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body, html {
  width: 100%;
  height: calc(100vh - env(safe-area-inset-top));
  background: var(--color-background);
  color: var(--color-text);
  font-family: var(--font-primary);
  padding-top: env(safe-area-inset-top);
  overflow: hidden;
}

/* GameBoy Layout */
.gameboy-bg-wrapper {
  position: relative;
  width: 100vw;
  height: 100%;
  background: url('assets/gameboy.png') no-repeat center top;
  background-size: 1150px auto;
  display: block;
  transform: scale(1.5);
  transform-origin: 50% 33%;
  z-index: 1;
}

.gameboy-bg-wrapper::after {
  content: '';
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.25);
  pointer-events: none;
  z-index: 1;
}

/* Screen Container */
.screen-container {
  position: absolute;
  width: var(--gameboy-width);
  height: var(--gameboy-height);
  left: 50%;
  top: var(--gameboy-offset);
  transform: translateX(-50%);
  z-index: 2;
}

/* Startup Screen */
.startup-screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: absolute;
  background: #001018;
  z-index: 1;
  overflow: hidden;
}

.startup-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(transparent 50%, rgba(0, 0, 0, 0.25) 50%);
  background-size: 100% 4px;
  animation: scanline 0.1s linear infinite;
  pointer-events: none;
}

.power-on-flash {
  position: absolute;
  inset: 0;
  background: var(--color-background);
  opacity: 0;
  animation: powerOn 0.5s ease-out forwards;
  animation-delay: 2.5s;
  z-index: 3;
}

.power-light {
  position: absolute;
  width: 1px;
  height: 1px;
  background: rgba(255, 0, 0, 0.8);
  box-shadow: 0 0 10px 10px rgba(255, 0, 0, 0.8);
  z-index: 3;
  top: 97px;
  left: -68px;
  transform: translate(-50%, -50%);
  opacity: 0;
  animation: powerLightOn 0.5s ease-out forwards;
  animation-delay: 1s;
}

@keyframes powerLightOn {
  0% {
    opacity: 0;
  }
  60% {
    opacity: 1;
  }
  100% {
    opacity: 0.7;
  }
}

@keyframes powerOn {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes logoFade {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  20% {
    opacity: 1;
    transform: scale(1);
  }
  80% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(0.8);
  }
}

@keyframes scanline {
  0% {
    transform: translateY(0);
  }
  100% {
    transform: translateY(4px);
  }
}

/* Home Screen */
.home-screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: absolute;
  background: var(--color-background);
  z-index: 1;
  opacity: 0;
  animation: fadeIn 1.5s ease-in-out forwards;
  animation-delay: 2.5s;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.home-screen h1 {
  color: var(--color-text);
  font-size: 1.25em;
  padding: 0.5em;
  text-shadow: 2px 2px var(--color-accent);
  opacity: 0;
  transform: translateX(50px);
  animation: slideInRight 0.5s ease-out forwards;
  animation-delay: 4.2s;
}

#titleCharacter {
  opacity: 0;
  transform: translateX(50px);
  animation: slideInRight 0.5s ease-out forwards;
  animation-delay: 5s;
  margin: 2em;
}

.enter-button {
  background: none;
  border: none;
  color: var(--color-text);
  font-family: var(--font-primary);
  font-size: 0.7em;
  padding: 0.5em 1em;
  cursor: pointer;
  letter-spacing: 1px;
  transition: color 0.2s;
  margin-bottom: 2.5em;
  opacity: 0;
  animation: fadeIn 0.5s ease-out forwards;
  animation-delay: 5.8s;
  z-index: 1000;
  position: relative;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(50px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.enter-button:hover {
  color: var(--color-accent);
}

.subtext {
  position: absolute;
  bottom: 6em;
  color: var(--color-text);
  font-size: 0.15em;
  font-weight: bold;
  text-align: center;
  letter-spacing: 1px;
  opacity: 0.8;
}

/* Game Container */
.game-container {
  width: 100%;
  height: 100%;
  display: none;
  position: absolute;
  background: var(--color-background);
  z-index: 1;
}

.game-shadow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: 0 0 0px 0px rgba(256, 256, 256, 0),
              inset 2px 2px 10px rgba(0, 0, 0, 0.5);
  z-index: 2;
  animation: shadowPulse 1.5s ease-in-out forwards;
  animation-delay: 2.5s;
}

@keyframes shadowPulse {
  0% {
    box-shadow: 0 0 0px 0px rgba(256, 256, 256, 0),
                inset 2px 2px 10px rgba(0, 0, 0, 0.5);
  }
  15% {
    box-shadow: 0 0 20px 8px rgba(256, 256, 256, 0.2),
                inset 2px 2px 10px rgba(0, 0, 0, 0.5);
  }
  25% {
    box-shadow: 0 0 20px 8px rgba(256, 256, 256, 0.02),
                inset 2px 2px 10px rgba(0, 0, 0, 0.5);
  }
  66% {
    box-shadow: 0 0 20px 8px rgba(256, 256, 256, 0.15),
                inset 2px 2px 10px rgba(0, 0, 0, 0.5);
  }
  80% {
    box-shadow: 0 0 20px 8px rgba(256, 256, 256, 0.17),
                inset 2px 2px 10px rgba(0, 0, 0, 0.5);
  }
  100% {
    box-shadow: 0 0 20px 8px rgba(256, 256, 256, 0.2),
                inset 2px 2px 10px rgba(0, 0, 0, 0.5);
  }
}



#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  display: block;
  image-rendering: pixelated;
}

/* Music Button */
.music-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 8px 16px;
  background: transparent;
  color: var(--color-text);
  border: none;
  cursor: pointer;
  font-size: 28px;
  transition: color 0.3s;
  z-index: 1000;
  outline: none;
}

.music-button:hover {
  color: var(--color-accent);
}

/* Text Box */
.text-box {
  position: absolute;
  left: 50%;
  bottom: 5%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 700px;
  min-height: 80px;
  background: var(--color-background);
  border: 4px double var(--color-border);
  color: var(--color-text);
  font-size: 0.55em;
  padding: 18px 24px;
  box-shadow: 0 4px 16px var(--color-shadow);
  letter-spacing: 1px;
  line-height: 1.5;
  display: inline-block;
  vertical-align: bottom;
  z-index: 10;
}

/* Fade Overlay for Sleep Effect */
.fade-overlay {
  position: absolute;
  inset: 0;
  background: #001018;
  opacity: 0;
  z-index: 15;
  pointer-events: none;
  transition: opacity 0.8s ease-in-out;
}

.fade-overlay.fade-in {
  opacity: 1;
}

.text-box a {
  color: var(--color-accent);
  text-decoration: none;
  border-bottom: 1px solid var(--color-accent);
  transition: all 0.2s ease;
}

.text-box a:hover {
  color: var(--color-text);
  border-bottom-color: var(--color-text);
}

.fullscreen-text-box {
  position: fixed;
  inset: 0;
  background: var(--color-background);
  border: 8px double var(--color-border);
  color: var(--color-text);
  font-size: 0.7em;
  padding: 40px 20px;
  box-shadow: 0 4px 16px var(--color-shadow);
  letter-spacing: 1px;
  line-height: 1.8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  overflow: hidden;
  text-align: center;
  -webkit-overflow-scrolling: touch;
}

.fullscreen-text-box .content {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 50vh;
}

.fullscreen-text-box .page {
  display: none;
  flex-direction: column;
  justify-content: center;
  min-height: 100%;
}

.fullscreen-text-box .page.active {
  display: flex;
}

.fullscreen-text-box p {
  margin-bottom: 1em;
}

.fullscreen-text-box .close-button {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--color-text);
  font-size: 1.2em;
  cursor: pointer;
  padding: 10px;
}

.fullscreen-text-box .close-button:hover {
  color: var(--color-text);
}

.fullscreen-text-box .close-button:active,
.fullscreen-text-box .close-button:focus {
  color: var(--color-text);
}

.fullscreen-text-box .next-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: none;
  border: 2px solid var(--color-border);
  color: var(--color-text);
  font-size: 0.8em;
  cursor: pointer;
  padding: 8px 16px;
  font-family: var(--font-primary);
  transition: all 0.2s ease;
  z-index: 1001;
}

.fullscreen-text-box .next-button:hover {
  color: var(--color-text);
  border-color: var(--color-text);
}

.fullscreen-text-box .next-button:active,
.fullscreen-text-box .next-button:focus {
  color: var(--color-text);
  border-color: var(--color-text);
}

.fullscreen-text-box a {
  color: var(--color-accent);
  text-decoration: none;
  border-bottom: 1px solid var(--color-accent);
  transition: all 0.2s ease;
}

.fullscreen-text-box a:hover {
  color: var(--color-text);
  border-bottom-color: var(--color-text);
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .fullscreen-text-box .content {
    width: 95%;
    padding: 1.5em;
    max-height: 85vh;
  }

  .fullscreen-text-box p {
    font-size: 0.9em;
    margin: 0.4em 0;
  }

  .fullscreen-text-box .next-button {
    bottom: 15px;
    right: 15px;
    padding: 8px 16px;
    font-size: 0.9em;
  }
}

@media (max-width: 480px) {
  .fullscreen-text-box .content {
    padding: 1.2em;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
  }

  .fullscreen-text-box p {
    font-size: 0.8em;
    margin: 0.3em 0;
  }

  .fullscreen-text-box .next-button {
    bottom: 10px;
    right: 10px;
    padding: 6px 12px;
    font-size: 0.8em;
  }

  .fullscreen-text-box .close-button {
    top: 0;
    right: 0;
  }
}

/* GameBoy Controls */
.controls-overlay {
  position: absolute;
  width: 1150px;
  height: 100%;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  pointer-events: none;
}

.dpad {
  position: absolute;
  left: 120px;
  top: 1000px;
  width: 120px;
  height: 120px;
  pointer-events: auto;
}

.dpad-button {
  position: absolute;
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.dpad-button:active {
  background: rgba(136, 136, 136, 0.3);
}

.dpad-up {
  top: 0;
  left: 50%;
  transform: translateX(-50%);
}

.dpad-right {
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}

.dpad-down {
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}

.dpad-left {
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}

.action-buttons {
  position: absolute;
  width: 100px;
  height: 100px;
  pointer-events: auto;
}

.action-button {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.action-button:active {
  background: rgba(136, 136, 136, 0.3);
}

.button-a {
  top: 1000px;
  left: 520px;
}

.button-b {
  top: 1000px;
  left: 425px;
}

/* Mobile Responsive Styles */
@media screen and (max-width: 768px) {
  :root {
    --gameboy-width: 330px;
    --gameboy-height: 250px;
    --gameboy-offset: 130px;
  }

  .gameboy-bg-wrapper {
    background-size: 900px auto;
    background-position: center top;
    transform: scale(1.2);
    transform-origin: 50% 25%;
    margin-top: env(safe-area-inset-top);
    height: calc(100% + 20px);
  }

  .power-light {
    top: 71px;
    left: -52px;
  }

  .home-screen h1 {
    font-size: 1em;
    /* margin-bottom: 2em; */
  }

  .enter-button {
    font-size: 0.6em;
  }

  .subtext {
    font-size: 0.4em;
    bottom: 2em;
  }

  .text-box {
    width: 95%;
    font-size: 0.45em;
    padding: 12px 16px;
    min-height: 60px;
    bottom: 2.5%;
  }

  .music-button {
    font-size: 24px;
    bottom: 15px;
    right: 15px;
  }

  .controls-overlay {
    width: 700px;  /* Match the mobile background-size width */
  }

  .dpad {
    left: 120px;
    top: 530px;
  }

  .button-a {
    top: 555px;
    left: 530px;
  }
  
  .button-b {
    top: 585px;
    left: 430px;
  }

  .fullscreen-text-box {
    padding: 20px 15px;
    font-size: 0.65em;
  }

  .fullscreen-text-box .content {
    padding: 10px 0;
  }

  .fullscreen-text-box p {
    margin-bottom: 0.8em;
  }

  .fullscreen-text-box .next-button {
    bottom: 15px;
    right: 15px;
    padding: 6px 12px;
  }
}

/* Small Mobile Devices */
@media screen and (max-width: 480px) {
  :root {
    --gameboy-width: 320px;
    --gameboy-height: 240px;
    --gameboy-offset: 110px;
  }

  .gameboy-bg-wrapper {
    background-size: 800px auto;
    background-position: center top;
    transform: scale(1);
    transform-origin: 50% 20%;
    margin-top: -30px;
    height: calc(100% + 30px);
  }

  .power-light {
    top: 67px;
    left: -34px;
  }

  .home-screen h1 {
    font-size: 0.8em;
  }

  .enter-button {
    font-size: 0.4em;
  }

  .subtext {
    font-size: 0.4em;
  }

  .text-box {
    font-size: 0.35em;
    padding: 10px 12px;
    min-height: 50px;
    bottom: 2.5%;
  }

  .music-button {
    font-size: 20px;
    bottom: 10px;
    right: 10px;
  }

  .controls-overlay {
    width: 600px;  /* Match the small mobile background-size width */
  }

  .dpad {
    left: 90px;
    top: 465px;
  }

  .button-a {
    top: 490px;
    left: 458px;
  }
  
  .button-b {
    top: 518px;
    left: 368px;
  }

  .fullscreen-text-box {
    padding: 15px 10px;
    font-size: 0.6em;
  }

  .fullscreen-text-box .content {
    padding: 5px 0;
  }

  .fullscreen-text-box p {
    margin-bottom: 0.7em;
  }

  .fullscreen-text-box .next-button {
    bottom: 10px;
    right: 10px;
    padding: 5px 10px;
  }
}

/* iPhone-specific adjustments */
@supports (-webkit-touch-callout: none) {
  .gameboy-bg-wrapper {
    margin-top: -50px;
  }
  
  @media screen and (max-width: 768px) {
    .gameboy-bg-wrapper {
      margin-top: -40px;
    }
  }
} 