:root {
  --bg: #0c1018;
  --panel: #141a26;
  --edge: #1e2735;
  --text: #edf1f7;
  --muted: #56627a;
  --accent: #5ad17a;
  --accent2: #ffc857;
  --danger: #ff5d73;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden {
  display: none !important;
}

/* full-screen menu screens */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(800px 500px at 50% -10%, #1a2740, var(--bg));
  z-index: 30;
  padding: 24px;
}
.card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 16px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card h1 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.muted {
  color: var(--muted);
  font-size: 14px;
}
label {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
}
input {
  background: var(--bg);
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 16px;
  outline: none;
}
input:focus {
  border-color: var(--accent);
}
button {
  border: none;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: #0c1018;
}
button.primary {
  background: var(--accent);
}
button.secondary {
  background: var(--accent2);
}
button.linkbtn {
  background: none;
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  padding: 8px;
  margin-top: 4px;
}
button.linkbtn:hover {
  color: var(--text);
}
.divider {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 6px 0;
}
.error {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
}

/* HUD */
#hud {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}
#room-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 6px;
  align-items: center;
  background: rgba(20, 26, 38, 0.8);
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 6px 8px;
  pointer-events: auto;
}
#room-code {
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent2);
}
#room-badge button {
  background: var(--edge);
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 500;
}
#crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px;
  color: rgba(255, 255, 255, 0.7);
}

#settings {
  position: absolute;
  top: 52px;
  left: 10px;
  width: 240px;
  background: rgba(20, 26, 38, 0.95);
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 12px 14px;
  z-index: 30;
  pointer-events: auto;
}
#settings.hidden {
  display: none;
}
#settings h2 {
  margin: 0 0 8px;
  font-size: 15px;
}
#settings label {
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
}
#settings input[type="range"] {
  width: 100%;
}
#settings .small {
  font-size: 11px;
  margin: 6px 0 10px;
}
#render-dist-val {
  color: var(--accent2);
  font-weight: 700;
}

#hotbar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  pointer-events: auto;
}
.slot {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  border: 2px solid var(--edge);
  background: var(--panel);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.slot .swatch {
  position: absolute;
  inset: 4px;
}
.slot .swatch svg {
  display: block;
  width: 100%;
  height: 100%;
}
.slot .key {
  position: relative;
  font-size: 10px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.4);
  padding: 0 3px;
  border-radius: 3px;
  margin-bottom: 2px;
}
.slot.active {
  border-color: var(--accent);
}

/* chat */
#chat {
  position: absolute;
  bottom: 72px;
  left: 10px;
  width: min(340px, 70vw);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#chat-log {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 28vh;
  overflow: hidden;
  font-size: 13px;
}
#chat-log .line {
  background: rgba(12, 16, 24, 0.55);
  padding: 2px 6px;
  border-radius: 6px;
  width: fit-content;
  max-width: 100%;
}
#chat-log .who {
  color: var(--accent2);
  font-weight: 600;
}
#chat-input {
  pointer-events: auto;
  font-size: 14px;
  padding: 8px 10px;
  display: none; /* hidden until Enter opens it */
}
#chat-input.open {
  display: block;
  opacity: 1;
}

/* touch controls */
#touch {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
#joystick {
  position: absolute;
  bottom: 80px;
  left: 24px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(30, 39, 53, 0.5);
  border: 1px solid var(--edge);
  pointer-events: auto;
}
#joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50px;
  height: 50px;
  margin: -25px 0 0 -25px;
  border-radius: 50%;
  background: rgba(90, 209, 122, 0.6);
}
#touch-buttons {
  position: absolute;
  bottom: 90px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#touch-buttons button {
  pointer-events: auto;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(30, 39, 53, 0.7);
  color: var(--text);
  font-size: 22px;
}

/* stats (health + hunger) */
#stats {
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: center;
  pointer-events: none;
}
.statrow {
  display: flex;
  gap: 2px;
  font-size: 15px;
  line-height: 1;
}
.statrow .pip {
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.6));
}
.statrow .pip.empty {
  opacity: 0.25;
  filter: grayscale(1);
}

/* hotbar counts */
.slot .count {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px #000;
}
.slot.depleted .swatch {
  opacity: 0.25;
}

/* crafting / inventory panel */
#craft-panel {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 16, 24, 0.7);
}
.panel-box {
  width: min(420px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 14px;
  padding: 16px 18px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 0 10px;
}
.panel-head h2 {
  font-size: 18px;
  font-weight: 600;
}
#craft-close {
  background: var(--edge);
  color: var(--text);
  padding: 4px 10px;
}
.recipe {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  margin-bottom: 6px;
}
.recipe .label {
  font-size: 14px;
}
.recipe .cost {
  font-size: 12px;
  color: var(--muted);
}
.recipe button {
  padding: 6px 12px;
  background: var(--accent);
}
.recipe button:disabled {
  background: var(--edge);
  color: var(--muted);
  cursor: default;
}
#inv-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.inv-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 13px;
}
.inv-item .sw {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid var(--edge);
}
.inv-item button {
  background: var(--accent2);
  padding: 2px 8px;
  font-size: 12px;
}

