*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #000;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  font-family: 'Segoe UI', system-ui, sans-serif;
}

#canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  transition: opacity 0.6s ease;
}

/* ── Weather bar ─────────────────────────────────────── */
#weather-bar {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  pointer-events: all;
}

.wx-btn {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.7);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.82rem;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  backdrop-filter: blur(4px);
}

.wx-btn:hover {
  background: rgba(255,255,255,0.22);
  color: #fff;
}

.wx-btn.active {
  background: rgba(255,255,255,0.28);
  border-color: rgba(255,255,255,0.5);
  color: #fff;
}

/* ── Controls hint ───────────────────────────────────── */
#controls-hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.07em;
  white-space: nowrap;
}

/* ── Mobile controls overlay ─────────────────────────── */
#mobile-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
}

.mobile-btn {
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 0.9rem;
  backdrop-filter: blur(8px);
  box-shadow: 0 0 12px rgba(0,0,0,0.6);
  cursor: pointer;
}

.mobile-btn.small {
  padding: 6px 10px;
  font-size: 0.8rem;
}

#mobile-steer {
  position: absolute;
  bottom: 24px;
  left: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: all;
}

.mobile-middle-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

#mobile-speed {
  position: absolute;
  bottom: 28px;
  right: 18px;
  display: flex;
  gap: 8px;
  pointer-events: all;
}

#mobile-top-right {
  position: absolute;
  top: 20px;
  right: 18px;
  display: flex;
  gap: 8px;
  pointer-events: all;
}

/* ── Start screen ───────────────────────────────────── */
#start-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.4) 50%, transparent 100%);
  cursor: pointer;
  transition: opacity 0.8s ease;
}
#start-screen.hidden {
  pointer-events: none;
  opacity: 0;
}
#start-text {
  font-size: clamp(3rem, 12vw, 6rem);
  font-weight: 300;
  color: #fff;
  letter-spacing: 0.2em;
  text-shadow: 0 0 40px rgba(255,255,255,0.3);
  animation: start-pulse 2.5s ease-in-out infinite;
}
#start-sub {
  margin-top: 12px;
  font-size: 0.9rem;
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.3em;
}
@keyframes start-pulse {
  0%, 100% { opacity: 0.9; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.02); }
}
#start-title {
  font-size: 1.1rem;
  color: rgba(255,255,255,0.75);
  letter-spacing: 0.5em;
  text-transform: lowercase;
  margin-bottom: 28px;
}
#start-nickname {
  margin-top: 26px;
  cursor: default;
}
#nickname-input {
  width: min(260px, 70vw);
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(10, 20, 40, 0.35);
  color: rgba(255,255,255,0.92);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-align: center;
  outline: none;
  transition: border-color 0.25s ease, background 0.25s ease;
}
#nickname-input::placeholder {
  color: rgba(255,255,255,0.4);
  letter-spacing: 0.15em;
}
#nickname-input:focus {
  border-color: rgba(255,255,255,0.55);
  background: rgba(10, 20, 40, 0.55);
}
#start-tagline {
  margin-top: 40px;
  max-width: min(520px, 84vw);
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.6;
  color: rgba(255,255,255,0.55);
}

/* Show mobile controls and hide desktop hint on small screens */
@media (max-width: 900px) {
  #mobile-controls {
    display: block;
  }
  #controls-hint {
    display: none;
  }
}

/* ── Approach prompt (double opt-in) ─────────────────────────────────── */
#approach-prompt {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8vh;
  pointer-events: none;
}

/* ── Island arrival toast ─────────────────────────────────────────────── */
#island-toast {
  position: fixed;
  top: 9vh;
  left: 50%;
  z-index: 20;
  pointer-events: none;
  white-space: nowrap;
  background: rgba(20, 24, 30, 0.55);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 10px 24px;
  color: #f4f6f8;
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, -10px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

#island-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

#approach-prompt-card {
  pointer-events: all;
  background: rgba(20, 24, 30, 0.55);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 16px;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: #f4f6f8;
  font-size: 15px;
  animation: approach-fade-in 0.4s ease;
}

@keyframes approach-fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

#approach-prompt-actions {
  display: flex;
  gap: 10px;
}

.approach-btn {
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 14px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.approach-btn:hover {
  transform: translateY(-1px);
}

.approach-btn-decline {
  background: rgba(255, 255, 255, 0.08);
  color: #e6e8eb;
}

.approach-btn-confirm {
  background: rgba(140, 200, 255, 0.85);
  color: #0a1420;
  font-weight: 600;
}

/* ── Ephemeral chat panel ─────────────────────────────────────────────── */
#chat-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: min(340px, calc(100vw - 40px));
  max-height: 55vh;
  z-index: 25;
  display: flex;
  flex-direction: column;
  background: rgba(20, 24, 30, 0.6);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.28);
  overflow: hidden;
  color: #f4f6f8;
  font-size: 14px;
  animation: approach-fade-in 0.4s ease;
  transition: width 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.28s cubic-bezier(0.2, 0.8, 0.2, 1),
    max-height 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), right 0.28s ease, bottom 0.28s ease,
    top 0.28s ease, left 0.28s ease, border-radius 0.28s ease;
}

