:root {
  --ink: #2c2118;
  --muted: #7a6554;
  --cream: #fff6ea;
  --panel: rgba(255, 246, 234, 0.9);
  --wood: #8b5e3c;
  --seed: #e8a317;
  --happy: #3aa87a;
  --hunger: #e07a3a;
  --energy: #4a90c8;
  --cash: #2f7d4a;
  --shadow: 0 16px 40px rgba(28, 18, 10, 0.28);
  --ui-scale: 1;
  --btn-pad-y: calc(0.42rem * var(--ui-scale));
  --btn-pad-x: calc(0.36rem * var(--ui-scale));
  --btn-font: calc(0.74rem * var(--ui-scale));
  --vpad-size: calc(118px * var(--ui-scale));
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: "Noto Sans TC", "Fredoka", sans-serif;
  color: var(--ink);
  background: #7eb3d4;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

.app {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

#c {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.25rem;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1rem 1.15rem;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(26, 18, 12, 0.4), transparent 90%);
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #ffe0bf, #f0c49a 55%, #d9a978);
  box-shadow:
    inset -4px -3px 0 rgba(0, 0, 0, 0.08),
    0 8px 18px rgba(0, 0, 0, 0.2);
  position: relative;
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  top: 18px;
  width: 6px;
  height: 7px;
  background: #2a1a14;
  border-radius: 50%;
}

.brand-mark::before { left: 14px; }
.brand-mark::after { right: 14px; }

.brand h1 {
  margin: 0;
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
  font-size: clamp(1.2rem, 2.8vw, 1.55rem);
  font-weight: 700;
  color: var(--cream);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.brand p {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: rgba(255, 246, 234, 0.85);
}

.shop-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  pointer-events: auto;
}

.stat {
  min-width: 5.5rem;
  padding: 0.55rem 0.75rem;
  background: var(--panel);
  border-radius: 14px;
  border: 1px solid rgba(139, 94, 60, 0.16);
  box-shadow: var(--shadow);
}

.stat span {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
}

.stat strong {
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
  font-size: 1.05rem;
  color: var(--cash);
}

.meters {
  display: grid;
  gap: 0.4rem;
  min-width: min(260px, 100%);
  padding: 0.7rem 0.85rem;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  border: 1px solid rgba(139, 94, 60, 0.18);
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.select-name {
  margin: 0 0 0.15rem;
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
}

.sale-tag {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.meter {
  display: grid;
  grid-template-columns: 2.6rem 1fr;
  gap: 0.55rem;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: rgba(44, 33, 24, 0.1);
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  width: 70%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f0a060, var(--hunger));
  transition: width 0.35s ease;
}

.bar.happy i {
  background: linear-gradient(90deg, #6ed4a4, var(--happy));
}

.bar.energy i {
  background: linear-gradient(90deg, #7eb8e8, var(--energy));
}

.toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -120%);
  z-index: 3;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  background: rgba(44, 33, 24, 0.82);
  color: var(--cream);
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
  font-weight: 500;
  letter-spacing: 0.02em;
  pointer-events: none;
  animation: toastIn 0.35s ease;
}

.toast[hidden] {
  display: none !important;
}

.dock {
  position: absolute;
  left: 50%;
  bottom: 1.1rem;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: center;
  align-items: center;
  width: min(720px, calc(100% - 1.2rem));
  padding: 0.8rem;
  background: var(--panel);
  backdrop-filter: blur(12px);
  border-radius: 22px;
  border: 1px solid rgba(139, 94, 60, 0.16);
  box-shadow: var(--shadow);
}

.action {
  appearance: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--cream);
  padding: 0.7rem 0.95rem;
  border-radius: 999px;
  background: linear-gradient(180deg, #c8894e, var(--wood));
  box-shadow: 0 6px 0 #5c3d2e, 0 10px 20px rgba(92, 61, 46, 0.28);
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.15s ease;
}

.action:hover {
  transform: translateY(-2px);
}

.action:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #5c3d2e, 0 6px 12px rgba(92, 61, 46, 0.25);
}

.action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.action:nth-child(2) {
  background: linear-gradient(180deg, #d4a06a, #a66b35);
  box-shadow: 0 6px 0 #6a4220, 0 10px 20px rgba(166, 107, 53, 0.28);
}

.action:nth-child(3) {
  background: linear-gradient(180deg, #6ed4a4, var(--happy));
  box-shadow: 0 6px 0 #246b4d, 0 10px 20px rgba(58, 168, 122, 0.28);
}

.action:nth-child(4) {
  background: linear-gradient(180deg, #7eb8e8, var(--energy));
  box-shadow: 0 6px 0 #2a5f88, 0 10px 20px rgba(74, 144, 200, 0.28);
}

.action:nth-child(5) {
  background: linear-gradient(180deg, #c4a882, #8b6b45);
  box-shadow: 0 6px 0 #5c4528, 0 10px 20px rgba(139, 107, 69, 0.28);
}

.action:nth-child(6) {
  background: linear-gradient(180deg, #e8d08a, #c9a227);
  box-shadow: 0 6px 0 #8a7020, 0 10px 20px rgba(201, 162, 39, 0.28);
}

.action:nth-child(7) {
  background: linear-gradient(180deg, #e8c46a, #c9952e);
  box-shadow: 0 6px 0 #8a6520, 0 10px 20px rgba(201, 149, 46, 0.28);
}

.action:nth-child(8) {
  background: linear-gradient(180deg, #6ec4a0, #2f8f6a);
  box-shadow: 0 6px 0 #1e5c45, 0 10px 20px rgba(47, 143, 106, 0.28);
}

.icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-block;
}

.seed-icon {
  background: radial-gradient(circle at 35% 30%, #ffe08a, var(--seed));
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
}

.pet-icon {
  background: radial-gradient(circle at 40% 35%, #fff, #f5d0a9 70%);
}

.wheel-icon {
  border: 3px solid rgba(255, 246, 234, 0.9);
  background: transparent;
}

.tunnel-icon {
  border-radius: 6px;
  background: linear-gradient(90deg, #5dade2, #85c1e9 40%, #5dade2);
}

.sand-icon {
  background: radial-gradient(circle at 40% 40%, #f5e6b8, #d4b85a);
}

.price-icon {
  background: linear-gradient(135deg, #ffe08a, #d4a017);
  border-radius: 3px;
  box-shadow: inset 0 0 0 2px rgba(80, 50, 10, 0.25);
}

.checkout-icon {
  background: linear-gradient(135deg, #7ddea8, #2f8f6a);
  border-radius: 3px;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
}

.stock-icon {
  background: linear-gradient(135deg, #f0d9b0, #c99560);
  border-radius: 4px;
}

.elev-icon {
  background: linear-gradient(180deg, #c0c8d0, #6a727c);
  border-radius: 3px;
  box-shadow: inset 0 0 0 2px rgba(255, 246, 234, 0.35);
}

.hire-icon {
  background: linear-gradient(135deg, #7eb8e8, #3d6b8f);
  border-radius: 50%;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}

.action:nth-child(11) {
  background: linear-gradient(180deg, #6a9ec4, #3d6b8f);
  box-shadow: 0 6px 0 #2a4a62, 0 10px 20px rgba(61, 107, 143, 0.28);
}

.quest-box {
  pointer-events: auto;
  min-width: min(220px, 100%);
  padding: 0.55rem 0.75rem;
  background: rgba(44, 33, 24, 0.78);
  border-radius: 14px;
  border: 1px solid rgba(255, 246, 234, 0.18);
  box-shadow: var(--shadow);
  color: var(--cream);
}

.quest-label {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: rgba(255, 246, 234, 0.65);
  margin-bottom: 0.2rem;
}

.quest-text {
  margin: 0;
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.35;
}

.story-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  background:
    radial-gradient(ellipse at 30% 20%, rgba(200, 137, 78, 0.35), transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(62, 110, 90, 0.28), transparent 45%),
    rgba(18, 12, 8, 0.72);
  backdrop-filter: blur(6px);
}

.story-overlay[hidden] {
  display: none !important;
}

.story-card {
  width: min(440px, 100%);
  padding: 1.35rem 1.4rem 1.15rem;
  border-radius: 22px;
  background:
    linear-gradient(165deg, rgba(255, 248, 238, 0.98), rgba(245, 228, 200, 0.95));
  border: 1px solid rgba(139, 94, 60, 0.28);
  box-shadow: 0 24px 50px rgba(12, 8, 4, 0.45);
  animation: storyIn 0.45s ease;
}

.story-chapter {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
}

.story-title {
  margin: 0.35rem 0 0.75rem;
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
  font-size: clamp(1.25rem, 4.5vw, 1.55rem);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
}

.story-body {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.7;
  color: #4a382c;
  white-space: pre-line;
  min-height: 6.5rem;
}

.story-actions {
  display: flex;
  gap: 0.55rem;
  justify-content: flex-end;
  margin-top: 1.1rem;
}

.story-btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.65rem 1.15rem;
  border-radius: 999px;
  color: var(--cream);
  background: linear-gradient(180deg, #c8894e, var(--wood));
  box-shadow: 0 5px 0 #5c3d2e;
}

.story-btn:active {
  transform: translateY(2px);
  box-shadow: 0 3px 0 #5c3d2e;
}

.story-btn.ghost {
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  border: 1px solid rgba(139, 94, 60, 0.25);
}

.story-progress {
  margin: 0.7rem 0 0;
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
}

@keyframes storyIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.elev-panel {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(280px, calc(100vw - 2rem));
  padding: 0.9rem 1rem 1rem;
  border-radius: 18px;
  background: rgba(255, 246, 234, 0.95);
  border: 1px solid rgba(139, 94, 60, 0.22);
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.pos-panel,
.price-panel {
  position: absolute;
  z-index: 6;
  right: max(0.6rem, env(safe-area-inset-right));
  bottom: max(5.5rem, calc(4.5rem + env(safe-area-inset-bottom)));
  width: min(300px, calc(100vw - 1.2rem));
  padding: 0.75rem 0.8rem 0.7rem;
  border-radius: 16px;
  background: linear-gradient(180deg, #3a3f48, #252830);
  border: 1px solid rgba(255, 246, 234, 0.18);
  box-shadow: var(--shadow);
  color: var(--cream);
  pointer-events: auto;
}

.price-panel {
  background: linear-gradient(180deg, #4a4030, #2c2418);
  border-color: rgba(232, 196, 106, 0.28);
}

.pos-panel[hidden],
.price-panel[hidden] {
  display: none !important;
}

.price-steps {
  grid-template-columns: repeat(5, 1fr);
}

.price-steps button[data-delta="suggest"] {
  background: linear-gradient(180deg, #ffe08a, #d4a017);
  color: #3a2a10;
}

.pos-brand {
  margin: 0 0 0.45rem;
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  color: #9ecf8e;
}

.pos-screen {
  background: #1a3d2e;
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.55rem;
  border: 1px solid #2f6b4f;
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
}

.pos-line {
  margin: 0.15rem 0;
  font-size: 0.92rem;
}

.pos-line.mute {
  font-size: 0.8rem;
  color: #a8d4bc;
}

.pos-line strong {
  color: #7dffa8;
}

.pos-bills {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.28rem;
  margin-bottom: 0.4rem;
}

.pos-bills button,
.pos-pad button,
.pos-actions button {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
  font-weight: 600;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}

.pos-bills button {
  padding: 0.4rem 0;
  font-size: 0.72rem;
  color: #1e2a20;
  background: linear-gradient(180deg, #c8e6c0, #7fbf74);
  box-shadow: 0 2px 0 #3e6b38;
}

.pos-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.3rem;
  margin-bottom: 0.45rem;
}

.pos-pad button {
  padding: 0.55rem 0;
  font-size: 1rem;
  color: var(--cream);
  background: linear-gradient(180deg, #5a6270, #3a404c);
  box-shadow: 0 3px 0 #1e2228;
}

.pos-pad button:active,
.pos-bills button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #1e2228;
}

.pos-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 0.35rem;
}

.pos-cancel {
  padding: 0.6rem 0.4rem;
  color: #d8dde6;
  background: #4a505c;
}

.pos-pay {
  padding: 0.6rem 0.4rem;
  color: #14301f;
  background: linear-gradient(180deg, #7ddea8, #2f8f6a);
  box-shadow: 0 3px 0 #1e5c45;
}

.pos-pay:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.pos-hint {
  margin: 0.45rem 0 0;
  font-size: 0.65rem;
  color: rgba(255, 246, 234, 0.55);
  text-align: center;
}

body.is-touch .pos-panel,
body.is-touch .price-panel {
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  bottom: max(6.8rem, calc(6rem + env(safe-area-inset-bottom)));
  width: min(calc(320px * var(--ui-scale)), calc(100vw - 1rem));
}

.elev-panel[hidden] {
  display: none !important;
}

.elev-title {
  margin: 0;
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  text-align: center;
}

.elev-now {
  margin: 0.35rem 0 0.7rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
}

.elev-btns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.4rem;
}

.elev-floor-btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
  font-weight: 600;
  font-size: 1rem;
  padding: 0.65rem 0.8rem;
  border-radius: 12px;
  color: var(--cream);
  background: linear-gradient(180deg, #7a8a9a, #4a5560);
  box-shadow: 0 4px 0 #2e3540;
}

.elev-floor-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #2e3540;
}

.elev-hint {
  margin: 0.65rem 0 0;
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
}

.action:nth-child(9) {
  background: linear-gradient(180deg, #9aa8b5, #5c6b78);
  box-shadow: 0 6px 0 #33404a, 0 10px 20px rgba(92, 107, 120, 0.28);
}

.action:nth-child(10) {
  background: linear-gradient(180deg, #a89070, #6e5538);
  box-shadow: 0 6px 0 #3f3020, 0 10px 20px rgba(110, 85, 56, 0.28);
}

.tip {
  flex-basis: 100%;
  margin: 0.1rem 0 0;
  text-align: center;
  font-size: 0.74rem;
  color: var(--muted);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate(-50%, -80%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -120%);
  }
}

/* —— 裝置角標 —— */
.device-badge {
  position: absolute;
  z-index: 5;
  top: max(0.45rem, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--cream);
  background: rgba(44, 33, 24, 0.72);
  border: 1px solid rgba(255, 246, 234, 0.22);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.device-badge.show {
  opacity: 1;
}

.device-badge.quiet {
  top: auto;
  bottom: max(0.35rem, env(safe-area-inset-bottom));
  left: max(0.45rem, env(safe-area-inset-left));
  transform: none;
  opacity: 0.55;
  font-size: 0.62rem;
  padding: 0.18rem 0.45rem;
}

body[data-device="desktop"] .device-badge.quiet {
  display: none;
}

/* —— 右側觸控快捷鍵 —— */
.touch-rail {
  display: none;
  position: absolute;
  z-index: 4;
  right: max(0.4rem, env(safe-area-inset-right));
  bottom: calc(4.6rem + env(safe-area-inset-bottom));
  flex-direction: column;
  gap: calc(0.22rem * var(--ui-scale));
  pointer-events: auto;
  opacity: 0.88;
}

.touch-rail:not([hidden]) {
  display: flex;
}

.touch-rail-btn {
  appearance: none;
  border: none;
  min-width: calc(2.55rem * var(--ui-scale));
  min-height: calc(1.85rem * var(--ui-scale));
  padding: var(--btn-pad-y) var(--btn-pad-x);
  border-radius: 10px;
  font-family: "Fredoka", "Noto Sans TC", sans-serif;
  font-size: calc(0.68rem * var(--ui-scale));
  font-weight: 600;
  color: var(--cream);
  background: linear-gradient(180deg, rgba(70, 58, 46, 0.82), rgba(40, 32, 24, 0.82));
  border: 1px solid rgba(255, 246, 234, 0.16);
  box-shadow: 0 3px 0 rgba(20, 14, 10, 0.35);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.touch-rail-btn.active,
.touch-rail-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(20, 14, 10, 0.45);
}

.touch-rail-btn[data-act="elev"] {
  background: linear-gradient(180deg, #9aa8b5, #5c6b78);
  color: #f5f7fa;
}

.touch-rail-btn[data-act="pay"] {
  background: linear-gradient(180deg, #6ec4a0, #2f8f6a);
}

.touch-rail-btn[data-act="price"] {
  background: linear-gradient(180deg, #e8c46a, #c9952e);
  color: #3a2a10;
}

.touch-rail-btn[data-act="feed"] {
  background: linear-gradient(180deg, #e0a060, #a66b35);
}

/* —— 虛擬搖桿（手機／平板：拖一鍵）—— */
.vpad {
  display: none;
  position: absolute;
  z-index: 4;
  left: max(0.35rem, env(safe-area-inset-left));
  bottom: calc(4.2rem + env(safe-area-inset-bottom));
  width: min(30vw, var(--vpad-size));
  height: min(30vw, var(--vpad-size));
  padding: 0;
  border-radius: 50%;
  background: transparent;
  border: none;
  box-shadow: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.vpad:not([hidden]) {
  display: block;
}

body.is-desktop .vpad,
body.is-desktop .touch-rail {
  display: none !important;
}

.vstick-base {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 45%, rgba(255, 246, 234, 0.28), rgba(44, 33, 24, 0.22) 62%, rgba(20, 14, 10, 0.35));
  border: 2px solid rgba(255, 246, 234, 0.28);
  box-shadow:
    inset 0 0 0 1px rgba(139, 94, 60, 0.18),
    0 8px 18px rgba(28, 18, 10, 0.18);
  backdrop-filter: blur(4px);
}

.vpad.active .vstick-base {
  border-color: rgba(232, 196, 106, 0.45);
  background:
    radial-gradient(circle at 50% 45%, rgba(255, 246, 234, 0.36), rgba(44, 33, 24, 0.28) 62%, rgba(20, 14, 10, 0.4));
}

.vstick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  height: 42%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(160deg, #e0a060, var(--wood) 55%, #5c3d2e);
  border: 2px solid rgba(255, 246, 234, 0.35);
  box-shadow:
    0 4px 0 rgba(60, 40, 20, 0.35),
    0 8px 14px rgba(28, 18, 10, 0.28),
    inset 0 2px 0 rgba(255, 246, 234, 0.25);
  pointer-events: none;
  transition: box-shadow 0.12s ease;
}

.vstick-knob.active {
  box-shadow:
    0 2px 0 rgba(60, 40, 20, 0.3),
    0 6px 12px rgba(28, 18, 10, 0.3),
    inset 0 1px 0 rgba(255, 246, 234, 0.3);
  filter: brightness(1.06);
}

/* 手機／平板：頂欄、底部按鈕自動縮放適配 */
body.is-touch .quest-box {
  width: 100%;
  min-width: 0;
}

body.is-touch .quest-text {
  font-size: calc(0.8rem * var(--ui-scale));
}

body.is-touch .story-card {
  padding: 1.1rem 1rem 1rem;
}

body.is-touch .story-body {
  font-size: 0.88rem;
  min-height: 5.5rem;
}

body.is-touch .top {
  padding: max(0.55rem, env(safe-area-inset-top)) 0.65rem 0.55rem;
  gap: 0.5rem;
}

body.is-touch .brand-mark {
  width: calc(36px * var(--ui-scale));
  height: calc(36px * var(--ui-scale));
}

body.is-touch .brand h1 {
  font-size: clamp(1rem, 4.5vw, calc(1.25rem * var(--ui-scale)));
}

body.is-touch .brand p {
  font-size: 0.72rem;
  max-width: 42vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.is-touch .shop-stats {
  gap: 0.35rem;
}

body.is-touch .stat {
  min-width: 0;
  padding: 0.4rem 0.55rem;
}

body.is-touch .stat span { font-size: 0.62rem; }
body.is-touch .stat strong { font-size: calc(0.9rem * var(--ui-scale)); }

body.is-touch .meters {
  width: 100%;
  min-width: 0;
  padding: 0.5rem 0.65rem;
  gap: 0.28rem;
}

body.is-touch .select-name { font-size: calc(0.82rem * var(--ui-scale)); }
body.is-touch .meter { font-size: 0.7rem; grid-template-columns: 2.2rem 1fr; }
body.is-touch .bar { height: 8px; }

body.is-touch .toast {
  top: 42%;
  max-width: min(90vw, 320px);
  text-align: center;
  font-size: 0.85rem;
  padding: 0.55rem 0.9rem;
}

body.is-touch .dock {
  left: auto;
  right: max(0.35rem, env(safe-area-inset-right));
  bottom: max(0.3rem, env(safe-area-inset-bottom));
  transform: none;
  width: min(calc(100% - 7.2rem), calc(320px * var(--ui-scale)));
  max-height: 26vh;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: calc(0.38rem * var(--ui-scale));
  gap: calc(0.28rem * var(--ui-scale));
  border-radius: 14px;
  justify-content: flex-start;
  background: rgba(255, 246, 234, 0.78);
}

body.is-touch .action {
  flex: 1 1 calc(33.33% - 0.28rem);
  justify-content: center;
  font-size: clamp(0.62rem, 2.6vw, var(--btn-font));
  padding: var(--btn-pad-y) var(--btn-pad-x);
  gap: 0.18rem;
  min-height: calc(1.9rem * var(--ui-scale));
  box-shadow: 0 3px 0 rgba(60, 40, 20, 0.25);
}

body.is-touch .action .icon {
  width: calc(11px * var(--ui-scale));
  height: calc(11px * var(--ui-scale));
}

body.is-touch .tip {
  font-size: 0.65rem;
  line-height: 1.35;
}

body.is-touch .vpad:not([hidden]) {
  display: grid;
}

/* 手機直式：更緊湊，留給中央看人物 */
body[data-device="phone"][data-orient="portrait"] .dock {
  width: min(calc(100% - 6.4rem), 100%);
  max-height: 22vh;
}

body[data-device="phone"][data-orient="portrait"] .vpad {
  width: min(28vw, calc(112px * var(--ui-scale)));
  height: min(28vw, calc(112px * var(--ui-scale)));
  bottom: calc(4.1rem + env(safe-area-inset-bottom));
}

body[data-device="phone"][data-orient="portrait"] .touch-rail {
  bottom: calc(4.3rem + env(safe-area-inset-bottom));
}

body[data-device="phone"] .action {
  flex-basis: calc(33.33% - 0.28rem);
}

body[data-device="phone"] .tip {
  display: none;
}

/* 平板：略大於手機，但仍不擋畫面 */
body[data-device="tablet"] {
  --vpad-size: calc(128px * var(--ui-scale));
}

body[data-device="tablet"] .dock {
  width: min(calc(100% - 8.5rem), calc(360px * var(--ui-scale)));
  max-height: 30vh;
}

body[data-device="tablet"] .touch-rail-btn {
  min-width: calc(2.9rem * var(--ui-scale));
  min-height: calc(2.1rem * var(--ui-scale));
}

body[data-device="tablet"] .action {
  flex: 1 1 calc(33.33% - 0.28rem);
}

/* 橫向手機／小平板 */
body.is-touch[data-orient="landscape"] .top {
  padding-top: max(0.35rem, env(safe-area-inset-top));
}

body.is-touch[data-orient="landscape"] .meters {
  max-width: 200px;
}

body.is-touch[data-orient="landscape"] .vpad {
  width: min(24vh, calc(104px * var(--ui-scale)));
  height: min(24vh, calc(104px * var(--ui-scale)));
  bottom: max(0.35rem, env(safe-area-inset-bottom));
}

body.is-touch[data-orient="landscape"] .touch-rail {
  bottom: max(0.35rem, env(safe-area-inset-bottom));
  right: max(0.35rem, env(safe-area-inset-right));
}

body.is-touch[data-orient="landscape"] .dock {
  width: min(38vw, calc(280px * var(--ui-scale)));
  max-height: 78vh;
  bottom: max(0.3rem, env(safe-area-inset-bottom));
}

body[data-device="phone"][data-orient="landscape"] .dock {
  width: min(34vw, 240px);
}

/* 窄視窗桌面仍可用媒體查詢做基本縮排（不顯示觸控鍵） */
@media (max-width: 820px) {
  body.is-desktop .top {
    padding: 0.65rem;
    gap: 0.5rem;
  }

  body.is-desktop .dock {
    max-width: min(96vw, 720px);
  }
}
