* {
  box-sizing: border-box;
}

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

body {
  align-items: center;
  background: #f4f6f1;
  color: #18201c;
  display: flex;
  flex-direction: column;
  font-family: "Blueaka", Arial, "Microsoft YaHei", "PingFang SC", sans-serif;
  font-weight: 400;
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding: 12px 0;
}

.page-shell {
  margin: auto;
  max-width: 960px;
  width: min(960px, calc(100vw - 24px));
}

.game-shell {
  background: #fffdf6;
  border: 2px solid #28342d;
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(32, 42, 35, 0.16);
  overflow: hidden;
  position: relative;
  width: 100%;
}

.hud {
  align-items: center;
  background: #ffffff;
  border-bottom: 2px solid #28342d;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  min-height: 56px;
  padding: 10px 16px;
}

.hud strong {
  display: block;
  font-size: 18px;
  line-height: 1.2;
}

.hud span {
  color: #5e665d;
  display: block;
  font-size: 13px;
  line-height: 1.4;
}

.scoreboard {
  color: #1b2f25;
  display: flex;
  flex-wrap: wrap;
  font-size: 18px;
  font-weight: 700;
  gap: 14px;
  justify-content: flex-end;
  min-width: 170px;
  text-align: right;
}

#hearts {
  color: #e05a4f;
  letter-spacing: 1px;
}

canvas {
  aspect-ratio: 8 / 3;
  background: #f7fbff;
  display: block;
  height: auto;
  touch-action: manipulation;
  width: 100%;
}

.mobile-controls {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
  margin-top: 12px;
  touch-action: none;
  user-select: none;
}

.control-button {
  border-radius: 8px;
  font-size: 20px;
  min-height: 58px;
  min-width: 0;
  padding: 0 12px;
  touch-action: none;
  width: 100%;
}

.jump-button {
  background: #1f6f4a;
}

.duck-button {
  background: #45534a;
}

.control-button.disabled {
  opacity: 0.4;
}

.bgm-control {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
  margin-top: 12px;
  padding: 0 6px 6px;
  touch-action: none;
  user-select: none;
}

.bgm-button {
  background: #5a4a7a;
  font-size: 15px;
  min-height: 40px;
  min-width: 0;
  width: 100%;
}

.help-button {
  background: #4a7a6a;
  font-size: 15px;
  min-height: 40px;
  min-width: 0;
  width: 100%;
}

@media (max-width: 560px) {
  .bgm-control {
    gap: 8px;
    margin-top: 8px;
    padding: 0 6px 4px;
  }

  .bgm-button {
    font-size: 13px;
    min-height: 36px;
  }
}

.overlay {
  align-items: center;
  background: rgba(255, 253, 246, 0.88);
  display: flex;
  flex-direction: column;
  inset: 56px 0 0;
  justify-content: center;
  padding: 24px;
  position: absolute;
  text-align: center;
}

.hidden {
  display: none;
}

.overlay.hidden {
  display: none;
}

.overlay h1 {
  font-size: clamp(30px, 7vw, 64px);
  letter-spacing: 0;
  line-height: 1;
  margin: 0 0 8px;
}

.overlay p {
  color: #4d554d;
  font-size: clamp(14px, 2.5vw, 18px);
  line-height: 1.5;
  margin: 0 0 10px;
  max-width: 520px;
}

#pauseText {
  font-size: clamp(20px, 5vw, 36px);
  font-weight: 700;
  color: #1b2f25;
}

button {
  background: #1f6f4a;
  border: 2px solid #163826;
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  font: 700 18px/1 "Blueaka", Arial, sans-serif;
  min-height: 40px;
  min-width: 40px;
  padding: 0 22px;
}

button:active {
  transform: translateY(1px);
}

