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

:root {
  --bg-deep: #05050a;
  --bg-ink: #0b0c17;
  --accent-pink: #ff4fd8;
  --accent-cyan: #45f3ff;
  --accent-lime: #9cff57;
  --accent-gold: #ffd86b;
  --glass: rgba(15, 18, 30, 0.72);
  --glass-edge: rgba(160, 170, 255, 0.22);
  --text-primary: #f3f6ff;
  --text-muted: #b1b7d4;
  --pixel-border: #a7f0ff;
  --pixel-panel: #0f1220;
  --pixel-panel-dark: #0a0c16;
  --pixel-shadow: #05060b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(1200px 800px at 15% 10%, rgba(255, 79, 216, 0.12), transparent 60%),
    radial-gradient(1100px 900px at 90% 10%, rgba(69, 243, 255, 0.12), transparent 55%),
    radial-gradient(1200px 900px at 60% 90%, rgba(156, 255, 87, 0.08), transparent 55%),
    linear-gradient(160deg, var(--bg-deep), var(--bg-ink));
  font-family: "Press Start 2P", "Courier New", monospace;
  color: var(--text-muted);
  overflow: hidden;
  letter-spacing: 0.6px;
  image-rendering: pixelated;
}

button:focus-visible {
  outline: 2px solid rgba(255, 216, 107, 0.9);
  outline-offset: 2px;
}

body::before,
body::after {
  content: "";
  position: absolute;
  inset: -20%;
  background: conic-gradient(
    from 180deg,
    rgba(255, 79, 216, 0.06), transparent 25%,
    rgba(69, 243, 255, 0.06), transparent 55%,
    rgba(156, 255, 87, 0.05)
  );
  filter: blur(30px);
  opacity: 0.6;
  animation: drift 18s linear infinite;
  z-index: 0;
}
body::after {
  animation-direction: reverse;
  opacity: 0.35;
}

@keyframes drift {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  body::before,
  body::after { animation: none !important; }
}

#gameContainer {
  position: relative;
  border: 4px solid var(--pixel-border);
  box-shadow:
    0 0 0 4px var(--pixel-shadow),
    0 0 0 8px #1a2036,
    0 18px 45px rgba(0, 0, 0, 0.6);
  background: linear-gradient(180deg, var(--pixel-panel), var(--pixel-panel-dark));
  width: 100%;
  min-width: 320px;
  max-width: 960px;
  aspect-ratio: 16 / 10;
  display: flex;
  flex-direction: column;
  border-radius: 0;
  overflow: hidden;
  z-index: 1;
}

#gameContainer::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.15),
    rgba(0, 0, 0, 0.15) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: soft-light;
  pointer-events: none;
  z-index: 2;
}

#gameContainer::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05),
    rgba(255, 255, 255, 0.05) 1px,
    transparent 1px,
    transparent 4px
  );
  pointer-events: none;
  z-index: 2;
}

#gameHeader {
  width: 100%;
  min-height: 50px;
  background: linear-gradient(120deg, #11182b, #1a1220);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 16px 8px;
  box-sizing: border-box;
  border-bottom: 4px solid var(--pixel-border);
  z-index: 5;
  gap: 12px;
}

.headerColumn {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.headerColumn.headerRight {
  align-items: flex-end;
  gap: 2px;
}

canvas {
  display: block;
  background-color: transparent;
  flex: 1;
  min-height: 0;
  opacity: 0;
  transition: opacity 1.2s ease-in 0.5s;
  position: relative;
  image-rendering: pixelated;
}
canvas.visible { opacity: 1; }

#uiOverlay {
  position: absolute;
  top: 50px;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.2s ease-in 0.5s;
  z-index: 10;
}
#uiOverlay.visible { opacity: 1; }

#levelNameDisplay {
  font-size: 9px;
  line-height: 1.6;
  color: var(--accent-cyan);
  text-shadow: 0 0 10px rgba(69, 243, 255, 0.4);
  padding: 0;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#scoreDisplay {
  font-size: 14px;
  line-height: 1.6;
  color: var(--accent-gold);
  text-shadow: 0 0 12px rgba(255, 216, 107, 0.45);
  padding: 0;
  margin: 0;
  text-transform: uppercase;
}

#aiChallengeTimerDisplay {
  font-size: 10px;
  line-height: 1.6;
  color: #ff7b65;
  text-shadow: 0 0 12px rgba(255, 123, 101, 0.45);
  padding: 0;
  margin: 0;
  display: block;
  text-transform: uppercase;
}

#dashCooldownDisplay {
  font-size: 10px;
  line-height: 1.6;
  color: var(--accent-cyan);
  text-shadow: 0 0 12px rgba(69, 243, 255, 0.45);
  padding: 0;
  margin: 0;
  display: block;
  text-transform: uppercase;
}

