* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #c8dff2;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  color: #f2f7ff;
}

#game-canvas {
  display: block;
  position: fixed;
  inset: 0;
  cursor: pointer;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

/* =========================================================================
   PONY TOWN-INSPIRED TRANSLUCENT WINTER HUD
   ========================================================================= */

.hud-panel {
  background: rgba(24, 30, 44, 0.78);
  border: 1px solid rgba(210, 232, 255, 0.24);
  border-radius: 8px;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 16px rgba(14, 24, 42, 0.35);
}

/* Top-Left Location & Hint Pill */
#top-left-hud {
  position: fixed;
  top: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 10;
}

.zone-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: #f4f9ff;
}

.zone-badge .snow-dot {
  color: #9ce0ff;
  font-size: 14px;
}

.controls-tip {
  font-size: 11px;
  color: rgba(235, 245, 255, 0.88);
  background: rgba(24, 30, 44, 0.62);
  border: 1px solid rgba(210, 232, 255, 0.16);
  border-radius: 6px;
  padding: 4px 9px;
  width: fit-content;
}

/* Top-Right Minimap & Environment Tools (Exact Pony Town layout!) */
#top-right-hud {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 10;
}

.top-toolbar {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  border: 1px solid rgba(210, 232, 255, 0.28);
  background: rgba(24, 30, 44, 0.82);
  color: #eef6ff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
  box-shadow: 0 2px 8px rgba(10, 18, 34, 0.3);
}

.icon-btn:hover {
  background: rgba(45, 58, 84, 0.92);
  border-color: rgba(156, 224, 255, 0.65);
  transform: translateY(-1px);
}

.icon-btn.active {
  background: rgba(58, 128, 196, 0.85);
  border-color: #a9e4ff;
}

.minimap-wrap {
  padding: 4px;
  position: relative;
}

#minimap-canvas {
  display: block;
  width: 144px;
  height: 104px;
  border-radius: 4px;
  image-rendering: pixelated;
  cursor: crosshair;
  border: 1px solid rgba(18, 24, 38, 0.85);
}

.minimap-hint {
  position: absolute;
  bottom: 6px;
  right: 8px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

/* Right-Edge Zoom Controls (Exact Pony Town +/- Placement!) */
#zoom-controls {
  position: fixed;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 10;
}

.zoom-btn {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid rgba(210, 232, 255, 0.32);
  background: rgba(24, 30, 44, 0.82);
  color: #ffffff;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.zoom-btn:hover {
  background: rgba(54, 72, 104, 0.94);
}

#zoom-indicator {
  font-size: 10px;
  color: #e4f2ff;
  background: rgba(24, 30, 44, 0.72);
  padding: 2px 5px;
  border-radius: 4px;
}

/* Bottom-Left Local Chat Box (Direct homage to Pony Town Screenshots!) */
#chat-panel {
  position: fixed;
  left: 12px;
  bottom: 64px;
  width: 320px;
  max-width: calc(100vw - 24px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
  transition: height 0.2s ease;
}

#chat-panel.collapsed #chat-messages,
#chat-panel.collapsed .chat-quick-bar,
#chat-panel.collapsed .chat-input-row {
  display: none;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px;
  background: rgba(16, 21, 32, 0.65);
  border-bottom: 1px solid rgba(210, 232, 255, 0.15);
  font-size: 12px;
}

.chat-tabs {
  display: flex;
  gap: 10px;
  align-items: center;
}

.chat-tab {
  color: #9ddcff;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}

.chat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6ee7a8;
  display: inline-block;
}

#btn-chat-toggle {
  background: transparent;
  border: none;
  color: #cfe4ff;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
}

#btn-chat-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
}

#chat-messages {
  height: 118px;
  overflow-y: auto;
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1.48;
  user-select: text;
  -webkit-user-select: text;
}

#chat-messages::-webkit-scrollbar {
  width: 5px;
}
#chat-messages::-webkit-scrollbar-thumb {
  background: rgba(180, 210, 240, 0.35);
  border-radius: 4px;
}

.chat-line {
  margin-bottom: 3px;
  word-break: break-word;
}

.chat-time {
  color: rgba(175, 198, 224, 0.72);
  font-size: 11px;
}

.chat-sender {
  color: #9de1ff;
  font-weight: 600;
}

.chat-line.system .chat-sender {
  color: #ffd978;
}

.chat-line.system .chat-text {
  color: #e4eefc;
}

.chat-quick-bar {
  display: flex;
  gap: 4px;
  padding: 4px 8px;
  background: rgba(16, 21, 32, 0.4);
  border-top: 1px solid rgba(210, 232, 255, 0.1);
  flex-wrap: wrap;
}

.quick-phrase {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  border: 1px solid rgba(180, 215, 245, 0.25);
  background: rgba(52, 70, 102, 0.55);
  color: #eef6ff;
  cursor: pointer;
  transition: background 0.12s;
}

.quick-phrase:hover {
  background: rgba(74, 118, 178, 0.85);
}

.chat-input-row {
  display: flex;
  border-top: 1px solid rgba(210, 232, 255, 0.16);
}

#chat-input {
  flex: 1;
  background: rgba(12, 17, 28, 0.72);
  border: none;
  outline: none;
  color: #ffffff;
  font-size: 12px;
  padding: 7px 10px;
  user-select: text;
  -webkit-user-select: text;
}

#chat-input::placeholder {
  color: rgba(190, 210, 235, 0.58);
}

