/* =========================================================
   Space Duel
   1. Tokens and base
   2. Header
   3. Background scenery (rocket, ship, kidnapped astronaut)
   4. Buttons
   5. Lobby (create / join)
   6. Game
   7. Round animation (hands flying in)
   8. Win screen
   9. Credits
   10. Keyframes
   11. Small screens and reduced motion
   ========================================================= */

/* ---------- 1. Tokens and base ---------- */

:root {
  font-size: 62.5%; /* 1rem = 10px */

  --font: "Yusei Magic", system-ui, sans-serif;
  --text: #fff;
  --text-muted: gray;
  --accent: rgba(170, 99, 19, 0.86);
  --code: orange;
  --astro: purple;
  --alien: green;
  --alien-soft: rgb(80, 131, 80);
  --selected: green;
  --win: #2ecc40;
  --lose: #ff4136;

  --panel: rgba(93, 97, 93, 0.4);
  --button: rgba(255, 255, 255, 0.42);
  --button-hover: #817d7b;
  --button-strong: #666563;

  /* Where the alien ship hovers: the kidnap animation ends there too. */
  --ship-x: 250px;
  --ship-offset: 0.1rem;
}

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  overflow-x: hidden;
  background: #000;
}

/* body stays unpositioned on purpose: the scenery and the round hands are placed against the viewport. */
body {
  min-height: 100vh;
  overflow-x: hidden;
  font-family: var(--font);
  font-size: 1.6rem;
  color: var(--text);
}

/* A fixed layer instead of background-attachment: fixed, which repaints the whole page on every scroll. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background: #000 url(Photos/galaxy.jpg) no-repeat center / cover;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--code);
  outline-offset: 3px;
}

/* ---------- 2. Header ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 12vh;
  padding: 0 2rem;
  background: linear-gradient(to right, rgba(93, 97, 93, 0.35), rgba(93, 97, 93, 0));
}

#logo {
  width: clamp(30rem, 50vw, 40rem);
  max-height: 10vh;
  object-fit: contain;
  object-position: left center;
}

.icon-button {
  padding: 5px;
  border-radius: 8px;
}

#sound img {
  height: 4rem;
  width: auto;
}

/* ---------- 3. Background scenery ---------- */

.scenery {
  position: absolute;
  inset: 0 0 auto;
  height: 100vh;
  overflow: hidden;
  pointer-events: none;
  z-index: -1;
}

.scenery img {
  position: absolute;
  will-change: transform;
}

#rocket {
  width: 8rem;
  top: 72vh;
  left: -8rem;
  animation: rocket 20s linear 3s infinite forwards;
}

#alienship {
  width: 8.5rem;
  top: -12rem;
  left: var(--ship-x);
  animation: ship 20s ease-out 3s infinite;
}

#kidnap {
  width: 5rem;
  top: 350px;
  left: -5rem;
  opacity: 0;
  animation: kidnap 20s linear 3s infinite;
}

/* ---------- 4. Buttons ---------- */

.limit,
.roomButton,
.win-actions button {
  background: var(--button);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 28%;
  transition: background-color 0.2s;
}

.limit:hover,
.roomButton:hover,
.win-actions button:hover,
.CHRicon:hover {
  background-color: var(--button-hover);
  animation: jelly 0.6s ease 150ms;
}

.limit:active,
.roomButton:active,
.win-actions button:active {
  color: #333131;
}

/* ---------- 5. Lobby ---------- */

#RoomSec {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 90vh;
}

#RoomStatusDIV {
  display: flex;
  justify-content: center;
}

#RoomStatus {
  white-space: pre-line;
  text-align: center;
  font-size: clamp(2rem, 4vw, 4rem);
}

.room-code {
  color: var(--code);
}

#RoomCreation {
  margin-top: min(0px, calc(-1 * (200px - 10vw)));
}

.Create {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  gap: 0.4rem;
}

.limitContainer {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: clamp(2rem, 5vw, 3rem);
}

.limit {
  min-width: 2.6em;
  padding: 0.3rem 0.5rem;
  font-size: 2.3rem;
  color: #000;
}

.limit[aria-pressed="true"] {
  background-color: var(--selected);
}

#characterChoice {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.roomButton {
  margin: 4px;
  padding: 0 1.2rem;
  font-size: clamp(2.5rem, 5vw, 5rem);
  color: rgba(255, 255, 255, 0.9);
  background: var(--button-strong);
  border-radius: 2rem;
}

.CHRicon {
  width: 5.5rem;
  border-radius: 20%;
  transition: background-color 0.2s;
}

.CHRicon[aria-pressed="true"] {
  background-color: var(--astro);
}

