:root {
  --ui-bg: rgba(12, 14, 20, 0.86);
  --ui-border: rgba(255, 255, 255, 0.14);
  --slot: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0c12;
  color: #f2f4f8;
  font-family: 'Lucida Console', 'Courier New', monospace;
  user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  cursor: crosshair;
}

.hidden {
  display: none !important;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.7);
}

#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  background:
    linear-gradient(#fff, #fff) center / 2px 18px no-repeat,
    linear-gradient(#fff, #fff) center / 18px 2px no-repeat;
  mix-blend-mode: difference;
  opacity: 0.9;
}

#stats {
  position: absolute;
  left: 14px;
  bottom: 88px;
}

.icon-row {
  display: flex;
  gap: 1px;
  height: 20px;
  margin-top: 2px;
}

.icon-row img {
  width: 18px;
  height: 18px;
  image-rendering: pixelated;
}

#topright {
  position: absolute;
  right: 14px;
  top: 12px;
  text-align: right;
  font-size: 14px;
  line-height: 1.5;
}

#clock {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 18px;
  font-weight: bold;
}

#clock img {
  width: 20px;
  height: 20px;
  image-rendering: pixelated;
}

#debug {
  margin-top: 6px;
  font-size: 12px;
  opacity: 0.85;
  white-space: pre;
}

#messages {
  position: absolute;
  left: 14px;
  bottom: 132px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 13px;
}

.msg {
  background: rgba(0, 0, 0, 0.45);
  padding: 3px 8px;
  border-radius: 3px;
  animation: fadeout 4s forwards;
}

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

#hotbar {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  gap: 3px;
  padding: 3px;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid var(--ui-border);
  border-radius: 4px;
}

.slot {
  position: relative;
  width: 48px;
  height: 48px;
  background: var(--slot);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.slot img {
  width: 38px;
  height: 38px;
  image-rendering: pixelated;
}

.slot .count {
  position: absolute;
  right: 3px;
  bottom: 1px;
  font-size: 13px;
  font-weight: bold;
  text-shadow: 1px 1px 0 #000;
}

.slot.selected {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5);
}

#dialog {
  position: absolute;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  width: min(620px, 92vw);
  background: var(--ui-bg);
  border: 2px solid var(--ui-border);
  border-radius: 6px;
  padding: 12px 16px;
  pointer-events: auto;
}

#dialogName {
  color: #ffd94a;
  font-weight: bold;
  margin-bottom: 5px;
}

#dialogText {
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 10px;
}

#dialogOptions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  font-family: inherit;
  font-size: 14px;
  color: #f2f4f8;
  background: #2a3040;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 4px;
  padding: 7px 14px;
  cursor: pointer;
}

button:hover {
  background: #3a4358;
}

button.primary {
  background: #3f7d3a;
  border-color: #77c46f;
}

button.primary:hover {
  background: #4c9646;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

#hurt {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, transparent 40%, rgba(200, 20, 20, 0.55) 100%);
  opacity: 0;
}

#waterOverlay {
  position: absolute;
  inset: 0;
  background: rgba(30, 80, 190, 0.35);
}

#inventory {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

#inventory .panel {
  background: var(--ui-bg);
  border: 2px solid var(--ui-border);
  border-radius: 8px;
  padding: 18px 20px;
}

#inventory h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

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

#invGrid .slot {
  cursor: pointer;
}

.hint {
  margin: 12px 0 0;
  font-size: 12px;
  opacity: 0.7;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #101725 0%, #06080d 100%);
  z-index: 30;
}

.panel {
  max-width: 680px;
  width: min(680px, 92vw);
}

.panel.center {
  text-align: center;
}

.panel h1 {
  margin: 0 0 8px;
  font-size: 46px;
  letter-spacing: 3px;
  color: #8fd46f;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.6);
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 30px;
}

.panel h2.dead {
  color: #e05353;
}

.panel p {
  line-height: 1.6;
  font-size: 14px;
}

.field {
  display: block;
  margin: 18px 0;
  font-size: 14px;
}

.field input {
  font-family: inherit;
  font-size: 14px;
  width: 160px;
  margin-left: 8px;
  padding: 6px 8px;
  color: #f2f4f8;
  background: #1a1f2c;
  border: 2px solid var(--ui-border);
  border-radius: 4px;
}

.buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 16px 0;
}

.controls-help {
  margin-top: 18px;
  font-size: 13px;
  opacity: 0.8;
  text-align: left;
}

.bar {
  width: 100%;
  height: 14px;
  margin-top: 14px;
  background: #1a1f2c;
  border: 2px solid var(--ui-border);
  border-radius: 7px;
  overflow: hidden;
}

#loadBar {
  height: 100%;
  width: 0%;
  background: #5ab552;
  transition: width 0.15s ease-out;
}

.fatal {
  margin-top: 14px;
  color: #ff8a8a;
  font-weight: bold;
  line-height: 1.5;
}

@media (max-width: 640px) {
  .grid {
    grid-template-columns: repeat(9, 34px);
  }
  .slot {
    width: 34px;
    height: 34px;
  }
  .slot img {
    width: 26px;
    height: 26px;
  }
}
