:root {
  --bg-color: #0b0c10;
  --panel-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.15);
  --neon-blue: #00f0ff;
  --neon-pink: #ff00c8;
  --neon-yellow: #ffee00;
  --neon-green: #00ff66;
  --neon-red: #ff3333;
  --font-family: 'Outfit', sans-serif;
  --obscure-emoji: "☄️";
}

[data-theme="pirate"] {
  --bg-color: #001f3f;
  --neon-blue: #00e5ff;
  --neon-pink: #ff9800;
  --neon-yellow: #ffd700;
  --obscure-emoji: "🦑";
}

[data-theme="jungle"] {
  --bg-color: #0b2010;
  --neon-blue: #00ff66;
  --neon-pink: #ffeb3b;
  --neon-yellow: #4caf50;
  --obscure-emoji: "🍃";
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  /* Prevent text selection during fast tapping */
}

body {
  background-color: var(--bg-color);
  color: white;
  font-family: var(--font-family);
  overflow: hidden;
  /* Hide scrollbars for the app feel */
  height: 100vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Starfield Background */
#stars,
#stars2,
#stars3 {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  background: transparent;
}

#stars {
  background-image:
    radial-gradient(1px 1px at 20px 30px, #eee, rgba(0, 0, 0, 0)),
    radial-gradient(1px 1px at 40px 70px, #fff, rgba(0, 0, 0, 0)),
    radial-gradient(1px 1px at 50px 160px, #ddd, rgba(0, 0, 0, 0)),
    radial-gradient(1px 1px at 90px 40px, #fff, rgba(0, 0, 0, 0)),
    radial-gradient(1px 1px at 130px 80px, #fff, rgba(0, 0, 0, 0)),
    radial-gradient(1px 1px at 160px 120px, #ddd, rgba(0, 0, 0, 0));
  background-repeat: repeat;
  background-size: 200px 200px;
  animation: animStar 50s linear infinite;
}

#stars2 {
  background-image:
    radial-gradient(2px 2px at 30px 40px, #eee, rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 80px 90px, #fff, rgba(0, 0, 0, 0)),
    radial-gradient(2px 2px at 120px 140px, #ddd, rgba(0, 0, 0, 0));
  background-repeat: repeat;
  background-size: 300px 300px;
  animation: animStar 100s linear infinite;
}

#stars3 {
  background-image:
    radial-gradient(3px 3px at 50px 50px, #eee, rgba(0, 0, 0, 0)),
    radial-gradient(3px 3px at 150px 150px, #fff, rgba(0, 0, 0, 0));
  background-repeat: repeat;
  background-size: 400px 400px;
  animation: animStar 150s linear infinite;
}

[data-theme="pirate"] #stars,
[data-theme="pirate"] #stars2,
[data-theme="pirate"] #stars3,
[data-theme="jungle"] #stars,
[data-theme="jungle"] #stars2,
[data-theme="jungle"] #stars3 {
  background-image: none !important;
  animation: none !important;
  transform: none !important;
}

[data-theme="pirate"] #stars {
  background: linear-gradient(180deg, #001f3f 0%, #0074D9 100%);
}

[data-theme="jungle"] #stars {
  background: linear-gradient(180deg, #0b2010 0%, #2ecc40 100%);
}

[data-theme="pirate"] body::after {
  content: "🌊";
  position: absolute;
  font-size: 40rem;
  opacity: 0.05;
  bottom: -10rem;
  right: -10rem;
  pointer-events: none;
}

[data-theme="jungle"] body::after {
  content: "🌿";
  position: absolute;
  font-size: 40rem;
  opacity: 0.05;
  bottom: -10rem;
  left: -10rem;
  pointer-events: none;
}

@keyframes animStar {
  from {
    transform: translateY(0px);
  }

  to {
    transform: translateY(-2000px);
  }
}

/* Layout Container */
#app {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.screen {
  position: absolute;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transition: opacity 0.5s ease;
}

.hidden {
  opacity: 0;
  pointer-events: none;
  z-index: -10;
}

/* Glassmorphism Panel */
.glass-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  padding: 40px;
  text-align: center;
}

/* Typography & Neon */
.neon-text {
  font-weight: 900;
  color: #fff;
  text-shadow:
    0 0 5px #fff,
    0 0 10px #fff,
    0 0 20px var(--neon-yellow),
    0 0 40px var(--neon-yellow),
    0 0 80px var(--neon-yellow);
}

.neon-blue {
  color: var(--neon-blue);
  text-shadow: 0 0 10px var(--neon-blue);
}

.neon-pink {
  color: var(--neon-pink);
  text-shadow: 0 0 10px var(--neon-pink);
}


/* Start Screen specific */
#start-screen {
  width: 95%;
  max-width: 900px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  padding: 2vh;
  box-sizing: border-box;
}

#start-screen .neon-text {
  font-size: clamp(2rem, 6vh, 4rem);
  margin-bottom: 0;
}

#start-screen p {
  font-size: clamp(0.9rem, 1.8vh, 1.2rem);
  margin-bottom: 1vh;
}

.player-setup {
  display: flex;
  gap: 2vw;
  margin-bottom: 1vh;
  flex-wrap: nowrap;
  justify-content: center;
}

.player-config {
  background: rgba(0, 0, 0, 0.3);
  padding: 1.5vh;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  flex: 1;
  max-width: 400px;
}

.game-settings-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5vh 1vw;
  justify-content: center;
  align-items: stretch;
  width: 100%;
}