/* hurt flash */
#hurt-flash {
  position: fixed;
  inset: 0;
  z-index: 38;
  background: radial-gradient(circle, transparent 40%, rgba(255, 0, 30, 0.55));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease;
}
#hurt-flash.show {
  opacity: 1;
  transition: opacity 0s;
}

/* death overlay */
#death {
  position: fixed;
  inset: 0;
  z-index: 42;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 4, 8, 0.72);
}

/* inventory / crafting overlay */
#inv-overlay {
  position: fixed;
  inset: 0;
  z-index: 36;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 16, 24, 0.72);
}
.inv-window {
  display: flex;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 14px;
  padding: 18px;
}
.inv-left {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.inv-title {
  font-size: 18px;
  font-weight: 600;
}
.inv-craft {
  display: flex;
  align-items: center;
  gap: 12px;
}
.inv-grid {
  display: grid;
  gap: 4px;
}
.inv-grid.g2 {
  grid-template-columns: repeat(2, 44px);
}
.inv-grid.g3 {
  grid-template-columns: repeat(3, 44px);
}
.inv-arrow {
  color: var(--muted);
  font-size: 22px;
}
/* furnace: input over fuel (with a flame gauge between), a cook-progress arrow,
   and the output slot — mirrors the server-authoritative tile entity. */
.inv-furnace {
  display: flex;
  align-items: center;
  gap: 14px;
}
.inv-furnace.hidden {
  display: none;
}
.furnace-io {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.furnace-flame {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: #20160a;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
}
.furnace-flame-fill {
  width: 100%;
  height: 0%;
  background: linear-gradient(to top, #ff7b00, #ffd34d);
  transition: height 0.1s linear;
}
.furnace-arrow {
  position: relative;
  width: 40px;
  height: 12px;
  background: #1a2230;
  border-radius: 3px;
  overflow: hidden;
}
.furnace-arrow-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(to right, var(--accent), var(--accent2));
  transition: width 0.1s linear;
}
/* worn-armor row (4 equipment slots) shown in the personal inventory */
.inv-armor {
  display: flex;
  align-items: center;
  gap: 4px;
}
.inv-armor.hidden {
  display: none;
}
.inv-armor-label {
  font-size: 12px;
  color: var(--muted);
  margin-right: 6px;
}
/* dimmed ghost icon hinting which piece an empty armor slot takes */
.inv-ic.ghost {
  opacity: 0.16;
}
/* PvP indicator: top-centre badge shown while the room's PvP toggle is on */
#pvp-badge {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(180, 40, 40, 0.85);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 12px;
  border-radius: 8px;
  z-index: 20;
  pointer-events: none;
  letter-spacing: 0.5px;
}
#pvp-badge.hidden {
  display: none;
}
.inv-main {
  display: grid;
  grid-template-columns: repeat(9, 44px);
  gap: 4px;
  margin-top: 6px;
}
.inv-hot {
  display: grid;
  grid-template-columns: repeat(9, 44px);
  gap: 4px;
  margin-top: 8px;
}
.inv-slot {
  width: 44px;
  height: 44px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: var(--bg);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.inv-slot.sel {
  border-color: var(--accent);
}
.inv-slot.small {
  width: 28px;
  height: 28px;
  cursor: default;
}
.inv-result {
  width: 52px;
  height: 52px;
  border-color: var(--accent2);
}
.inv-ic {
  width: 26px;
  height: 26px;
  display: block;
}
.inv-ic svg {
  display: block;
  width: 100%;
  height: 100%;
}
.inv-slot.small .inv-ic {
  width: 18px;
  height: 18px;
}
.inv-n {
  position: absolute;
  right: 2px;
  bottom: 1px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px #000;
}
.inv-dur {
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 2px;
  height: 3px;
  background: #222;
  border-radius: 2px;
  overflow: hidden;
}
.inv-dur > span {
  display: block;
  height: 100%;
}
.inv-ref {
  width: 220px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.inv-ref-title {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.inv-ref-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 240px;
  overflow-y: auto;
}
.inv-ref-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 6px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.inv-ref-item:hover {
  background: var(--edge);
}
.inv-preview {
  display: grid;
  grid-template-columns: repeat(3, 28px);
  gap: 3px;
}
.inv-hint {
  font-size: 12px;
  color: var(--accent2);
  min-height: 16px;
}
#inv-tip {
  position: fixed;
  z-index: 70;
  display: none;
  transform: translate(-50%, -100%);
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent2);
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
}
#inv-held {
  position: fixed;
  z-index: 60;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  pointer-events: none;
  display: none;
  align-items: center;
  justify-content: center;
}

/* overlay */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 16, 24, 0.78);
}
.overlay-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.spinner {
  width: 38px;
  height: 38px;
  border: 4px solid var(--edge);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
