:root {
  --bg-ui: rgba(14, 20, 25, 0.82);
  --ui-border: rgba(255, 255, 255, 0.18);
  --accent: #6fcf97;
  --danger: #ef5b5b;
  --hunger: #f2a444;
  --xp: #6de971;
  --oxygen: #67b5ff;
  --text: #f2f5f7;
  --font: "Trebuchet MS", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 15% 20%, #233245, #0d141d 60%, #081017);
  color: var(--text);
  font-family: var(--font);
}

#game {
  width: 100vw;
  height: 100vh;
  display: block;
}

#crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.95);
  font-size: 28px;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  z-index: 9;
}

#hud {
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}

.bars {
  position: fixed;
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%);
  width: min(560px, 82vw);
  background: rgba(0, 0, 0, 0.48);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  padding: 6px 10px 8px;
  backdrop-filter: blur(2px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "hp hu"
    "xp xp"
    "o2 o2";
  gap: 4px 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 30px 1fr 40px;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  margin: 0;
}

.bars .bar-row:nth-child(1) { grid-area: hp; }
.bars .bar-row:nth-child(2) { grid-area: hu; }
.bars .bar-row:nth-child(3) { grid-area: xp; }
.bars .bar-row:nth-child(4) { grid-area: o2; }

.bar {
  background: rgba(255, 255, 255, 0.1);
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
}

.bar > div {
  height: 100%;
}

#health-fill {
  background: linear-gradient(90deg, #ff6767, var(--danger));
}

#hunger-fill {
  background: linear-gradient(90deg, #f8c26a, var(--hunger));
}

#xp-fill {
  background: linear-gradient(90deg, #9af79f, var(--xp));
}

#oxygen-fill {
  background: linear-gradient(90deg, #9cd0ff, var(--oxygen));
}

#mode-pill,
#coords,
#clock {
  position: fixed;
  left: 12px;
  font-size: 12px;
  background: var(--bg-ui);
  border: 1px solid var(--ui-border);
  padding: 4px 8px;
  border-radius: 999px;
  width: fit-content;
}

#mode-pill { top: 12px; }
#coords { top: 42px; }
#clock { top: 72px; }

#minimap {
  position: fixed;
  left: 12px;
  top: 102px;
  border: 1px solid var(--ui-border);
  background: rgba(0, 0, 0, 0.28);
  border-radius: 8px;
}

#hotbar {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(9, 56px);
  gap: 5px;
  z-index: 9;
}

.slot {
  border: 1px solid var(--ui-border);
  background: rgba(0, 0, 0, 0.48);
  border-radius: 6px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.item-icon {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.38);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
  display: grid;
  place-items: center;
  position: relative;
}

.item-code {
  font-size: 9px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 2px #000;
  letter-spacing: 0.02em;
}

.item-label {
  position: absolute;
  left: 4px;
  top: 4px;
  font-size: 9px;
  max-width: calc(100% - 8px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.9;
}

.slot.selected {
  outline: 2px solid var(--accent);
  transform: translateY(-2px);
}

.slot .count,
.slot .dur {
  position: absolute;
  font-size: 11px;
  text-shadow: 0 1px 2px #000;
}

.slot .count {
  right: 5px;
  bottom: 4px;
}

.slot .dur {
  left: 5px;
  bottom: 4px;
  color: #d7ffbf;
}

.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-width: 360px;
  max-width: min(92vw, 660px);
  max-height: 86vh;
  overflow: auto;
  background: linear-gradient(165deg, rgba(18, 28, 37, 0.94), rgba(10, 15, 22, 0.95));
  border: 1px solid var(--ui-border);
  border-radius: 12px;
  padding: 14px;
  z-index: 12;
}

.panel.hidden {
  display: none;
}

.panel h1,
.panel h2 {
  margin: 0 0 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.panel label {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 13px;
}

.panel input,
.panel select,
.panel button {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--ui-border);
  color: var(--text);
  border-radius: 7px;
  padding: 7px 9px;
}

.panel button {
  cursor: pointer;
}

.panel button:hover {
  background: rgba(255, 255, 255, 0.18);
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

#inventory-grid,
#chest-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
}

.grid-slot {
  min-height: 44px;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  padding: 2px;
}

.grid-slot .item-icon {
  width: 24px;
  height: 24px;
}

.grid-slot.hotbar-slot {
  outline: 1px dashed rgba(120, 210, 150, 0.28);
}

.grid-slot .count {
  position: absolute;
  right: 3px;
  bottom: 2px;
}

.grid-slot .dur {
  position: absolute;
  left: 3px;
  bottom: 2px;
  font-size: 10px;
  color: #d7ffbf;
}

#inventory-cursor {
  position: fixed;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 30;
}

.recipes {
  display: grid;
  gap: 6px;
}

.recipe {
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  padding: 8px;
  display: grid;
  gap: 6px;
  background: rgba(255, 255, 255, 0.05);
}

#furnace-ui {
  display: grid;
  gap: 10px;
}

#interaction-hint {
  position: fixed;
  left: 50%;
  bottom: 138px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.56);
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  z-index: 10;
  min-height: 30px;
  min-width: 120px;
  text-align: center;
}

#touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 11;
}

#touch-controls button,
#stick-left {
  pointer-events: auto;
}

#stick-left {
  position: absolute;
  left: 20px;
  bottom: 20px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.07);
}

#touch-buttons {
  position: absolute;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 10px;
}

#touch-buttons button {
  min-width: 82px;
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid var(--ui-border);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
}

.chat {
  left: 20px;
  top: 20px;
  transform: none;
  min-width: 300px;
  width: min(440px, 45vw);
}

#chat-log {
  min-height: 140px;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  padding: 6px;
  font-size: 12px;
  margin-bottom: 8px;
}

.tiny {
  opacity: 0.85;
  font-size: 11px;
  line-height: 1.4;
}

.hidden {
  display: none !important;
}

@media (max-width: 920px) {
  .bars { bottom: 62px; width: min(92vw, 500px); }

  #hotbar {
    grid-template-columns: repeat(9, 44px);
  }

  .slot {
    height: 44px;
  }

  #mode-pill { top: 6px; left: 6px; }
  #coords { top: 34px; left: 6px; }
  #clock { top: 62px; left: 6px; }
  #minimap { top: 90px; left: 6px; transform: scale(0.9); transform-origin: top left; }
  #interaction-hint { bottom: 124px; }

  #touch-controls {
    display: block;
  }
}
