:root {
  --app-width: 100vw;
  --app-height: 100dvh;
  --desktop-preview-ratio: 2.1641025641;
  --text: #eff4eb;
  --muted: rgba(235, 242, 229, 0.72);
  --line: rgba(236, 244, 231, 0.14);
  --glass: rgba(7, 14, 15, 0.16);
  --glass-strong: rgba(7, 14, 15, 0.3);
  --shadow: 0 10px 26px rgba(0, 0, 0, 0.2);
  --meter-bg: rgba(255, 255, 255, 0.12);
  --danger: #d47663;
  --safe-top: max(10px, env(safe-area-inset-top));
  --safe-right: max(10px, env(safe-area-inset-right));
  --safe-bottom: max(12px, env(safe-area-inset-bottom));
  --safe-left: max(10px, env(safe-area-inset-left));
}

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

html,
body {
  margin: 0;
  width: var(--app-width);
  height: var(--app-height);
  overflow: hidden;
  touch-action: none;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(156, 181, 145, 0.12), transparent 34%),
    linear-gradient(180deg, #182220 0%, #091112 100%);
  user-select: none;
  overscroll-behavior: none;
}

body.desktop-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(circle at 50% 18%, rgba(194, 212, 165, 0.1), transparent 32%),
    linear-gradient(180deg, #182220 0%, #091112 100%);
}

.mobile-world-view {
  position: relative;
  width: var(--app-width);
  height: var(--app-height);
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  background: #111a1a;
}

body.desktop-preview .mobile-world-view {
  width: min(430px, calc(var(--app-width) - 40px), calc((var(--app-height) - 40px) / var(--desktop-preview-ratio)));
  height: auto;
  aspect-ratio: 390 / 844;
  border-radius: 28px;
  border: 1px solid rgba(240, 247, 232, 0.08);
  box-shadow:
    0 28px 60px rgba(0, 0, 0, 0.34),
    0 0 0 8px rgba(255, 255, 255, 0.03);
}

.mobile-canvas-shell {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 10%, rgba(240, 248, 232, 0.08), transparent 32%),
    linear-gradient(180deg, #dce7d2 0%, #94a978 100%);
}

.mobile-canvas-shell canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  transform: translate(-50%, -50%);
  filter: saturate(1.04) contrast(1.02);
}

.mobile-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at center, transparent 52%, rgba(4, 9, 10, 0.04) 72%, rgba(4, 8, 9, 0.28) 100%),
    linear-gradient(180deg, rgba(8, 12, 14, 0.24) 0%, transparent 16%, transparent 88%, rgba(8, 12, 14, 0.2) 100%);
}

.mobile-hud-layer,
.mobile-controls-layer {
  position: absolute;
  inset: 0;
}

.mobile-hud-layer {
  z-index: 3;
  pointer-events: none;
}

.mobile-topbar,
.mobile-corner,
.hint-toast,
.respawn-banner,
.mobile-overlay,
.mobile-entry-panel,
.action-button {
  pointer-events: auto;
}

.mobile-topbar {
  position: absolute;
  top: var(--safe-top);
  left: var(--safe-left);
  right: var(--safe-right);
}

.top-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 0 2px;
}

