:root {
  --bg-dark: #0a0c14;
  --bg-panel: #141828;
  --bg-card: #1a1f35;
  --text: #f0f4ff;
  --muted: #8892b0;
  --accent-blue: #64b5f6;
  --accent-pink: #f06292;
  --accent-green: #81c784;
  --accent-yellow: #ffd54f;
  --accent-red: #e57373;
  --accent-purple: #ba68c8;
  --accent-orange: #ffb74d;
  --accent-cyan: #4dd0e1;
  --treasure: #ffc107;
  --gold-gradient: linear-gradient(135deg, #ffd700, #ffaa00, #ffd700);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  --glow-blue: 0 0 30px rgba(100, 181, 246, 0.4);
  --glow-green: 0 0 30px rgba(129, 199, 132, 0.4);
  --glow-purple: 0 0 30px rgba(186, 104, 200, 0.4);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: linear-gradient(135deg, #0a0c14 0%, #1a1f35 50%, #0f1220 100%);
  color: var(--text);
  font-family:
    "Lexend",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial,
    sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

/* Header */
.app-header {
  padding: 14px 28px;
  border-bottom: 1px solid rgba(100, 181, 246, 0.2);
  background: linear-gradient(
    180deg,
    rgba(20, 24, 40, 0.98) 0%,
    rgba(10, 12, 20, 0.95) 100%
  );
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.title-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.help-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bg-card), var(--bg-panel));
  border: 2px solid var(--accent-cyan);
  color: var(--accent-cyan);
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 0 20px rgba(77, 208, 225, 0.3),
    inset 0 0 10px rgba(77, 208, 225, 0.1);
}

.help-btn:hover {
  background: var(--accent-cyan);
  color: var(--bg-dark);
  box-shadow: 0 0 35px rgba(77, 208, 225, 0.7);
  transform: scale(1.15) rotate(15deg);
}

.limit-badge {
  font-size: 24px;
  font-weight: 900;
  color: var(--accent-purple);
  line-height: 1;
  text-shadow: 0 0 15px var(--accent-purple);
  margin: 0;
  padding: 6px 12px;
  background: rgba(186, 104, 200, 0.15);
  border-radius: 8px;
  border: 1px solid rgba(186, 104, 200, 0.3);
}

.game-title {
  font-size: 32px;
  font-weight: 900;
  background: linear-gradient(
    135deg,
    var(--accent-cyan),
    var(--accent-blue),
    var(--accent-purple)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
  text-shadow: none;
  margin: 0;
  letter-spacing: -0.5px;
}

.stats-display {
  display: flex;
  gap: 16px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--bg-card), var(--bg-panel));
  border: 2px solid;
  border-radius: 14px;
  padding: 8px 18px;
  position: relative;
  overflow: hidden;
}

.stat-item::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.3),
    transparent
  );
}

.stat-item:first-child {
  border-color: var(--accent-cyan);
  box-shadow: var(--glow-blue);
}

.stat-item:last-child {
  border-color: var(--treasure);
  box-shadow: 0 0 30px rgba(255, 193, 7, 0.4);
}