@media (max-width: 560px) {
  body {
    padding: 6px 0;
  }

  .page-shell {
    width: calc(100vw - 12px);
    max-width: none;
  }

  .hud {
    align-items: flex-start;
    min-height: 52px;
    padding: 6px 8px;
  }

  .hud strong {
    font-size: 15px;
  }

  .hud span {
    font-size: 11px;
  }

  .scoreboard {
    font-size: 14px;
    gap: 4px;
    min-width: 100px;
  }

  .overlay {
    inset: 52px 0 0;
  }

  .mobile-controls {
    gap: 8px;
    margin-top: 8px;
    padding: 0 6px 6px;
  }

  .control-button {
    font-size: 18px;
    min-height: 52px;
  }
}

.cheat-modal {
  align-items: center;
  background: rgba(0, 0, 0, 0);
  display: flex;
  inset: 0;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  transition: opacity 0.2s ease, background 0.2s ease;
  visibility: hidden;
  z-index: 20;
}

.cheat-modal:not(.hidden) {
  background: rgba(0, 0, 0, 0.5);
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.cheat-modal:not(.hidden) .cheat-dialog {
  animation: modalDialogIn 0.25s ease;
}

.cheat-dialog {
  background: #fffdf6;
  border: 2px solid #28342d;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  width: 320px;
}

.cheat-dialog h2 {
  font-size: 20px;
  margin: 0 0 16px;
}

.cheat-dialog input {
  border: 2px solid #28342d;
  border-radius: 4px;
  font-family: "Blueaka", Arial, "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 18px;
  margin-bottom: 8px;
  padding: 8px 12px;
  text-align: center;
  width: 100%;
}

.cheat-error {
  color: #c0392b;
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 8px;
}

.cheat-error.hidden {
  display: none;
}

.cheat-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

#cheatCancel {
  background: #8c9890;
}

.rank-btn {
  background: #1f6f4a;
  border: 2px solid #163826;
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  display: inline-block;
  font: 700 15px/1 "Blueaka", Arial, sans-serif;
  min-width: 52px;
  padding: 6px 10px;
  text-align: center;
  text-decoration: none;
}

.rank-btn:hover {
  background: #268a5c;
}

