:root {
  color-scheme: dark;
  --bg: #0b0b14;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 50% 15%, #1a1b2e 0%, #0b0b14 65%, #07070f 100%);
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  display: flex;
  min-height: 100vh;
  align-items: flex-start;
  justify-content: center;
  color: #e8f6ff;
  overflow-x: hidden;
  overflow-y: auto;
}

#app, .layout {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 16px;
}

.credits {
  width: min(100vw, 960px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  color: #fa660f;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  font-size: 13px;
  gap: 10px;
}

.credit-line {
  text-align: right;
}

.credits {
  width: min(100vw, 960px);
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  color: #fa660f;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  font-size: 14px;
  gap: 12px;
}

.credit-line {
  text-align: right;
}

.music-credit {
  text-align: left;
  display: flex;
  align-items: center;
  gap: 6px;
}

.music-credit-mobile {
  display: none;
}

.credit-icon {
  width: 18px;
  height: 18px;
  filter: brightness(0) saturate(100%) invert(45%) sepia(96%) saturate(2854%) hue-rotate(2deg)
    brightness(101%) contrast(104%);
}

.music-toggle {
  cursor: pointer;
  transition: opacity 0.15s ease, filter 0.15s ease;
  display: inline-flex;
  align-items: center;
}

.music-toggle.off {
  opacity: 0.45;
  filter: grayscale(1) brightness(0.5);
}

.music-credit .music-toggle {
  margin-left: 6px;
}

.credits a {
  color: #fa660f;
  text-decoration: none;
}

.credits a:hover {
  text-decoration: underline;
}

#game {
  width: min(100vw, 960px);
  height: min(calc(100vw * 0.5625), 540px); /* keep aspect 16:9 when fitting width */
  outline: 2px solid #1e314a;
  box-shadow: 0 0 40px rgba(0, 255, 210, 0.18);
  position: relative;
  overflow: hidden;
}

.hud-tip {
  width: min(100vw, 960px);
  text-align: center;
  color: #fa660f;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  font-size: 16px;
  background: rgba(8, 12, 20, 0.65);
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(250, 102, 15, 0.35);
}

.fullscreen-btn {
  display: none;
  margin: 4px 0 8px;
  padding: 8px 12px;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  font-size: 14px;
  color: #fa660f;
  background: rgba(8, 12, 20, 0.7);
  border: 1px solid rgba(250, 102, 15, 0.5);
  border-radius: 8px;
  cursor: pointer;
}

.fullscreen-btn:hover {
  background: rgba(8, 12, 20, 0.9);
}

.mobile-only {
  display: none;
}

.desktop-only {
  display: block;
}

#mobile-fs-btn {
  display: none;
  width: 100vw;
  max-width: 100vw;
  background: rgba(8, 12, 20, 0.95);
  padding: 20px;
  border-bottom: 0px solid rgba(250, 102, 15, 0.5);
  text-align: center;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-sizing: border-box;
}

.rotate-icon {
  width: 60px;
  height: 60px;
  filter: brightness(0) saturate(100%) invert(100%);
  animation: rotate-hint 2s ease-in-out infinite;
}

@keyframes rotate-hint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}

.rotate-label {
  color: #ffffff;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  font-size: 16px;
  font-weight: bold;
}

#mobile-controls {
  position: absolute;
  inset: 0;
  z-index: 1600;
  pointer-events: none;
  display: none;
}

#mobile-controls.visible {
  display: block;
}

#mobile-controls.visible > * {
  pointer-events: auto;
}

#mobile-action {
  position: absolute;
  right: 16px;
  bottom: 30px;
  width: clamp(70px, 16vw, 30px);
  height: clamp(70px, 16vw, 30px);
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.3);
  color: #fa660f;
  font-size: clamp(32px, 7vw, 40px);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  touch-action: none;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

#mobile-dpad {
  position: absolute;
  left: 16px;
  bottom: 14px;
  width: clamp(120px, 26vw, 60px);
  height: clamp(120px, 26vw, 60px);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  border: 6px solid rgba(255, 255, 255, 0.22);
  display: grid;
  place-items: center;
  padding: 10px;
  pointer-events: auto;
  touch-action: none;
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.35);
}

#mobile-dpad::before {
  content: "";
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
}

#mobile-dpad .dpad-up,
#mobile-dpad .dpad-left,
#mobile-dpad .dpad-right {
  position: absolute;
  font-size: clamp(22px, 4.5vw, 28px);
  color: #fa660f;
  user-select: none;
  pointer-events: none;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

