:root {
  --bg-0: #84c6f4;
  --bg-1: #d6f0ff;
  --panel-bg: rgba(10, 20, 26, 0.78);
  --panel-border: rgba(129, 214, 189, 0.45);
  --text-main: #f0f8ff;
  --text-soft: #d0e6f2;
  --accent: #7ed08f;
  --accent-strong: #cce45a;
  --hud-bg: rgba(5, 10, 15, 0.55);
  --slot-bg: rgba(12, 19, 24, 0.72);
  --slot-border: rgba(214, 227, 236, 0.35);
  --slot-active: #f0d172;
  --danger: #ff7272;
}

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

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 20% 15%, var(--bg-1), var(--bg-0));
  color: var(--text-main);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

#app {
  position: fixed;
  inset: 0;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

.panel {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  backdrop-filter: blur(3px);
  z-index: 40;
}

.panel.visible {
  display: grid;
}

.panel-card {
  width: min(90vw, 640px);
  border: 1px solid var(--panel-border);
  background: linear-gradient(170deg, rgba(7, 13, 18, 0.92), var(--panel-bg));
  box-shadow: 0 18px 60px rgba(5, 10, 16, 0.45);
  border-radius: 16px;
  padding: 24px 24px 28px;
  animation: panel-in 450ms ease;
}

.menu-pane {
  display: none;
}

.menu-pane.visible {
  display: block;
}

.menu-title {
  margin: 10px 0 10px;
  font-size: 26px;
  line-height: 1.1;
}

.world-select-pane {
  width: min(92vw, 760px);
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.panel-kicker {
  margin: 0;
  color: var(--accent);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  font-size: 12px;
}

.panel h1 {
  margin: 12px 0 14px;
  font-size: clamp(26px, 5vw, 42px);
  line-height: 1.1;
}

.panel-copy {
  margin: 10px 0;
  color: var(--text-soft);
  line-height: 1.5;
  font-size: 14px;
}

.menu-actions {
  margin-top: 12px;
}

.world-meta {
  min-height: 42px;
  margin: 10px 0 2px;
}

.world-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.world-actions .cta {
  margin-top: 0;
  padding: 10px 16px;
  font-size: 15px;
}

.ghost-btn {
  border: 1px solid rgba(206, 223, 234, 0.35);
  background: rgba(10, 20, 28, 0.78);
  color: var(--text-main);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  cursor: pointer;
}

.ghost-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ghost-btn.danger {
  border-color: rgba(255, 130, 130, 0.46);
  color: #ffd2d2;
}

.world-list {
  min-height: 260px;
  max-height: 52vh;
  overflow: auto;
  border: 1px solid rgba(189, 213, 228, 0.25);
  border-radius: 12px;
  background: rgba(8, 17, 25, 0.62);
  padding: 8px;
  display: grid;
  gap: 6px;
}

.world-item {
  border: 1px solid rgba(214, 227, 236, 0.2);
  border-radius: 10px;
  background: rgba(12, 22, 30, 0.74);
  color: var(--text-main);
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
}

.world-item:hover {
  border-color: rgba(214, 227, 236, 0.46);
}

.world-item.active {
  border-color: #8de8ff;
  box-shadow: 0 0 0 2px rgba(141, 232, 255, 0.25);
}

.world-item-name {
  font-size: 14px;
  font-weight: 700;
}

.world-item-meta {
  margin-top: 4px;
  font-size: 12px;
  color: #c9dfed;
  opacity: 0.92;
}

.menu-dialog {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(3, 8, 12, 0.55);
  z-index: 5;
}

.menu-dialog.visible {
  display: grid;
}

.menu-dialog-card {
  width: min(92vw, 420px);
  border: 1px solid rgba(182, 215, 230, 0.4);
  border-radius: 14px;
  background: rgba(7, 14, 20, 0.95);
  padding: 14px;
}

.field-label {
  display: block;
  margin: 8px 0 4px;
  font-size: 12px;
  color: #c8dde9;
}

.field-input {
  width: 100%;
  border: 1px solid rgba(186, 212, 228, 0.4);
  border-radius: 10px;
  background: rgba(8, 18, 25, 0.82);
  color: #f2fbff;
  padding: 9px 10px;
  font-size: 14px;
}

.dialog-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

.dialog-actions .cta {
  margin-top: 0;
  padding: 10px 14px;
  font-size: 14px;
}

.cta {
  margin-top: 14px;
  border: 0;
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 16px;
  font-weight: 700;
  color: #06220d;
  background: linear-gradient(140deg, var(--accent-strong), var(--accent));
  cursor: pointer;
}

.cta:active {
  transform: translateY(1px);
}

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease;
  z-index: 20;
}