#InsertDIV {
  display: flex;
  align-items: center;
}

#insert {
  font-size: clamp(2rem, 3vw, 3.5rem);
  color: var(--accent);
  background-color: rgba(182, 182, 182, 0.2);
}

#box {
  width: clamp(5rem, 10vw, 8rem);
  height: clamp(3rem, 5vw, 4rem);
  margin-left: 5px;
  font: inherit;
  font-size: 2rem;
  text-transform: lowercase;
  color: var(--text);
  background-color: rgba(255, 255, 255, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

/* ---------- 6. Game ---------- */

#gameSec {
  height: 90vh;
}

#GameContainer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: max(20px, calc(110px - 10vw));
}

#Goal {
  font-size: 2rem;
  padding: 0 0.6rem;
  background: linear-gradient(var(--panel) 35%, rgba(93, 97, 93, 0));
}

#crowd {
  font-size: 2rem;
  text-align: center;
}

.msg-astro { color: var(--astro); }
.msg-alien { color: var(--alien); }
.msg-gray { color: var(--text-muted); }

.scoreboard {
  display: flex;
  align-items: flex-end;
  font-size: 3.5rem;
  background: linear-gradient(rgba(93, 97, 93, 0) 45%, var(--panel) 35%, rgba(93, 97, 93, 0));
}

.icon {
  width: 7rem;
}

.game {
  display: flex;
  align-items: center;
  justify-content: center;
}

.choice {
  width: clamp(90px, 20vw, 200px);
  margin-top: max(0px, calc(60px - 10vw)); /* grows only on small screens */
  margin-left: 3%;
  border-radius: 30%;
  transition: transform 0.3s, background-color 0.3s;
  animation: appearFromLeft 0.5s ease;
}

#rockBtn {
  animation: appearFromTop 1s ease;
}

#scissorsBtn {
  animation: appearFromTop 1.5s ease;
}

.choice:hover,
.choice:focus-visible {
  background-color: rgba(49, 48, 48, 0.3);
  transform: scale(1.2);
}

.choice:active {
  background-color: rgba(49, 48, 48, 0.8);
}

#status {
  margin-top: 2%;
  white-space: pre-line;
  text-align: center;
  font-size: clamp(2rem, 4vw, 3.3rem);
}

/* ---------- 7. Round animation ---------- */

.animDIV {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.winAnimation,
.winAnimationUp {
  position: absolute;
  height: 50vh;
  width: auto;
  max-width: none;
  opacity: 0;
  z-index: -1;
  pointer-events: none;
}

.winAnimation {
  bottom: -50vh;
}

.winAnimationUp {
  top: -50vh;
  transform: rotate(180deg);
}

.botAnim {
  animation: handFromBottom 3s linear;
  will-change: transform;
}

.upAnim {
  animation: handFromTop 3s linear;
  will-change: transform;
}

/* ---------- 8. Win screen ---------- */

#winningDIV {
  display: grid;
  min-height: 100vh;
}

#winContain {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#winContain .icon {
  width: 18vw;
}

#winContain .scoreboard span {
  font-size: 8rem;
}

#score3.win, #score4.win { color: var(--win); }
#score3.lose, #score4.lose { color: var(--lose); }

#RematchBOX {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  font-size: 4rem;
  text-align: center;
}

.win-actions {
  display: flex;
  gap: 1rem;
}

.win-actions button {
  width: 20rem;
  height: 8rem;
  font-size: 3rem;
}

/* ---------- 9. Credits ---------- */

#Info {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#designer {
  display: flex;
  flex-direction: column;
  font-size: 2.6rem;
}

#CreatorsContainer {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  column-gap: clamp(0.5rem, 6vw, 5.5rem);
  row-gap: clamp(1rem, 6vw, 8rem);
  margin: auto auto 3rem;
}

.gridContainer {
  display: flex;
  flex-direction: column;
}

.JobTitle {
  font-size: clamp(2rem, 4vw, 3.3rem);
  color: var(--accent);
}

.credit {
  display: flex;
  align-items: center;
}

.names {
  position: relative;
  overflow: hidden;
  font-size: clamp(2rem, 4vw, 4rem);
  border-radius: 20%;
}

/* The shine sweeping across each name: a transform on its own layer instead of repainting a gradient every frame. */
.names::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.3));
  transform-origin: right center;
  transform: scaleX(0);
  animation: shine 3s linear infinite;
  will-change: transform;
}

.review {
  align-self: flex-end;
  font-size: clamp(1.2rem, 2vw, 2rem);
  color: var(--text-muted);
}

.social {
  width: clamp(3rem, 5vw, 5rem);
  margin-left: 0.4rem;
  transition: transform 0.15s;
}

