:root {
  color-scheme: light;
  --ink: #25241f;
  --paper: #f8f4e9;
  --paper-deep: #ece3d1;
  --amber: #c78335;
  --amber-dark: #87531f;
  --grid: rgba(71, 67, 56, 0.075);
  --shadow: rgba(52, 43, 30, 0.16);
  font-family: "KaiTi", "STKaiti", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 18%, rgba(199, 131, 53, 0.12), transparent 22rem),
    radial-gradient(circle at 85% 88%, rgba(135, 83, 31, 0.08), transparent 26rem),
    #d8cdb9;
}

button {
  color: inherit;
  font: inherit;
  touch-action: manipulation;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: 18px;
}

.game-card {
  width: min(1120px, 100%);
  overflow: hidden;
  border: 2px solid rgba(37, 36, 31, 0.8);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: 0 22px 70px var(--shadow), 8px 8px 0 rgba(37, 36, 31, 0.12);
}

.hud {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 22px;
  min-height: 92px;
  padding: 14px 20px;
  border-bottom: 2px solid var(--ink);
  background: rgba(248, 244, 233, 0.96);
}

.level-chip {
  display: grid;
  min-width: 106px;
  padding: 8px 14px 7px;
  border: 2px solid var(--ink);
  border-radius: 16px 14px 18px 13px;
  background: #fffdf7;
  box-shadow: 3px 3px 0 rgba(37, 36, 31, 0.22);
  cursor: pointer;
  transform: rotate(-1deg);
}

.level-chip span {
  font-size: 1.14rem;
  font-weight: 800;
}

.level-chip small {
  margin-top: 2px;
  color: var(--amber-dark);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
}

.level-copy {
  display: grid;
  justify-items: center;
  line-height: 1.2;
  text-align: center;
}

.level-copy strong {
  font-size: clamp(1.22rem, 2.8vw, 2rem);
  letter-spacing: 0.12em;
}

.level-copy span {
  margin-top: 5px;
  color: #706b5e;
  font-size: 0.84rem;
}

.hud-actions,
.move-controls,
.finish-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 9px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: #fffdf7;
  box-shadow: 2px 2px 0 rgba(37, 36, 31, 0.2);
  cursor: pointer;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 1.2rem;
  font-weight: 900;
}

.icon-button svg,
.control-button svg {
  width: 100%;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button svg {
  stroke-width: 2.4;
}

.stage {
  position: relative;
  aspect-ratio: 16 / 9;
  min-height: 310px;
  overflow: hidden;
  background-color: #fbf8ef;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.toast {
  position: absolute;
  top: 22px;
  left: 50%;
  z-index: 5;
  max-width: min(88%, 520px);
  padding: 10px 18px;
  border: 2px solid var(--ink);
  border-radius: 12px 16px 13px 17px;
  background: rgba(255, 253, 247, 0.96);
  box-shadow: 4px 4px 0 rgba(37, 36, 31, 0.14);
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px) rotate(-0.5deg);
  transition: 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0) rotate(-0.5deg);
}

