html,
body {
  height: 100%;
  margin: 0;
  background: #0b0f14;
  color: #e7eef7;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

#bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0.25;
}

#ui {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  overflow-x: auto;
}

#displayWrap {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  font-size: 13px;
  overflow-x: auto;
}

#hud {
  display: flex;
  gap: 8px;
  align-items: center;
}

.pill {
  padding: 4px 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  font-size: 11px;
}

#bottom {
  display: flex;
  gap: 10px;
  align-items: stretch;
  min-height: 160px;
  max-height: 220px;
}

#log {
  flex: 1;
  min-width: 0;
  overflow: auto;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  font-size: 12px;
  line-height: 1.3;
}

#inv {
  width: 320px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
}

#inv h2 {
  margin: 0 0 6px 0;
  font-size: 13px;
  letter-spacing: 0.02em;
  font-weight: 700;
  color: #cfe6ff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#invMeta {
  font-size: 11px;
  color: #b7c7da;
  margin-bottom: 6px;
}

#invList {
  margin: 0;
  padding: 0 0 0 12px;
  font-size: 12px;
  line-height: 1.3;
}

#invList li {
  margin: 3px 0;
  word-break: break-word;
}

#help {
  width: 240px;
  flex-shrink: 0;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  color: #b7c7da;
  line-height: 1.3;
  font-size: 11px;
  overflow-y: auto;
}

#help > div {
  margin-bottom: 4px;
}

.tile {
  font-weight: 700;
}

.vinyl {
  color: #ffd56a;
}

.espresso {
  color: #7dffb7;
}

.spray {
  color: #9bc8ff;
}

.scalper {
  color: #ff6b6b;
}

.actually {
  color: #ffb86b;
}

.dust {
  color: #d7d7ff;
}

.exit {
  color: #ff00ff;
  font-weight: bold;
}

.feral {
  color: #00ffff;
  font-weight: bold;
}

.bandage {
  color: #ff6b6b;
}

.elevator_key {
  color: #00ff00;
  font-weight: bold;
}

.identify_scroll {
  color: #ff00ff;
  font-weight: bold;
}

.boss {
  color: #ff0000;
  font-weight: bold;
  font-size: 1.1em;
}

/* Expandable sections */
.collapsible-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
  margin-bottom: 4px;
}

.collapsible-header:hover {
  opacity: 0.8;
}

.collapsible-icon {
  font-size: 14px;
  transition: transform 0.2s;
}

.collapsible-icon.expanded {
  transform: rotate(180deg);
}

.collapsible-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.collapsible-content.expanded {
  max-height: 180px;
  overflow-y: auto;
}

/* ===================================================================== */
/*  Virtual d-pad (touch controls)                                        */
/* ===================================================================== */

/* Hidden by default; revealed on touch devices or small screens. */
#dpad { display: none; }

/* Show on coarse-pointer (touch) OR <=768px screens. */
@media (hover: none) and (pointer: coarse), (max-width: 768px) {
  #dpad {
    display: grid;
    position: fixed;
    right: max(14px, env(safe-area-inset-right, 0px));
    bottom: max(14px, env(safe-area-inset-bottom, 0px));
    width: 168px;
    height: 168px;
    grid-template-areas:
      ".  up    ."
      "lf .     rt"
      ".  dn    .";
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows:    1fr 1fr 1fr;
    gap: 4px;
    z-index: 50;
    pointer-events: none;             /* parent doesn't intercept */
  }
  #dpad .dpad-btn {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.55);
    color: #e7eef7;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 10px;
    font-size: 22px;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    transition: background 0.08s ease, transform 0.06s ease;
    backdrop-filter: blur(2px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    line-height: 1;
  }
  #dpad .dpad-btn.dpad-active {
    background: rgba(140, 220, 255, 0.45);
    transform: scale(0.94);
  }
  .dpad-up    { grid-area: up; }
  .dpad-left  { grid-area: lf; }
  .dpad-right { grid-area: rt; }
  .dpad-down  { grid-area: dn; }

  /* Don't let the d-pad eclipse log/inventory content. */
  #ui { padding-bottom: 190px; }
}

/* ===================================================================== */
/*  Mobile responsive                                                     */
/* ===================================================================== */

@media (max-width: 768px) {
  #ui {
    gap: 6px;
    padding: 8px;
  }

  #hud {
    flex-wrap: wrap;
  }
  .pill {
    font-size: 12px;
    padding: 6px 10px;
  }

  #displayWrap {
    font-size: 12px;
    padding: 6px;
  }

  #bottom {
    flex-direction: column;
    max-height: none;
    min-height: 0;
  }

  #log {
    min-height: 90px;
    max-height: 130px;
    font-size: 12.5px;
  }

  #inv {
    width: 100%;
    max-height: 220px;
  }

  #help {
    width: 100%;
    font-size: 11px;
  }

  #inv h2 {
    font-size: 13px;
    padding: 4px 0;       /* bigger touch target */
  }
  #invList { font-size: 12.5px; line-height: 1.45; }
  #invList li { padding: 2px 0; }

  /* Forms: prevent iOS auto-zoom-on-focus. */
  input[type="text"], input[type="password"], textarea {
    font-size: 16px !important;
  }

  .collapsible-header { padding: 8px 0; font-size: 13px; }
  .collapsible-content.expanded { max-height: 280px; }

  /* The high scores button */
  #highScoresBtn { font-size: 14px !important; padding: 10px !important; }
}

@media (max-width: 480px) {
  #ui {
    padding: 6px;
    padding-bottom: 180px;       /* match d-pad height */
  }
  #inv { padding: 6px; }
  #help { font-size: 10.5px; }
  .pill { font-size: 11px; padding: 5px 8px; }
  /* Slightly smaller d-pad on tiny phones so it doesn't eat the screen. */
  #dpad { width: 144px; height: 144px; }
  #dpad .dpad-btn { font-size: 19px; border-radius: 9px; }
}