.game-settings {
  padding: 1vh !important;
  margin-bottom: 0 !important;
  flex: 1 1 200px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.game-settings h3 {
  font-size: clamp(0.8rem, 1.5vh, 1.1rem) !important;
  margin-bottom: 0.5vh !important;
}

.table-selector {
  gap: 5px !important;
}

.table-btn,
.avatar-btn {
  padding: 0.5vh 1vh !important;
  font-size: clamp(0.8rem, 1.8vh, 1.2rem) !important;
}

.avatar-selector {
  display: flex;
  gap: 5px;
  margin-top: 1vh;
  justify-content: center;
}

.avatar-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid transparent;
  font-size: 2.5rem;
  border-radius: 12px;
  cursor: pointer;
  padding: 10px;
  transition: all 0.3s ease;
}

.avatar-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.avatar-btn.selected {
  border-color: var(--neon-yellow);
  background: rgba(255, 238, 0, 0.2);
  box-shadow: 0 0 15px var(--neon-yellow);
  transform: scale(1.15);
}

/* Table Selector */
.table-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.table-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  font-family: var(--font-family);
  font-size: 1.2rem;
  font-weight: 700;
  padding: 8px 15px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.table-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

.table-btn.selected {
  background: rgba(0, 240, 255, 0.3);
  border-color: var(--neon-blue);
  box-shadow: 0 0 10px var(--neon-blue);
  color: var(--neon-yellow);
}

/* Primary Button */
.primary-btn {
  background: linear-gradient(45deg, var(--neon-blue), var(--neon-pink));
  border: none;
  border-radius: 50px;
  padding: 1.5vh 3vh;
  font-size: clamp(1rem, 2.5vh, 1.8rem);
  font-weight: 700;
  color: white;
  cursor: pointer;
  box-shadow: 0 0 20px rgba(255, 0, 200, 0.5);
  transition: all 0.3s ease;
  font-family: var(--font-family);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin: 1vh auto;
}

.primary-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 30px rgba(255, 0, 200, 0.8);
}

.primary-btn:active {
  transform: scale(0.95);
}

