:root {
  --shell-bg: #5a3a21;
  --shell-hi: #734b2c;
  --shell-lo: #3d2513;
  --bezel-bg: #54361e;
  --bezel-border: #2c1a0d;
  --btn-ab: #c42b5c;
  --btn-ab-hi: #e44478;
  --btn-ab-lo: #7d1739;
  --text-main: #fff8e6;
  --text-muted: #dec499;
  --ink-dark: #3b2314;
  --parchment: #faf0d7;
  --accent-gold: #ffe699;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 30%, #33261b 0%, #1e1610 70%, #140e0a 100%);
  color: var(--text-main);
  font-family: "Leelawadee UI", "Tahoma", "Noto Sans Thai", "Segoe UI", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 100dvh;
  overflow: hidden;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* Top Handheld Utility Bar */
#topbar {
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 36px;
  padding: 4px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: linear-gradient(180deg, #6e4728 0%, #4c2f19 100%);
  border-bottom: 2px solid #c89648;
  box-shadow: 0 2px 10px rgba(15, 8, 3, 0.55), inset 0 1px 0 rgba(255, 224, 165, 0.25);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5ce06b;
  box-shadow: 0 0 8px rgba(92, 224, 107, 0.8);
  flex-shrink: 0;
}

.brand-title {
  font-family: Consolas, "Courier New", monospace;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--accent-gold);
  white-space: nowrap;
}

