:root {
  color-scheme: dark;
  font-family: "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  --wood: #a95b31;
  --wood-light: #d98b55;
  --ink: #211a13;
  --cream: #f4e8cb;
  --leaf: #8be000;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 18%, #315d2b 0, #122b19 56%, #08130d 100%);
  touch-action: none;
}

button { font: inherit; }

.page-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(0px, 1.5vw, 18px);
}

.game-frame {
  position: relative;
  width: min(100vw, calc(100dvh * 1.778333));
  aspect-ratio: 1067 / 600;
  overflow: hidden;
  background: #10240d;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: clamp(0px, 1.2vw, 18px);
  box-shadow: 0 28px 80px rgba(0,0,0,.48), inset 0 0 0 1px rgba(255,255,255,.08);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  background: #193c12;
}

.hud {
  position: absolute;
  inset: 18px 18px auto 18px;
  z-index: 8;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.hud-card {
  color: #322217;
  background: linear-gradient(#f5e8c9, #dccaa4);
  border: 2px solid rgba(91,53,31,.72);
  border-radius: 12px;
  padding: 9px 14px 10px;
  box-shadow: 0 4px 0 #673a25, 0 8px 20px rgba(0,0,0,.24);
  min-width: 155px;
}

.hud-card strong { display: block; font-size: 17px; }
.eyebrow { font-size: 11px; font-weight: 800; color: #7b4d30; letter-spacing: .12em; }
.hud-stats { display: flex; align-items: center; gap: 16px; min-width: auto; font-size: 13px; }
.hud-stats b { color: #c43b25; }

.toast {
  position: absolute;
  z-index: 16;
  left: 50%;
  top: 18%;
  transform: translate(-50%, -16px);
  opacity: 0;
  padding: 10px 18px;
  color: #20160f;
  font-weight: 900;
  letter-spacing: .04em;
  border: 2px solid #6d3e24;
  border-radius: 999px;
  background: linear-gradient(#fff2c9, #e5c98d);
  box-shadow: 0 4px 0 #6c3c21, 0 12px 28px rgba(0,0,0,.32);
  transition: .24s ease;
  pointer-events: none;
  white-space: nowrap;
}

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

.fade {
  position: absolute;
  z-index: 20;
  inset: 0;
  background: #020504;
  opacity: 0;
  pointer-events: none;
  transition: opacity .55s ease;
}
.fade.on { opacity: 1; }

.menu, .dialog, .loading {
  position: absolute;
  inset: 0;
  z-index: 30;
}

.menu {
  display: grid;
  place-items: center;
  color: white;
  background-image: url("./assets/forest-course.png");
  background-position: center 72%;
  background-size: cover;
}

.menu-shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(2,12,4,.64), rgba(3,17,5,.18) 48%, rgba(2,12,4,.62)),
    radial-gradient(circle at 50% 42%, rgba(21,58,15,.04), rgba(2,12,4,.7));
  backdrop-filter: saturate(1.1);
}

.title-lockup {
  position: relative;
  width: min(610px, 90%);
  padding: clamp(22px, 4vw, 38px) clamp(22px, 4vw, 44px) 30px;
  text-align: center;
  text-shadow: 0 3px 0 #17330d, 0 8px 25px rgba(0,0,0,.6);
  border: 1px solid rgba(231,245,185,.28);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(21,49,21,.78), rgba(7,24,10,.88)),
    radial-gradient(circle at 50% 0, rgba(183,231,64,.2), transparent 54%);
  box-shadow: inset 0 0 0 3px rgba(8,20,9,.3), 0 24px 60px rgba(0,0,0,.46);
  backdrop-filter: blur(8px) saturate(1.12);
}

.cover-badges {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 15px;
  text-shadow: none;
}

.cover-badges span {
  padding: 5px 10px;
  color: #e8f5be;
  border: 1px solid rgba(202,236,107,.38);
  border-radius: 999px;
  background: rgba(20,52,17,.72);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .08em;
}

.kicker, .dialog-kicker {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .22em;
  text-transform: uppercase;
}

.title-lockup h1 {
  margin: 0;
  color: #c9f23f;
  font-size: clamp(40px, 7.2vw, 78px);
  line-height: .98;
  letter-spacing: -.08em;
  transform: rotate(-1.5deg);
  -webkit-text-stroke: 2px #17320d;
}

.cover-tagline { margin: 15px 0 22px; color: #f0f3df; font-weight: 700; }

.menu-actions { width: min(320px, 90%); display: grid; gap: 10px; margin: auto; }

.wood-button {
  appearance: none;
  border: 2px solid #6d361f;
  border-radius: 8px;
  padding: 10px 18px;
  color: #2a180f;
  font-weight: 900;
  letter-spacing: .03em;
  cursor: pointer;
  background:
    linear-gradient(90deg, transparent 9%, rgba(92,42,20,.12) 10%, transparent 11%, transparent 72%, rgba(92,42,20,.12) 73%, transparent 74%),
    linear-gradient(#e39a62, #bd6b3d);
  box-shadow: inset 0 2px rgba(255,255,255,.32), 0 4px 0 #6f3c26, 0 9px 18px rgba(0,0,0,.24);
  transition: transform .12s ease, filter .12s ease;
}

.wood-button:hover { filter: brightness(1.1); transform: translateY(-1px); }
.wood-button:active { transform: translateY(3px); box-shadow: inset 0 2px rgba(255,255,255,.24), 0 1px 0 #6f3c26; }
.wood-button.primary { font-size: 18px; }
.wood-button.quiet { filter: saturate(.65); }

.dialog {
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4,14,7,.74);
  backdrop-filter: blur(5px);
}

.dialog-card {
  width: min(430px, 92%);
  max-height: 92%;
  overflow: auto;
  text-align: center;
  color: var(--ink);
  background: linear-gradient(145deg, #f1e8d2, #d7c8a9);
  border: 3px solid #654331;
  border-radius: 18px;
  padding: 22px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.55), 0 16px 42px rgba(0,0,0,.45);
}

.dialog-card h2 { margin: 0 0 12px; }
.dialog-card img { width: min(190px, 45%); max-height: 210px; object-fit: contain; filter: drop-shadow(0 10px 9px rgba(57,35,17,.28)); }
.dialog-card .wood-button { display: block; width: 100%; margin-top: 10px; }
.dialog-kicker { color: #8b4b2f; }
.text-button { margin-top: 14px; border: 0; color: #633c29; background: transparent; font-weight: 800; cursor: pointer; }
.finish-card p { text-align: left; line-height: 1.7; }

.help-card {
  width: min(610px, 94%);
  padding: clamp(18px, 3vw, 28px);
  background:
    linear-gradient(145deg, rgba(255,249,230,.98), rgba(218,202,169,.98)),
    repeating-linear-gradient(0deg, transparent 0 7px, rgba(100,67,45,.04) 8px);
}

.help-card h2 { margin-bottom: 17px; }

.control-guide {
  display: grid;
  grid-template-columns: 154px 1fr;
  align-items: center;
  gap: 18px;
  padding: 15px 17px;
  text-align: left;
  border: 2px solid rgba(94,62,39,.36);
  border-radius: 14px;
  background: rgba(255,252,236,.55);
  box-shadow: inset 0 1px rgba(255,255,255,.7);
}

.keyboard-demo {
  display: grid;
  justify-items: center;
  gap: 6px;
}

.key-row { display: flex; gap: 6px; }

.keyboard-demo kbd {
  display: grid;
  place-items: center;
  width: 42px;
  height: 38px;
  color: #375112;
  font: 1000 18px/1 "Microsoft YaHei UI", sans-serif;
  border: 2px solid #6f8f1d;
  border-radius: 6px;
  background: linear-gradient(#dfff60, #a8dc22);
  box-shadow: inset 0 2px rgba(255,255,255,.55), 0 4px 0 #547311, 0 6px 10px rgba(53,70,15,.22);
}

.control-copy { display: grid; gap: 5px; }
.control-copy strong { color: #3c4d19; font-size: 17px; }
.control-copy span { color: #5e5142; font-size: 13px; line-height: 1.65; }

.help-rules {
  display: grid;
  gap: 8px;
  margin: 13px 0 14px;
}

.help-rule {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: start;
  gap: 10px;
  padding: 9px 11px;
  text-align: left;
  border-bottom: 1px solid rgba(103,74,50,.18);
}

.rule-index {
  padding-top: 4px;
  color: #9b4e2e;
  font-size: 12px;
  font-weight: 1000;
  letter-spacing: .08em;
}

.help-rule p { margin: 0; color: #5a4b3c; font-size: 13px; line-height: 1.55; }
.help-rule strong { display: block; margin-bottom: 2px; color: #2c281e; font-size: 14px; }

.touch-pad {
  position: absolute;
  z-index: 12;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: none;
  grid-template: repeat(3, 46px) / repeat(3, 46px);
  gap: 5px;
}

.touch-pad button {
  border: 2px solid rgba(245,232,203,.82);
  border-radius: 11px;
  color: #26310e;
  font-weight: 1000;
  background: rgba(181,226,60,.88);
  box-shadow: 0 4px 0 rgba(41,77,15,.75), 0 8px 16px rgba(0,0,0,.25);
  backdrop-filter: blur(4px);
  user-select: none;
  -webkit-user-select: none;
}
.touch-pad button.active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(41,77,15,.75); }
.touch-pad .up { grid-column: 2; grid-row: 1; }
.touch-pad .left { grid-column: 1; grid-row: 2; }
.touch-pad .down { grid-column: 2; grid-row: 2; }
.touch-pad .right { grid-column: 3; grid-row: 2; }

.loading {
  z-index: 45;
  display: grid;
  place-content: center;
  gap: 14px;
  text-align: center;
  color: #e8f6cf;
  font-weight: 800;
  background: #0e2411;
}
.loading-mark {
  width: 58px;
  height: 58px;
  margin: auto;
  border: 8px solid #335725;
  border-top-color: #a7e32e;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

[hidden] { display: none !important; }
@keyframes spin { to { transform: rotate(1turn); } }

@media (hover: none), (pointer: coarse) {
  .touch-pad.playing { display: grid; }
  .hud { inset: 10px 10px auto; }
  .hud-card { transform: scale(.86); transform-origin: top left; }
  .hud-stats { transform-origin: top right; }
}

@media (max-aspect-ratio: 1/1) {
  .page-shell { padding: 0; }
  .game-frame { width: 100vw; border-radius: 0; }
}

@media (max-width: 680px), (max-height: 560px) {
  .title-lockup { width: min(560px, 92%); padding: 18px 22px 20px; }
  .title-lockup h1 { font-size: clamp(36px, 8vw, 58px); }
  .cover-badges { margin-bottom: 10px; }
  .cover-tagline { margin: 10px 0 15px; font-size: 13px; }
  .menu-actions { gap: 7px; }
  .wood-button { padding: 8px 16px; }
  .help-card { max-height: 96%; padding: 16px; }
  .help-card h2 { margin-bottom: 10px; font-size: 21px; }
  .control-guide { grid-template-columns: 132px 1fr; padding: 10px 12px; }
  .keyboard-demo kbd { width: 36px; height: 31px; font-size: 15px; box-shadow: inset 0 2px rgba(255,255,255,.55), 0 3px 0 #547311; }
  .help-rules { gap: 2px; margin: 7px 0 9px; }
  .help-rule { padding: 6px 8px; }
}

@media (max-width: 460px) {
  .control-guide { grid-template-columns: 1fr; text-align: center; }
  .control-copy { text-align: center; }
  .cover-badges span { font-size: 9px; }
}