/* New UI Elements */
.icon-btn {
  position: absolute;
  top: 20px;
  left: 20px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  font-size: 1.5rem;
  color: white;
  cursor: pointer;
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(5px);
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.name-input {
  background: rgba(0, 0, 0, 0.3);
  border: none;
  border-bottom: 2px solid;
  color: white;
  font-family: var(--font-family);
  font-size: clamp(1rem, 2.2vh, 1.5rem);
  font-weight: 700;
  text-align: center;
  padding: 0.5vh;
  margin-bottom: 1vh;
  width: 100%;
  outline: none;
}

.blue-input {
  border-color: var(--neon-blue);
}

.pink-input {
  border-color: var(--neon-pink);
}

.player-name-display {
  font-size: clamp(1.2rem, 3vh, 2rem);
  margin-bottom: 1vh;
}

#game-timer {
  position: absolute;
  top: 1vh;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(3rem, 8vh, 6rem);
  text-shadow: 0 0 20px var(--neon-yellow);
  z-index: 100;
  pointer-events: none;
}

.streak-text {
  position: absolute;
  top: 30%;
  font-size: 3rem;
  font-weight: 900;
  color: var(--neon-yellow);
  text-shadow: 0 0 15px #ff5500;
  transform: rotate(-10deg) scale(1.5);
  animation: streakPop 0.5s ease-out forwards;
  z-index: 20;
}

@keyframes streakPop {
  0% {
    opacity: 0;
    transform: rotate(-10deg) scale(0);
  }

  50% {
    opacity: 1;
    transform: rotate(-10deg) scale(1.5);
  }

  100% {
    opacity: 1;
    transform: rotate(-10deg) scale(1);
  }
}

.freeze-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 50, 150, 0.4);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  border-radius: 24px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border: 3px solid #00f0ff;
  box-shadow: inset 0 0 50px rgba(0, 240, 255, 0.5);
}

.freeze-overlay span {
  font-size: 6rem;
  animation: freezeShake 0.1s infinite;
}

.freeze-overlay p {
  font-size: 3rem;
  font-weight: 900;
  color: #00f0ff;
  text-shadow: 0 0 10px #fff;
  margin-top: 10px;
}

@keyframes freezeShake {
  0% {
    transform: translate(2px, 1px) rotate(0deg);
  }

  10% {
    transform: translate(-1px, -2px) rotate(-1deg);
  }

  20% {
    transform: translate(-3px, 0px) rotate(1deg);
  }

  30% {
    transform: translate(0px, 2px) rotate(0deg);
  }

  40% {
    transform: translate(1px, -1px) rotate(1deg);
  }

  50% {
    transform: translate(-1px, 2px) rotate(-1deg);
  }

  60% {
    transform: translate(-3px, 1px) rotate(0deg);
  }

  70% {
    transform: translate(2px, 1px) rotate(-1deg);
  }

  80% {
    transform: translate(-1px, -1px) rotate(1deg);
  }

  90% {
    transform: translate(2px, 2px) rotate(0deg);
  }

  100% {
    transform: translate(1px, -2px) rotate(-1deg);
  }
}

/* Game Screen Layout */
#game-screen {
  flex-direction: row;
  padding: 1vh;
  gap: 1vh;
}

.player-side {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  position: relative;
  padding: 2vh 1vw;
  border-radius: 24px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.05);
  min-height: 0;
}

.blue-side {
  box-shadow: inset 0 0 50px rgba(0, 240, 255, 0.1);
}

.pink-side {
  box-shadow: inset 0 0 50px rgba(255, 0, 200, 0.1);
}

.divider {
  width: 4px;
  height: 90%;
  background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.3), transparent);
  border-radius: 2px;
}

/* Progress Track */
.progress-track {
  width: 40px;
  flex: 1;
  max-height: 30%;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 30px;
  position: relative;
  margin: 1vh 0;
  border: 2px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: center;
}

.treasure-top {
  font-size: clamp(1.5rem, 4vh, 3rem);
  filter: drop-shadow(0 0 10px var(--neon-yellow));
  animation: float 3s ease-in-out infinite;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-10px);
  }
}

.progress-fill {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: var(--prog, 0%);
  background: linear-gradient(to top, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.3));
  border-radius: 30px;
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.avatar-container {
  position: absolute;
  bottom: var(--prog, 0%);
  transform: translateY(50%);
  font-size: clamp(2rem, 4vh, 3.5rem);
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 10;
  filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.5));
}

