/* The Stope — Web Terminal
   Mobile-first, dark terminal theme with ruin decay. */

/* --- Utility --- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Reset & Base --- */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0a0a0a;
  --fg: #c8c8c8;
  --fg-dim: #888;
  --fg-accent: #e0d8c0;
  --fg-error: #c87070;
  --fg-system: #607860;
  --fg-italic: #d0c8b0;         /* NPC narration / speech — warm parchment */
  --fg-dim-italic: #706858;     /* system hints — muted earth */
  --border: #333;
  --chip-bg: #1a1a1a;
  --chip-border: #444;
  --chip-hover: #252525;
  --chip-active: #303020;
  --separator-color: #444;
  --input-bg: #111;

  /* Formation bleed — triboluminescence blue-violet (quartz/tourmaline) */
  --formation-color: #7B68EE;
  --formation-glow: rgba(123, 104, 238, 0.15);

  /* Ruin decay — overridden per data-ruin level */
  --ruin-opacity: 1;
  --ruin-text-color: var(--fg);
  --ruin-separator-color: var(--separator-color);
  --ruin-chip-opacity: 1;
  --ruin-formation-bleed: transparent;

  font-size: 16px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ruin-text-color);
}

body {
  font-family: 'Courier New', Courier, monospace;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

/* --- Connection Banner --- */

.banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding: 8px 16px;
  background: #442200;
  color: #ffcc80;
  text-align: center;
  font-size: 0.85rem;
  transition: transform 0.3s ease;
}

.banner--hidden {
  transform: translateY(-100%);
}

/* --- Main Output --- */

#output {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 8px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

#output > * + * {
  margin-top: 0.6em;
}

.scroll-anchor {
  height: 0;
  margin: 0;
  padding: 0;
}

/* Text chunks */

.text {
  line-height: 1.5;
  white-space: pre-line;
  word-wrap: break-word;
  opacity: var(--ruin-opacity);
}

/* --- Base text variants --- */

.text--normal { color: var(--ruin-text-color); }

.text--dim { color: var(--fg-dim); }

.text--bold {
  color: var(--ruin-text-color);
  font-weight: bold;
}

/* NPC narration, speech, authored prose — warm parchment with left border */
.text--italic {
  color: var(--fg-italic);
  font-style: italic;
  border-left: 2px solid #3a3428;
  padding-left: 12px;
  margin-left: 2px;
}

.text--bold_italic {
  color: var(--fg-italic);
  font-style: italic;
  font-weight: bold;
  border-left: 2px solid #3a3428;
  padding-left: 12px;
  margin-left: 2px;
}

/* System hints — parentheticals like "(Recorded in journal.)" */
.text--dim_italic {
  color: var(--fg-dim-italic);
  font-style: italic;
  font-size: 0.9em;
}

.text--accent { color: var(--fg-accent); }

.text--error { color: var(--fg-error); }

.text--system {
  color: var(--fg-system);
  font-size: 0.9em;
}

.text--title {
  color: var(--fg-accent);
  font-weight: bold;
}

.text--strike {
  text-decoration: line-through;
  color: var(--fg-dim);
}

.text--debug {
  color: #555;
  font-size: 0.8em;
}

/* --- Semantic overrides (applied via data attributes in JS) --- */

/* NPC speech (when explicitly tagged) */
.text--npc_speech {
  color: var(--fg-accent);
  font-style: italic;
  border-left: 2px solid var(--fg-accent);
  padding-left: 12px;
  margin-left: 2px;
  background: rgba(224, 216, 192, 0.03);
}

/* Location header */
.text--location_name {
  color: var(--fg-accent);
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.9rem;
}

/* Separator */

.separator {
  border: none;
  text-align: center;
  color: var(--ruin-separator-color);
  margin: 0.4em 0;
  line-height: 1;
  white-space: pre;
  opacity: var(--ruin-opacity);
}

/* ASCII art */

.ascii-art {
  font-size: 0.8rem;
  line-height: 1.2;
  color: var(--fg-dim);
  overflow-x: auto;
  opacity: var(--ruin-opacity);
}

/* Chat messages (talk mode) */

.message {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 4px;
  margin: 4px 0;
  line-height: 1.4;
}

.message--npc {
  align-self: flex-start;
  background: #1a1a18;
  border-left: 2px solid var(--fg-accent);
  color: var(--fg-accent);
}

.message--player {
  align-self: flex-end;
  margin-left: auto;
  background: #141418;
  border-right: 2px solid var(--fg-dim);
  color: var(--fg-dim);
  text-align: right;
}

/* --- Action Bar --- */

#action-bar {
  position: relative;
  z-index: 10;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Chip rows */

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.chip-row--hidden {
  display: none;
}

