/* styles.css */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  overflow: hidden;
  cursor: none;
  background: #000;
  font-family: Courier New, monospace;
}

canvas {
  display: block;
}

#hud {
  position: fixed;
  pointer-events: none;
  z-index: 10;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

#crosshair {
  position: absolute;
  color: #fff;
  text-shadow: 0 0 2px #000;
  user-select: none;
  font-size: 24px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

#hotbar {
  position: absolute;
  display: flex;
  gap: 4px;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
}

.hotbar-slot {
  display: flex;
  color: #fff;
  text-align: center;
  position: relative;
  background: #0009;
  border: 2px solid #555;
  justify-content: center;
  align-items:  center;
  width: 50px;
  height: 50px;
  font-size: 10px;
}

.hotbar-slot.selected {
  background: #fff3;
  border-color: #fff;
}

.hotbar-slot .slot-number {
  position: absolute;
  color: #aaa;
  font-size: 9px;
  top: 2px;
  left: 4px;
}

.hotbar-slot .block-name {
  display: none;
}

.block-preview {
  image-rendering: pixelated;
  width: 32px;
  height: 32px;
}

#info {
  position: absolute;
  color: #fff;
  text-shadow: 1px 1px 1px #000;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  top: 10px;
  left: 10px;
}

#chat {
  position: absolute;
  color: #fff;
  text-shadow: 1px 1px 2px #000;
  display: flex;
  overflow-y: auto;
  pointer-events: auto;
  flex-direction: column;
  gap: 4px;
  max-width: 550px;
  max-height: 300px;
  font-size: 14px;
  bottom: 90px;
  left: 10px;
}

.chat-msg {
  background: #00000080;
  border-radius: 4px;
  padding: 6px 10px;
  line-height: 1.3;
}

.chat-msg b {
  color: #ffdd57;
}

#chat-input {
  position: absolute;
  color: #fff;
  outline: none;
  display: none;
  pointer-events: auto;
  z-index: 20;
  background: #000000b3;
  border: 2px solid #ffffff4d;
  border-radius: 4px;
  width: 540px;
  padding: 8px 12px;
  font-family: Courier New, monospace;
  font-size: 16px;
  bottom: 80px;
  left: 10px;
}

#chat-input:focus {
  border-color: #ffdd5799;
}

#chat-input.active {
  display: block;
}

@keyframes chatFade {
  0%, 70% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

#menu {
  position: fixed;
  display: flex;
  color: #fff;
  z-index: 100;
  cursor: default;
  background: radial-gradient(at 50% 0%, #5b873126 0%, #0000 60%), #000000e6;
  flex-direction: column;
  justify-content: center;
  align-items:  center;
  gap: 28px;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

#menu-title {
  text-align: center;
  position: relative;
}

#title-shadow {
  position: absolute;
  letter-spacing: 6px;
  color: #2a3f15;
  -webkit-text-stroke: 0;
  text-shadow: 0 6px 20px #000c;
  pointer-events: none;
  user-select: none;
  font-size: 72px;
  font-weight: bold;
  top: 4px;
  left: 0;
  right: 0;
}

#menu h1 {
  color: #6db33a;
  text-shadow: 0 0 40px #6db33a4d, 3px 3px #3b5721, -1px -1px #8dd35f;
  letter-spacing: 6px;
  position: relative;
  font-size: 72px;
}

#menu-subtitle {
  color: #6a8a4a;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-top: 8px;
  font-size: 14px;
}

#menu-online {
  color: #6a8a4a;
  letter-spacing: 2px;
  display: flex;
  align-items:  center;
  gap: 8px;
  font-size: 13px;
}

#menu-online .online-dot {
  display: inline-block;
  animation: pulse 2s ease-in-out infinite;
  background: #6db33a;
  border-radius: 50%;
  width: 8px;
  height: 8px;
  box-shadow: 0 0 6px #6db33a99;
}

#menu-card {
  display: flex;
  backdrop-filter: blur(8px);
  background: #ffffff0a;
  border: 1px solid #ffffff14;
  border-radius: 12px;
  flex-direction: column;
  align-items:  center;
  gap: 14px;
  padding: 28px 40px;
}

#name-label {
  text-transform: uppercase;
  letter-spacing: 3px;
  color: #7a9a5a;
  align-self:  flex-start;
  margin-left: 4px;
  font-size: 11px;
}

.menu-input {
  color: #fff;
  letter-spacing: 2px;
  text-align: center;
  outline: none;
  background: #00000080;
  border: 2px solid #6db33a4d;
  border-radius: 8px;
  width: 300px;
  padding: 14px 24px;
  transition: border-color .2s, box-shadow .2s, background .2s;
  font-family: Courier New, monospace;
  font-size: 20px;
}

