*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  background: #111;
  color: #fff;
  font-family: Tahoma, Arial, Helvetica, sans-serif;
  font-weight: 700;
  overflow: hidden;
  height: 100%;
  height: 100dvh;
}
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#layout {
  display: flex;
  flex: 1;
  min-height: 0;
}
#play-window {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: #161616;
  border: 3px solid #000;
  margin: 8px;
  overflow: auto;
}
#main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
}
#sidebar {
  width: 340px;
  flex-shrink: 0;
  background: #1c1c1c;
  border-left: 3px solid #000;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
  padding: 10px 12px 16px;
}
#sidebar h2 {
  margin: 12px 0 4px;
  font-size: 15px;
  letter-spacing: 0.5px;
  color: #ffe566;
  text-shadow: 1px 1px 0 #000;
}
#sidebar h2:first-child { margin-top: 0; }
.side-note {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: #ddd;
  line-height: 1.35;
}
.side-note a { color: #7ec8ff; }
#how-list {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.4;
  color: #eee;
}
#how-list li { margin: 6px 0; }
#topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 6px 12px;
  background: #222;
  border-bottom: 3px solid #000;
  font-size: 16px;
  text-shadow: 1px 1px 0 #000;
  flex-shrink: 0;
}
#title {
  letter-spacing: 2px;
  color: #fff;
}
#hud-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  min-width: 0;
}
#hud-place { color: #ffe566; }
#hud-coords { color: #7ec8ff; }
#hud-online { color: #7dff7d; }
#hud-cpu { color: #7dff7d; }
#top-links {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}
#topbar a { color: #7ec8ff; text-decoration: underline; }
#stage {
  position: relative;
  width: min(100%, 960px);
  margin: 8px auto;
  flex: 0 0 auto;
}
#view {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 100%;
  height: auto;
  display: block;
  border: 4px solid #111;
  background: #5d9c3f;
  cursor: default;
  box-shadow: 0 0 0 3px #000;
  touch-action: none;
  vertical-align: top;
}
#hover-tip {
  position: absolute;
  left: 8px;
  top: 8px;
  background: rgba(0,0,0,.65);
  color: #fff;
  padding: 2px 8px;
  font-size: 16px;
  font-weight: 700;
  text-shadow: 1px 1px 0 #000;
  pointer-events: none;
}
#hover-tip.hidden { display: none; }
#play-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 2;
}
#xp {
  width: min(420px, 80%);
  text-align: center;
  pointer-events: none;
}
#xp-bar {
  height: 8px;
  background: #3d3d3d;
  border: 2px solid #000;
  margin-top: 2px;
}
#xp-fill {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(#b7ff4a, #4caf00);
}
#hotbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  background: rgba(0,0,0,.45);
  padding: 4px;
  border: 2px solid #000;
  pointer-events: auto;
}
.slot {
  width: 42px;
  height: 42px;
  background: #8b8b8b;
  border: 3px solid #373737;
  box-shadow: inset 2px 2px 0 #fff8, inset -2px -2px 0 #0006;
  color: #fff;
  font: 700 11px Tahoma, Arial, sans-serif;
  position: relative;
  cursor: pointer;
  touch-action: manipulation;
}
.slot.active {
  border-color: #fff;
  outline: 2px solid #000;
}
.slot .n {
  position: absolute;
  top: 0;
  left: 3px;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 1px 1px 0 #000;
}
.slot .lbl {
  position: absolute;
  bottom: 1px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000;
}
#log {
  flex: 0 0 180px;
  min-height: 120px;
  overflow-y: auto;
  background: #000;
  border: 2px solid #555;
  padding: 6px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}
