@font-face {
  font-family: "pwbubbles";
  src: url("fonts/pwbubbles.ttf");
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  overflow: hidden;
  font-family: "pwbubbles";
  color: white;
  font-family: "pwbubbles", system-ui, sans-serif;
}

h1 {
  font-size: 50px;
  text-shadow: 5px 5px 8px rgb(0, 0, 0);
  padding-top: 20px;
}

.background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url("img/background/background.png");
  background-size: cover;
  background-position: center;
  z-index: -1;
}

#canvas {
  z-index: 1;
  display: block;
}

#game-container {
  position: relative;
}

#start-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
}

#start-overlay .overlay-bg {
  position: absolute;
  inset: 0;
}

#start-btn-img {
  padding-top: 100px;
  position: relative;
  width: 240px;
  cursor: pointer;
  transition: transform 0.15s ease;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.35));
}
#start-btn-img:hover {
  transform: scale(1.05);
}

#info-btn-img {
  position: relative;
  width: 70px;
  cursor: pointer;
  transition: transform 0.15s ease;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.35));
}

#info-btn-img:hover {
  transform: scale(1.05);
}

#info-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
#info-modal.show {
  display: flex;
}

#info-modal .modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

#info-modal .modal-content {
  position: relative;
  z-index: 1;
  display: inline-block;
  width: fit-content;
  height: fit-content;
  padding: 0;
  margin: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  border-radius: 0;
}

#info-modal .modal-content img {
  display: block;
  width: auto;
  height: auto;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 48px);
  border-radius: 12px;
}

.fs-btn {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

#game-container.started .fs-btn {
  opacity: 1;
  pointer-events: auto;
}

.fs-btn {
  position: absolute;
  right: 10px;
  bottom: 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: white;
}

.fs-btn:hover {
  background: rgba(0, 0, 0, 0.5);
}

.fs-btn img {
  width: 40px;
  height: 40px;
}

#end-overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  z-index: 30;
}
#end-overlay.show {
  display: grid;
}

#end-overlay .end-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

#end-overlay .end-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 0;
}

#end-image {
  width: 400px;
  height: auto;
  user-select: none;
  pointer-events: none;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.35));
}

#restart-btn {
  width: 200px;
  height: auto;
  cursor: pointer;
  transition: transform 0.15s ease;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.35));
}
#restart-btn:hover {
  transform: scale(1.05);
}

.end-overlay {
  position: absolute;
  inset: 0;
  z-index: 999;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.55);
}

.end-panel {
  display: grid;
  gap: 16px;
  place-items: center;
}

.end-image {
  max-width: 80%;
  height: auto;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.35));
}

.restart-btn {
  width: 220px;
  cursor: pointer;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.35));
  transition: transform 0.15s ease;
}
.restart-btn:hover {
  transform: scale(1.04);
}

#loading-overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  z-index: 20;
  background: #000;
}
#loading-overlay.show {
  display: grid;
}

#start-overlay.hide {
  display: none;
}

.spinner {
  width: 72px;
  height: 72px;
  border: 6px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.35));
}

#controls {
  width: 100%;
  max-width: 880px;
  margin: 8px auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  opacity: 1;
  pointer-events: auto;
}

#game-container.started + #controls {
  justify-content: flex-start;
}

#audio-toggle-btn {
  width: 40px;
  height: 40px;
  cursor: pointer;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.35));
  transition: transform 0.15s ease;
}
#audio-toggle-btn:hover {
  transform: scale(1.05);
}

#rotate-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background-image: url("img/background/background.png");
  z-index: 99999;
}

#rotate-overlay.show {
  display: flex;
}

#rotate-overlay img {
  width: 70vw;
  max-width: 420px;
  height: auto;
}

#fs-nudge {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 50000;
}

#fs-nudge.show {
  display: flex;
}

#fs-nudge button {
  font: inherit;
  padding: 12px 18px;
  border-radius: 12px;
  border: 0;
  background: #111;
  color: #fff;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.legal-links {
  margin: 16px 0;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  padding-top: 20px;
}
.legal-links a {
  color: #fff;
  text-decoration: none;
  opacity: 0.85;
}
.legal-links a:hover {
  opacity: 1;
  text-decoration: none;
}