a:hover .social {
  transform: scale(1.3);
}

a:active .social {
  opacity: 0.8;
}

#paragraph {
  width: min(90vw, 110rem);
  margin: clamp(4rem, 8vw, 9rem) auto clamp(4rem, 6vw, 7rem);
  padding: clamp(1.6rem, 3vw, 3rem) clamp(1.8rem, 4vw, 4rem);
  font-size: clamp(1.6rem, 1.8vw, 2.1rem);
  line-height: 1.7;
  color: #f8f8f8;
  background: rgba(40, 40, 40, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-left: 4px solid var(--accent);
  border-radius: 1.2rem;
  -webkit-text-stroke: 0.4px black;
}

.green-word {
  font-size: 1.2em;
  color: var(--alien-soft);
}

/* ---------- 10. Keyframes (transform and opacity only, so they stay on the compositor) ---------- */

@keyframes rocket {
  12.5% { transform: translate(32.5vw, 1vw) rotate(5deg); }
  25% { transform: translate(65vw, -1vw) rotate(-5deg); }
  37.5% { transform: translate(97.5vw, 1vw) rotate(5deg); }
  50% { transform: translate(130vw, 5vw) rotate(15deg); opacity: 1; }
  50.001%, 100% { transform: translate(0, 5vw) rotate(15deg); opacity: 0; }
}

@keyframes ship {
  0%, 60% { transform: translateY(0); }
  70% { transform: translateY(450px); }
  79% { transform: translateY(0); }
}

@keyframes kidnap {
  34.99% { transform: translateX(calc(100vw + 5rem)); opacity: 0; }
  35% { transform: translateX(calc(100vw + 5rem)); opacity: 1; }
  52.5% { transform: translateX(calc((100vw + 12rem + var(--ship-x)) / 2)) translateY(-65px) rotate(270deg); opacity: 1; }
  70% { transform: translateX(calc(var(--ship-x) + 7rem - var(--ship-offset))) translateY(65px) rotate(540deg); opacity: 1; }
  75% { transform: translateX(calc(var(--ship-x) + 7rem - var(--ship-offset))) translateY(-270px) rotate(360deg); opacity: 1; }
  79%, 100% { transform: translateX(calc(var(--ship-x) + 7rem - var(--ship-offset))) translateY(calc(-350px - 10rem)) rotate(360deg); opacity: 1; }
}

@keyframes appearFromLeft {
  from { transform: translateX(-100vw); }
  to { transform: translateX(0); }
}

@keyframes appearFromTop {
  from { transform: translateY(-100vh); }
  to { transform: translateY(0); }
}

@keyframes jelly {
  25% { transform: scale(0.8, 1.3); }
  50% { transform: scale(1.1, 0.8); }
  75% { transform: scale(0.7, 1.2); }
}

@keyframes handFromBottom {
  0%, 100% { transform: translateY(0); opacity: 1; }
  33%, 66% { transform: translateY(-45vh); opacity: 1; }
}

@keyframes handFromTop {
  0%, 100% { transform: translateY(0) rotate(180deg); opacity: 1; }
  33%, 66% { transform: translateY(45vh) rotate(180deg); opacity: 1; }
}

@keyframes shine {
  0% { transform: scaleX(0); }
  5% { transform: scaleX(0.9); }
  50% { transform: scaleX(0); }
  100% { transform: scaleX(0); }
}

/* ---------- 11. Small screens and reduced motion ---------- */

@media (max-width: 500px) {
  :root {
    --ship-x: 40px;
    --ship-offset: 1.5rem;
  }

  .site-header {
    justify-content: center;
  }

  #sound {
    position: absolute;
    top: 14vh;
    right: 10px;
  }

  #rocket { width: 7rem; }
  #alienship { width: 7rem; }
  #kidnap { width: 4rem; }

  .CHRicon { width: 3.3rem; }

  #crowd { font-size: 2.2rem; }

  #CreatorsContainer {
    grid-template-columns: auto;
  }

  #paragraph {
    width: 92vw;
    font-size: 1.5rem;
    line-height: 1.6;
  }

  #winContain .icon { width: 27vw; }
  #winContain .scoreboard span { font-size: 6rem; }
  #RematchBOX { font-size: 2.3rem; }

  .win-actions button {
    width: 15rem;
    height: 6rem;
    font-size: 2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scenery,
  .names::after {
    display: none;
  }

  .choice,
  .limit:hover,
  .roomButton:hover,
  .win-actions button:hover,
  .CHRicon:hover {
    animation: none;
  }

  /* Keep the round result readable, just without the slide. */
  .botAnim,
  .upAnim {
    animation-timing-function: steps(1, end);
  }
}