#log .sys { color: #ffff55; }
#log .err { color: #ff5555; }
#log .ok { color: #55ff55; }
#log .emote { color: #ff77ff; }
#say { margin: 8px 0 4px; }
#say label { display: block; font-size: 13px; margin-bottom: 4px; color: #ffe566; }
#say-row { display: flex; gap: 6px; }
#say-input {
  flex: 1;
  min-width: 0;
  background: #000;
  color: #fff;
  border: 2px solid #555;
  padding: 6px;
  font: inherit;
  font-size: 16px;
}
#say button {
  background: #8b8b8b;
  color: #111;
  border: 3px solid #373737;
  padding: 6px 12px;
  font: inherit;
  cursor: pointer;
}
#modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  z-index: 5;
}
#modal.hidden { display: none; }
#panel {
  width: min(480px, 100%);
  max-height: 86vh;
  max-height: 86dvh;
  overflow: auto;
  background: #c6c6c6;
  color: #111;
  border: 4px solid #fff;
  outline: 4px solid #000;
  box-shadow: 8px 8px 0 #000;
  padding: 10px 12px;
  font-size: 16px;
  font-weight: 700;
}
#panel-title {
  background: #8b8b8b;
  color: #fff;
  text-shadow: 2px 2px 0 #000;
  font-size: 18px;
  font-weight: 700;
  padding: 4px 8px;
  margin: -10px -12px 10px;
  border-bottom: 4px solid #000;
}
#panel-body label { display: block; margin: 8px 0 2px; }
#panel-body input, #panel-body textarea, #panel-body select {
  width: 100%;
  box-sizing: border-box;
  background: #fff;
  border: 3px solid #555;
  font: inherit;
  padding: 4px;
  font-size: 16px;
}
#panel-body input[type="color"] { height: 32px; }
#panel-body textarea { min-height: 90px; }
#panel-body .list { margin: 0; padding-left: 18px; }
#panel-body .list li { margin: 4px 0; cursor: pointer; color: #1038a0; }
#panel-body .list li:hover { text-decoration: underline; }
#panel-body .flow {
  display: grid;
  gap: 8px;
}
#panel-body .flow button, #panel-actions button {
  background: #8b8b8b;
  color: #111;
  border: 3px solid #373737;
  box-shadow: inset 2px 2px 0 #fff8, inset -2px -2px 0 #0004;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
#panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
#panel-actions button:hover, #panel-body .flow button:hover { filter: brightness(1.08); }
#panel-actions button.primary { background: #c4a06a; }
#panel-body .list li.picked { color: #6b4a22; font-weight: 700; }
#panel-actions button, #panel-body .flow button {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.btn-hint, #panel-body .flow button small {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: #222;
  opacity: 0.85;
}
.entry {
  border-top: 2px solid #555;
  margin-top: 8px;
  padding-top: 8px;
  overflow-wrap: anywhere;
}
.evm { font-size: 14px; word-break: break-all; }

@media (max-width: 900px) {
  html, body {
    overflow: auto;
    height: auto;
    min-height: 100%;
    min-height: 100dvh;
  }
  #app {
    height: auto;
    min-height: 100dvh;
  }
  #layout {
    flex-direction: column;
    height: auto;
  }
  #play-window {
    margin: 6px;
    overflow: visible;
    flex: none;
    width: auto;
  }
  #stage {
    width: 100%;
    max-width: none;
    margin: 0;
    display: flex;
    flex-direction: column;
  }
  #view {
    width: 100%;
    height: auto;
    flex: none;
  }
  #play-controls {
    position: static;
    pointer-events: auto;
    padding: 8px 6px 10px;
    background: #111;
    border-top: 2px solid #000;
  }
  #xp { width: min(420px, 94%); }
  #hotbar {
    width: 100%;
  }
  .slot {
    width: 44px;
    height: 44px;
  }
  #sidebar {
    width: 100%;
    height: auto;
    border-left: 0;
    border-top: 3px solid #000;
  }
  #log {
    flex: none;
    height: 140px;
  }
  #topbar {
    font-size: 14px;
  }
  #top-links {
    margin-left: 0;
    width: 100%;
  }
  #panel {
    width: 100%;
    max-height: calc(100dvh - 24px);
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  html, body {
    overflow: hidden;
    height: 100dvh;
  }
  #app {
    height: 100dvh;
  }
  #layout {
    flex-direction: row;
    height: auto;
    flex: 1;
    min-height: 0;
  }
  #play-window {
    flex: 1;
    min-width: 0;
    margin: 4px;
    overflow: auto;
    justify-content: flex-start;
  }
  #stage {
    width: 100%;
    margin: 0;
  }
  #sidebar {
    width: min(280px, 38vw);
    border-left: 3px solid #000;
    border-top: 0;
  }
  #log { height: 90px; }
  #play-controls {
    position: static;
  }
  .slot { width: 36px; height: 36px; }
}

@media (max-width: 420px) {
  #title { width: 100%; }
  #hud-stats { width: 100%; gap: 6px 10px; }
  .slot { width: 40px; height: 40px; }
  .slot .lbl { font-size: 9px; }
}