.menu-input::placeholder {
  color: #555;
  letter-spacing: 1px;
}

.menu-input:focus {
  background: #000000b3;
  border-color: #6db33a;
  box-shadow: 0 0 20px #6db33a26;
}

.menu-btn {
  color: #fff;
  cursor: pointer;
  letter-spacing: 3px;
  text-transform: uppercase;
  position: relative;
  overflow: hidden;
  background: linear-gradient(#6db33a66 0%, #3b572166 100%);
  border: 2px solid #5b8731;
  border-radius: 8px;
  width: 300px;
  padding: 14px 48px;
  transition: all .2s;
  font-family: Courier New, monospace;
  font-size: 20px;
}

.menu-btn .btn-icon {
  margin-right: 6px;
  font-size: 14px;
}

.menu-btn:hover {
  background: linear-gradient(#6db33a99 0%, #5b873180 100%);
  border-color: #7bb741;
  transform: translateY(-1px);
  box-shadow: 0 0 24px #6db33a33;
}

.menu-btn:active {
  box-shadow: none;
  transform: translateY(1px);
}

.menu-btn.hidden {
  display: none;
}

#customizer {
  display: flex;
  align-items:  flex-start;
  gap: 16px;
}

#preview-canvas {
  background: #0006;
  border: 1px solid #ffffff14;
  border-radius: 8px;
}

#swatch-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.swatch-category label {
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #7a9a5a;
  display: block;
  margin-bottom: 4px;
  font-size: 10px;
}

.swatch-row, .model-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.model-btn {
  color: #aaa;
  cursor: pointer;
  letter-spacing: 1px;
  background: #ffffff0f;
  border: 2px solid #ffffff26;
  border-radius: 10px;
  padding: 3px 8px;
  transition: transform .15s, border-color .15s, color .15s;
  font-family: Courier New, monospace;
  font-size: 10px;
}

.model-btn:hover {
  color: #fff;
  border-color: #ffffff80;
  transform: scale(1.08);
}

.model-btn.selected {
  color: #fff;
  background: #6db33a26;
  border-color: #6db33a;
  box-shadow: 0 0 6px #6db33a80;
}

.swatch {
  cursor: pointer;
  border: 2px solid #ffffff26;
  border-radius: 4px;
  width: 24px;
  height: 24px;
  transition: transform .15s, border-color .15s;
}

.swatch:hover {
  border-color: #ffffff80;
  transform: scale(1.2);
}

.swatch.selected {
  border-color: #6db33a;
  box-shadow: 0 0 6px #6db33a80;
}

#controls-help {
  display: flex;
  flex-direction: column;
  align-items:  center;
  gap: 8px;
}

.controls-row {
  display: flex;
  color: #666;
  align-items:  center;
  gap: 6px;
  font-size: 12px;
}

.controls-row .key {
  display: inline-block;
  color: #999;
  letter-spacing: 1px;
  background: #ffffff14;
  border: 1px solid #ffffff1f;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: bold;
}

.controls-row .key-sep {
  background: #ffffff1a;
  width: 1px;
  height: 14px;
  margin: 0 4px;
}

#menu-footer {
  position: absolute;
  color: #444;
  letter-spacing: 2px;
  font-size: 11px;
  bottom: 16px;
}

#menu-footer a {
  color: #6a8a4a;
  text-decoration: none;
  transition: color .2s;
}

#menu-footer a:hover {
  color: #6db33a;
  text-decoration: underline;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }

  50% {
    opacity: .5;
  }
}

#crafting-screen {
  position: fixed;
  z-index: 200;
  color: #fff;
  cursor: default;
  overflow-y: auto;
  background: #1e1e1ef2;
  border: 3px solid #555;
  max-height: 80vh;
  padding: 20px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

#crafting-screen.hidden {
  display: none;
}

#crafting-screen h2 {
  text-align: center;
  margin-bottom: 12px;
}

#crafting-screen h3 {
  color: #aaa;
  margin-bottom: 8px;
  font-size: 14px;
}

.craft-area {
  display: flex;
  justify-content: center;
  align-items:  center;
  gap: 16px;
  margin-bottom: 12px;
}

.craft-grid {
  display: grid;
  gap: 4px;
}

.craft-slot {
  display: flex;
  cursor: pointer;
  position: relative;
  background: #00000080;
  border: 2px solid #444;
  flex-direction: column;
  justify-content: center;
  align-items:  center;
  width: 50px;
  height: 50px;
}

.craft-slot:hover {
  background: #ffffff26;
  border-color: #fff;
}