#btn-chat-send {
  background: rgba(62, 134, 206, 0.85);
  border: none;
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  padding: 0 12px;
  cursor: pointer;
}

#btn-chat-send:hover {
  background: rgba(82, 156, 228, 0.95);
}

/* =========================================================================
   BOTTOM PONY TOWN ACTION BAR
   ========================================================================= */
#bottom-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 10;
}

.action-dock {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 7px;
  overflow-x: auto;
  max-width: 100%;
}

.dock-divider {
  width: 1px;
  height: 28px;
  background: rgba(210, 232, 255, 0.22);
  margin: 0 3px;
}

.action-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 40px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid rgba(210, 232, 255, 0.22);
  background: rgba(38, 48, 70, 0.72);
  color: #f0f7ff;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
}

.action-btn:hover {
  background: rgba(58, 76, 112, 0.9);
  border-color: rgba(164, 224, 255, 0.65);
  transform: translateY(-1px);
}

.action-btn.active {
  background: rgba(56, 134, 206, 0.86);
  border-color: #b4e9ff;
}

.action-btn .btn-ico {
  font-size: 14px;
  line-height: 1.1;
}

.action-btn .btn-sub {
  font-size: 10px;
  color: rgba(232, 244, 255, 0.92);
  white-space: nowrap;
}

.action-btn .key-badge {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 8px;
  color: rgba(190, 222, 255, 0.75);
  font-weight: 700;
}

/* Quick Preset Pony Strip */
#preset-strip {
  display: flex;
  align-items: center;
  gap: 5px;
}

.preset-chip {
  width: 38px;
  height: 38px;
  border-radius: 7px;
  border: 2px solid rgba(210, 232, 255, 0.25);
  background: rgba(216, 236, 250, 0.24);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, border-color 0.15s, background 0.15s;
}

.preset-chip canvas {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
}

.preset-chip:hover {
  transform: translateY(-2px);
  border-color: #a6e3ff;
  background: rgba(220, 240, 255, 0.42);
}

.preset-chip.active {
  border-color: #ffe26a;
  background: rgba(255, 234, 148, 0.3);
  box-shadow: 0 0 10px rgba(255, 226, 106, 0.45);
}

/* =========================================================================
   PONY APPEARANCE CUSTOMIZER DRAWER
   ========================================================================= */
#customizer-drawer {
  position: fixed;
  top: 12px;
  right: 12px;
  bottom: 66px;
  width: 316px;
  max-width: calc(100vw - 24px);
  display: flex;
  flex-direction: column;
  z-index: 30;
  overflow: hidden;
}

#customizer-drawer.hidden,
#help-modal.hidden {
  display: none;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(16, 22, 34, 0.72);
  border-bottom: 1px solid rgba(210, 232, 255, 0.18);
}

.drawer-header h2 {
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
}

.close-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-size: 16px;
  cursor: pointer;
}

.close-btn:hover {
  background: rgba(230, 80, 96, 0.8);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.drawer-body::-webkit-scrollbar {
  width: 5px;
}
.drawer-body::-webkit-scrollbar-thumb {
  background: rgba(180, 210, 240, 0.35);
  border-radius: 4px;
}

.preview-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#preview-canvas {
  width: 168px;
  height: 160px;
  border-radius: 10px;
  border: 2px solid rgba(210, 234, 255, 0.45);
  image-rendering: pixelated;
  background: #d7eaf7;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-group label {
  font-size: 12px;
  color: #c9e2ff;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.text-input, .select-input {
  width: 100%;
  background: rgba(14, 20, 32, 0.82);
  border: 1px solid rgba(200, 224, 250, 0.25);
  border-radius: 6px;
  color: #ffffff;
  padding: 6px 9px;
  font-size: 12px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

.text-input:focus, .select-input:focus {
  border-color: #82d4ff;
}

.species-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.species-btn {
  padding: 6px 4px;
  border-radius: 6px;
  border: 1px solid rgba(210, 232, 255, 0.24);
  background: rgba(36, 46, 68, 0.72);
  color: #e8f4ff;
  font-size: 11px;
  cursor: pointer;
}

.species-btn.active {
  background: rgba(62, 140, 214, 0.9);
  border-color: #a9e5ff;
  font-weight: 700;
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  cursor: pointer;
  transition: transform 0.1s;
}

.swatch:hover {
  transform: scale(1.14);
  border-color: #ffffff;
}

.color-pick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: #c4dcf7;
}

.color-pick-row input[type="color"] {
  width: 30px;
  height: 24px;
  border: none;
  background: transparent;
  cursor: pointer;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.field-group label.checkbox-row {
  justify-content: flex-start;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #edf6ff;
  cursor: pointer;
}

/* =========================================================================
   HELP / KEYBINDINGS POPOVER
   ========================================================================= */
#help-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 380px;
  max-width: calc(100vw - 32px);
  z-index: 40;
  overflow: hidden;
}

.help-body {
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.65;
  color: #e6f2ff;
}

.help-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 6px 10px;
  margin-top: 8px;
}

.kbd {
  display: inline-block;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(210, 234, 255, 0.32);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: Consolas, monospace;
  color: #fff3b0;
}

@media (max-width: 720px) {
  #chat-panel {
    width: 260px;
    bottom: 62px;
  }
  #minimap-canvas {
    width: 112px;
    height: 80px;
  }
  .controls-tip {
    display: none;
  }
}
