:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  --night: #101919;
  --paper: #fff0d6;
  --muted: #c7c3b1;
  --gold: #f6c778;
  --mint: #8cd7c6;
  --line: #b3a47b55;
  --frame: 8px;
  background: var(--night);
  color: var(--paper);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  min-width: 280px;
  margin: 0;
  background:
    radial-gradient(ellipse at 72% 11%, #20302f, transparent 62%),
    linear-gradient(180deg, #172222, #0e1717);
  min-height: 100svh;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 3px; }
h1[tabindex="-1"]:focus, #panel-title:focus { outline: none; }
h1, h2, h3, p { margin: 0; }
img { display: block; max-width: 100%; }

.shell {
  width: min(1240px, 100%);
  margin-inline: auto;
  padding: 0 max(25px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(25px, env(safe-area-inset-left));
}
.topbar {
  height: 76px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding-top: env(safe-area-inset-top);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 800;
}
.brand img { border-radius: 8px; border: 1px solid #f9d99e4a; }
.brand strong { color: var(--gold); margin-left: 3px; font-variant-numeric: tabular-nums; }
.plain { appearance: none; background: transparent; border: 0; padding: 0; }
.nav { display: flex; gap: 6px; }
.button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  gap: 14px;
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #293333;
  color: var(--paper);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  transition: background-color .16s ease, border-color .16s ease, transform .14s ease;
}
.button:active:not(:disabled) { transform: translateY(1px); }
.button.ghost { border-color: transparent; background: transparent; color: #e9e4d4; }
.button.gold { background: #f6ca83; border-color: #ffe1a7; color: #261b11; box-shadow: 0 3px 0 #9b6839; }
.button.glass { background: #13201ee3; border-color: #ddd1a66e; }
@media (hover: hover) {
  .button:hover:not(:disabled) { border-color: #dbd1b0; background: #394945; }
  .button.gold:hover:not(:disabled) { background: #ffdfa1; }
}
.frame { border: 1px solid var(--line); border-radius: var(--frame); overflow: hidden; }
.home {
  position: relative;
  isolation: isolate;
  min-height: clamp(470px, 71svh, 690px);
  display: grid;
  align-items: center;
  padding: clamp(28px, 5vw, 83px);
  background:
    linear-gradient(90deg, #101b1cf9 2%, #101b1ce8 27%, #101b1c6f 58%, #0a17223b 100%),
    linear-gradient(0deg, #111f28c9, transparent 50%),
    url("./assets/bg_overworld_map.webp") center center / cover;
  box-shadow: 0 20px 70px #06100f8c;
}
.home::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid #fad79852;
  border-radius: 3px;
  pointer-events: none;
  z-index: -1;
}
.home-copy { z-index: 1; max-width: 494px; }
.home h1 {
  font-size: 96px;
  line-height: 1.02;
  font-weight: 950;
  text-shadow: 0 7px 30px #0a1514;
}
.home h1 span {
  display: inline-block;
  margin-left: 12px;
  color: var(--gold);
  font: italic 800 1.09em/0.9 Georgia, serif;
}
.home-copy > p:not(.load-status) {
  margin: 22px 0 29px;
  max-width: 310px;
  color: #eee6d1;
  font-size: 17px;
  line-height: 1.75;
}
.home-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.home-actions .button { min-height: 51px; padding-inline: 19px; }
.hero-alpaca {
  position: absolute;
  right: 13%;
  bottom: 13%;
  width: clamp(150px, 22%, 248px);
  height: auto;
  pointer-events: none;
  filter: drop-shadow(0 7px 0 #142323b5) drop-shadow(0 10px 38px #151d205f);
  animation: idle 3.9s ease-in-out infinite;
}
@keyframes idle { 50% { transform: translateY(-5px); } }
.load-status { margin-top: 18px; color: #fdc999; font-size: 13px; }

.screen-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin: 3px 0 16px;
}
.screen-head h1 { font-size: 36px; line-height: 1.2; }
.screen-head p { margin-top: 5px; font-size: 14px; color: var(--muted); }
.wallet { display: flex; gap: 8px; flex-wrap: wrap; justify-content: end; }
.wallet span, .coin-count {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  min-height: 33px;
  padding: 5px 9px;
  color: #ffe4a9;
  background: #111c1cd4;
  border: 1px solid #b3a47b43;
  border-radius: 6px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(245px, 294px); gap: 13px; }
.map-window { overflow: auto hidden; background: #17252c; scrollbar-color: #c8a365 #263336; }
.map-plane {
  position: relative;
  isolation: isolate;
  min-width: 650px;
  min-height: 370px;
  height: 100%;
  background: linear-gradient(0deg, #101c27b0, #0c141c22 60%, #10202040), url("./assets/bg_overworld_map.webp") center / cover;
}
.edge {
  position: absolute;
  height: 0;
  border-top: 2px dashed #e1c39a95;
  transform-origin: left center;
  pointer-events: none;
}
.edge.open { border-color: #ffe0a0; border-top-style: solid; filter: drop-shadow(0 0 4px #1b241d); }
.map-node {
  position: absolute;
  transform: translate(-50%, -50%);
  display: grid;
  place-content: center;
  padding: 0;
  width: 47px;
  height: 47px;
  border: 2px solid #fece86;
  border-radius: 50%;
  color: white;
  background: #203632;
  box-shadow: 0 2px 8px #061312c9;
  font-weight: 800;
}
.map-node img { width: 38px; height: 38px; object-fit: contain; }
.map-node.locked { border-color: #c1c3bca6; background: #282d31; color: #f0eee5; }
.map-node.locked img { filter: grayscale(.95); opacity: .64; }
.map-node.cleared { border-color: #99ebcf; }
.map-node[aria-pressed="true"] { box-shadow: 0 0 0 4px #fff0c0a3, 0 0 28px #ffca73c9; z-index: 2; }
.node-tag {
  position: absolute;
  left: 50%;
  top: calc(100% + 4px);
  transform: translateX(-50%);
  min-width: 44px;
  white-space: nowrap;
  padding: 3px 6px;
  border-radius: 4px;
  background: #132022ed;
  font-size: 11px;
  font-weight: 700;
  color: #f6ebd3;
}
.map-detail { display: flex; flex-direction: column; background: #1c2928; min-width: 0; }
.detail-picture { aspect-ratio: 2.12; background: #17242a center 60% / cover; border-bottom: 1px solid var(--line); }
.detail-body { display: grid; gap: 11px; align-content: start; flex: 1; padding: 15px; }
.detail-heading { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.detail-heading h2 { font-size: 22px; overflow-wrap: anywhere; }
.detail-heading > span { flex: none; color: var(--mint); font-size: 12px; }
.detail-body p { font-size: 14px; line-height: 1.55; color: #e5dec8; }
.detail-reward { min-height: 38px; display: flex; align-items: center; gap: 9px; color: #f6d8a5; font-size: 13px; }
.detail-reward img { width: 34px; height: 34px; object-fit: contain; }
.detail-body .button { margin-top: auto; width: 100%; }
.map-legend { display: flex; flex-wrap: wrap; justify-content: end; gap: 18px; padding-top: 12px; font-size: 12px; color: #ddd5bf; }
.map-legend span[class]::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; }
#map-scroll-hint { flex-basis: 100%; color: var(--muted); }
.legend-ready::before { background: var(--gold); }
.legend-clear::before { background: var(--mint); }
.legend-locked::before { background: #93999b; }

.playing .topbar { display: none; }
.playing.shell { padding-top: max(9px, env(safe-area-inset-top)); }
.stage {
  width: 100%;
  height: calc(100svh - max(9px, env(safe-area-inset-top)) - max(18px, env(safe-area-inset-bottom)));
  max-height: 820px;
  min-height: 242px;
  display: grid;
  grid-template-rows: auto minmax(120px, 1fr) auto;
  gap: 8px;
}
.stage-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.stage-ident, .stage-tools { display: flex; align-items: center; gap: 10px; min-width: 0; }
.stage-ident > span {
  flex: none;
  border-radius: 4px;
  border: 1px solid #daa76870;
  padding: 4px 6px;
  color: #ffe2ae;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.stage-ident h1 { font-size: 21px; overflow-wrap: anywhere; }
.stage-tools .pause { font-size: 18px; padding-inline: 13px; min-width: 44px; }
.hearts { white-space: nowrap; color: #ff9a8b; font-size: 19px; line-height: 1; }
.playfield { position: relative; min-height: 0; background: #16242e; }
#game { display: block; width: 100%; height: 100%; touch-action: none; }
.stage-banner {
  position: absolute;
  top: 10px;
  left: 10px;
  display: grid;
  gap: 3px;
  max-width: calc(100% - 20px);
  padding: 7px 10px;
  border: 1px solid #f7db9f46;
  border-radius: 5px;
  background: #0d181bd9;
  pointer-events: none;
}
.stage-banner strong { font-size: 14px; line-height: 1.25; }
.stage-banner span { color: #d4e1d9; font-size: 12px; line-height: 1.3; }
.large-hud .stage-banner strong { font-size: 16px; }
.large-hud .stage-banner span { font-size: 14px; }
.stage-toast {
  position: absolute;
  left: 50%;
  top: 13px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 26px);
  padding: 8px 12px;
  background: #182724eb;
  border: 1px solid #f4d39487;
  border-radius: 5px;
  color: #fff2cb;
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
  pointer-events: none;
}
progress {
  position: absolute;
  inset: auto 0 0;
  width: 100%;
  height: 4px;
  appearance: none;
  border: 0;
  background: #102521;
  accent-color: var(--gold);
  pointer-events: none;
}
progress::-webkit-progress-bar { background: #102521; }
progress::-webkit-progress-value { background: var(--gold); }
progress::-moz-progress-bar { background: var(--gold); }
.controls { display: flex; justify-content: space-between; gap: 6px; user-select: none; touch-action: none; }
.controls > div { display: flex; gap: 8px; }
.control {
  appearance: none;
  min-width: 68px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 6px 12px;
  border: 1px solid #9ec8b465;
  border-radius: 7px;
  background: #263c38;
  box-shadow: 0 3px 0 #061411;
  font-size: 23px;
  font-weight: 800;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.control.tool { background: #3b3044; border-color: #ddb4e472; font-size: 14px; }
.control.jump { background: #f4c77d; border-color: #fff0be; color: #2c2015; font-size: 18px; }
.control[data-held], .control:active { transform: translateY(2px); filter: brightness(1.18); }
.control[data-cooldown] { filter: saturate(.55); }
kbd {
  display: inline-block;
  padding: 2px 5px;
  border: 1px solid currentColor;
  border-radius: 4px;
  font: 650 11px ui-monospace, monospace;
  opacity: .76;
}
.storage-notice { margin: 10px 0 0; color: #fbe4ab; font-size: 13px; }

dialog {
  width: min(560px, calc(100% - 26px));
  max-height: calc(100svh - max(26px, env(safe-area-inset-top)) - env(safe-area-inset-bottom));
  overflow: auto;
  padding: 0;
  color: var(--paper);
  background: #1b2a29;
  border: 1px solid #d0b98989;
  border-radius: 8px;
  box-shadow: 0 24px 90px #090f11b8;
}
dialog::backdrop { background: #070e13c8; }
.dialog-inner { display: grid; gap: 14px; padding: 20px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 9px; }
.dialog-head h2 { font-size: 25px; overflow-wrap: anywhere; }
.dialog-head .close { flex: none; min-width: 44px; font-size: 20px; padding: 2px; }
.dialog-inner p, .dialog-inner li { color: #e9e1cd; line-height: 1.65; font-size: 14px; }
.dialog-inner ul { margin: 0; padding-left: 20px; }
.dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.dialog-actions > button { flex: 1; white-space: normal; }
.result-art { width: 100%; height: 100px; border-radius: 5px; object-fit: cover; object-position: center 62%; }
.notice-box { border-left: 3px solid var(--gold); padding: 7px 11px; background: #0e191a70; }
.switches { display: grid; gap: 9px; }
.switches label {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 10px;
  border: 1px solid #aeaa8a45;
  border-radius: 5px;
}
.switches input { width: 22px; height: 22px; accent-color: #92dbbd; }
.book-tabs { display: flex; gap: 8px; }
.book-tabs .button[aria-pressed="true"] { border-color: var(--mint); background: #294743; }
.book-list { display: grid; gap: 6px; }
.book-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-bottom: 1px solid #bfb19339;
  font-size: 14px;
}
.book-row.unknown { color: var(--muted); }
.stamp-set { display: flex; flex-wrap: wrap; gap: 5px; }
.stamp {
  display: inline-grid;
  place-items: center;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid #deccb14c;
  color: #d6ccbc;
  font-size: 12px;
}
.stamp.earned { border-color: #f7ca879e; color: #ffe2a9; background: #5c472b; }
.favorite { min-width: 44px; color: var(--gold); font-size: 18px; }
.supply-list { display: grid; gap: 7px; }
.offer { width: 100%; display: grid; gap: 3px; text-align: left; justify-content: stretch; padding: 9px 11px; }
.offer span { font-size: 12px; font-weight: 500; color: #e4ddc9; }
.offer[aria-pressed="true"] { border-color: #f5cc8e; background: #53452f; }
.supply-actions { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; margin-top: 7px; }

@media (max-width: 850px) {
  .map-layout { grid-template-columns: minmax(0, 1fr); }
  .map-plane { min-height: 255px; }
  .map-detail { display: grid; grid-template-columns: minmax(108px, 1fr) minmax(0, 2fr); }
  .detail-picture { aspect-ratio: auto; border: 0; min-height: 140px; }
  .map-legend { justify-content: start; }
  .stage-toast { top: auto; bottom: 12px; }
}
@media (max-width: 600px) {
  .shell { padding-inline: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right)); }
  .topbar { height: 64px; }
  .topbar .button { padding-inline: 12px; }
  .home { min-height: calc(100svh - 90px); align-items: end; padding: 27px 23px; background-position: 56% center; }
  .home {
    background-image: linear-gradient(0deg, #102020 5%, #102020e8 30%, #12212b41 74%, #101f2556), url("./assets/bg_overworld_map.webp");
  }
  .home-copy > p:not(.load-status) { margin: 15px 0 22px; font-size: 15px; }
  .home h1 { font-size: 66px; }
  .hero-alpaca { width: 140px; top: 12%; bottom: auto; right: 11%; }
  .screen-head h1 { font-size: 27px; }
  .screen-head p { font-size: 12px; }
  .map-plane { min-width: 620px; min-height: 218px; }
  .map-node { width: 44px; height: 44px; }
  .detail-body { padding: 11px; gap: 7px; }
  .detail-heading h2 { font-size: 18px; }
  .detail-heading > span { font-size: 11px; }
  .map-legend { gap: 6px 15px; }
  .stage-ident, .stage-tools { gap: 6px; }
  .stage-ident h1 { font-size: 16px; }
  .stage-ident > span { padding-inline: 4px; }
  .hearts { font-size: 17px; }
  .coin-count { padding-inline: 6px; }
  .control { min-width: 59px; min-height: 58px; padding-inline: 9px; }
  .control.jump { min-width: 68px; }
}
@media (pointer: coarse) { .control kbd { display: none; } }
@media (max-height: 480px) and (orientation: landscape) {
  .topbar { height: 49px; }
  .home { min-height: calc(100svh - 69px); }
  .home h1 { font-size: 58px; }
  .home-copy > p:not(.load-status) { margin: 12px 0 14px; }
  .hero-alpaca { width: min(146px, 17%); bottom: 9%; }
  .playing.shell { padding-inline: max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-right)); }
  .stage { gap: 5px; }
  .controls .control { min-height: 45px; }
  .stage-banner { top: 6px; left: 6px; padding: 5px 7px; }
  .stage-toast { top: 6px; bottom: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; transition: none !important; }
}