.level-flash {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background: rgba(248, 244, 233, 0.9);
  font-size: clamp(2rem, 7vw, 4.8rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  opacity: 0;
  pointer-events: none;
}

.level-flash.play {
  animation: flash-level 780ms ease both;
}

.finish-panel {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 30px;
  background:
    linear-gradient(rgba(248, 244, 233, 0.94), rgba(248, 244, 233, 0.98)),
    repeating-linear-gradient(0deg, transparent 0 27px, var(--grid) 27px 28px);
  text-align: center;
}

.finish-panel[hidden] {
  display: none;
}

.finish-panel h1 {
  margin: 4px 0 8px;
  font-size: clamp(2.2rem, 7vw, 4.5rem);
  line-height: 1;
}

.finish-panel p:not(.eyebrow) {
  margin: 0 0 24px;
  color: #6c6658;
}

.finish-egg {
  width: 60px;
  height: 76px;
  margin-bottom: 10px;
  border: 3px solid var(--ink);
  border-radius: 48% 48% 44% 44% / 56% 56% 42% 42%;
  background: radial-gradient(circle at 65% 20%, #fff 0 16%, transparent 17%), #e7c899;
  box-shadow: inset 8px 4px 0 rgba(199, 131, 53, 0.3);
  transform: rotate(5deg);
}

.eyebrow {
  margin: 0;
  color: var(--amber-dark);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.primary-button,
.secondary-button {
  min-width: 122px;
  padding: 11px 18px;
  border: 2px solid var(--ink);
  border-radius: 12px 15px 11px 14px;
  box-shadow: 3px 3px 0 rgba(37, 36, 31, 0.2);
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  color: #fffdf7;
  background: var(--ink);
}

.secondary-button {
  background: #fffdf7;
}

.controls {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  min-height: 112px;
  padding: 14px 24px calc(14px + env(safe-area-inset-bottom));
  border-top: 2px solid var(--ink);
  background: var(--paper-deep);
}

.control-button {
  position: relative;
  display: grid;
  width: 68px;
  height: 68px;
  padding: 16px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 20px 18px 22px 17px;
  background: #fffdf7;
  box-shadow: 4px 5px 0 rgba(37, 36, 31, 0.24);
  cursor: pointer;
  user-select: none;
}

.control-button svg {
  stroke-width: 4;
}

.control-button:active,
.control-button.active {
  box-shadow: 1px 1px 0 rgba(37, 36, 31, 0.2);
  transform: translate(3px, 4px);
}

.jump-button {
  grid-column: 3;
  width: 76px;
  height: 76px;
  padding: 9px 19px 18px;
  border-radius: 50% 48% 52% 45%;
  background: #edd2a9;
}

.jump-button span {
  position: absolute;
  bottom: 8px;
  font-size: 0.72rem;
  font-weight: 900;
}

.controls-note {
  display: grid;
  justify-items: center;
  gap: 3px;
  margin: 0;
  color: #777061;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.67rem;
  text-align: center;
}

.paper-dialog {
  width: min(560px, calc(100% - 32px));
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 22px 18px 24px 19px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 10px 12px 0 rgba(37, 36, 31, 0.2);
}

.paper-dialog::backdrop {
  background: rgba(39, 35, 29, 0.48);
  backdrop-filter: blur(3px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px 14px;
}

.dialog-header h2 {
  margin: 4px 0 0;
  font-size: 1.7rem;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 10px 24px 26px;
}

.level-option {
  min-height: 116px;
  padding: 14px 10px;
  border: 2px solid var(--ink);
  border-radius: 16px 13px 17px 14px;
  background: #fffdf7;
  box-shadow: 3px 4px 0 rgba(37, 36, 31, 0.16);
  cursor: pointer;
  text-align: left;
}

.level-option.current {
  background: #edd2a9;
}

.level-option strong,
.level-option span {
  display: block;
}

.level-option strong {
  font-size: 1.5rem;
}

.level-option span {
  margin-top: 9px;
  color: #716b5d;
  font-size: 0.76rem;
  line-height: 1.35;
}

button:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 3px;
}

@keyframes flash-level {
  0% { opacity: 0; transform: scale(0.96); }
  18%, 62% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.03); }
}

@media (max-width: 700px) {
  .app-shell {
    padding: 0;
  }

  .game-card {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-height: 100vh;
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .hud {
    min-height: 78px;
    gap: 9px;
    padding: 10px 12px;
  }

  .level-chip {
    min-width: 82px;
    padding-inline: 8px;
  }

  .level-copy span,
  .controls-note,
  #hintButton {
    display: none;
  }

  .stage {
    aspect-ratio: auto;
    min-height: 0;
  }

  #gameCanvas {
    object-fit: contain;
  }

  .controls {
    min-height: 116px;
    padding-inline: 18px;
  }

  .control-button {
    width: 62px;
    height: 62px;
  }

  .jump-button {
    width: 72px;
    height: 72px;
  }
}

@media (max-width: 420px) {
  .level-copy strong {
    font-size: 1rem;
    letter-spacing: 0.04em;
  }

  .hud-actions {
    gap: 5px;
  }

  .icon-button {
    width: 39px;
    height: 39px;
  }

  .controls {
    gap: 8px;
    padding-inline: 12px;
  }

  .move-controls {
    gap: 7px;
  }

  .control-button {
    width: 58px;
    height: 58px;
    padding: 14px;
  }

  .jump-button {
    width: 66px;
    height: 66px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
