:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel-bg: #161922ee;
  --border: #2a2e3a;
  --text: #e6e8ec;
  --text-dim: #9aa0ac;
  --accent: #6ea8fe;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

#hud {
  position: fixed;
  top: 16px;
  left: 16px;
  font-size: 13px;
  color: var(--text-dim);
  pointer-events: none;
}

#hud .title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

#hud .hint-text-touch {
  display: none;
}

#hud .quest-hint {
  margin-top: 8px;
  padding: 6px 10px;
  border-left: 2px solid var(--accent);
  background: rgba(110, 168, 254, 0.08);
  color: var(--text);
  font-size: 12px;
  max-width: 360px;
}

#support-banner {
  position: fixed;
  bottom: 16px;
  right: 16px;
  max-width: 280px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
  z-index: 10;
}

/* On a small/landscape-phone screen 280px is a large fraction of the width, and it was
   overlapping the dialogue panel's input/send button (confirmed via elementFromPoint: taps
   on the right ~40% of #dialogue-input were landing on this banner instead, since it had an
   explicit z-index while #dialogue-panel had none -- explicit z-index always wins over
   z-index:auto regardless of DOM order). Shrinking it and hiding it while a conversation is
   open (it's non-essential chrome, not something a player mid-conversation needs) removes
   the overlap instead of just reshuffling which element wins it. */
@media (max-width: 820px), (max-height: 480px) {
  #support-banner {
    max-width: 180px;
    padding: 6px 10px;
    font-size: 10.5px;
    bottom: 8px;
    right: 8px;
  }
}

body.dialogue-open #support-banner {
  display: none;
}

#support-banner a {
  color: var(--accent);
  text-decoration: none;
}

#support-banner a:hover {
  text-decoration: underline;
}

#support-banner .close-btn {
  position: absolute;
  top: 4px;
  right: 6px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1;
  pointer-events: auto;
}

#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: rgba(230, 232, 236, 0.8);
  pointer-events: none;
}

#interact-prompt {
  position: fixed;
  bottom: 22%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  pointer-events: none;
  backdrop-filter: blur(6px);
}

#interact-prompt[hidden] { display: none; }

#interact-prompt kbd {
  background: var(--accent);
  color: #0f1115;
  border-radius: 4px;
  padding: 1px 7px;
  font-weight: 700;
  font-family: inherit;
}

#dialogue-panel {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  width: min(640px, 88vw);
  /* Above #support-banner (z-index 10) and the touch joystick/look zones (z-index 30/31) --
     an open conversation is the one thing on screen that should never lose a tap to
     background chrome underneath it. */
  z-index: 50;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  backdrop-filter: blur(10px);
  animation: rise-in 0.15s ease-out;
  /* Caps the panel's own height so it can never be taller than the visible viewport --
     without this, a tall dialogue-log + header + input on a short landscape-phone screen
     (~375-420px tall) could make the panel itself exceed what's on screen, independent of
     the keyboard-overlap problem #dialogue-panel-bottom-offset (set from JS, see
     touch-controls.js) solves for. max-height + overflow-y here, not on the panel itself
     being scrollable as a whole, since the header/input must stay visible/reachable --
     only the log scrolls (see #dialogue-log below).
  */
  max-height: min(360px, 70vh);
  display: flex;
  flex-direction: column;
}

/* On a short landscape-phone screen (~375-420px tall is the phone-in-landscape range this
   game is locked to via the rotate overlay) the desktop sizing above is still too tall and
   leaves too little of the 3D scene visible/no room once the on-screen keyboard opens.
   Tighter padding/gaps and a shorter log cap keep the whole panel comfortably above a
   keyboard on the shortest real devices (iPhone SE landscape is 375px). */
@media (max-height: 480px) {
  #dialogue-panel {
    padding: 10px 14px;
    max-height: min(220px, 60vh);
    bottom: 12px;
  }

  #dialogue-panel-header {
    margin-bottom: 4px;
  }

  #dialogue-log {
    max-height: none;
    flex: 1;
    margin-bottom: 8px;
  }

  #dialogue-hint {
    display: none;
  }
}

@keyframes rise-in {
  from { transform: translate(-50%, 16px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

#dialogue-panel[hidden] { display: none; }

#dialogue-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

#dialogue-npc-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#dialogue-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 0 0 12px;
}

#dialogue-close:hover {
  color: var(--text);
}

#dialogue-log {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
  /* #dialogue-panel is now a flex column with its own max-height (see above) so this can
     grow to fill the remaining space instead of using its own fixed max-height once the
     short-screen media query below takes over layout -- min-height: 0 is required for a
     flex child to actually shrink/scroll within its parent instead of forcing the parent
     to grow past its max-height to fit this element's content. */
  min-height: 0;
}

.dialogue-line {
  font-size: 14px;
  line-height: 1.5;
}

.dialogue-line.player {
  color: var(--text-dim);
  font-style: italic;
}

.dialogue-line.npc {
  color: var(--text);
}

.dialogue-line.system {
  color: #e5735a;
  font-size: 12px;
}

#dialogue-form {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

#dialogue-input {
  flex: 1;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

#dialogue-input:focus {
  outline: none;
  border-color: var(--accent);
}

#dialogue-form button {
  background: var(--accent);
  color: #0f1115;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

#dialogue-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-dim);
}

/* ---- Voice (voice-io.js): mic button and status line inside the same dialogue panel ---- */

#dialogue-form #mic-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#dialogue-form #mic-button svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

#dialogue-form #mic-button[hidden] { display: none; }

#dialogue-form #mic-button.recording {
  background: #e5735a;
  border-color: #e5735a;
  color: #0f1115;
}

#scene-status {
  font-size: 12px;
  color: var(--text-dim);
  margin: -4px 0 10px;
}

#scene-status[hidden] { display: none; }

/* Group conversation lines (tavern.html): who said it, reactions, actions, cut-off lines. */
.dialogue-line .speaker {
  font-weight: 700;
  margin-right: 8px;
}

.dialogue-line .speaker::after { content: ":"; }

.dialogue-line.reaction { margin-left: 14px; }

.dialogue-line.action {
  color: var(--accent);
  font-size: 12px;
}

.mood-tag {
  margin-right: 8px;
  font-size: 11px;
  color: var(--text-dim);
}

.dialogue-line.cut-off {
  opacity: 0.75;
  cursor: help;
}
