:root {
  --ink: #234c38;
  --ink-deep: #173a2a;
  --cream: #fff8e8;
  --paper: #fffaf0;
  --red: #ed5a4f;
  --red-dark: #bd3f39;
  --green: #5a9e4c;
  --yellow: #f5bf45;
  --shadow: rgba(34, 66, 43, 0.2);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 16px;
  color: var(--ink);
  background-color: #f1cf7f;
  background-image: radial-gradient(rgba(35, 76, 56, 0.11) 1.2px, transparent 1.2px);
  background-size: 20px 20px;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

button:focus-visible,
canvas:focus-visible {
  outline: 3px solid #f7c64f;
  outline-offset: 4px;
}

.game-shell {
  width: min(1180px, 100%);
  height: min(860px, calc(100dvh - 32px));
  min-height: 480px;
  filter: drop-shadow(0 22px 28px rgba(70, 64, 33, 0.2));
}

.game-frame {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 32px;
  background: var(--cream);
  isolation: isolate;
}

.awning {
  position: absolute;
  z-index: 30;
  top: 0;
  left: 0;
  width: 100%;
  height: 30px;
  border-bottom: 3px solid var(--ink);
  background: repeating-linear-gradient(90deg, var(--red) 0 56px, var(--cream) 56px 112px);
  box-shadow: 0 5px 0 rgba(35, 76, 56, 0.09);
  pointer-events: none;
}

.awning::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  height: 9px;
  background: repeating-linear-gradient(90deg, var(--red) 0 56px, var(--cream) 56px 112px);
  clip-path: polygon(0 0, 100% 0, 100% 35%, 98% 100%, 96% 35%, 94% 100%, 92% 35%, 90% 100%, 88% 35%, 86% 100%, 84% 35%, 82% 100%, 80% 35%, 78% 100%, 76% 35%, 74% 100%, 72% 35%, 70% 100%, 68% 35%, 66% 100%, 64% 35%, 62% 100%, 60% 35%, 58% 100%, 56% 35%, 54% 100%, 52% 35%, 50% 100%, 48% 35%, 46% 100%, 44% 35%, 42% 100%, 40% 35%, 38% 100%, 36% 35%, 34% 100%, 32% 35%, 30% 100%, 28% 35%, 26% 100%, 24% 35%, 22% 100%, 20% 35%, 18% 100%, 16% 35%, 14% 100%, 12% 35%, 10% 100%, 8% 35%, 6% 100%, 4% 35%, 2% 100%, 0 35%);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

.canvas-gloss {
  position: absolute;
  inset: 0;
  border-radius: 29px;
  box-shadow: inset 0 0 70px rgba(93, 91, 43, 0.08);
  pointer-events: none;
  z-index: 2;
}

.hud {
  position: absolute;
  z-index: 8;
  top: 51px;
  left: 24px;
  right: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

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

.stat-card {
  display: flex;
  align-items: baseline;
  gap: 9px;
  min-width: 106px;
  padding: 9px 15px 10px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: rgba(255, 250, 240, 0.94);
  box-shadow: 0 4px 0 var(--ink);
}

.stat-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.stat-card strong {
  color: var(--red);
  font-family: "Trebuchet MS", "Microsoft YaHei UI", sans-serif;
  font-size: 27px;
  line-height: 1;
}

.best-card {
  min-width: 94px;
}

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

.timer-card {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 9px 17px 10px;
  border: 2px solid var(--cream);
  border-radius: 999px;
  color: var(--cream);
  background: var(--ink);
  box-shadow: 0 4px 0 rgba(23, 58, 42, 0.28);
  transition: background 180ms ease, transform 180ms ease;
}

.timer-card span,
.timer-card small {
  font-size: 12px;
  font-weight: 700;
}

.timer-card strong {
  min-width: 34px;
  text-align: center;
  font-family: "Trebuchet MS", sans-serif;
  font-size: 28px;
  line-height: 1;
}

.timer-card.is-urgent {
  background: var(--red-dark);
  transform: rotate(-2deg) scale(1.05);
}

.controls {
  pointer-events: auto;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.95);
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
  touch-action: manipulation;
}

.icon-button svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.icon-button:hover:not(:disabled) {
  background: #fff;
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--ink);
}

.icon-button:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

.icon-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.play-icon,
.mute-mark {
  display: none;
}