#mobile-dpad .dpad-up {
  top: 18%;
}

#mobile-dpad .dpad-left {
  left: 18%;
}

#mobile-dpad .dpad-right {
  right: 18%;
}

#mobile-dpad .dpad-row {
  display: none; /* deprecated row layout */
}

#mobile-controls button {
  font-family: inherit;
}


@media (max-width: 1024px) {
  html,
  body {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    overflow: hidden;
    touch-action: none;
  }
  * {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .desktop-only {
    display: none !important;
  }
  #mobile-fs-btn {
    display: flex !important;
  }
  body, html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
  }
  canvas, #game {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
  }
  #game {
    width: 100vw;
    height: auto;
    max-height: none;
  display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    outline: none;
    box-shadow: none;
    max-width: 100vw;
    touch-action: none;
  }
  .layout {
    padding: 0 4px 10px;
    gap: 2px;
    justify-content: flex-start;
    width: 100vw;
    max-width: 100vw;
    overflow-x: hidden;
  }
  .credits {
    width: 100vw;
    max-width: 100vw;
    justify-content: center;
    align-items: center;
    flex-direction: column;
  }
  #donate,
  .donate-card {
    width: 100vw;
    max-width: 100vw;
    box-sizing: border-box;
  }
  
  .music-credit-mobile {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #fa660f;
    font-size: 14px;
  }
  #game canvas {
    margin-top: 0 !important;
    margin-left: 0 !important;
  }
}

/* Strict landscape on mobile: remove padding/gaps that could overflow */
@media (max-width: 1024px) and (orientation: landscape) {
  body {
    justify-content: flex-start;
    align-items: flex-start;
    overflow-x: hidden;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    margin: 0;
    padding: 0;
  }
  .layout {
    padding: 0;
    gap: 2px;
    width: 100vw;
    max-width: 100vw;
    margin: 0;
    overflow: hidden;
  }
  .credits,
  #donate,
  .donate-card {
    display: none !important;
  }
  .mobile-only {
    display: none !important;
  }
  #mobile-fs-btn {
    display: none !important;
  }
  #game {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    margin: 0;
    overflow: hidden;
  }
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

#donate {
  width: 100%;
  display: flex;
  justify-content: center;
}

.donate-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 16px;
  color: #fa660f;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  background: #0f1424;
  padding: 12px 18px;
  border-radius: 10px;
  border: 1px solid rgba(250, 102, 15, 0.35);
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.3);
  max-width: 760px;
}

.donate-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.donate-text h1 {
  margin: 0;
  font-size: 20px;
}

.donate-text p {
  margin: 0;
  color: #e8f6ff;
  font-size: 14px;
}

.qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.donate-card img {
  max-width: 100px;
  width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid rgba(250, 102, 15, 0.35);
  background: #fff;
}

.qr-caption {
  font-size: 12px;
  color: #e8f6ff;
}

/* SEO content - hidden visually but accessible to search engines */
.seo-content {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* Character selection overlay */
.character-select-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: radial-gradient(ellipse at center, #1a1b2e 0%, #0b0b14 60%, #07070f 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 40px;
  z-index: 9999;
  transition: opacity 0.4s ease-out;
}

.character-select-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.character-select-title {
  color: #fa660f;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  font-size: clamp(24px, 5vw, 36px);
  text-align: center;
  margin: 0;
  text-shadow: 0 0 20px rgba(250, 102, 15, 0.5);
}

.character-options {
  display: flex;
  flex-direction: row;
  gap: clamp(30px, 8vw, 80px);
  justify-content: center;
  align-items: center;
}

.character-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  padding: 20px;
  border-radius: 16px;
  border: 3px solid transparent;
  background: rgba(15, 20, 36, 0.8);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.character-option:hover,
.character-option:active {
  transform: scale(1.05);
  border-color: #fa660f;
  box-shadow: 0 0 30px rgba(250, 102, 15, 0.4);
}

.character-avatar {
  width: clamp(100px, 25vw, 180px);
  height: clamp(100px, 25vw, 180px);
  object-fit: contain;
  border-radius: 12px;
  background: rgba(30, 49, 74, 0.5);
  padding: 10px;
}

.character-name {
  color: #e8f6ff;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  font-size: clamp(18px, 4vw, 24px);
  font-weight: bold;
}

@media (max-width: 1024px) {
  .character-select-overlay {
    touch-action: auto !important;
  }

  .character-option {
    touch-action: auto !important;
    -webkit-tap-highlight-color: rgba(250, 102, 15, 0.3);
  }
}
