html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

:root[data-mystery-theme='amber'] {
  --m-bg: #1a0d00;
  --m-fg: #ffb000;
  --m-accent-1: #ffb000;
  --m-accent-2: #ffb000;
  --m-dim: rgba(255, 176, 0, 0.55);
  --m-bezel: #0a0500;
  --m-divider-style: dashed;
}

:root[data-mystery-theme='ansi'] {
  --m-bg: #000080;
  --m-fg: #ffffff;
  --m-accent-1: #ffff55;
  --m-accent-2: #55ffff;
  --m-dim: #aaaaaa;
  --m-bezel: #000040;
  --m-divider-style: double;
}

:root[data-mystery-cursor='bar'],
:root:not([data-mystery-cursor]) {
  --m-cursor-preview: '|';
  --m-cursor-preview-size: 1em;
  --m-cursor-preview-weight: normal;
  --m-cursor-preview-offset: 0;
}

:root[data-mystery-cursor='block'] {
  --m-cursor-preview: '█';
  --m-cursor-preview-size: 0.9em;
  --m-cursor-preview-weight: normal;
  --m-cursor-preview-offset: 0;
}

:root[data-mystery-cursor='underscore'] {
  --m-cursor-preview: '_';
  --m-cursor-preview-size: 1.15em;
  --m-cursor-preview-weight: bold;
  --m-cursor-preview-offset: 0.18em;
}

.mystery-root {
  position: fixed;
  inset: 0;
  height: 100dvh;
  min-height: 0;
  background: var(--m-bezel);
  color: var(--m-fg);
  font-family: 'Courier New', 'Cascadia Mono', 'Consolas', monospace;
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0.02em;
  display: flex;
  flex-direction: column;
  padding: 16px;
  box-sizing: border-box;
  text-shadow: 0 0 1.5px currentColor;
}

.mystery-bezel {
  flex: 1;
  min-height: 0;
  background: var(--m-bg);
  border-radius: 6px;
  padding: 22px 26px 14px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.55);
}

.mystery-footer {
  position: relative;
  z-index: 2;
  padding: 8px 4px 0;
  color: var(--m-dim);
  font-size: 11px;
  line-height: 1.35;
  text-align: center;
}

.mystery-footer a {
  color: var(--m-fg);
  text-decoration: none;
}

.mystery-footer span {
  margin: 0 0.5ch;
}

.mystery-bezel::before {
  /* scanlines overlay */
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(0, 0, 0, 0.18) 2px,
    rgba(0, 0, 0, 0.18) 3px
  );
  opacity: 0.6;
  z-index: 1;
}

.mystery-options {
  position: absolute;
  top: 8px;
  right: 32px;
  z-index: 3;
  font-size: 11px;
}

.mystery-options-toggle {
  width: 34px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  position: relative;
  padding: 0;
}

.mystery-options-icon {
  width: 23px;
  height: 23px;
  display: block;
  fill: currentColor;
  flex: 0 0 auto;
}

.mystery-options-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  padding: 8px;
  background: var(--m-bg);
  border: 1px solid var(--m-dim);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45);
}

.mystery-options-menu::after {
  content: 'Cursor  ' var(--m-cursor-preview);
  display: block;
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid var(--m-dim);
  color: var(--m-fg);
  font-size: 12px;
  font-weight: var(--m-cursor-preview-weight);
  line-height: 1;
}

.mystery-options-group {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.mystery-options-group + .mystery-options-group {
  margin-top: 8px;
}

.mystery-options-label {
  flex: 0 0 100%;
  color: var(--m-dim);
}

.mystery-options button {
  background: transparent;
  color: var(--m-dim);
  border: 1px solid var(--m-dim);
  border-radius: 2px;
  padding: 2px 6px;
  font: inherit;
  cursor: pointer;
}

.mystery-options .mystery-options-toggle {
  padding: 0;
}

.mystery-options button[aria-pressed='true'],
.mystery-options-toggle[aria-expanded='true'] {
  color: var(--m-fg);
  border-color: var(--m-fg);
}

.mystery-transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--m-dim) var(--m-bg);
  scrollbar-width: thin;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  position: relative;
  z-index: 2;
  padding-right: 6px;
}

.mystery-transcript::-webkit-scrollbar {
  width: 6px;
}

.mystery-transcript::-webkit-scrollbar-track {
  background: var(--m-bg);
  border: 0;
}

.mystery-transcript::-webkit-scrollbar-thumb {
  background: var(--m-dim);
  border: 0;
}

.mystery-transcript > div {
  max-width: 80ch;
}

.mystery-transcript .system {
  color: var(--m-accent-1);
  font-weight: bold;
  margin-top: 0.6em;
}

