/* Haunted Adventure: dark, haunted presentation */

/* Cover the full viewport with a dark background and light text. */
html,
body {
  height: 100vh;          /* fill at least the whole screen */
  margin: 0;                 /* remove default page margins */
  background-color: #0a0a0a; /* near-black, haunted background */
  color: #33ff66;            /* light gray text, readable on dark */
  overflow: hidden;
}

/* Lay the page out as a column: output grows, input stays at the bottom. */
body {
  display: flex;
  flex-direction: column;
}

/* Wrapper: takes the space #output used to take. The loading screen covers it. */
#output-wrap {
  position: relative;         /* anchor for the loading screen */
  flex: 1;
  min-height: 0;              /* lets #output scroll inside */
  display: flex;
  flex-direction: column;
}

/* Output_Display: monospace, left-aligned, grows with content and scrolls. */
#output {
  flex: 1;                    /* take all space left after the input */
  overflow-y: auto;           /* scroll only when text overflows */
  font-family: monospace;     /* classic terminal look, no external fonts */
  font-size: 18px;
  text-align: left;           /* lines read from the left edge */
  padding: 16px;             /* a little breathing room from the edges */
  padding-bottom: 45vh;
  position: relative;
}

/* The prompt line: ">>" followed by the typing area, side by side. */
#command-form {
  display: flex;
  margin: 0;
  padding: 0;
}

/* While text is typing, hide the prompt but keep its space and focus. */
#command-form.typing {
  opacity: 0;
}

#prompt {
  margin-right: 10px;
}

/* The real input is kept but made invisible. It still receives the typing. */
#command-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  border: none;
  padding: 0;
}

/* Show the typed text, keeping its spaces. */
#typed {
  white-space: pre;
}

/* The cursor is an underscore drawn under the character at the caret. */
#cursor {
  white-space: pre;
  border-bottom: 2px solid #33ff66;
  animation: blink 1s steps(1) infinite;
}

#typed-after {
  white-space: pre;
}

@keyframes blink {
  50% {
    border-bottom-color: transparent;
  }
}

/* Status bar: a green strip across the top, like a classic terminal header. */
#status-bar {
  background-color: #33ff66;
  color: #0a0a0a;
  font-family: monospace;
  font-size: 18px;
  padding: 6px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;       /* keep title and room text centered next to the taller button */
}

/* Loading screen: hidden by default, covers only the output area. */
#loading-screen {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
}

/* While the body is "starting", show the screen and hide the output. */
body.starting #loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  padding: 16px;
  box-sizing: border-box;
  text-align: center;
}

body.starting #output {
  visibility: hidden;
}

/* LOADING word and dots stay on one line. JS sets the word's font size. */
#loading-title {
  font-family: monospace;
  color: #33ff66;
  white-space: nowrap;
}

/* Fixed width so the word does not jump as the dots change. */
#loading-dots {
  display: inline-block;
  width: 3ch;
  text-align: left;
}

/* Blinking prompt. */
#loading-prompt {
  font-family: monospace;
  font-size: 18px;
  color: #33ff66;
  margin-top: 32px;
  animation: blink-prompt 1s steps(1) infinite;
}

@keyframes blink-prompt {
  50% {
    opacity: 0;
  }
}

/* Small, dim skip hint. */
#loading-hint {
  font-family: monospace;
  font-size: 14px;
  color: #1f9940;
  opacity: 0.7;
  margin-top: 12px;
}

/* Hidden but still takes its space, so nothing moves when it appears. */
.loading-hidden {
  visibility: hidden;
}

/* Sound toggle: a plain button styled to fit the green status bar. */
#sound-toggle {
  font-family: monospace;
  font-size: 18px;
  color: #0a0a0a;            /* dark text, readable on the green bar */
  background: transparent;   /* let the green bar show through */
  border: 2px solid #0a0a0a;
  min-width: 44px;           /* tap area at least 44 x 44 px */
  min-height: 44px;
  cursor: pointer;
}

/* Visible outline when the button is reached with the Tab key. */
#sound-toggle:focus-visible {
  outline: 2px solid #0a0a0a;
  outline-offset: 2px;
}

#status-info {
  margin-left: 0;
  margin-right: 16px;
}

@media (max-width: 600px) {
  #status-bar {
    flex-wrap: wrap;
    font-size: 14px;
  }

  #sound-toggle {
    font-size: 14px;
  }

  /* Smaller text so the prompt fits at 320px */
  #loading-prompt {
    font-size: 13px;
  }

  #loading-hint {
    font-size: 11px;
  }
}