.hud.visible {
  opacity: 1;
}

.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 24px;
  height: 24px;
  transform: translate(-50%, -50%);
}

.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.45);
}

.crosshair::before {
  width: 2px;
  height: 24px;
  left: 11px;
  top: 0;
}

.crosshair::after {
  width: 24px;
  height: 2px;
  left: 0;
  top: 11px;
}

.status-bar {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  display: flex;
  gap: 18px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--hud-bg);
  font-size: 13px;
}

.hit-flash,
.damage-flash {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 100ms ease;
}

.hit-flash.visible {
  opacity: 0.22;
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0));
}

.damage-flash.visible {
  opacity: 0.18;
  background: radial-gradient(circle at center, rgba(255, 68, 68, 0.2), rgba(160, 20, 20, 0.02));
}

.inventory-panel {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  pointer-events: none;
  z-index: 35;
}

.inventory-panel.visible {
  display: grid;
}

.inventory-card {
  width: min(860px, 92vw);
  border: 1px solid rgba(186, 212, 228, 0.34);
  background: rgba(7, 14, 20, 0.9);
  border-radius: 14px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.35);
  padding: 12px;
  pointer-events: auto;
}

.inventory-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.inventory-tab {
  border: 1px solid rgba(216, 233, 245, 0.3);
  background: rgba(12, 22, 30, 0.82);
  color: var(--text-main);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
}

.inventory-tab.active {
  border-color: #f0d172;
  box-shadow: 0 0 0 2px rgba(240, 209, 114, 0.25);
}

.inventory-body {
  display: none;
}

.inventory-panel:not(.tab-craft) .inventory-body-main {
  display: block;
}

.inventory-panel.tab-craft .inventory-body-craft {
  display: block;
}

.inventory-label {
  margin: 4px 0 8px;
  font-size: 12px;
  color: #c8dde9;
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 8px;
}

.inventory-hotbar-grid {
  margin-top: 4px;
}

.craft-list {
  display: grid;
  gap: 6px;
  max-height: 46vh;
  overflow: auto;
}

.craft-item {
  border: 1px solid rgba(214, 227, 236, 0.26);
  border-radius: 8px;
  background: rgba(15, 26, 35, 0.72);
  color: var(--text-main);
  text-align: left;
  padding: 7px 8px;
  font-size: 12px;
  line-height: 1.35;
  cursor: pointer;
}

.craft-item:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.craft-item-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
}

.craft-item-cost {
  margin-top: 2px;
  color: #d4e4ee;
}

.craft-item-missing {
  margin-top: 2px;
  color: #ff9f9f;
  min-height: 15px;
}

.inventory-label.tips {
  margin-top: 10px;
  color: #accddf;
}

.cursor-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #cbe3f1;
  font-size: 12px;
}

.furnace-panel {
  position: absolute;
  right: 14px;
  top: 56px;
  display: none;
  z-index: 34;
  pointer-events: none;
}

.furnace-panel.visible {
  display: block;
}

.furnace-card {
  pointer-events: auto;
  width: 280px;
  border: 1px solid rgba(210, 229, 242, 0.28);
  border-radius: 12px;
  background: rgba(6, 14, 20, 0.84);
  padding: 10px;
}

.furnace-title {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #c9dfed;
}

.furnace-hint {
  margin: -2px 0 8px;
  color: #bbd8e8;
  font-size: 11px;
  line-height: 1.35;
}

.furnace-slots {
  display: grid;
  grid-template-columns: 60px 1fr 60px;
  gap: 8px;
  align-items: center;
}

.furnace-bars {
  display: grid;
  gap: 6px;
}

.bar-wrap {
  display: grid;
  gap: 4px;
  font-size: 11px;
  color: #d0e5f2;
}

.bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  transition: width 120ms linear;
}