[data-state="paused"] #pauseButton .pause-icon {
  display: none;
}

[data-state="paused"] #pauseButton .play-icon {
  display: block;
}

#muteButton.is-muted .sound-waves {
  display: none;
}

#muteButton.is-muted .mute-mark {
  display: block;
}

[data-state="ready"] .hud-left,
[data-state="ready"] .timer-card,
[data-state="ready"] #pauseButton,
[data-state="ready"] #restartButton {
  display: none;
}

.combo-badge {
  position: absolute;
  z-index: 9;
  top: 120px;
  left: 27px;
  padding: 9px 15px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 0 4px 0 var(--ink);
  font-size: 15px;
  font-weight: 900;
  transform: rotate(-3deg);
  animation: combo-pop 180ms ease-out;
  pointer-events: none;
}

@keyframes combo-pop {
  from { transform: rotate(-3deg) scale(0.65); }
  to { transform: rotate(-3deg) scale(1); }
}

.screen {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: 68px 22px 24px;
  background: rgba(32, 73, 50, 0.2);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.paper-panel {
  position: relative;
  width: min(490px, 100%);
  padding: 32px 40px 28px;
  border: 3px solid var(--ink);
  border-radius: 32px;
  text-align: center;
  background: var(--paper);
  box-shadow: 0 9px 0 var(--ink), 0 24px 45px rgba(23, 58, 42, 0.24);
}

.paper-panel::before,
.paper-panel::after {
  content: "";
  position: absolute;
  top: 24px;
  width: 30px;
  height: 10px;
  border-radius: 2px;
  background: rgba(245, 191, 69, 0.7);
}

.paper-panel::before {
  left: -12px;
  transform: rotate(-38deg);
}

.paper-panel::after {
  right: -12px;
  transform: rotate(38deg);
}

.melon-logo {
  width: 84px;
  height: 84px;
  margin: -10px auto 3px;
  filter: drop-shadow(0 5px 0 rgba(35, 76, 56, 0.12));
  transform: rotate(-4deg);
}

.melon-logo svg {
  width: 100%;
  height: 100%;
}

.eyebrow {
  margin: 8px 0;
  color: #53705e;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.18em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  font-family: "YouYuan", "Microsoft YaHei UI", sans-serif;
}

h1 {
  margin-bottom: 3px;
  color: var(--ink);
  font-size: clamp(52px, 8vw, 72px);
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: 0.04em;
  text-shadow: 0 4px 0 #e6dbbd;
}

h1 span {
  color: var(--red);
}

.tagline {
  margin-bottom: 23px;
  color: #577061;
  font-size: 15px;
  letter-spacing: 0.12em;
}

.tips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin-bottom: 24px;
}

.tip {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 13px 5px 11px;
  border: 1.5px solid #d8d7b9;
  border-radius: 16px;
  background: #f7f3df;
}

.tip svg {
  width: 27px;
  height: 27px;
  margin-bottom: 7px;
  color: var(--green);
}

.tip:nth-child(2) svg {
  color: var(--yellow);
}

.tip:nth-child(3) svg {
  color: var(--ink-deep);
}

.tip span {
  font-size: 13px;
  font-weight: 900;
}

.tip small {
  margin-top: 3px;
  color: #748276;
  font-size: 10px;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 190px;
  min-height: 52px;
  padding: 13px 28px;
  border: 2px solid var(--ink-deep);
  border-radius: 999px;
  color: #fffdf3;
  background: var(--red);
  box-shadow: 0 6px 0 var(--ink-deep);
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
  touch-action: manipulation;
}

.primary-button svg {
  width: 22px;
  height: 22px;
}

.primary-button:hover {
  background: #f2695c;
  transform: translateY(-2px);
  box-shadow: 0 8px 0 var(--ink-deep);
}

.primary-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--ink-deep);
}

.start-best {
  margin: 18px 0 0;
  color: #6a7a6d;
  font-size: 12px;
}

.start-best strong {
  margin: 0 3px;
  color: var(--ink);
  font-size: 16px;
}

.keyboard-hint {
  margin: 8px 0 0;
  color: #95a092;
  font-size: 10px;
  letter-spacing: 0.08em;
}

.compact-panel {
  width: min(390px, 100%);
  padding: 38px 34px 30px;
}

