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;
}

.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-theme-toggle {
  position: absolute;
  top: 8px;
  right: 12px;
  z-index: 3;
  display: flex;
  gap: 6px;
  font-size: 11px;
}

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

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

.mystery-transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  position: relative;
  z-index: 2;
  padding-right: 6px;
}

.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;
}

.mystery-transcript .help {
  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 .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;
}

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

.mystery-input {
  flex: 1;
  background: transparent;
  color: var(--m-fg);
  border: none;
  outline: none;
  font: inherit;
  text-shadow: inherit;
  caret-color: var(--m-fg);
}

.mystery-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 0 4px;
  position: relative;
  z-index: 2;
  margin-top: 8px;
}

.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;
  }
}

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