#messageDisplayContainer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: none;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(145deg, #0e1220, #0a0c18);
  padding: 35px 40px;
  border-radius: 0;
  border: 4px solid var(--pixel-border);
  box-shadow:
    0 0 0 4px var(--pixel-shadow),
    0 10px 20px rgba(0, 0, 0, 0.6);
  z-index: 20;
  max-width: 85%;
  text-align: center;
}

#messageDisplay {
  font-size: 12px;
  line-height: 2.0;
  color: #f5f5f5;
  text-align: center;
  margin-bottom: 25px;
  padding: 0 20px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

#restartGameButton {
  background: #ffd86b;
  color: #11131b;
  padding: 10px 20px;
  border: 4px solid #11131b;
  border-radius: 0;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 4px 4px 0 #0a0c16;
  transition: all 0.3s ease;
  pointer-events: auto;
  text-transform: uppercase;
}
#restartGameButton:hover {
  background: #fff0a6;
  color: #0f111a;
  transform: translate(-1px, -1px);
  box-shadow: 6px 6px 0 #0a0c16;
}

#onboardingScreen {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: linear-gradient(150deg, #091321, #0c0f1b, #070911);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 30;
  padding: 30px;
  box-sizing: border-box;
  opacity: 1;
  cursor: pointer;
}
#onboardingScreen.fade-out {
  opacity: 0 !important;
  transition: opacity 1s ease-out 0.5s;
  pointer-events: none;
}
#onboardingScreen.no-cursor { cursor: default; }

#onboardingScreen h1 {
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 36px;
  font-weight: 400;
  letter-spacing: 1px;
  color: #f6f2ff;
  text-shadow:
    0 0 18px rgba(255, 79, 216, 0.6),
    0 0 35px rgba(69, 243, 255, 0.35),
    0 0 60px rgba(255, 79, 216, 0.2);
  margin-bottom: 20px;
  opacity: 0;
  transform: translateY(-20px);
  animation: titleAppear 1.2s cubic-bezier(0.23, 1, 0.32, 1) forwards,
             titleGlow 3s ease-in-out 1.2s infinite;
}
#onboardingScreen h1.phase2 {
  animation: titleAppear 1.2s cubic-bezier(0.23, 1, 0.32, 1) forwards,
             titleGlow 3s ease-in-out infinite;
  margin-bottom: 25px;
}

@keyframes titleAppear {
  to { opacity: 1; transform: translateY(0); }
}
@keyframes titleGlow {
  0%, 100% { text-shadow: 0 0 18px rgba(255,79,216,0.6), 0 0 35px rgba(69,243,255,0.35), 0 0 60px rgba(255,79,216,0.2); }
  50% { text-shadow: 0 0 28px rgba(255,79,216,0.9), 0 0 50px rgba(69,243,255,0.6), 0 0 80px rgba(255,79,216,0.35); }
}

#clickToEnter {
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 10px;
  color: var(--accent-cyan);
  text-shadow: 0 0 10px rgba(69, 243, 255, 0.5);
  margin-bottom: 25px;
  opacity: 0;
  text-transform: uppercase;
  animation: pulseText 1.5s ease-in-out 1.5s infinite;
}
#clickToEnter.fade-out-click {
  opacity: 0 !important;
  transition: opacity 0.3s ease-out;
  pointer-events: none;
}

@keyframes pulseText {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.06); }
}

#poweredBy {
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 7px;
  color: var(--text-muted);
  opacity: 0.45;
  letter-spacing: 1px;
  margin-top: -14px;
  margin-bottom: 30px;
}

#typewriterContainer,
#fruitIntroContainer {
  margin-bottom: 30px;
  min-height: 160px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 1;
  transition: opacity 0.5s ease-out, display 0s linear 0.5s;
}
#typewriterContainer.hidden,
#fruitIntroContainer.hidden {
  opacity: 0;
  pointer-events: none;
  display: none !important;
}
#fruitIntroContainer { opacity: 0; display: none; }
#fruitIntroContainer.visible {
  opacity: 1;
  display: flex;
  transition: opacity 0.7s ease-in;
}

#typewriterContainer p {
  font-size: 11px;
  line-height: 2.2;
  color: #f3f6ff;
  text-shadow: 0 0 12px rgba(69, 243, 255, 0.2);
  margin: 0 0 10px 0;
  padding: 0 30px;
  max-width: 750px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.5s ease 0.1s, transform 0.5s ease 0.1s, color 0.5s ease;
  text-transform: uppercase;
}
#typewriterContainer p.visible-line { opacity: 1; transform: translateY(0); }
#typewriterContainer p.dimmed-line { opacity: 0.5; color: #a7b0d0; }