.compact-panel h2,
.result-panel h2 {
  margin-bottom: 12px;
  font-size: 36px;
}

.compact-panel > p:not(.eyebrow) {
  margin-bottom: 25px;
  color: #6b7e6f;
  font-size: 14px;
}

.text-button {
  display: block;
  margin: 20px auto 0;
  padding: 5px 10px;
  border: 0;
  border-bottom: 1px solid currentColor;
  color: #65776a;
  background: transparent;
  font-size: 13px;
  cursor: pointer;
}

.text-button:hover {
  color: var(--red-dark);
}

.result-panel {
  width: min(440px, 100%);
}

.final-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin: 4px 0 22px;
  color: var(--red);
}

.final-score strong {
  font-family: "Trebuchet MS", sans-serif;
  font-size: 86px;
  line-height: 1;
  text-shadow: 0 5px 0 #f3d4b4;
}

.final-score span {
  font-size: 18px;
  font-weight: 900;
}

.new-record {
  position: absolute;
  top: 87px;
  right: 29px;
  padding: 6px 10px;
  border: 2px solid var(--ink);
  border-radius: 9px;
  color: var(--ink);
  background: var(--yellow);
  font-size: 12px;
  font-weight: 900;
  transform: rotate(9deg);
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 26px;
  padding: 16px 0;
  border-top: 1px dashed #b8bba4;
  border-bottom: 1px dashed #b8bba4;
}

.result-stats > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.result-stats > div + div {
  border-left: 1px solid #d8d9c3;
}

.result-stats strong {
  font-family: "Trebuchet MS", sans-serif;
  font-size: 25px;
}

.result-stats span {
  color: #728174;
  font-size: 11px;
}

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

  .game-shell {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    filter: none;
  }

  .game-frame {
    border: 0;
    border-radius: 0;
  }

  .canvas-gloss {
    border-radius: 0;
  }

  .awning {
    height: 23px;
    background-size: auto;
  }

  .hud {
    top: 40px;
    left: 12px;
    right: 12px;
    gap: 7px;
  }

  .hud-left,
  .controls {
    gap: 6px;
  }

  .best-card {
    display: none;
  }

  .stat-card {
    min-width: 79px;
    padding: 8px 10px;
    border-radius: 13px;
  }

  .stat-card strong {
    font-size: 23px;
  }

  .stat-label {
    font-size: 10px;
  }

  .timer-card {
    gap: 3px;
    padding: 9px 11px;
  }

  .timer-card strong {
    min-width: 28px;
    font-size: 24px;
  }

  .timer-card span {
    display: none;
  }

  .icon-button {
    width: 39px;
    height: 39px;
    padding: 8px;
    border-radius: 12px;
  }

  .icon-button svg {
    width: 20px;
    height: 20px;
  }

  .combo-badge {
    top: 98px;
    left: 14px;
    font-size: 13px;
  }

  .screen {
    padding: 54px 16px 20px;
  }

  .paper-panel {
    padding: 27px 20px 24px;
    border-radius: 26px;
  }

  .melon-logo {
    width: 72px;
    height: 72px;
  }

  .tips {
    gap: 6px;
  }

  .tip {
    padding-inline: 3px;
  }

  .tip span {
    font-size: 12px;
  }

  .primary-button {
    min-height: 50px;
  }
}

@media (max-width: 370px) {
  .controls {
    gap: 4px;
  }

  .icon-button {
    width: 35px;
    height: 37px;
    padding: 7px;
  }

  .stat-card {
    min-width: 69px;
  }

  .timer-card {
    padding-inline: 8px;
  }
}

@media (max-height: 650px) {
  .screen {
    place-items: start center;
    padding-top: 52px;
  }

  .paper-panel {
    padding-top: 18px;
    padding-bottom: 18px;
  }

  .melon-logo {
    width: 55px;
    height: 55px;
    margin-top: 0;
  }

  h1 {
    font-size: 45px;
  }

  .tagline {
    margin-bottom: 13px;
  }

  .tips {
    margin-bottom: 15px;
  }

  .tip {
    padding-block: 8px;
  }

  .tip svg {
    width: 22px;
    height: 22px;
    margin-bottom: 3px;
  }

  .start-best {
    margin-top: 12px;
  }

  .final-score strong {
    font-size: 65px;
  }
}

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