/* "Dedicated section" mode — same page, no navigation, just a much bigger
   in-place view. Toggled by #chat-expand-btn; only built because the small
   corner widget genuinely gets cramped for a longer conversation. */
#chat-panel.chat-expanded {
  right: 50%;
  bottom: 50%;
  transform: translate(50%, 50%);
  width: min(560px, calc(100vw - 48px));
  max-height: min(720px, calc(100vh - 64px));
  height: min(720px, calc(100vh - 64px));
  border-radius: 20px;
}

@media (max-width: 640px) {
  #chat-panel.chat-expanded {
    right: 0;
    bottom: 0;
    left: 0;
    top: 0;
    transform: none;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
}

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#chat-header-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.chat-avatar {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #0a1420;
  background: linear-gradient(135deg, rgba(140, 200, 255, 0.95), rgba(160, 220, 190, 0.95));
}

#chat-title {
  font-weight: 600;
  font-size: 13px;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-expand-btn {
  font-size: 13px;
  line-height: 1;
  padding: 3px 7px;
}

/* Disclosure tag for the AI companion bird — kept small, faded, and light
   (not dark/bold) so it reads as a quiet detail, not a warning label. */
.ai-tag {
  font-weight: 400;
  font-size: 10px;
  opacity: 0.55;
  color: #e6ebf5;
  margin-left: 6px;
  letter-spacing: 0.02em;
  vertical-align: middle;
}

#chat-safety {
  display: flex;
  gap: 4px;
}

.chat-icon-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #d7dbe0;
  border-radius: 8px;
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
}

.chat-icon-btn:hover { background: rgba(255, 255, 255, 0.16); }

.chat-leave {
  background: rgba(255, 150, 130, 0.18);
  border-color: rgba(255, 150, 130, 0.35);
  color: #ffc9bd;
}

#chat-status {
  font-size: 12px;
  color: #ffd9a0;
  padding: 0 12px;
  min-height: 0;
}

#chat-status:not(:empty) { padding: 6px 12px; }

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 60px;
  max-height: 34vh;
}

#chat-panel.chat-expanded #chat-messages {
  max-height: none;
  padding: 16px 20px;
  gap: 4px;
}

.chat-msg {
  max-width: 85%;
  padding: 6px 10px;
  border-radius: 12px;
  line-height: 1.35;
  word-wrap: break-word;
  animation: chat-msg-in 0.2s ease;
  position: relative;
}

/* Tighten spacing between consecutive messages from the same sender —
   read as one visual "turn" instead of separate bubbles every time. */
.chat-msg + .chat-msg-grouped {
  margin-top: -1px;
}

@keyframes chat-msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-msg-them {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.1);
  border-bottom-left-radius: 4px;
}

.chat-msg-me {
  align-self: flex-end;
  background: rgba(140, 200, 255, 0.28);
  border-bottom-right-radius: 4px;
}

.chat-msg-system {
  align-self: center;
  background: none;
  color: #aeb6bf;
  font-size: 12px;
  font-style: italic;
  max-width: 95%;
  text-align: center;
}

.chat-msg-time {
  display: inline-block;
  font-size: 10px;
  opacity: 0.5;
  margin-left: 7px;
  vertical-align: baseline;
}

/* ── Typing indicator ─────────────────────────────────────────────────── */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px 6px;
  font-size: 11px;
  color: #aeb6bf;
}

.chat-typing-dots {
  display: inline-flex;
  gap: 3px;
  padding: 5px 9px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

.chat-typing-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #cfd6de;
  opacity: 0.5;
  animation: chat-typing-bounce 1.1s infinite ease-in-out;
}

.chat-typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-3px); opacity: 1; }
}

#chat-form {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

#chat-panel.chat-expanded #chat-form {
  padding: 14px 20px 18px;
}

#chat-panel.chat-expanded #chat-input {
  padding: 10px 16px;
  font-size: 15px;
}

#chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: #f4f6f8;
  padding: 7px 14px;
  font-size: 14px;
  outline: none;
}

#chat-input:focus { border-color: rgba(140, 200, 255, 0.6); }

#chat-send-btn {
  background: rgba(140, 200, 255, 0.85);
  color: #0a1420;
  border: none;
  border-radius: 999px;
  padding: 7px 16px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
