:root {
  --bg-base: #efeffa;
  --bg-dot: #dcdbf2;
  --ink: #221f26;
  --card-bg: #ffffff;
  --accent-green: #59d86c;
  --accent-purple: #b57ef5;
  --accent-orange: #f17c5d;
  --accent-yellow: #ffe680;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-base);
  background-image:
    radial-gradient(var(--bg-dot) 14px, transparent 15px),
    radial-gradient(var(--bg-dot) 14px, transparent 15px);
  background-size: 76px 76px;
  background-position: 0 0, 38px 38px;
  font-family: "Fredoka", "Arial Rounded MT Bold", "Trebuchet MS", "Microsoft YaHei", sans-serif;
  color: var(--ink);
}

.app-shell {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
}

.stage-wrap {
  position: relative;
  width: min(96vw, calc((100vh - 76px) * (820 / 560)));
  aspect-ratio: 820 / 560;
  max-width: 980px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 18px;
  border: 3.5px solid var(--ink);
  box-shadow: 0 10px 0 rgba(34, 31, 38, 0.14);
  background: var(--bg-base);
  touch-action: none;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(239, 239, 250, 0.68);
  backdrop-filter: blur(3px);
  border-radius: 18px;
  padding: 16px;
  z-index: 10;
}

.modal-overlay.hidden {
  display: none;
}

.comic-card {
  width: min(440px, 92%);
  background: var(--card-bg);
  border: 4px solid var(--ink);
  border-radius: 22px;
  padding: 20px 24px;
  box-shadow: 6px 6px 0 var(--ink);
  text-align: center;
}

.comic-card.compact {
  width: min(370px, 90%);
}

.badge-pill {
  display: inline-block;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  background: var(--accent-yellow);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  margin-bottom: 6px;
}

.badge-pill.danger {
  background: var(--accent-orange);
  color: #fff;
}

.game-title {
  margin: 0 0 8px;
  font-size: clamp(34px, 5vw, 46px);
  line-height: 1;
  color: var(--accent-green);
  text-shadow:
    -2px -2px 0 var(--ink),
     2px -2px 0 var(--ink),
    -2px  2px 0 var(--ink),
     2px  2px 0 var(--ink),
     4px  4px 0 var(--ink);
  letter-spacing: 0.04em;
}

.modal-heading {
  margin: 4px 0 10px;
  font-size: 24px;
  color: var(--ink);
}

.rule-zh {
  margin: 6px 0;
  font-size: 14px;
  line-height: 1.5;
  color: #2f2b36;
}

.rule-en {
  margin: 4px 0 12px;
  font-size: 12px;
  line-height: 1.4;
  color: #605b6b;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  background: #f5f4fc;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 12px;
  text-align: left;
  margin-bottom: 8px;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  margin-right: 2px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 6px;
  box-shadow: 0 2px 0 var(--ink);
}

.pointer-tip {
  margin: 6px 0 14px;
  font-size: 11.5px;
  color: #696475;
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 12px 0 16px;
}

.stat-box {
  background: #f5f4fc;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-box span {
  font-size: 11px;
  font-weight: 700;
  color: #6b6578;
}

.stat-box strong {
  font-size: 22px;
  color: var(--ink);
}

.btn-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 12px;
}

.comic-btn {
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  padding: 10px 20px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.comic-btn.primary-btn {
  background: var(--accent-green);
}

.comic-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 0 var(--ink);
}

.comic-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tool-btn {
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.12s ease;
}

.tool-btn:hover:not(:disabled) {
  background: var(--accent-yellow);
}

.tool-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--ink);
}

.tool-btn.shake-btn {
  background: #eceaf7;
}

.tool-btn.shake-btn.ready {
  background: var(--accent-yellow);
  animation: pulseReady 0.8s ease-in-out infinite alternate;
}

.tool-btn:disabled {
  opacity: 0.7;
  cursor: default;
}

@keyframes pulseReady {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.05);
  }
}

@media (max-width: 640px) {
  .controls-grid {
    grid-template-columns: 1fr;
  }
  .comic-card {
    padding: 16px;
  }
}

.i18n-off {
  display: none !important;
}

.comic-card > .lang-toggle {
  display: flex;
  width: fit-content;
  margin: 0 auto 10px;
}

.lang-toggle {
  display: inline-flex;
  align-items: stretch;
  margin: 0 0 10px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 0 var(--ink);
}

.toolbar .lang-toggle {
  margin: 0;
  box-shadow: 0 3px 0 var(--ink);
}

.lang-btn {
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 11px;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.lang-btn + .lang-btn {
  border-left: 2px solid var(--ink);
}

.lang-btn[aria-pressed="true"] {
  background: var(--accent-yellow);
}
