:root {
  --bg-top: #ffd89c;
  --bg-mid: #ff8a5b;
  --bg-deep: #17304f;
  --card: rgba(255, 249, 239, 0.9);
  --card-strong: rgba(255, 246, 230, 0.98);
  --ink: #1f2430;
  --ink-soft: #5d6573;
  --accent: #ff5a36;
  --accent-deep: #bf2e17;
  --line: rgba(31, 36, 48, 0.12);
  --shadow: 0 30px 80px rgba(48, 24, 8, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Trebuchet MS", "Microsoft YaHei UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 242, 192, 0.9), transparent 34%),
    radial-gradient(circle at 80% 20%, rgba(255, 130, 85, 0.42), transparent 24%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-mid) 38%, var(--bg-deep) 100%);
  user-select: none;
  -webkit-user-select: none;
}

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

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  pointer-events: none;
  z-index: 0;
}

body::before {
  width: 28rem;
  height: 28rem;
  left: -8rem;
  bottom: -8rem;
  background: radial-gradient(circle, rgba(255, 232, 156, 0.35), transparent 70%);
}

body::after {
  width: 30rem;
  height: 30rem;
  right: -10rem;
  top: -8rem;
  background: radial-gradient(circle, rgba(255, 99, 71, 0.25), transparent 72%);
}

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr;
  align-items: start;
  gap: 24px;
  max-width: 98%;
  margin: 0 auto;
  padding: 16px;
}

.intro-card,
.game-card {
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.intro-card {
  background: linear-gradient(180deg, var(--card-strong), rgba(255, 240, 221, 0.9));
  padding: 28px;
}

.eyebrow,
.section-kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.76rem;
  color: var(--accent-deep);
  font-weight: 700;
}

h1 {
  margin: 10px 0 14px;
  font-family: "Bahnschrift", "Microsoft YaHei UI", sans-serif;
  font-size: clamp(2.3rem, 4vw, 4rem);
  line-height: 0.95;
}

.lede,
.section-copy,
.controls {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.7;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 22px 0 24px;
}

.pill {
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 90, 54, 0.1);
  border: 1px solid rgba(255, 90, 54, 0.18);
  font-size: 0.92rem;
  color: var(--accent-deep);
  font-weight: 700;
}

.clip-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  gap: 18px;
  align-items: center;
  margin: 26px 0;
  padding: 18px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.54);
  border: 1px solid rgba(31, 36, 48, 0.07);
}

.clip-preview {
  width: 100%;
  aspect-ratio: 14 / 27;
  object-fit: cover;
  border-radius: 18px;
  background: #060707;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.hud-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 20px;
}

.hud-box {
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(31, 36, 48, 0.08);
}

.hud-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.hud-box strong {
  font-size: 1.5rem;
}

kbd {
  display: inline-block;
  padding: 4px 8px;
  margin: 0 3px;
  border-radius: 8px;
  background: rgba(31, 36, 48, 0.08);
  border: 1px solid rgba(31, 36, 48, 0.12);
  font-family: inherit;
  font-size: 0.92rem;
}

.game-card {
  position: relative;
  overflow: hidden;
  align-self: start;
  height: fit-content;
  order: -1;
  background:
    linear-gradient(180deg, rgba(255, 248, 238, 0.24), rgba(16, 27, 45, 0.1)),
    rgba(12, 20, 34, 0.18);
}

#game {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
}

.canvas-overlay {
  position: absolute;
  left: 18px;
  top: 18px;
  pointer-events: none;
}

