html,
body {
  height: 100%;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--ink);
  cursor: crosshair;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  font-family: var(--font-body);
  user-select: none;
}

#hud-top {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.26em;
  font-size: 15px;
  color: var(--mint-bright);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}

#clock {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(24, 20, 58, 0.72);
  border: 1px solid var(--line);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

#clock::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 10px rgba(240, 180, 78, 0.8);
}

#hud.is-night #clock::before {
  background: var(--lilac);
  box-shadow: 0 0 10px rgba(185, 160, 230, 0.8);
}

#btn-new {
  pointer-events: auto;
  margin-left: auto;
  padding: 7px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(34, 28, 78, 0.8);
  color: var(--cream);
  font: inherit;
  font-size: 12.5px;
  letter-spacing: 0.08em;
  cursor: pointer;
}

#btn-new:hover {
  border-color: var(--mint);
  color: var(--mint-bright);
}

#meta-line {
  position: absolute;
  left: 16px;
  bottom: 118px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: rgba(246, 240, 226, 0.75);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}

#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  transform: translate(-50%, -50%);
}

#crosshair span {
  position: absolute;
  background: rgba(246, 240, 226, 0.92);
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.7);
}

#crosshair span:first-child {
  left: 50%;
  top: 0;
  width: 2px;
  height: 100%;
  transform: translateX(-50%);
}

#crosshair span:last-child {
  top: 50%;
  left: 0;
  height: 2px;
  width: 100%;
  transform: translateY(-50%);
}

#hud.action-break #crosshair {
  animation: pop-break 0.28s ease-out;
}

#hud.action-place #crosshair {
  animation: pop-place 0.28s ease-out;
}

@keyframes pop-break {
  0% { transform: translate(-50%, -50%) scale(1.5); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0.9; }
}

@keyframes pop-place {
  0% { transform: translate(-50%, -50%) scale(0.7); opacity: 0.7; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0.9; }
}

#hotbar {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 14px;
  background: rgba(18, 14, 44, 0.72);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  max-width: min(94vw, 640px);
  overflow-x: auto;
}

.slot {
  position: relative;
  pointer-events: auto;
  width: 62px;
  padding: 6px 4px 5px;
  border-radius: 10px;
  border: 1px solid rgba(58, 49, 115, 0.9);
  background: rgba(27, 23, 64, 0.85);
  text-align: center;
  transition: border-color 0.15s, transform 0.15s;
}

.slot img {
  display: block;
  margin: 0 auto;
  width: 34px;
  height: 34px;
  image-rendering: pixelated;
  border-radius: 4px;
}

.slot-key {
  position: absolute;
  top: 3px;
  left: 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}

.slot-name {
  display: block;
  margin-top: 4px;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.slot.is-selected {
  border-color: var(--mint);
  background: rgba(45, 66, 78, 0.9);
  transform: translateY(-4px);
}

.slot.is-selected .slot-name {
  color: var(--mint-bright);
}

#hint {
  position: absolute;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  font-size: 11px;
  letter-spacing: 0.07em;
  color: rgba(246, 240, 226, 0.55);
  white-space: nowrap;
  max-width: 96vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

#hud.is-locked #hint {
  color: rgba(146, 242, 198, 0.7);
}

#hud.fresh-world::after {
  content: "New world generated";
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(18, 14, 44, 0.85);
  border: 1px solid var(--mint);
  color: var(--mint-bright);
  font-size: 13px;
  letter-spacing: 0.1em;
}

/* start screen */
#start-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(47, 143, 122, 0.28), transparent 60%),
    linear-gradient(160deg, #171235 0%, #101027 60%, #0b0a1e 100%);
  z-index: 5;
}

#start-screen[hidden] {
  display: none;
}

.start-panel {
  width: min(560px, 100%);
  padding: 30px 30px 26px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(43, 35, 96, 0.95), rgba(24, 20, 56, 0.95));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: center;
}

.start-panel h1 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: clamp(30px, 6vw, 46px);
  letter-spacing: 0.18em;
  color: var(--mint-bright);
}

.start-panel p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14.5px;
}

.start-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.start-actions button {
  font: inherit;
  font-size: 15px;
  padding: 12px 22px;
  border-radius: 12px;
  cursor: pointer;
  border: 1px solid transparent;
}

#start-play {
  background: linear-gradient(135deg, var(--mint), var(--jade));
  color: #0c1b18;
  font-weight: 700;
  letter-spacing: 0.06em;
}

#start-new {
  background: transparent;
  border-color: var(--line);
  color: var(--cream);
}

.start-keys {
  margin-top: 18px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.7;
}

/* touch controls */
.touch-ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.touch-ui[hidden] {
  display: none;
}

.touch-pad {
  position: absolute;
  left: 22px;
  bottom: 104px;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  pointer-events: auto;
  background: radial-gradient(circle at 50% 50%, rgba(99, 217, 166, 0.22), rgba(18, 14, 44, 0.55) 70%);
  border: 1px solid rgba(99, 217, 166, 0.5);
  touch-action: none;
}

.touch-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 40% 35%, var(--mint-bright), var(--jade));
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.touch-actions {
  position: absolute;
  right: 18px;
  bottom: 104px;
  display: grid;
  gap: 10px;
}

.touch-btn {
  pointer-events: auto;
  touch-action: none;
  min-width: 92px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(185, 160, 230, 0.55);
  background: rgba(30, 25, 68, 0.78);
  color: var(--cream);
  font: inherit;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.touch-btn.is-active {
  border-color: var(--mint);
  background: rgba(47, 143, 122, 0.6);
}

.touch-place {
  border-color: rgba(99, 217, 166, 0.6);
}

.touch-break {
  border-color: rgba(242, 101, 92, 0.6);
}

@media (max-width: 640px) {
  .slot {
    width: 52px;
  }

  .slot img {
    width: 28px;
    height: 28px;
  }

  #meta-line {
    bottom: 106px;
    font-size: 11px;
  }

  #hint {
    display: none;
  }
}
