/* ================== Base ================== */
:root {
  --bg: #0b0f14;
  --panel: rgba(10, 14, 22, 0.86);
  --panel-border: rgba(255,255,255,0.10);
  --panel-strong: rgba(255,255,255,0.18);
  --text: #e8ecff;
  --muted: #aab6e5;
  --accent: #67a8ff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, "Apple Color Emoji", "Segoe UI Emoji";
  overscroll-behavior: none;
}

/* Canvas fills viewport (actual pixel size set by JS) */
#game {
  display: block;
  width: 100vw;
  height: 100vh;
  background: #0b0f14;
  touch-action: none; /* better mobile drag */
}

/* ================== HUD (top) ================== */
.hud {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: env(safe-area-inset-left, 0px);
  right: env(safe-area-inset-right, 0px);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 4;
  pointer-events: none; /* display-only */
}

.hud .title {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.2px;
  color: #f3f6ff;
  text-shadow: 0 1px 0 rgba(0,0,0,0.35);
}

.hud .hint {
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  opacity: 0.9;
}

.status {
  margin-left: auto;
  font-weight: 700;
  font-size: 13px;
  border: 1px solid var(--panel-border);
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(0,0,0,0.35);
  color: #d7defc;
}
.status.ok  { border-color: rgba(104, 220, 161, 0.35); }
.status.err { border-color: rgba(255, 120, 120, 0.35); }

/* ================== Name modal ================== */
.name-modal {
  position: fixed;
  inset: 0;
  display: none; /* JS toggles to flex */
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
  background: radial-gradient(1200px 800px at 50% 40%, rgba(18,24,38,0.85), rgba(10,12,18,0.9));
  backdrop-filter: blur(4px);
}

.name-modal .panel {
  width: min(520px, 92vw);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35), inset 0 0 0 1px rgba(255,255,255,0.04);
  padding: 22px 22px 18px;
}

.name-modal h1 {
  margin: 0 0 14px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.2px;
}

#nameForm {
  display: flex;
  gap: 10px;
}

#nameInput {
  flex: 1;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(0,0,0,0.55);
  color: var(--text);
  padding: 0 12px;
  outline: none;
  font-weight: 600;
}
#nameInput::placeholder { color: rgba(200,210,255,0.5); }

#nameForm button {
  height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-strong);
  color: #0c1220;
  background: linear-gradient(180deg, #8ec1ff, #4c91ff);
  font-weight: 800;
  letter-spacing: 0.2px;
  cursor: pointer;
}
#nameForm button:hover { filter: brightness(1.03); }
#nameForm button:active { transform: translateY(1px); }

.name-modal .note {
  margin: 10px 2px 0;
  color: #b7c4ef;
  font-size: 12px;
  font-weight: 600;
  opacity: 0.9;
}

/* ================== Chat box ================== */
/* Always visible (dim). Sits above the hotbar so they don't overlap. */
.chatbox {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 110px);
  width: min(560px, 92vw);
  z-index: 7;

  opacity: 0.35;           /* visible but subtle */
  pointer-events: auto;    /* click/tap focuses input */
  transition: opacity 120ms ease, transform 120ms ease;
}
.chatbox:hover { opacity: 0.55; }
/* Bright when focused (works even without JS via :focus-within) */
.chatbox:focus-within,
.chatbox.open { opacity: 1; }

.chatbox input {
  width: 100%;
  height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.55);
  color: #e8ecff;
  outline: none;
  font: 600 14px Inter, system-ui, -apple-system, Segoe UI, Roboto, "Apple Color Emoji", "Segoe UI Emoji";
  backdrop-filter: blur(6px);
}
.chatbox input::placeholder { color: rgba(200,210,255,0.55); }

/* Lift a bit more on small screens so it clears the hotbar/D-pad */
@media (max-width: 640px) {
  .chatbox {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 132px);
    width: min(520px, 94vw);
  }
}

/* ================== Mobile D-pad ================== */
.dpad {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  left: calc(env(safe-area-inset-left, 0px) + 16px);
  display: none; /* hidden on desktop */
  z-index: 6;
  gap: 6px;
  user-select: none;
}

.dpad .mid {
  display: grid;
  grid-template-columns: repeat(3, 40px);
  grid-template-rows: 40px;
  align-items: center;
  gap: 6px;
}

.dpad button {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(0,0,0,0.45);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dpad button:active {
  transform: translateY(1px);
  background: rgba(0,0,0,0.55);
}

/* Show D-pad on small screens or coarse pointers */
@media (max-width: 900px), (pointer: coarse) {
  .dpad { display: flex; }
}

/* ================== Utility ================== */
.hidden { display: none !important; }

input:focus, button:focus {
  outline: 2px solid rgba(103,168,255,0.45);
  outline-offset: 0;
}

/* Safe-area padding helpers */
@supports (padding: max(0px)) {
  .hud { padding-top: max(12px, env(safe-area-inset-top)); }
  .dpad {
    bottom: max(16px, env(safe-area-inset-bottom));
    left: max(16px, env(safe-area-inset-left));
  }
}
