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

html, body {
  margin: 0; padding: 0;
  height: 100%; width: 100%;
  overflow: hidden;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#bg {
  position: fixed; inset: 0; z-index: 0;
  background: linear-gradient(180deg, #0a0a0f 0%, #1a1025 55%, #0d0d1a 100%);
  background-size: cover;
  background-position: center;
}

#l2d-box {
  position: absolute; top: 0; left: 0; width: 100%; height: 100vh;
  pointer-events: auto; z-index: 5;
}
#l2d-canvas { width: 100%; height: 100%; display: block; }

#bubble {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: 50%; transform: translateX(-50%);
  max-width: 80vw;
  background: rgba(30, 25, 40, 0.92);
  border: 2px solid #c8a86e;
  border-radius: 14px;
  padding: 9px 14px;
  font-size: 14px; line-height: 1.5;
  color: #f0e0c0;
  z-index: 50; opacity: 1; transition: opacity 0.25s;
  pointer-events: none;
}
#bubble.hidden { opacity: 0; }

#chat-area {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 69px);
  left: 0; right: 0;
  max-height: 55vh;
  overflow-y: auto;
  z-index: 30;
  padding: 0 10px;
  display: flex; flex-direction: column;
  gap: 6px;
  pointer-events: none;
  -webkit-overflow-scrolling: touch;
}

.chat-msg {
  max-width: 72%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  animation: msgIn 0.25s ease-out;
  pointer-events: auto;
}
.chat-msg.user {
  align-self: flex-end;
  background: rgba(100, 80, 60, 0.85);
  color: #f0e0c0;
  border-bottom-right-radius: 6px;
}
.chat-msg.pet {
  align-self: flex-start;
  background: rgba(20, 15, 30, 0.85);
  color: #f0e0c0;
  border: 1px solid #5a4a30;
  border-bottom-left-radius: 6px;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

#bottom-bar {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  left: 50%; transform: translateX(-50%);
  width: 90%;
  z-index: 50;
}
#input-row {
  display: flex; gap: 6px; align-items: center;
}
#chat-input {
  flex: 1; min-width: 0;
  box-sizing: border-box;
  border: 2px solid #c8a86e;
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 16px;
  background: rgba(20, 15, 30, 0.88);
  outline: none;
  color: #f0e0c0;
}
#chat-input::placeholder { color: #6a5a40; }
#chat-input:focus { border-color: #e0c080; }

#input-row button {
  border: 2px solid #c8a86e;
  background: rgba(20, 15, 30, 0.88);
  color: #c8a86e;
  border-radius: 20px;
  padding: 10px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
#btn-audio.muted { border-color: #555; color: #555; }

.panel {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  background: rgba(20, 15, 30, 0.92);
  border: 2px solid #c8a86e;
  border-radius: 14px;
  padding: 8px;
  margin-bottom: 8px;
}
.panel.hidden { display: none; }
.panel button {
  border: 1px solid #5a4a30;
  background: rgba(30, 20, 40, 0.9);
  border-radius: 10px;
  padding: 10px 2px;
  font-size: 13px;
  color: #c8a86e;
  cursor: pointer;
}
.panel button:active { background: #3a2a20; }

.panel.settings {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.panel.settings.hidden { display: none; }
.set-row {
  display: flex; align-items: center; gap: 6px;
}
.set-row label { width: 30px; font-size: 13px; color: #c8a86e; text-align: right; flex-shrink: 0; }
.set-row input[type=range] { flex: 1; accent-color: #c8a86e; }
.set-row span { width: 34px; font-size: 12px; color: #c8a86e; text-align: right; flex-shrink: 0; }
#btn-reset {
  border: 1.5px solid #c8a86e;
  background: rgba(30, 20, 40, 0.9);
  color: #c8a86e;
  border-radius: 12px;
  padding: 8px;
  font-size: 13px;
  cursor: pointer;
}