.typewriter-cursor {
  display: inline-block;
  background-color: #FFD700;
  width: 8px;
  height: 16px;
  animation: blink 0.8s step-end infinite;
  margin-left: 2px;
  vertical-align: text-bottom;
}

@keyframes blink {
  from, to { background-color: transparent; }
  50% { background-color: #FFD700; }
}

#fruitIntroContainer h2 {
  font-size: 12px;
  line-height: 1.5;
  font-weight: bold;
  color: var(--accent-gold);
  margin-bottom: 20px;
  text-shadow: 0 0 12px rgba(255, 216, 107, 0.35);
  text-transform: uppercase;
}

.fruit-display-area {
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  width: 100%;
  max-width: 700px;
  margin-bottom: 25px;
}

.fruit-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: #FFFFE0;
}
.fruit-visual {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  margin-bottom: 8px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.35);
}
.fruit-item p {
  font-size: 12px;
  line-height: 1.5;
  margin: 4px 0;
  text-transform: uppercase;
}

#beginRestorationButton,
#startGameButton {
  background: #45f3ff;
  color: #071018;
  padding: 12px 25px;
  border: 4px solid #071018;
  border-radius: 0;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 4px 4px 0 #0a0c16;
  transition: all 0.3s ease;
  opacity: 0;
  transform: scale(0.7) translateY(20px);
  pointer-events: none;
  margin-top: 20px;
  text-transform: uppercase;
}
#beginRestorationButton.visible,
#startGameButton.visible {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
  transition: opacity 0.8s ease-out 0.3s, transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.3s;
}
#beginRestorationButton:hover,
#startGameButton:hover {
  background: #7cf7ff;
  color: #041018;
  transform: translate(-1px, -1px);
  box-shadow: 6px 6px 0 #0a0c16;
}
#beginRestorationButton.hidden,
#startGameButton.hidden {
  opacity: 0 !important;
  pointer-events: none !important;
  display: none !important;
}

#levelSelectScreen {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 700px;
  opacity: 1;
  transition: opacity 0.4s ease-in;
}
#levelSelectScreen.hidden {
  opacity: 0;
  pointer-events: none;
  display: none !important;
}
#levelSelectScreen h2 {
  font-size: 10px;
  line-height: 1.5;
  color: var(--accent-cyan);
  text-shadow: 0 0 12px rgba(69, 243, 255, 0.4);
  margin-bottom: 20px;
  text-transform: uppercase;
}
#levelCards {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-bottom: 20px;
}
.level-card {
  background: linear-gradient(150deg, #0f1425, #0a0d18);
  border: 3px solid #2b3550;
  box-shadow: 4px 4px 0 #0a0c16;
  padding: 18px 14px;
  width: 180px;
  cursor: pointer;
  transition: all 0.25s ease;
  text-align: center;
  text-transform: uppercase;
}
.level-card:hover {
  border-color: var(--accent-cyan);
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 #0a0c16;
}
.level-card .lc-color-bar {
  height: 6px;
  margin-bottom: 12px;
  border-radius: 0;
}
.level-card .lc-name {
  font-size: 10px;
  color: #f3f6ff;
  margin-bottom: 8px;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.15);
}
.level-card .lc-sub {
  font-size: 7px;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.4;
}
.level-card .lc-diff {
  font-size: 7px;
  color: var(--accent-gold);
}

#backFromLevelSelect {
  background: transparent;
  color: var(--text-muted);
  border: 2px solid #2b3550;
  padding: 6px 16px;
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 9px;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.2s ease;
}
#backFromLevelSelect:hover {
  color: #fff;
  border-color: var(--accent-cyan);
}

#dynamicMessageOverlay {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: #0e1320;
  color: #d3f7ff;
  padding: 14px 22px;
  border-radius: 0;
  border: 3px solid #2b3550;
  box-shadow: 3px 3px 0 #0a0c16;
  font-size: 10px;
  line-height: 1.8;
  text-align: center;
  max-width: 80%;
  z-index: 25;
  opacity: 0;
  transition: opacity 0.4s ease-in-out;
  pointer-events: none;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#dynamicMessageOverlay.visible { opacity: 1; }

#levelTransitionOverlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 10, 0.85);
  z-index: 35;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease-in;
}
#levelTransitionOverlay.visible {
  opacity: 1;
  pointer-events: auto;
}
#levelTransitionTitle {
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 24px;
  color: var(--accent-cyan);
  text-shadow: 0 0 20px rgba(69, 243, 255, 0.7);
  margin-bottom: 15px;
  text-transform: uppercase;
}
#levelTransitionSub {
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 10px;
  color: var(--text-muted);
  text-shadow: 0 0 8px rgba(177, 183, 212, 0.3);
  text-transform: uppercase;
  text-align: center;
  max-width: 80%;
}