.brand-tag {
  font-family: Consolas, "Courier New", monospace;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: linear-gradient(180deg, #875a33 0%, #5b3a1e 100%);
  border: 1px solid #d4a359;
  color: #fff3cc;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: nowrap;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}

.toolbar::-webkit-scrollbar {
  display: none;
}

.tool-btn {
  appearance: none;
  border: 1.5px solid #7a4e28;
  background: linear-gradient(180deg, #f6e7c4 0%, #dfc38d 100%);
  color: #3b2314;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 4px 9px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), 0 1px 3px rgba(15, 8, 3, 0.45);
  transition: border-color 0.12s, background 0.12s, transform 0.08s;
}

.tool-btn:hover {
  border-color: #a66b38;
  background: linear-gradient(180deg, #fff2d4 0%, #ebd19e 100%);
}

.tool-btn:active {
  transform: translateY(1px);
}

.tool-btn-accent {
  border-color: #2f6824;
  background: linear-gradient(180deg, #6bbf4e 0%, #3e8830 100%);
  color: #ffffff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}

.tool-btn-accent:hover {
  border-color: #ffe078;
  background: linear-gradient(180deg, #7ad15c 0%, #489a38 100%);
}

.tool-btn-bag {
  border-color: #7a4e28;
  background: linear-gradient(180deg, #f4c86a 0%, #c7892b 100%);
  color: #3b2314;
}

.tool-btn-bag:hover:not(:disabled) {
  border-color: #ffe078;
  background: linear-gradient(180deg, #ffd880 0%, #d89836 100%);
}

.tool-btn-bag.active {
  border-color: #ffe078;
  background: linear-gradient(180deg, #6bbf4e 0%, #3e8830 100%);
  color: #ffffff;
  box-shadow: 0 0 8px rgba(115, 224, 138, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.tool-btn-bag:disabled {
  opacity: 0.48;
  cursor: default;
  filter: grayscale(0.35);
}

.tool-btn-map {
  border-color: #1e4f75;
  background: linear-gradient(180deg, #74c6f2 0%, #3680b5 100%);
  color: #ffffff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}

.tool-btn-map:hover:not(:disabled) {
  border-color: #aee6ff;
  background: linear-gradient(180deg, #87d2fa 0%, #418fc7 100%);
}

.tool-btn-map.active {
  border-color: #ffe078;
  background: linear-gradient(180deg, #6bbf4e 0%, #3e8830 100%);
  color: #ffffff;
  box-shadow: 0 0 8px rgba(115, 224, 138, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.tool-btn-map:disabled {
  opacity: 0.45;
  cursor: default;
  filter: grayscale(0.35);
}

/* Main Landscape Handheld Body */
#handheld {
  flex: 1 1 auto;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2vw, 26px);
  padding: clamp(6px, 1.4vw, 18px);
}

/* Virtual Controls Visibility Modes (Touch-First: hidden in auto unless toggled 'show') */
body[data-pad-mode="hide"] .pad-wing,
body[data-pad-mode="auto"] .pad-wing {
  display: none;
}

.pad-wing {
  flex: 0 0 auto;
  width: clamp(112px, 16vw, 176px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 14px 10px;
  border-radius: 22px;
  background: linear-gradient(180deg, #6e4728 0%, #4c2f19 100%);
  border: 2px solid #c89648;
  box-shadow:
    inset 0 1px 0 rgba(255, 224, 165, 0.35),
    inset 0 -4px 8px rgba(0, 0, 0, 0.45),
    0 10px 24px rgba(15, 8, 3, 0.55);
}

/* Cross D-Pad */
.dpad {
  position: relative;
  width: clamp(100px, 13vw, 134px);
  height: clamp(100px, 13vw, 134px);
  border-radius: 50%;
  background: radial-gradient(circle, #181e24 0%, #202830 68%, transparent 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.dpad-cross {
  position: relative;
  width: 92%;
  height: 92%;
}

.dpad-arm {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #2d353e 0%, #1c2228 100%);
  color: #6b7885;
  font-size: 11px;
  border: 1px solid #0d1115;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 3px 5px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  transition: background 0.05s, color 0.05s;
}

.dpad-arm.active {
  background: linear-gradient(180deg, #43505d 0%, #273038 100%);
  color: var(--accent-gold);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.65);
}

.dpad-up {
  top: 0;
  left: 33.33%;
  width: 33.33%;
  height: 36%;
  border-radius: 6px 6px 0 0;
}

.dpad-down {
  bottom: 0;
  left: 33.33%;
  width: 33.33%;
  height: 36%;
  border-radius: 0 0 6px 6px;
}

.dpad-left {
  left: 0;
  top: 33.33%;
  width: 36%;
  height: 33.33%;
  border-radius: 6px 0 0 6px;
}

.dpad-right {
  right: 0;
  top: 33.33%;
  width: 36%;
  height: 33.33%;
  border-radius: 0 6px 6px 0;
}

.dpad-center {
  position: absolute;
  left: 33.33%;
  top: 33.33%;
  width: 33.33%;
  height: 33.33%;
  background: radial-gradient(circle at 50% 45%, #161b20 0%, #252c33 65%);
}

/* Center Retro LCD Bezel */
.lcd-shell {
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
}

.lcd-bezel {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  min-width: 0;
  padding: clamp(6px, 1vw, 14px) clamp(8px, 1.4vw, 18px) clamp(8px, 1.2vw, 18px);
  border-radius: 16px 16px 26px 16px;
  background: linear-gradient(180deg, #6e4728 0%, #4c2f19 100%);
  border: 2px solid #c89648;
  box-shadow:
    inset 0 1px 0 rgba(255, 224, 165, 0.35),
    inset 0 -3px 8px rgba(15, 8, 3, 0.55),
    0 16px 40px rgba(15, 8, 3, 0.68);
}

.lcd-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
  padding: 0 4px;
}

.power-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
}

.power-led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ce67c;
  box-shadow: 0 0 7px 2px rgba(76, 230, 124, 0.72);
}

.power-label,
.lcd-model {
  font-family: Consolas, "Courier New", monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #f3d69d;
}

.lcd-frame {
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  padding: 3px;
  background: #23150b;
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px #9c7036, 0 1px 0 rgba(255, 232, 180, 0.16);
  line-height: 0;
}

#game {
  display: block;
  width: 256px;
  height: 144px;
  background: #1a120c;
  image-rendering: auto;
}

/* Right Action Cluster (B / A + SELECT / START) */
.ab-cluster {
  position: relative;
  width: clamp(98px, 12vw, 134px);
  height: clamp(80px, 10vw, 102px);
}

.ab-btn {
  position: absolute;
  appearance: none;
  border: 2px solid #480b20;
  border-radius: 50%;
  width: clamp(44px, 5.4vw, 56px);
  height: clamp(44px, 5.4vw, 56px);
  background: radial-gradient(circle at 35% 30%, var(--btn-ab-hi) 0%, var(--btn-ab) 58%, var(--btn-ab-lo) 100%);
  color: #fff2f6;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 2px rgba(255, 255, 255, 0.25), 0 4px 7px rgba(0, 0, 0, 0.55);
  transition: transform 0.05s, box-shadow 0.05s;
}

.ab-btn .ab-cap {
  font-size: 16px;
  line-height: 1;
}

.ab-btn .ab-hint {
  position: absolute;
  bottom: -14px;
  font-size: 8px;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
  pointer-events: none;
}

.btn-b {
  left: 2px;
  bottom: 10px;
}

.btn-a {
  right: 2px;
  top: 2px;
}

.ab-btn.active,
.ab-btn:active {
  transform: translateY(2px) scale(0.96);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.55), 0 1px 2px rgba(0, 0, 0, 0.5);
}

.meta-cluster {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 4px;
}

.pill-btn {
  appearance: none;
  background: transparent;
  border: none;
  padding: 4px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  touch-action: none;
}

.pill-cap {
  width: 34px;
  height: 11px;
  border-radius: 6px;
  background: linear-gradient(180deg, #4b5661 0%, #2b333b 100%);
  border: 1px solid #101418;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 2px 4px rgba(0, 0, 0, 0.5);
  transform: rotate(-16deg);
}

.pill-btn.active .pill-cap,
.pill-btn:active .pill-cap {
  transform: rotate(-16deg) translateY(1px);
  background: linear-gradient(180deg, #62717f 0%, #37414b 100%);
}

.pill-label {
  font-family: inherit;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* Modals (Help & Account) */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 16, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  z-index: 50;
}

.modal.hidden,
.hidden {
  display: none !important;
}

.modal-card {
  width: min(560px, 100%);
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--parchment);
  color: var(--ink-dark);
  border: 2px solid #8e5e32;
  border-radius: 12px;
  box-shadow: 0 18px 48px rgba(15, 8, 3, 0.78), inset 0 0 0 1px rgba(255, 245, 220, 0.7);
  user-select: text;
  -webkit-user-select: text;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 2px solid #c89648;
  background: linear-gradient(180deg, #6e4728 0%, #52331c 100%);
}

.modal-head h2 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--accent-gold);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.45);
}

.tool-btn.modal-close-crimson {
  background: #b8323a;
  border: 1px solid #ffd4d4;
  color: #ffffff;
  font-weight: 800;
  min-width: 28px;
  height: 24px;
  padding: 0 7px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.tool-btn.modal-close-crimson:hover {
  background: #d13b44;
  border-color: #ffffff;
}

.mob-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  margin: -10px -10px 2px;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(180deg, #6e4728 0%, #52331c 100%);
  border-bottom: 2px solid #c89648;
}

.mob-drawer-title {
  font-size: 11px;
  font-weight: 700;
  color: #ffe699;
}

.modal-body {
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink-dark);
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.guide-grid h3,
.acc-section h3 {
  margin: 0 0 6px;
  font-size: 11px;
  color: #2f6e2a;
  letter-spacing: 0.04em;
}

.guide-grid ul {
  margin: 0;
  padding-left: 16px;
}

.guide-grid li {
  margin-bottom: 5px;
}

/* Account Modal Controls */
.acc-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.status-pill {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  background: #ead7b0;
  color: #4f311b;
  border: 1px solid #b8905a;
}

.status-pill.cloud {
  background: #d7f2cc;
  color: #22541d;
  border-color: #4c9644;
}

.acc-muted {
  font-size: 10px;
  color: #725034;
}

.acc-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.acc-divider {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #d7be92;
}

.acc-desc {
  margin: 0;
  color: #5b3a22;
  font-size: 11px;
}

.acc-form-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.acc-form-row label,
.acc-label {
  font-size: 10px;
  font-weight: 700;
  color: #6b4324;
  letter-spacing: 0.04em;
}

.modal-card input,
.modal-card textarea {
  width: 100%;
  padding: 7px 9px;
  border-radius: 5px;
  border: 1.5px solid #b8905a;
  background: #fff9ec;
  color: #3b2314;
  font-family: inherit;
  font-size: 12px;
}

.modal-card input:focus,
.modal-card textarea:focus {
  outline: none;
  border-color: #6bbf4e;
  box-shadow: 0 0 0 2px rgba(107, 191, 78, 0.25);
}

.acc-btn-row,
.acc-inline-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.acc-inline-row input {
  flex: 1 1 200px;
}

.acc-user-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 6px;
  background: #f0dfb9;
  border: 1px solid #b8905a;
}

.acc-user-title {
  font-size: 14px;
  font-weight: 700;
  color: #6b3d17;
}

.acc-feedback {
  margin-top: 10px;
  padding: 7px 10px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  background: #d8f2ce;
  border: 1px solid #4c9644;
  color: #21541b;
}

.acc-feedback.err {
  background: #fbe1e3;
  border-color: #b8323a;
  color: #7c1820;
}

/* Floating Mobile / Fullscreen Right Carved Oak Rail & Drawer */
#mobile-quickbar {
  display: none;
  position: fixed;
  top: 50%;
  right: max(5px, env(safe-area-inset-right));
  transform: translateY(-50%);
  z-index: 40;
  width: 58px;
  padding: 5px;
  gap: 5px;
  border-radius: 12px;
  flex-direction: column;
  align-items: stretch;
  background: linear-gradient(180deg, #6e4728 0%, #4c2f19 100%);
  border: 2px solid #c89648;
  box-shadow: 0 4px 14px rgba(15, 8, 3, 0.65), inset 0 1px 0 rgba(255, 224, 165, 0.35);
  pointer-events: auto;
  touch-action: manipulation;
}

.mob-pill-btn {
  appearance: none;
  border: 1.5px solid #7a4e28;
  background: linear-gradient(180deg, #f6e7c4 0%, #dfc38d 100%);
  color: #3b2314;
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.15;
  width: 100%;
  height: 44px;
  padding: 4px 2px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), 0 2px 4px rgba(15, 8, 3, 0.4);
  transition: transform 0.08s, filter 0.1s;
}

.mob-pill-btn:active {
  transform: scale(0.94);
}

.mob-pill-btn .mob-ico {
  font-size: 14px;
  line-height: 1;
}

.mob-pill-btn .mob-lbl {
  font-size: 10px;
  line-height: 1.1;
  font-weight: 700;
  white-space: nowrap;
}

.mob-qbtn {
  display: none;
}

.mob-qbtn-bag {
  background: linear-gradient(180deg, #f4c86a 0%, #c7892b 100%);
  border-color: #7a4e28;
  color: #3b2314;
}

.mob-qbtn-map {
  background: linear-gradient(180deg, #74c6f2 0%, #3680b5 100%);
  border-color: #1e4f75;
  color: #ffffff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}

.mob-qbtn.active {
  background: linear-gradient(180deg, #6bbf4e 0%, #3e8830 100%);
  border-color: #ffe078;
  color: #ffffff;
  box-shadow: 0 0 9px rgba(115, 224, 138, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

body.in-playscene .mob-qbtn,
.mob-qbtn.active {
  display: flex;
}

.mob-drawer {
  position: fixed;
  top: 50%;
  right: calc(max(5px, env(safe-area-inset-right)) + 64px);
  transform: translateY(-50%);
  z-index: 45;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  min-width: 182px;
  border-radius: 12px;
  background: var(--parchment);
  color: var(--ink-dark);
  border: 2px solid #8e5e32;
  box-shadow: 0 10px 28px rgba(15, 8, 3, 0.72), inset 0 0 0 1px rgba(255, 245, 220, 0.7);
}

.mob-drawer .tool-btn {
  text-align: left;
  padding: 7px 10px;
  font-size: 12px;
}

/* Mobile & Fullscreen Edge-to-Edge Stage */
body.is-fullscreen #topbar {
  display: none !important;
}

body.is-fullscreen .lcd-header {
  display: none !important;
}

body.is-fullscreen .lcd-bezel,
body.is-fullscreen .lcd-frame {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

body.is-fullscreen #handheld {
  padding: 0;
  gap: 0;
  background: transparent;
}

body.is-fullscreen #mobile-quickbar {
  display: flex;
}

@media (pointer: coarse) and (max-width: 1024px), (max-height: 560px) {
  #topbar {
    display: none !important;
  }

  .lcd-header {
    display: none !important;
  }

  .lcd-bezel,
  .lcd-frame {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  #handheld {
    padding: 0;
    gap: 0;
    background: transparent;
  }

  #mobile-quickbar {
    display: flex;
  }
}

/* Landscape Mobile & Fullscreen Translucent Floating Controls */
@media (pointer: coarse) and (max-width: 1024px) and (orientation: landscape), (max-height: 560px) and (orientation: landscape) {
  .pad-wing {
    position: fixed;
    z-index: 25;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    width: auto;
    pointer-events: none;
  }

  .pad-left {
    left: max(10px, env(safe-area-inset-left));
    bottom: max(8px, env(safe-area-inset-bottom));
  }

  .pad-right {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    gap: 6px;
    align-items: flex-end;
  }

  .pad-wing .dpad,
  .pad-wing .ab-btn,
  .pad-wing .pill-btn {
    pointer-events: auto;
    opacity: 0.48;
    transition: opacity 0.08s, transform 0.05s;
  }

  .pad-wing .dpad:active,
  .pad-wing .ab-btn.active,
  .pad-wing .ab-btn:active,
  .pad-wing .pill-btn.active,
  .pad-wing .pill-btn:active {
    opacity: 0.9;
  }

  .dpad {
    width: 104px;
    height: 104px;
  }

  .ab-cluster {
    width: 112px;
    height: 82px;
  }

  .ab-btn {
    width: 52px;
    height: 52px;
  }

  .ab-btn .ab-hint {
    display: none;
  }
}

@media (orientation: landscape) {
  body.is-fullscreen .pad-wing {
    position: fixed;
    z-index: 25;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    width: auto;
    pointer-events: none;
  }

  body.is-fullscreen .pad-left {
    left: max(10px, env(safe-area-inset-left));
    bottom: max(8px, env(safe-area-inset-bottom));
  }

  body.is-fullscreen .pad-right {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    gap: 6px;
    align-items: flex-end;
  }

  body.is-fullscreen .pad-wing .dpad,
  body.is-fullscreen .pad-wing .ab-btn,
  body.is-fullscreen .pad-wing .pill-btn {
    pointer-events: auto;
    opacity: 0.48;
    transition: opacity 0.08s, transform 0.05s;
  }

  body.is-fullscreen .pad-wing .dpad:active,
  body.is-fullscreen .pad-wing .ab-btn.active,
  body.is-fullscreen .pad-wing .ab-btn:active,
  body.is-fullscreen .pad-wing .pill-btn.active,
  body.is-fullscreen .pad-wing .pill-btn:active {
    opacity: 0.9;
  }

  body.is-fullscreen .dpad {
    width: 104px;
    height: 104px;
  }

  body.is-fullscreen .ab-cluster {
    width: 112px;
    height: 82px;
  }

  body.is-fullscreen .ab-btn {
    width: 52px;
    height: 52px;
  }

  body.is-fullscreen .ab-btn .ab-hint {
    display: none;
  }
}

/* Mobile Portrait Ergonomic Stacked Deck */
@media (max-width: 760px) and (orientation: portrait) {
  #topbar {
    display: none !important;
  }

  .lcd-header {
    display: none !important;
  }

  #mobile-quickbar {
    display: flex;
    top: calc(min(100vw, 100dvh * 16 / 9) * 0.5625 + 8px);
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    flex-direction: row;
    width: min(94vw, 360px);
    padding: 5px;
    gap: 5px;
    border-radius: 12px;
  }

  #mobile-quickbar .mob-pill-btn {
    flex: 1 1 0;
    flex-direction: row;
    height: 36px;
    gap: 4px;
    padding: 4px 5px;
  }

  .mob-drawer {
    top: calc(min(100vw, 100dvh * 16 / 9) * 0.5625 + 52px);
    right: max(8px, env(safe-area-inset-right));
    transform: none;
  }

  #handheld {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    align-items: center;
    justify-items: center;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    gap: 8px;
    padding: 0 0 10px;
    background: transparent;
  }

  .lcd-shell {
    grid-column: 1 / -1;
    grid-row: 1;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    justify-content: center;
  }

  .lcd-bezel,
  .lcd-frame {
    max-width: 100%;
    min-width: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .pad-left {
    grid-column: 1;
    grid-row: 2;
    justify-self: center;
    position: static;
  }

  .pad-right {
    grid-column: 2;
    grid-row: 2;
    justify-self: center;
    position: static;
  }

  .pad-wing {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 10px 6px;
    gap: 8px;
    border-radius: 18px;
    pointer-events: auto;
  }

  .dpad {
    width: min(108px, 28vw);
    height: min(108px, 28vw);
    opacity: 0.92;
  }

  .ab-cluster {
    width: min(100px, 26vw);
    height: 80px;
  }

  .ab-btn {
    width: 44px;
    height: 44px;
    opacity: 0.92;
  }
}

/* Touch-First 4-Pill Easy Farm Dock (Carved Oak Rail, Symmetrical with #mobile-quickbar) */
#mobile-action-strip {
  position: fixed;
  left: max(5px, env(safe-area-inset-left));
  top: 50%;
  transform: translateY(-50%);
  z-index: 26;
  display: none;
  flex-direction: column;
  align-items: stretch;
  width: 58px;
  gap: 5px;
  padding: 5px;
  border-radius: 12px;
  background: linear-gradient(180deg, #6e4728 0%, #4c2f19 100%);
  border: 2px solid #c89648;
  box-shadow: 0 4px 14px rgba(15, 8, 3, 0.65), inset 0 1px 0 rgba(255, 224, 165, 0.35);
  pointer-events: auto;
  touch-action: manipulation;
}

.act-pill-btn {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 44px;
  gap: 2px;
  border: 1.5px solid #7a4e28;
  background: linear-gradient(180deg, #f6e7c4 0%, #dfc38d 100%);
  color: #3b2314;
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.15;
  padding: 4px 2px;
  border-radius: 8px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), 0 2px 4px rgba(15, 8, 3, 0.4);
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}

.act-pill-btn .act-ico {
  font-size: 14px;
  line-height: 1;
}

.act-pill-btn .act-lbl {
  font-size: 10px;
  line-height: 1.1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.act-pill-btn:active {
  transform: scale(0.94);
}

.act-pill-btn.active {
  background: linear-gradient(180deg, #6bbf4e 0%, #3e8830 100%);
  border-color: #ffe078;
  color: #ffffff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
  box-shadow: 0 0 9px rgba(115, 224, 138, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.act-pill-btn.act-pill-farm.active {
  background: linear-gradient(180deg, #6bbf4e 0%, #3e8830 100%);
  border-color: #ffe078;
  color: #ffffff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
  box-shadow: 0 0 10px rgba(145, 232, 96, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.act-pill-btn.act-pill-item,
.act-pill-btn.act-pill-item.active {
  border-color: #7a4e28;
  background: linear-gradient(180deg, #f6e7c4 0%, #dfc38d 100%);
  color: #3b2314;
  text-shadow: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), 0 2px 4px rgba(15, 8, 3, 0.4);
}

.act-pill-btn.act-pill-use {
  background: linear-gradient(180deg, #f6bd58 0%, #cc7d20 100%);
  border-color: #82490e;
  color: #3b2314;
}

body.touch-dock-visible.in-playscene #mobile-action-strip {
  display: flex;
}

@media (max-width: 760px) and (orientation: portrait) {
  body.touch-dock-visible.in-playscene #mobile-action-strip {
    top: calc(min(100vw, 100dvh * 16 / 9) * 0.5625 + 64px);
    bottom: auto;
    left: 50%;
    transform: translateX(-50%);
    flex-direction: row;
    width: min(94vw, 360px);
    justify-content: space-between;
    padding: 5px;
    border-radius: 12px;
  }

  body.touch-dock-visible.in-playscene #mobile-action-strip .act-pill-btn {
    flex: 1 1 0;
    flex-direction: row;
    justify-content: center;
    height: 36px;
    padding: 4px 5px;
    font-size: 11px;
    gap: 4px;
  }
}