.overlay-chip {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(13, 18, 27, 0.48);
  color: #fff7e7;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
  text-transform: uppercase;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.loading-progress {
  margin-top: 10px;
  width: 200px;
  height: 8px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.loading-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #ff9d00);
  transition: width 0.1s ease-out;
}

.controls kbd {
  background: rgba(255, 255, 255, 0.4);
  padding: 2px 6px;
  border-radius: 4px;
  border-bottom: 2px solid rgba(0, 0, 0, 0.2);
  font-family: monospace;
}

.stage-select-container {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.68);
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid rgba(31, 36, 48, 0.08);
  margin-bottom: 20px;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.stage-select {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid rgba(31, 36, 48, 0.12);
  background: white;
  font-family: inherit;
  cursor: pointer;
}
.stage-select:disabled {
  background: #eee;
  cursor: not-allowed;
  color: #999;
}

.skip-btn {
  position: absolute;
  right: 18px;
  bottom: 18px;
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 14px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  z-index: 20;
  transition: background 0.2s;
}

.skip-btn:hover {
  background: rgba(0, 0, 0, 0.8);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .layout {
    padding: 16px;
    gap: 16px;
  }

  .intro-card,
  .game-card {
    border-radius: 22px;
  }

  .intro-card {
    padding: 20px;
  }

  .clip-card {
    grid-template-columns: 1fr;
  }

  .clip-preview {
    max-width: 180px;
  }

  .hud-grid {
    grid-template-columns: 1fr;
  }
}

/* Settings and Mobile UI */
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.settings-btn {
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transition: transform 0.2s;
}
.settings-btn:hover {
  transform: scale(1.1);
}

.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--card-strong);
  padding: 30px;
  border-radius: 24px;
  width: 90%;
  max-width: 400px;
  box-shadow: var(--shadow);
  text-align: center;
}

.modal-content h2 {
  margin-top: 0;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 20px 0;
  font-size: 1.1rem;
}

.setting-item input[type="range"] {
  width: 60%;
}

.setting-item select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.2);
  font-size: 1rem;
}

.close-btn {
  margin-top: 20px;
  padding: 10px 24px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
}

/* Mobile Controls Overlay */
.mobile-controls {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; /* Let clicks pass through empty areas */
  z-index: 50;
}

.joystick-zone {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 220px;
  height: 220px;
  pointer-events: auto;
}

.joystick-base {
  position: absolute;
  bottom: 30px;
  left: 30px;
  width: 160px;
  height: 160px;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.joystick-nub {
  width: 80px;
  height: 80px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  position: absolute;
  transition: transform 0.1s ease-out;
}

.action-buttons {
  position: absolute;
  bottom: 40px;
  right: 40px;
  display: flex;
  gap: 30px;
  pointer-events: auto;
}

.action-btn {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.6);
  color: white;
  font-weight: bold;
  font-size: 1.5rem;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  backdrop-filter: blur(4px);
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
}

/* Credits Overlay */
.credits-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: black;
  color: white;
  z-index: 1500;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  opacity: 0;
  transition: opacity 1s ease-in-out;
}

.credits-text {
  text-align: center;
  font-size: 1.5rem;
  line-height: 2;
  transform: translateY(100vh);
  animation: scrollCredits 8s linear forwards;
}

.credits-text h3 {
  font-size: 2.5rem;
  margin-bottom: 20px;
  color: #ff9d00;
}

@keyframes scrollCredits {
  0% { transform: translateY(100vh); }
  100% { transform: translateY(-100vh); }
}