#rotate-overlay .legal-rotate {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  font-size: 14px;
}
#rotate-overlay .legal-rotate a {
  color: #fff;
  text-decoration: none;
}

@media (max-width: 360px) {
  .legal-links,
  #rotate-overlay .legal-rotate {
    font-size: 13px;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  html,
  body {
    height: 100svh;
    width: 100svw;
    overflow: hidden;
  }
  h1,
  .fs-btn {
    display: none !important;
  }
  .background {
    display: none !important;
  }

  #rotate-overlay {
    display: none !important;
  }

  #game-container {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 0;
    margin: 0;
  }

  #canvas {
    width: 100svw !important;
    height: 100svh !important;
    max-width: 100svw;
    max-height: 100svh;
    display: block;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  #controls {
    position: fixed;
    right: 12px;
    top: 12px;
    z-index: 10000;
    width: auto;
    max-width: none;
    margin: 0;
    padding: 6px 8px;
    justify-content: center;
    backdrop-filter: blur(3px);
    border-radius: 999px;
  }

  #game-container.started + #controls {
    opacity: 1;
    pointer-events: auto;
  }

  #audio-toggle-btn {
    width: 44px;
    height: 44px;
  }

  #start-overlay {
    background-image: url("img/background/background.png");
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  #touch-controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 8px 16px;
    z-index: 1000;
    pointer-events: none;
  }
  #touch-controls[hidden] {
    display: none;
  }

  .tc-left,
  .tc-right {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .tc-right img{
    width: 35px;
  }

  .tc-dpad {
    display: grid;
    grid-template-columns: repeat(3, 64px);
    grid-template-rows: repeat(3, 64px);
    gap: 6px;
  }

  .tc-btn {
    width: 64px;
    height: 64px;
    border-radius: 12px;
    border: 0;
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    font-size: 22px;
    display: grid;
    place-items: center;
    pointer-events: auto;
    user-select: none;
    touch-action: none;
  }
  .tc-btn:active {
    transform: scale(0.96);
  }

  .tc-up {
    grid-column: 2;
    grid-row: 1;
  }
  .tc-left {
    grid-column: 1;
    grid-row: 2;
  }
  .tc-down {
    grid-column: 2;
    grid-row: 3;
  }
  .tc-right {
    grid-column: 3;
    grid-row: 2;
  }

  .tc-btn.tc-a,
  .tc-btn.tc-b,
  .tc-btn.tc-f {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    font-weight: 700;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-width: 700px) {
  .tc-dpad {
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(3, 56px);
    gap: 4px;
  }
  .tc-btn {
    width: 56px;
    height: 56px;
    font-size: 20px;
  }
  .tc-btn.tc-a,
  .tc-btn.tc-b,
  .tc-btn.tc-f {
    width: 64px;
    height: 64px;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: portrait) {
  #rotate-overlay {
    position: fixed;
    inset: 0;
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: #000;
    z-index: 99999;
    background-image: url("img/background/background.png");
  }

  #game-container,
  h1,
  #controls {
    display: none !important;
  }

  #rotate-overlay img {
    width: 70vw;
    max-width: 420px;
    height: auto;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media only screen and (max-width: 880px) {
  #canvas {
    width: 100%;
  }
}

@media only screen and (max-height: 520px) {
  #canvas {
    height: 100vh;
  }
}

@media (max-width: 550px) {
  #start-btn-img {
    padding-bottom: 20px;
    width: 190px;
  }

  #info-btn-img {
    width: 60px;
  }

  #audio-toggle-btn {
    width: 20px;
    height: 20px;
  }

  .fs-btn img {
    width: 20px;
    height: 20px;
  }
}

@media (hover: hover) and (pointer: fine) and (max-width: 550px) {
  #rotate-overlay {
    position: fixed;
    inset: 0;
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: #000;
    z-index: 99999;
    background-image: url("img/background/background.png");
  }

  #game-container,
  #controls,
  h1,
  .background {
    display: none !important;
  }
}

#game-container,
#canvas,
#touch-controls,
#touch-controls .tc-btn,
#controls,
#controls img {
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#touch-controls .tc-btn {
  touch-action: none;
}

img,
canvas {
  -webkit-user-drag: none;
}