.craft-slot-name {
  color: #aaa;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 48px;
  margin-top: 1px;
  font-size: 7px;
}

.craft-arrow {
  color: #888;
  user-select: none;
  font-size: 32px;
}

.craft-output {
  display: flex;
  cursor: pointer;
  position: relative;
  background: #5b873133;
  border: 2px solid #5b8731;
  flex-direction: column;
  justify-content: center;
  align-items:  center;
  width: 60px;
  height: 60px;
}

.craft-output:hover {
  background: #5b873166;
  border-color: #7bb741;
}

.craft-output-count {
  color: #ffdd57;
  font-size: 11px;
  font-weight: bold;
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(9, 50px);
  gap: 4px;
}

.inventory-slot {
  display: flex;
  color: #fff;
  text-align: center;
  cursor: pointer;
  position: relative;
  background: #00000080;
  border: 2px solid #444;
  flex-direction: column;
  justify-content: center;
  align-items:  center;
  width: 50px;
  height: 50px;
  font-size: 9px;
}

.inventory-slot:hover {
  background: #ffffff26;
  border-color: #fff;
}

.inventory-slot.empty {
  opacity: .4;
  cursor: default;
}

.slot-count {
  position: absolute;
  color: #ffdd57;
  text-shadow: 1px 1px 1px #000;
  font-size: 10px;
  font-weight: bold;
  bottom: 2px;
  right: 4px;
}

#oxygen-bar {
  position: absolute;
  overflow: hidden;
  background: #00000080;
  border: 1px solid #ffffff4d;
  border-radius: 4px;
  width: 200px;
  height: 8px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, 30px);
}

#oxygen-bar.hidden {
  display: none;
}

#oxygen-fill {
  background: #4af;
  border-radius: 3px;
  width: 100%;
  height: 100%;
  transition: width .2s, background-color .3s;
}

#oxygen-fill.low {
  background: #f44;
}

#oxygen-text {
  position: absolute;
  color: #8cf;
  text-shadow: 1px 1px 1px #000;
  font-size: 11px;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
}

#death-screen {
  position: fixed;
  display: flex;
  color: #fff;
  z-index: 150;
  pointer-events: auto;
  cursor: pointer;
  background: #b4000099;
  flex-direction: column;
  justify-content: center;
  align-items:  center;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

#death-screen.hidden {
  display: none;
}

#death-screen h2 {
  text-shadow: 2px 2px 4px #000;
  margin-bottom: 16px;
  font-size: 48px;
}

#death-screen p {
  animation: pulse 2s infinite;
  font-size: 18px;
}

#time-display {
  position: absolute;
  color: #fff;
  text-shadow: 1px 1px 1px #000;
  font-size: 14px;
  top: 10px;
  right: 10px;
}

#water-overlay {
  position: fixed;
  pointer-events: none;
  z-index: 5;
  display: none;
  background: #1e50b44d;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

#water-overlay.active {
  display: block;
}

#touch-controls {
  position: fixed;
  pointer-events: none;
  z-index: 40;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

.touch-joystick-base {
  position: fixed;
  pointer-events: none;
  opacity: .5;
  z-index: 42;
  background: #ffffff14;
  border: 2px solid #fff3;
  border-radius: 50%;
  width: 120px;
  height: 120px;
  transition: opacity .15s;
}

.touch-joystick-base.active {
  opacity: .9;
}

.touch-joystick-left {
  bottom: 80px;
  left: 24px;
}

.touch-joystick-right {
  bottom: 80px;
  right: 24px;
}

.touch-joystick-knob {
  position: absolute;
  background: #ffffff4d;
  border: 2px solid #ffffff80;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.touch-btn-jump, .touch-btn-break, .touch-btn-place, .touch-btn-inventory, .touch-btn-chat {
  position: fixed;
  display: flex;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  z-index: 45;
  background: #ffffff1a;
  border: 2px solid #ffffff40;
  border-radius: 50%;
  justify-content: center;
  align-items:  center;
  width: 56px;
  height: 56px;
  transition: background .1s, transform .1s;
}

.touch-btn-icon {
  color: #ffffffb3;
  pointer-events: none;
  font-size: 20px;
}

.touch-btn-jump.active, .touch-btn-break.active, .touch-btn-place.active, .touch-btn-inventory.active, .touch-btn-chat.active {
  background: #ffffff4d;
  transform: scale(.9);
}

.touch-btn-jump {
  width: 64px;
  height: 64px;
  bottom: 160px;
  left: 50%;
  transform: translateX(-50%);
}

.touch-btn-jump .touch-btn-icon {
  font-size: 26px;
}