.overlay-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.pause-btn {
  background: rgba(255, 253, 246, 0.8);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 6px;
  cursor: pointer;
  width: 30px;
  height: 30px;
  padding: 2px;
  position: absolute;
  right: 8px;
  top: 63px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pause-btn.hidden {
  display: none;
}

.pause-btn:hover {
  background: rgba(0, 0, 0, 0.08);
}

.submit-modal {
  align-items: center;
  background: rgba(0, 0, 0, 0);
  display: flex;
  inset: 0;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  transition: opacity 0.2s ease, background 0.2s ease;
  visibility: hidden;
  z-index: 25;
}

.submit-modal:not(.hidden) {
  background: rgba(0, 0, 0, 0.5);
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.submit-modal:not(.hidden) .submit-dialog {
  animation: modalDialogIn 0.25s ease;
}

.submit-dialog {
  background: #fffdf6;
  border: 2px solid #28342d;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  width: 360px;
}

.submit-dialog h2 {
  font-size: 20px;
  margin: 0 0 12px;
}

.submit-score {
  color: #4d554d;
  font-size: 16px;
  margin: 0 0 14px;
}

.submit-score strong {
  color: #1b2f25;
  font-size: 22px;
}

.submit-dialog input {
  border: 2px solid #28342d;
  border-radius: 4px;
  font-family: "Blueaka", Arial, "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 16px;
  margin-bottom: 10px;
  padding: 8px 12px;
  width: 100%;
}

#uploadScoreBtn {
  background: #45534a;
  border-color: #2a332e;
}

b, strong, h1, h2, h3, h4, h5, h6, .bold-text {
  font-weight: 700;
}

.toast {
  align-items: center;
  background: #1b2f25;
  border-radius: 8px;
  color: #ffffff;
  display: flex;
  font-size: 16px;
  font-weight: 700;
  left: 50%;
  line-height: 1.5;
  max-width: 420px;
  opacity: 0;
  padding: 14px 24px;
  pointer-events: none;
  position: fixed;
  text-align: center;
  top: 24px;
  transform: translateX(-50%) translateY(-12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  visibility: hidden;
  z-index: 30;
}

.toast:not(.hidden) {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
  visibility: visible;
}

.footer-links {
  text-align: center;
  padding: 14px 20px;
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-links a {
  font-size: 12px;
  color: #5e665d;
  text-decoration: none;
}

.footer-links a:hover {
  color: #1f6f4a;
  text-decoration: underline;
}

@keyframes modalDialogIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.help-modal {
  align-items: center;
  background: rgba(0, 0, 0, 0);
  display: flex;
  inset: 0;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  transition: opacity 0.2s ease, background 0.2s ease;
  visibility: hidden;
  z-index: 25;
}

.help-modal:not(.hidden) {
  background: rgba(0, 0, 0, 0.5);
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.help-modal:not(.hidden) .help-dialog {
  animation: modalDialogIn 0.25s ease;
}

.help-dialog {
  background: #fffdf6;
  border: 2px solid #28342d;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  width: 380px;
  max-width: calc(100vw - 40px);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.help-dialog h2 {
  font-size: 22px;
  margin: 0 0 16px;
  flex-shrink: 0;
}

.help-content {
  text-align: left;
  font-size: 15px;
  line-height: 1.8;
  color: #3a403a;
  margin: 0 0 20px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #a0b8c8 transparent;
}

.help-content::-webkit-scrollbar {
  width: 6px;
}

.help-content::-webkit-scrollbar-track {
  background: transparent;
}

.help-content::-webkit-scrollbar-thumb {
  background: #a0b8c8;
  border-radius: 3px;
}

.help-content p {
  margin: 0 0 6px;
}

.help-content strong {
  display: block;
  font-size: 16px;
  margin-top: 12px;
  margin-bottom: 4px;
}

.help-content a {
  color: #1e90ff;
  text-decoration: none;
}

.help-content a:hover {
  text-decoration: underline;
}

.help-buttons {
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

.server-error-modal {
  align-items: center;
  background: rgba(0, 0, 0, 0);
  display: none;
  inset: 0;
  justify-content: center;
  opacity: 0;
  position: fixed;
  transition: opacity 0.2s ease, background 0.2s ease;
  z-index: 30;
}

.server-error-modal:not(.hidden) {
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  opacity: 1;
  pointer-events: auto;
}

.server-error-dialog {
  background: #fffdf6;
  border: 2px solid #28342d;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  max-width: 90vw;
  width: 800px;
}

.server-error-header {
  align-items: center;
  border-bottom: 2px solid #dde7e1;
  display: flex;
  justify-content: space-between;
  padding: 12px 16px;
  flex-shrink: 0;
}

.server-error-header h2 {
  font-size: 18px;
  margin: 0;
}

.server-error-close-btn {
  background: #c0392b;
  border: 2px solid #8b1a1a;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  min-height: 28px;
  min-width: 36px;
  padding: 0 10px;
}

.server-error-frame {
  border: none;
  flex: 1;
  min-height: 400px;
  width: 100%;
}

.jumpscare {
  align-items: center;
  background: #0e0906;
  cursor: pointer;
  display: flex;
  inset: 0;
  justify-content: center;
  overflow: hidden;
  position: fixed;
  z-index: 60;
}

.jumpscare.hidden {
  display: none;
}

.jumpscare img {
  animation: jumpscarePop 0.42s cubic-bezier(0.16, 1.2, 0.3, 1) both;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
  width: 100%;
}

@keyframes jumpscarePop {
  0% {
    opacity: 0;
    transform: scale(2.3) rotate(-5deg);
  }
  45% {
    opacity: 1;
    transform: scale(1.02) rotate(1.5deg);
  }
  70% {
    transform: scale(1.1) rotate(-1deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}