.stat-label {
  font-family: "Space Mono", monospace;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.stat-value {
  font-family: "Space Mono", monospace;
  font-size: 22px;
  font-weight: 900;
  color: var(--accent-cyan);
  text-shadow: 0 0 15px var(--accent-cyan);
  min-width: 70px;
  text-align: center;
}

.stat-value.treasure {
  color: var(--treasure);
  text-shadow: 0 0 15px var(--treasure);
  background: linear-gradient(135deg, #ffd700, #ffaa00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-value.warning {
  color: var(--accent-red);
  animation: pulse-timer 0.5s ease-in-out infinite;
}

@keyframes pulse-timer {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

.tagline {
  font-family: "Space Mono", monospace;
  font-size: 13px;
  color: var(--accent-pink);
  text-shadow: 0 0 20px rgba(240, 98, 146, 0.5);
  margin-top: 8px;
  text-align: center;
  letter-spacing: 0.5px;
}

/* Game Container */
#gameContainer {
  position: relative;
  width: 100%;
  height: calc(100vh - 130px);
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #1a1040 0%, #0d0820 60%, #050310 100%);
}

/* Stage Info */
.stage-info {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(
    135deg,
    rgba(26, 31, 53, 0.98),
    rgba(20, 24, 40, 0.95)
  );
  border: 2px solid var(--accent-purple);
  border-radius: 16px;
  padding: 18px 40px;
  box-shadow: var(--glow-purple), var(--shadow);
  text-align: center;
  backdrop-filter: blur(15px);
}

.stage-info::before {
  content: "";
  position: absolute;
  top: 0;
  left: 20px;
  right: 20px;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(186, 104, 200, 0.6),
    transparent
  );
}

.stage-info h3 {
  margin: 0 0 8px;
  color: var(--accent-purple);
  font-size: 26px;
  font-weight: 900;
  text-shadow: 0 0 20px rgba(186, 104, 200, 0.5);
}

.stage-info p {
  margin: 0;
  color: var(--text);
  font-size: 15px;
  opacity: 0.9;
}

/* Controls Info */
.controls-info {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(
    135deg,
    rgba(26, 31, 53, 0.95),
    rgba(20, 24, 40, 0.9)
  );
  border: 2px solid rgba(100, 181, 246, 0.5);
  border-radius: 12px;
  padding: 10px 18px;
  backdrop-filter: blur(15px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.control-key {
  font-family: "Space Mono", monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-yellow);
  background: linear-gradient(135deg, #1a1f35, #141828);
  padding: 6px 10px;
  border-radius: 6px;
  min-width: 50px;
  text-align: center;
}

.control-desc {
  font-size: 13px;
  color: var(--text);
}

/* Puzzle Overlay */
.puzzle-overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: linear-gradient(
    135deg,
    rgba(10, 12, 20, 0.97),
    rgba(26, 16, 64, 0.95)
  );
  backdrop-filter: blur(15px);
  z-index: 50;
  padding: 20px;
}

.puzzle-overlay:not(.hidden) {
  display: grid;
}

.puzzle-card {
  background: linear-gradient(135deg, var(--bg-dark), #1a1540);
  border: 3px solid;
  border-image: linear-gradient(
      135deg,
      var(--accent-purple),
      var(--accent-cyan)
    )
    1;
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--glow-purple), var(--shadow);
  max-width: 620px;
  width: 100%;
  animation: puzzle-appear 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.puzzle-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(
    90deg,
    var(--accent-purple),
    var(--accent-cyan),
    var(--accent-purple)
  );
}

@keyframes puzzle-appear {
  from {
    opacity: 0;
    transform: scale(0.85) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.puzzle-card h2 {
  margin: 0 0 16px;
  font-size: 28px;
  text-align: center;
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
}

.puzzle-info {
  text-align: center;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: linear-gradient(
    135deg,
    rgba(26, 31, 53, 0.8),
    rgba(20, 24, 40, 0.6)
  );
  border-radius: 12px;
  border: 1px solid rgba(186, 104, 200, 0.3);
}

.decimals-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.decimal-item {
  background: linear-gradient(
    135deg,
    rgba(26, 31, 53, 0.9),
    rgba(13, 8, 32, 0.8)
  );
  border: 2px solid var(--accent-cyan);
  border-radius: 12px;
  padding: 18px 24px;
  text-align: center;
  box-shadow: var(--glow-blue);
  position: relative;
  overflow: hidden;
}

.decimal-item::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--accent-cyan),
    transparent
  );
}

.decimal-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.decimal-value {
  font-family: "Space Mono", monospace;
  font-size: 42px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.combination-lock {
  background: linear-gradient(
    135deg,
    rgba(26, 31, 53, 0.9),
    rgba(20, 24, 40, 0.8)
  );
  border: 2px solid var(--accent-yellow);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 0 30px rgba(255, 213, 79, 0.2);
}

.combination-lock h3 {
  margin: 0 0 16px;
  color: var(--accent-yellow);
  text-align: center;
  font-size: 18px;
  text-shadow: 0 0 15px rgba(255, 213, 79, 0.5);
}

.lock-display {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
}

.lock-digit {
  width: 52px;
  height: 68px;
  background: linear-gradient(180deg, #0a0c15, #050810);
  border: 3px solid #3a3f60;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Space Mono", monospace;
  font-size: 36px;
  font-weight: 900;
  color: var(--accent-green);
  text-shadow: 0 0 15px var(--accent-green);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
}

.lock-digit.filled {
  border-color: var(--accent-green);
  box-shadow:
    var(--glow-green),
    inset 0 2px 10px rgba(0, 0, 0, 0.5);
}

.lock-digit.empty {
  color: #303560;
}

.lock-digit::before {
  content: attr(data-label);
  position: absolute;
  top: -20px;
  font-size: 10px;
  color: var(--muted);
  font-weight: 400;
}

.lock-hint {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
}

.puzzle-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-action {
  padding: 14px 32px;
  border-radius: 10px;
  border: 2px solid #4a4f80;
  background: var(--bg-panel);
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
}

.btn-action:hover {
  transform: translateY(-2px);
  border-color: var(--accent-blue);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.btn-action.primary {
  background: linear-gradient(135deg, #74c0fc, #339af0);
  border-color: var(--accent-blue);
  color: #fff;
}

.btn-action.primary:hover {
  box-shadow: 0 8px 24px rgba(111, 168, 255, 0.5);
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(13, 15, 26, 0.8);
  backdrop-filter: blur(8px);
  z-index: 100;
  overflow-y: auto;
  padding: 20px;
}

.overlay.visible {
  display: grid;
}

.overlay .card {
  background: var(--bg-dark);
  border: 2px solid #303560;
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
  color: var(--text);
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  width: 100%;
}

.overlay .card h2 {
  margin: 0 0 16px;
  color: var(--accent-blue);
  font-size: 32px;
  text-align: center;
}

.overlay .card h3 {
  color: var(--accent-pink);
  font-size: 20px;
  margin: 16px 0 8px;
}

/* Instructions */
.instructions {
  width: min(800px, 90vw);
}

.instructions-content {
  max-height: 50vh;
  overflow-y: auto;
  padding-right: 10px;
  line-height: 1.6;
}

.instructions-content ul,
.instructions-content ol {
  padding-left: 24px;
}

.instructions-content li {
  margin: 6px 0;
}

.countdown {
  margin-top: 20px;
  text-align: center;
  color: var(--accent-yellow);
  font-family: "Space Mono", monospace;
  font-size: 18px;
  font-weight: 700;
}

/* Setup */
.setup {
  width: min(380px, 90vw);
}

.setup form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.setup label {
  display: block;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}

.setup input,
.setup select {
  width: 100%;
  padding: 10px;
  margin-top: 6px;
  border-radius: 8px;
  background: #141938;
  color: var(--text);
  border: 2px solid #4a4f80;
  font-size: 15px;
  font-family: inherit;
}

.setup input:focus,
.setup select:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 20px rgba(111, 168, 255, 0.3);
}

button.primary {
  padding: 16px 32px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #74c0fc, #339af0);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: var(--shadow);
  font-family: inherit;
}

button.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
}

button.primary:active {
  transform: translateY(0);
}

.instructions button.primary {
  display: block;
  margin: 0 auto;
}

/* Game Over / Victory */
.gameover {
  width: min(700px, 90vw);
}

.gameover h2 {
  color: var(--accent-red);
}

.gameover.victory h2 {
  color: var(--accent-green);
}

.game-over-message,
.victory-message {
  text-align: center;
  font-size: 18px;
  line-height: 1.6;
  margin: 20px 0;
  padding: 20px;
  background: var(--bg-panel);
  border-radius: 12px;
}

.final-score-section {
  text-align: center;
  margin: 20px 0;
}

.score-display-large {
  font-family: "Space Mono", monospace;
  font-size: 64px;
  font-weight: 900;
  color: var(--treasure);
  text-shadow: 0 0 20px var(--treasure);
  margin: 20px 0;
}

.leaderboard-section {
  margin: 30px 0;
  padding: 20px;
  background: var(--bg-panel);
  border-radius: 12px;
}

.leaderboard-section h3 {
  text-align: center;
  color: var(--accent-yellow);
  margin-bottom: 16px;
}

#leaderboardContent {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.leaderboard-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #141938;
  border-radius: 8px;
  border-left: 4px solid var(--accent-cyan);
}

.leaderboard-entry.current {
  border-left-color: var(--accent-green);
  background: rgba(111, 227, 162, 0.1);
}

.leaderboard-rank {
  font-family: "Space Mono", monospace;
  font-weight: 700;
  font-size: 18px;
  color: var(--accent-yellow);
  min-width: 40px;
}

.leaderboard-name {
  flex: 1;
  font-size: 16px;
  color: var(--text);
}

.leaderboard-score {
  font-family: "Space Mono", monospace;
  font-weight: 700;
  font-size: 18px;
  color: var(--treasure);
}

.gameover-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 20px;
}

.action-btn {
  padding: 16px 32px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #74c0fc, #339af0);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: var(--shadow);
  font-family: inherit;
}

.action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
}

.action-btn:active {
  transform: translateY(0);
}

button.chip {
  background: linear-gradient(135deg, #b794f6, #8b5cf6);
}

/* Utility */
.hidden {
  display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #141938;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: #4a4f80;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #5a5f90;
}

/* Responsive */
@media (max-width: 768px) {
  .stats-display {
    flex-direction: column;
    gap: 6px;
  }

  .stage-info {
    padding: 12px 20px;
  }

  .stage-info h3 {
    font-size: 18px;
  }

  .lock-display {
    gap: 8px;
  }

  .lock-digit {
    width: 50px;
    height: 70px;
    font-size: 32px;
  }

  .decimal-value {
    font-size: 36px;
  }
}