.top-strip-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.top-strip-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.strip-pill,
.strip-stat,
.mini-meter-block,
.mini-status-chip,
.respawn-banner,
.hint-toast,
.mobile-entry-panel {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--glass) 0%, rgba(7, 14, 15, 0.06) 100%);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.strip-pill {
  min-width: 0;
  max-width: 24vw;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.strip-stat {
  min-width: 58px;
  max-width: 20vw;
  padding: 6px 8px;
  border-radius: 999px;
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

.emphasis-pill {
  background: linear-gradient(180deg, rgba(7, 14, 15, 0.24) 0%, rgba(7, 14, 15, 0.1) 100%);
}

.mobile-corner {
  position: absolute;
  top: calc(var(--safe-top) + 40px);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mobile-left-hud {
  left: var(--safe-left);
  width: min(36vw, 140px);
}

.mobile-right-hud {
  right: var(--safe-right);
  width: min(34vw, 132px);
}

.mini-meter-block,
.mini-status-chip {
  border-radius: 12px;
  padding: 7px 8px;
}

.mini-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.mini-label {
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mini-value {
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
}

.mini-meter {
  margin-top: 5px;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--meter-bg);
}

.mini-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  transition: width 120ms linear;
}

.mini-tip {
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
}

.hunger-fill {
  background: linear-gradient(90deg, #d6aa5c 0%, #a8b75b 52%, #6b8441 100%);
}

.aux-fill {
  background: linear-gradient(90deg, #b76050 0%, #d1a54f 54%, #d8de95 100%);
}

.skill-fill {
  background: linear-gradient(90deg, #7f95ad 0%, #9fb4c9 52%, #d7e3ea 100%);
}

.respawn-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: min(72vw, 260px);
  max-width: calc(100vw - 32px);
  padding: 14px 16px 16px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(7, 14, 15, 0.42) 0%, rgba(7, 14, 15, 0.18) 100%);
}

.respawn-banner.visible {
  display: flex;
}

.respawn-kicker {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.respawn-text {
  font-size: clamp(46px, 15vw, 72px);
  font-weight: 700;
  line-height: 0.95;
  color: #f7f9f2;
  text-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

.respawn-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}

.hint-toast {
  position: absolute;
  top: calc(var(--safe-top) + 84px);
  right: var(--safe-right);
  max-width: 42vw;
  padding: 6px 9px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
  text-align: right;
}

.debug-badge {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 8px);
  transform: translateX(-50%);
  max-width: calc(100vw - 128px);
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(7, 14, 15, 0.22);
  color: var(--muted);
  font-size: 9px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

.mobile-hidden-meta {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.mobile-controls-layer {
  z-index: 4;
  pointer-events: none;
}

.joystick-zone {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  pointer-events: auto;
  touch-action: none;
}

.joystick-base {
  position: absolute;
  width: 108px;
  height: 108px;
  margin-left: -54px;
  margin-top: -54px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.02) 60%),
    rgba(7, 14, 15, 0.22);
  border: 1px solid rgba(240, 247, 232, 0.14);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: scale(0.88);
  transition: opacity 120ms ease, transform 120ms ease;
}

.joystick-base.visible {
  opacity: 1;
  transform: scale(1);
}

.joystick-stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin-left: -24px;
  margin-top: -24px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0.08) 62%),
    rgba(214, 225, 201, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.control-caption {
  color: rgba(240, 247, 232, 0.72);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.left-caption {
  position: absolute;
  left: calc(var(--safe-left) + 16px);
  bottom: calc(var(--safe-bottom) + 8px);
}

.right-caption {
  position: static;
}

.action-cluster {
  position: absolute;
  right: var(--safe-right);
  bottom: calc(var(--safe-bottom) + 6px);
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.action-button {
  width: 86px;
  height: 86px;
  border: 1px solid rgba(240, 247, 232, 0.16);
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.22), transparent 40%),
    linear-gradient(180deg, rgba(157, 183, 97, 0.9), rgba(109, 132, 64, 0.96));
  color: #f7f9f2;
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.24);
  pointer-events: auto;
  touch-action: manipulation;
}

.action-button.secondary {
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.18), transparent 40%),
    linear-gradient(180deg, rgba(111, 136, 162, 0.92), rgba(57, 78, 96, 0.98));
}

.action-button:active,
.action-button.is-active {
  transform: scale(0.96);
  filter: brightness(1.06);
}

.action-button.is-disabled {
  opacity: 0.48;
  filter: grayscale(0.22);
}

.mobile-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 18px 14px calc(var(--safe-bottom) + 12px);
  background: linear-gradient(180deg, rgba(9, 16, 17, 0.06), rgba(8, 12, 13, 0.24) 56%, rgba(8, 12, 13, 0.42));
}

.mobile-overlay.visible {
  display: flex;
}

.mobile-entry-panel {
  width: min(100%, 380px);
  padding: 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(8, 13, 14, 0.42) 0%, rgba(8, 13, 14, 0.22) 100%);
}

.modal-tag {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.mobile-entry-head h1 {
  margin: 6px 0 0;
  font-size: clamp(24px, 8vw, 34px);
  line-height: 1.02;
}

.mobile-entry-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 14px;
}

.mobile-entry-button,
.primary-button,
.secondary-button {
  width: 100%;
  min-height: 52px;
  border-radius: 999px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.primary-button {
  border: 1px solid rgba(208, 221, 167, 0.24);
  background: linear-gradient(135deg, rgba(172, 193, 105, 0.9) 0%, rgba(127, 150, 76, 0.92) 100%);
  color: #f7f9f2;
}

.secondary-button {
  border: 1px solid rgba(242, 247, 237, 0.16);
  background: rgba(244, 248, 240, 0.08);
}

.secondary-button.is-disabled,
.secondary-button:disabled {
  opacity: 0.42;
  filter: grayscale(0.24);
  cursor: not-allowed;
}

.mobile-entry-foot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

.entry-mini-copy {
  color: var(--muted);
  font-size: 11px;
}

.error-text {
  margin: 0;
  min-height: 16px;
  color: var(--danger);
  font-size: 12px;
  text-align: right;
}

body.in-world .mobile-overlay {
  background: transparent;
}

@media (min-width: 480px) {
  .action-button {
    width: 92px;
    height: 92px;
  }

  .joystick-base {
    width: 114px;
    height: 114px;
    margin-left: -57px;
    margin-top: -57px;
  }
}

@media (orientation: landscape) {
  .mobile-left-hud,
  .mobile-right-hud {
    width: 128px;
  }

  .hint-toast {
    max-width: 180px;
  }

  .debug-badge {
    max-width: calc(100vw - 180px);
  }
}