@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* Stats Card */
.stats-card {
  background: rgba(20, 25, 35, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 32px;
  border-radius: 24px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.6), inset 0 1px 1px rgba(255, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 90%;
  max-width: 400px;
  color: #fff;
  text-align: center;
  transform: translateY(-20px);
  opacity: 0;
  animation: modalEnter 0.5s ease-out forwards;
}

.stats-card h2 {
  font-size: 2rem;
  margin: 0;
  background: linear-gradient(90deg, #ff945f, #ffe7a8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  text-align: left;
}

.stats-item {
  background: rgba(0, 0, 0, 0.3);
  padding: 12px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.stats-item span {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 4px;
}

.stats-item strong {
  font-size: 1.4rem;
  color: #fff;
}

.rank-box {
  background: rgba(255, 215, 0, 0.1);
  border: 2px solid rgba(255, 215, 0, 0.3);
  border-radius: 16px;
  padding: 20px;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  overflow: hidden;
}

.rank-label {
  font-size: 1.2rem;
  color: #ffd700;
  font-weight: bold;
}

.rank-stamp {
  font-size: 4rem;
  line-height: 1;
  color: #ff3300;
  text-shadow: 0 0 10px rgba(255, 50, 0, 0.8);
  font-style: italic;
  font-weight: 900;
  transform: scale(5) rotate(-15deg);
  opacity: 0;
}

.rank-stamp.stamped {
  animation: stampAnim 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes stampAnim {
  0% { transform: scale(5) rotate(-15deg); opacity: 0; }
  50% { opacity: 1; }
  100% { transform: scale(1) rotate(-15deg); opacity: 1; text-shadow: 0 0 20px rgba(255, 50, 0, 0.8); }
}

.action-btn:active {
  background: rgba(255, 255, 255, 0.6);
  transform: scale(0.95);
}

.stats-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 8px;
}

.danger-btn {
  background: linear-gradient(to bottom, #ff4d4d, #cc0000);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 14px 20px;
  font-weight: bold;
  font-size: 1.1rem;
  box-shadow: 0 4px 15px rgba(255, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.danger-btn:active {
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(255, 0, 0, 0.4);
}

/* Hell Mode UI */
.hell-mode-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  padding: 12px;
  background: rgba(255, 0, 0, 0.1);
  border: 1px solid rgba(255, 0, 0, 0.3);
  border-radius: 12px;
  box-shadow: 0 0 15px rgba(255, 0, 0, 0.2);
}

.hell-label {
  color: #ff3333;
  font-weight: bold;
  font-size: 1.1rem;
  text-shadow: 0 0 5px rgba(255, 0, 0, 0.5);
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.2);
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
}

input:checked + .slider {
  background-color: #ff1100;
  box-shadow: 0 0 10px #ff1100;
}

input:focus + .slider {
  box-shadow: 0 0 1px #ff1100;
}

input:checked + .slider:before {
  transform: translateX(22px);
}

.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

.hell-unlock-msg {
  color: #ff3333;
  font-weight: bold;
  text-shadow: 0 0 10px rgba(255, 0, 0, 0.8);
  animation: hellPulse 1.5s infinite alternate;
}

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

/* Mode Select Screen */
.mode-select-screen {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(10, 15, 25, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
  animation: modalEnter 0.4s ease-out;
}

.mode-cards-container {
  display: flex;
  gap: 40px;
}

.mode-card {
  width: 320px;
  min-height: 220px;
  background: linear-gradient(145deg, rgba(30,35,45,0.9), rgba(15,20,30,0.9));
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 24px;
  color: white;
  text-align: left;
  transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.mode-card:hover:not(.locked) {
  transform: translateY(-8px) scale(1.02);
  border-color: rgba(255,255,255,0.4);
  box-shadow: 0 20px 40px rgba(0,0,0,0.6);
}

.mode-card:active:not(.locked) {
  transform: translateY(2px) scale(0.98);
}

.normal-mode {
  border-top: 4px solid #4caf50;
}

.hell-mode {
  border-top: 4px solid #f44336;
}

.mode-card h3 {
  font-size: 1.8rem;
  margin-bottom: 16px;
  margin-top: 0;
}

.mode-card p {
  font-size: 1.05rem;
  color: rgba(255,255,255,0.7);
  margin: 0;
  margin-bottom: 20px;
}

.card-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-footer select {
  width: 100%;
  padding: 8px 12px;
  background: rgba(255,255,255,0.1);
  color: white;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  font-size: 0.95rem;
}

.card-footer select option {
  color: #333;
}

.card-footer select option:disabled {
  color: #a0a0a0;
  background-color: #f5f5f5;
  font-style: italic;
}

.card-footer .action-btn {
  width: 100%;
  padding: 12px;
  font-size: 1.1rem;
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
}

.card-footer .action-btn:hover:not(.locked) {
  background: rgba(255,255,255,0.25);
}

.card-footer .action-btn.locked {
  cursor: not-allowed;
  opacity: 0.6;
}

.mode-card.locked {
  filter: grayscale(1) brightness(0.6);
}

.lock-icon {
  font-size: 1.4rem;
  margin-left: 8px;
}

.toast-notification {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 60, 60, 0.9);
  color: white;
  padding: 16px 32px;
  border-radius: 12px;
  font-weight: bold;
  font-size: 1.4rem;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
}