/* Drawer mode — expands target row for 5+ targets (keyboard height) */
.chip-row--drawer {
  max-height: 40vh;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  animation: drawer-slide-up 150ms ease-out;
}

@keyframes drawer-slide-up {
  from { max-height: 0; opacity: 0; }
  to   { max-height: 40vh; opacity: 1; }
}

/* Chips */

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--fg);
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, opacity 0.3s, border-color 0.15s;
  opacity: var(--ruin-chip-opacity);
  outline: none;
}

.chip:hover {
  background: var(--chip-hover);
}

.chip:active,
.chip--active {
  background: var(--chip-active);
  border-color: var(--fg-accent);
}

.chip:focus-visible {
  border-color: var(--fg-accent);
  box-shadow: 0 0 0 2px rgba(224, 216, 192, 0.3);
}

.chip--disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

/* Chip variants */

.chip--verb { }

.chip--target {
  border-color: #555;
}

.chip--intent {
  color: var(--fg-accent);
  border-color: #554;
}

.chip--topic {
  font-size: 0.8rem;
  color: var(--fg-dim);
  border-color: #444;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  text-align: left;
}

.chip--prompt {
  font-size: 0.8rem;
  color: var(--fg-dim);
  opacity: 0.5;
  font-family: 'Courier New', Courier, monospace;
  letter-spacing: 0.05em;
}

.chip--back {
  font-size: 0.8rem;
  color: var(--fg-dim);
}

/* Chip number badge (keyboard shortcut hint) */

.chip__number {
  display: none;
  font-size: 0.7rem;
  color: var(--fg-dim);
  margin-right: 4px;
}

/* Show number badges on desktop (pointer devices) */
@media (pointer: fine) {
  .chip__number {
    display: inline;
  }
}

/* --- Command Palette (/ to summon) --- */

.command-palette {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 150;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  background: rgba(10, 10, 10, 0.95);
  border-top: 1px solid var(--fg-accent);
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.command-palette--hidden {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}

.command-palette input,
.talk-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--fg);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}

.command-palette input:focus,
.talk-input:focus {
  border-color: var(--fg-accent);
}

.command-palette input::placeholder,
.talk-input::placeholder {
  color: #555;
}

/* Talk-mode inline input (appears in target chip row) */

.talk-input {
  flex: 1 1 100%;
  min-height: 38px;
  font-size: 0.85rem;
  margin-top: 2px;
}

/* --- Action Bar Toggle (desktop) --- */

.action-bar-toggle {
  display: none; /* hidden on mobile — chips are essential */
  position: fixed;
  bottom: 8px;
  right: 8px;
  z-index: 50;
  width: 32px;
  height: 32px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  border-radius: 4px;
  color: var(--fg-dim);
  font-size: 0.75rem;
  cursor: pointer;
  line-height: 32px;
  text-align: center;
}

.action-bar-toggle:hover {
  background: var(--chip-hover);
  color: var(--fg);
}

@media (pointer: fine) {
  .action-bar-toggle {
    display: block;
  }
}

#action-bar.action-bar--minimized {
  max-height: 0;
  overflow: hidden;
  border-top: none;
  padding: 0;
  transition: max-height 0.2s ease;
}

#action-bar {
  transition: max-height 0.3s ease;
  max-height: 400px;
}

/* --- Shortcuts Overlay --- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}

.overlay--hidden {
  display: none;
}

.overlay__content {
  background: #151515;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  max-width: 360px;
  width: 90%;
}

.overlay__content h2 {
  color: var(--fg-accent);
  font-size: 1rem;
  margin-bottom: 16px;
}

.shortcut-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  margin-bottom: 16px;
}

.shortcut-list dt {
  text-align: right;
}

.shortcut-list kbd {
  display: inline-block;
  padding: 2px 6px;
  background: #222;
  border: 1px solid #444;
  border-radius: 3px;
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--fg-accent);
}

.shortcut-list dd {
  color: var(--fg-dim);
  font-size: 0.85rem;
}

.playtest-toggle {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin: 0.8em 0;
  font-size: 0.85rem;
  color: var(--fg-dim);
  cursor: pointer;
}
.playtest-toggle input { cursor: pointer; }

/* --- Ruin Decay Levels --- */

/* Ruin 1-2: Full clarity */
[data-ruin="1"],
[data-ruin="2"] {
  --ruin-opacity: 1;
  --ruin-text-color: #c8c8c8;
  --ruin-separator-color: #444;
  --ruin-chip-opacity: 1;
  --ruin-formation-bleed: transparent;
}

/* Ruin 3: Light dimming */
[data-ruin="3"] {
  --ruin-opacity: 0.88;
  --ruin-text-color: #aaa;
  --ruin-separator-color: #383838;
  --ruin-chip-opacity: 0.9;
  --ruin-formation-bleed: transparent;
}