.mystery-transcript .ascii-art {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
  font-size: clamp(9px, 2vw, 14px);
  line-height: 1.1;
  margin-bottom: 0.75em;
}

.mystery-transcript .help {
  position: relative;
  color: var(--m-fg);
  font-weight: normal;
  border: 1px var(--m-divider-style) var(--m-dim);
  padding: 0.75em;
  margin: 0.75em 0;
}

.mystery-transcript .help .mystery-help-body {
  padding-right: 3ch;
}

.mystery-transcript .help .mystery-help-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--m-fg);
  border: 1px solid var(--m-dim);
  border-radius: 2px;
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

.mystery-transcript .help .mystery-help-close:hover,
.mystery-transcript .help .mystery-help-close:focus-visible {
  border-color: var(--m-fg);
  outline: none;
}

.mystery-transcript .player {
  color: var(--m-accent-2);
}

.mystery-transcript .player::before { content: '> '; }

.mystery-transcript .narration {
  margin: 0.25em 0;
}

.mystery-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  position: relative;
  z-index: 2;
  min-height: 1.45em;
  cursor: text;
}

.mystery-input-row::before {
  content: '>';
  color: var(--m-accent-2);
  flex: 0 0 auto;
}

.mystery-input {
  position: absolute;
  inset: 0;
  width: 100%;
  min-width: 0;
  opacity: 0;
  color: transparent;
  caret-color: transparent;
  background: transparent;
  border: none;
  outline: none;
  font: inherit;
}

.mystery-input-display {
  flex: 1;
  min-width: 0;
  color: var(--m-fg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  pointer-events: none;
}

.mystery-input-display[data-placeholder='true'] {
  color: var(--m-dim);
  font-style: italic;
}

.mystery-input-display::after {
  content: var(--m-cursor-preview);
  display: inline-block;
  color: var(--m-fg);
  font-size: var(--m-cursor-preview-size);
  font-style: normal;
  font-weight: var(--m-cursor-preview-weight);
  line-height: 1;
  transform: translateY(var(--m-cursor-preview-offset));
  margin-left: 0.1ch;
  opacity: 0;
}

.mystery-input:focus + .mystery-input-display::after {
  animation: mystery-cursor-blink 1.05s steps(1, end) infinite;
}

@keyframes mystery-cursor-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.mystery-controls {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  position: relative;
  z-index: 2;
  margin-top: 8px;
}

.mystery-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 0 4px;
  min-width: 0;
  flex: 1 1 auto;
}

.mystery-light-meter {
  flex: 0 0 auto;
  width: 98px;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  color: var(--m-fg);
  opacity: 0.8;
}

.mystery-light-meter[data-lit='true'] {
  color: var(--m-fg);
  opacity: 1;
}

.mystery-light-icon {
  width: 30px;
  height: 30px;
  display: block;
  color: var(--m-dim);
  opacity: 0.85;
}

.mystery-light-icon svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: currentColor;
}

.mystery-light-leds {
  width: 100%;
  display: flex;
  gap: 4px;
  justify-content: center;
}

.mystery-light-segment {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--m-dim);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15) inset;
  opacity: 0.45;
}

.mystery-light-segment[data-segment-state='lit'] {
  background: currentColor;
  opacity: 1;
  box-shadow: 0 0 7px currentColor;
}

.mystery-light-meter[data-lit='true'] .mystery-light-icon {
  color: var(--m-fg);
  opacity: 1;
  filter: drop-shadow(0 0 2px currentColor) drop-shadow(0 0 6px currentColor);
}

.mystery-chip {
  background: transparent;
  color: var(--m-fg);
  border: 1px solid var(--m-fg);
  border-radius: 2px;
  padding: 3px 7px;
  font: inherit;
  cursor: pointer;
  font-size: 11px;
}

.mystery-chip[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
}

.mystery-transcript .ending {
  margin-top: 2em;
  margin-bottom: 1em;
  padding-top: 1em;
  border-top: 1px solid currentColor;
  font-style: italic;
  white-space: pre-wrap;
}

@media (max-width: 640px) {
  .mystery-root {
    padding: 8px;
    font-size: 13px;
  }

  .mystery-bezel {
    padding: 18px 14px 12px;
  }

  .mystery-transcript .ascii-art {
    font-size: clamp(7px, 2.35vw, 10px);
  }

  .mystery-chip {
    padding: 4px 7px;
  }

  .mystery-controls {
    gap: 10px;
  }

  .mystery-light-meter {
    width: 90px;
  }

  .mystery-light-icon {
    width: 27px;
    height: 27px;
  }
}

[data-mystery-input].ended {
  opacity: 0.55;
}