.bar-fill.burn {
  background: linear-gradient(90deg, #ff965f, #ffc16a);
}

.bar-fill.progress {
  background: linear-gradient(90deg, #7fd0ff, #c4f2ff);
}

.furnace-fuel-row {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: #cde3f0;
}

.hotbar {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.hotbar-slot {
  --slot-size: 58px;
  width: var(--slot-size);
  height: var(--slot-size);
  border-radius: 10px;
  border: 1px solid var(--slot-border);
  background: var(--slot-bg);
  display: grid;
  place-items: center;
  position: relative;
  cursor: pointer;
  color: var(--text-main);
  font-size: 11px;
  text-align: center;
  line-height: 1.2;
}

.inventory-slot {
  --slot-size: 58px;
  width: var(--slot-size);
  height: var(--slot-size);
  border-radius: 10px;
  border: 1px solid var(--slot-border);
  background: var(--slot-bg);
  display: grid;
  place-items: center;
  position: relative;
  cursor: pointer;
  color: var(--text-main);
  font-size: 11px;
  text-align: center;
  line-height: 1.2;
}

.hotbar-slot::after,
.inventory-slot::after {
  content: attr(data-count);
  position: absolute;
  right: 6px;
  bottom: 4px;
  font-size: 11px;
  color: #fff;
}

.hotbar-slot::before,
.inventory-slot::before {
  content: attr(data-durability);
  position: absolute;
  left: 5px;
  bottom: 4px;
  font-size: 9px;
  color: #d6f0ff;
}

.hotbar-slot.active,
.inventory-slot.active {
  border-color: var(--slot-active);
  box-shadow: 0 0 0 2px rgba(240, 209, 114, 0.3);
}

.inventory-slot.drag-target {
  border-color: #8de8ff;
  box-shadow: 0 0 0 2px rgba(141, 232, 255, 0.28);
}

.inventory-slot.drag-source {
  border-color: #ffe095;
  box-shadow: 0 0 0 2px rgba(255, 224, 149, 0.28);
}

.inventory-slot.drag-invalid {
  border-color: #ff9e9e;
  box-shadow: 0 0 0 2px rgba(255, 158, 158, 0.25);
}

.hotbar-slot.empty,
.inventory-slot.empty {
  color: rgba(219, 235, 246, 0.35);
}

.cursor-slot {
  --slot-size: 48px;
}

.touch-ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 25;
}

.touch-ui.visible {
  pointer-events: auto;
}

.touch-zone {
  position: absolute;
  top: 0;
  bottom: 0;
}

.left-zone {
  left: 0;
  width: 45%;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 16px;
}

.right-zone {
  right: 0;
  width: 55%;
}

.joy-base {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(4, 10, 14, 0.32);
  border: 1px solid rgba(202, 220, 231, 0.25);
  position: relative;
}

.joy-knob {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  position: absolute;
  left: 34px;
  top: 34px;
  background: rgba(228, 246, 255, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.touch-buttons {
  position: absolute;
  right: 14px;
  bottom: 20px;
  display: flex;
  gap: 8px;
}

.touch-btn {
  pointer-events: auto;
  border: 1px solid rgba(215, 233, 245, 0.5);
  background: rgba(6, 12, 18, 0.55);
  color: #f8fdff;
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 58px;
  font-size: 13px;
}

.toast {
  position: absolute;
  left: 50%;
  top: 72px;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 8px;
  background: rgba(6, 11, 16, 0.45);
  opacity: 0;
  transition: opacity 220ms ease;
  z-index: 30;
}

.toast.visible {
  opacity: 1;
}

.toast.danger {
  background: rgba(111, 21, 21, 0.72);
}

@media (hover: hover) and (pointer: fine) {
  .touch-ui {
    display: none;
  }
}

@media (max-width: 860px) {
  .inventory-card {
    width: min(96vw, 680px);
  }

  .panel-card {
    width: min(96vw, 720px);
  }

  .world-actions {
    gap: 6px;
  }

  .hotbar-slot,
  .inventory-slot {
    width: 46px;
    height: 46px;
  }

  .inventory-grid {
    gap: 6px;
  }

  .status-bar {
    flex-direction: column;
    gap: 4px;
    align-items: center;
  }

  .furnace-panel {
    right: 8px;
    left: 8px;
    top: auto;
    bottom: 86px;
  }

  .furnace-card {
    width: auto;
  }
}