/* Ruin 4: Moderate dimming — faintest formation hint on separators */
[data-ruin="4"] {
  --ruin-opacity: 0.75;
  --ruin-text-color: #909090;
  --ruin-separator-color: #353040;
  --ruin-chip-opacity: 0.78;
  --ruin-formation-bleed: rgba(123, 104, 238, 0.06);
}

/* Ruin 5: Deep dimming — formation bleeds through separators and borders */
[data-ruin="5"] {
  --ruin-opacity: 0.6;
  --ruin-text-color: #757575;
  --ruin-separator-color: #4a3a6a;
  --ruin-chip-opacity: 0.6;
  --ruin-formation-bleed: rgba(123, 104, 238, 0.12);
}

/* Ruin 6: Near-dissolution — formation asserts itself */
[data-ruin="6"] {
  --ruin-opacity: 0.45;
  --ruin-text-color: #606060;
  --ruin-separator-color: #5a4a8a;
  --ruin-chip-opacity: 0.45;
  --ruin-formation-bleed: rgba(123, 104, 238, 0.2);
}

/* Formation bleed effects — elements that show the triboluminescence */

.separator {
  transition: color 1.5s ease, opacity 1.5s ease, text-shadow 2s ease;
}

[data-ruin="5"] .separator,
[data-ruin="6"] .separator {
  text-shadow: 0 0 8px var(--formation-color);
}

[data-ruin="5"] .text--italic,
[data-ruin="5"] .text--bold_italic {
  border-left-color: #4a3a6a;
}

[data-ruin="6"] .text--italic,
[data-ruin="6"] .text--bold_italic,
[data-ruin="6"] .text--npc_speech {
  border-left-color: #5a4a8a;
}

/* At ruin 6, chip borders get formation tint */
[data-ruin="6"] .chip {
  border-color: #3a3060;
}

[data-ruin="6"] .chip:hover {
  border-color: #5a4a8a;
}

/* Smooth ruin transitions */
body {
  transition: --ruin-opacity 1.5s ease,
              --ruin-text-color 1.5s ease;
}

.text, .separator, .ascii-art, .chip {
  transition: color 1.5s ease, opacity 1.5s ease, border-color 1.5s ease,
              text-shadow 2s ease, background 1.5s ease;
}

/* --- Responsive --- */

/* Narrow screens: chips fill width */
@media (max-width: 480px) {
  .chip-row {
    gap: 4px;
    padding: 6px 8px;
  }

  .chip {
    flex: 1 1 auto;
    min-width: 60px;
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  #output {
    padding: 12px;
    font-size: 0.9rem;
  }
}

/* Wide screens */
@media (min-width: 768px) {
  #output {
    max-width: 72ch;
    margin: 0 auto;
    padding: 24px;
  }

  #action-bar {
    max-width: 72ch;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* Tall phones: give more output space */
@media (min-height: 700px) {
  #output {
    padding-bottom: 16px;
  }
}

/* --- Scrollbar (subtle) --- */

#output::-webkit-scrollbar {
  width: 4px;
}

#output::-webkit-scrollbar-track {
  background: transparent;
}

#output::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 2px;
}

/* --- Loading indicator --- */

.loading {
  color: var(--fg-dim);
  font-size: 0.85rem;
}

/* --- Cloud save flash --- */

.cloud-save-flash {
  animation: cloud-save-fade 3s ease-out forwards;
}

@keyframes cloud-save-fade {
  0% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

/* --- Gate inputs (beta password, account promotion) --- */

.gate-input {
  display: block;
  width: 100%;
  padding: 8px 12px;
  margin: 8px 0;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  font-family: inherit;
  font-size: 0.9rem;
}

.gate-input:focus {
  outline: none;
  border-color: var(--fg-dim);
}

.gate-error {
  color: var(--fg-error);
  font-size: 0.85rem;
  margin: 4px 0;
}

.gate-buttons {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.overlay__content p {
  color: var(--fg-dim);
  font-size: 0.85rem;
  margin-bottom: 8px;
  line-height: 1.4;
}

/* Feedback textarea (playtest modals) */
.feedback-textarea {
  resize: vertical;
  min-height: 60px;
  max-height: 200px;
}

.feedback-question {
  color: var(--fg);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

#ending-questions .feedback-question {
  margin-top: 12px;
}

#ending-questions .feedback-question:first-child {
  margin-top: 0;
}

/* Beta badge -- subtle corner indicator */

.beta-badge {
  position: fixed;
  top: 8px;
  right: 12px;
  z-index: 10;
  font-family: inherit;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #999;
  opacity: 0.7;
  pointer-events: none;
  user-select: none;
}

.beta-badge--hidden {
  display: none;
}

/* Command palette quick-action row */

.command-palette__actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