.score-display {
  font-size: clamp(1rem, 2vh, 1.5rem);
  font-weight: 700;
  margin-bottom: 1vh;
  color: rgba(255, 255, 255, 0.8);
}

/* Math Problem */
.problem-container {
  width: 100%;
  max-width: 400px;
  padding: 1vh 2vh;
  margin-bottom: 1vh;
  position: relative;
  overflow: hidden;
  flex-shrink: 1;
}

.problem {
  font-size: clamp(2.5rem, 6vh, 4.5rem);
  font-weight: 900;
  letter-spacing: 5px;
}

.feedback {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.shield-icon {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 3rem;
  filter: drop-shadow(0 0 15px rgba(50, 255, 50, 0.8));
  animation: pulse 1s infinite;
  z-index: 20;
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 0.8;
  }

  50% {
    transform: scale(1.1);
    opacity: 1;
  }

  100% {
    transform: scale(1);
    opacity: 0.8;
  }
}

.ink-blot {
  background: rgba(0, 0, 0, 0.95) !important;
  color: transparent !important;
  text-shadow: none !important;
}

.ink-blot::after {
  content: var(--obscure-emoji);
  font-size: 4rem;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
}

/* Numpad */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1vh;
  width: 100%;
  max-width: 400px;
  flex: 2;
  min-height: 0;
}

.num-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  color: white;
  font-size: clamp(1.5rem, 3.5vh, 2.2rem);
  font-weight: 700;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all 0.1s ease;
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  min-height: 0;
}

.num-btn:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.3);
}

.blue-side .num-btn:hover {
  border-color: var(--neon-blue);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.3);
}

.pink-side .num-btn:hover {
  border-color: var(--neon-pink);
  box-shadow: 0 0 10px rgba(255, 0, 200, 0.3);
}

.btn-zero {
  grid-column: 2;
}

.btn-del {
  grid-column: 1;
  background: rgba(255, 50, 50, 0.2);
  font-size: 1.5rem;
}

.btn-ok {
  grid-column: 3;
  background: rgba(50, 255, 50, 0.2);
  font-size: 1.5rem;
}

/* Animations for Success and Error */
@keyframes successPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(0, 255, 102, 0.7);
    background: rgba(0, 255, 102, 0.2);
  }

  70% {
    box-shadow: 0 0 0 20px rgba(0, 255, 102, 0);
    background: transparent;
  }

  100% {
    box-shadow: 0 0 0 0 rgba(0, 255, 102, 0);
  }
}

@keyframes errorShake {

  0%,
  100% {
    transform: translateX(0);
  }

  20%,
  60% {
    transform: translateX(-10px);
  }

  40%,
  80% {
    transform: translateX(10px);
  }
}

.success-anim {
  animation: successPulse 0.5s ease-out;
}

.error-anim {
  animation: errorShake 0.4s ease-in-out;
  border-color: var(--neon-red) !important;
  box-shadow: 0 0 15px rgba(255, 51, 51, 0.5) !important;
}

/* Win Screen */
#win-screen {
  width: auto;
  min-width: 400px;
  height: auto;
  z-index: 100;
}

.winner-avatar {
  font-size: 8rem;
  margin: 20px 0 40px 0;
  animation: float 2s ease-in-out infinite;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.5));
}

/* Responsive adjustments */
@media (max-width: 768px) {
  #game-screen {
    flex-direction: column;
  }

  .divider {
    width: 90%;
    height: 4px;
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.3), transparent);
    margin: 0.5vh 0;
  }

  .progress-track {
    flex: none;
    height: 2vh;
    max-height: 15px;
    width: 60%;
    margin: 0.5vh 0;
  }

  .progress-fill {
    width: var(--prog, 0%);
    height: 100%;
    bottom: auto;
    left: 0;
    background: linear-gradient(to right, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.3));
  }

  .avatar-container {
    bottom: auto;
    left: var(--prog, 0%);
    transform: translateX(-50%);
    top: -2vh;
  }

  .treasure-top {
    position: absolute;
    right: 15%;
    top: 0;
  }
}