.touch-btn-break {
  bottom: 100px;
  left: calc(50% - 52px);
}

.touch-btn-place {
  bottom: 100px;
  left: calc(50% - 4px);
}

.touch-btn-inventory {
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: 16px;
}

.touch-btn-chat {
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: 16px;
}

body.is-mobile {
  cursor: default;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

body.is-mobile.game-active, body.is-mobile canvas {
  touch-action: none;
}

body.is-mobile #crosshair, body.is-mobile #controls-help {
  display: none;
}

body.is-mobile #menu {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 24px 16px;
  padding-top: env(safe-area-inset-top, 24px);
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
  justify-content: flex-start;
  gap: 16px;
}

body.is-mobile #menu h1, body.is-mobile #title-shadow {
  letter-spacing: 3px;
  font-size: 40px;
}

body.is-mobile #menu-card {
  box-sizing: border-box;
  width: 100%;
  max-width: 340px;
  padding: 16px 20px;
}

body.is-mobile .menu-input {
  box-sizing: border-box;
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
}

body.is-mobile .menu-btn {
  box-sizing: border-box;
  width: 100%;
  padding: 14px 24px;
  font-size: 18px;
}

body.is-mobile #customizer {
  flex-direction: column;
  align-items:  center;
}

body.is-mobile #preview-canvas {
  width: 120px;
  height: 190px;
}

body.is-mobile #menu-footer {
  position: static;
  padding-bottom: env(safe-area-inset-bottom, 16px);
  margin-top: 16px;
}

body.is-mobile #hotbar {
  pointer-events: auto;
}

#rotate-device {
  display: none;
}

@media (orientation: portrait) {
  body.is-mobile #rotate-device {
    display: flex;
    position: fixed;
    z-index: 9999;
    color: #fff;
    background: #000000f2;
    flex-direction: column;
    justify-content: center;
    align-items:  center;
    gap: 16px;
    width: 100%;
    height: 100%;
    font-family: Courier New, monospace;
    top: 0;
    left: 0;
  }

  body.is-mobile #rotate-icon {
    animation: rotateHint 2s ease-in-out infinite;
    font-size: 64px;
  }

  body.is-mobile #rotate-device p {
    color: #aaa;
    letter-spacing: 1px;
    font-size: 16px;
  }

  @keyframes rotateHint {
    0%, 100% {
      transform: rotate(0);
    }

    50% {
      transform: rotate(90deg);
    }
  }
}

@media (width <= 768px) {
  #menu h1, #title-shadow {
    letter-spacing: 3px;
    font-size: 40px;
  }

  #menu-subtitle {
    letter-spacing: 2px;
    font-size: 11px;
  }

  #menu {
    overflow-y: auto;
    gap: 16px;
    padding: 16px;
  }

  #menu-card {
    width: calc(100% - 32px);
    max-width: 400px;
    padding: 16px 20px;
  }

  .menu-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
  }

  .menu-btn {
    width: 100%;
    padding: 14px 24px;
    font-size: 16px;
  }

  #customizer {
    flex-direction: column;
    align-items:  center;
    width: 100%;
  }

  #preview-canvas {
    width: 120px;
    height: 180px;
  }

  #swatch-controls {
    width: 100%;
  }

  .swatch {
    border-radius: 6px;
    width: 36px;
    height: 36px;
  }

  .model-btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  #chat {
    max-width: calc(100vw - 80px);
    max-height: 150px;
    font-size: 12px;
    bottom: 100px;
  }

  #chat-input {
    width: calc(100vw - 80px);
    font-size: 14px;
    bottom: 90px;
  }

  #info {
    font-size: 10px;
    top: 6px;
    left: 6px;
  }

  #time-display {
    font-size: 11px;
  }

  .hotbar-slot {
    width: 40px;
    height: 40px;
  }

  .block-preview {
    width: 26px;
    height: 26px;
  }

  .hotbar-slot .slot-number {
    font-size: 8px;
  }

  #hotbar {
    gap: 2px;
    bottom: 10px;
  }

  #crafting-screen {
    width: calc(100vw - 20px);
    max-width: 400px;
    max-height: 70vh;
    padding: 12px;
  }

  .inventory-grid {
    grid-template-columns: repeat(9, 1fr);
  }

  .inventory-slot {
    width: auto;
    height: 40px;
  }

  .craft-slot {
    width: 40px;
    height: 40px;
  }

  .craft-output {
    width: 50px;
    height: 50px;
  }

  #death-screen h2 {
    font-size: 32px;
  }

  #death-screen p {
    font-size: 14px;
  }

  #hud {
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }
}