/* No blinking for players who prefer less motion. */
@media (prefers-reduced-motion: reduce) {
  #loading-prompt {
    animation: none;
  }

  /* Static flame, no pickup flash. */
  .carried-icon.flash {
    animation: none;
  }

  .carried-icon.lamp-lit .px-l {
    animation: none;
  }
}

/* The page itself never scrolls. Only the output box does. */
html,
body {
  height: 100%;
  overflow: hidden;
}

/* Phones: use the visible height, not the height under the address bar. */
body {
  height: 100vh;
  height: 100dvh;
}

/* The header keeps its size and stays pinned at the top. */
#header {
  flex: 0 0 auto;
  position: sticky;
  top: 0;
  z-index: 20;
}

/* Inventory strip: one row with a label and the carried icons. */
/* Inventory strip: a small dark pocket in the green header, holding the backpack and the carried items. */
#inventory-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  box-sizing: border-box;
  height: 38px;
  /* always the same height, 0 to 6 items */
  padding: 3px 8px;
  margin-left: auto;
  /* pushes the pocket right, before the room and fear text */
  margin-right: 12px;
  background-color: #0a0a0a;
  /* dark, so the icons read well on the green bar */
  border-radius: 8px;
  overflow: hidden;
}

/* Hide the strip while the loading screen shows (body has "starting"). */
body.starting #inventory-strip {
  display: none;
}

/* The backpack is dim when empty and bright when it holds something. */
.strip-pack.pack-empty {
  opacity: 0.5;
}
/* One carried icon. It may shrink, but never below 24px. */
.carried-icon {
  flex: 0 1 var(--icon-size, 32px);
  min-width: 24px;
  max-width: var(--icon-size, 32px);
  aspect-ratio: 1 / 1;
}

/* The drawing fills its square box. */
.carried-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Pickup flash: one short brightening. The length comes from --flash-ms. */
.carried-icon.flash {
  animation: icon-flash var(--flash-ms, 600ms) ease-out 1;
}

@keyframes icon-flash {
  from { background-color: #33ff66; box-shadow: 0 0 8px #33ff66; }
  to   { background-color: transparent; box-shadow: none; }
}

/* Lit lamp: only its flame cells (the letter "l") flicker. */
.carried-icon.lamp-lit .px-l {
  animation: flame-flicker 1.6s ease-in-out infinite;
}

@keyframes flame-flicker {
  50% { opacity: 0.55; }
}

/* Anything that sticks out of the output area is clipped here, so it
   cannot stretch the page. */
#output-wrap {
  overflow: hidden;
}

/* When the output box hits its end, do not pass the scrolling on to the page. */
#output {
  overscroll-behavior: contain;
}

/* The hidden typing box stays inside the prompt line and can't be clicked. */
#command-form {
  position: relative;
}

#command-input {
  left: 0;
  top: 0;
  pointer-events: none;
}

/* Skull sound switch */
#sound-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 44px;
  padding: 0 2px;
  border: none;
  background: transparent;
  color: #0a0a0a;
  font-family: monospace;
  font-size: 14px;
  cursor: pointer;
}

.sw-track {
  position: relative;
  display: block;
  box-sizing: border-box;
  width: 66px;
  height: 34px;
  border: 2px solid #0a0a0a;
  border-radius: 17px;
  background: #0a0a0a;
  transition: box-shadow 0.2s;
}

.sw-knob {
  position: absolute;
  top: 1px;
  left: 2px;
  width: 28px;
  height: 28px;
  transition: left 0.2s, transform 0.2s;
}

.sw-knob svg {
  display: block;
  width: 100%;
  height: 100%;
}

.sw-crack {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  pointer-events: none;
}

.sw-crack path {
  fill: none;
  stroke: #6b6b6b;
  stroke-width: 2;
}

/* ON: green glow, skull on the right with its mouth open. */
#sound-toggle.sound-on .sw-track {
  box-shadow: inset 0 0 9px #33ff66;
}

#sound-toggle.sound-on .sw-knob {
  left: 32px;
}

/* OFF: dull cracked track, skull tilted on the left with its mouth stitched shut. */
#sound-toggle.sound-off .sw-track {
  background: #1d1d1d;
}

#sound-toggle.sound-off .sw-crack {
  display: block;
}

#sound-toggle.sound-off .sw-knob {
  transform: rotate(-14deg) translateY(2px);
  filter: grayscale(0.6) brightness(0.8);
}

@media (max-width: 600px) {
  .sw-label {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {

  .sw-track,
  .sw-knob {
    transition: none;
  }
}