/* ═══════════════════════════════════════════════════════════════
   style.css — MUTA
   All CSS custom properties live here as the mutation surface.
   Every visual aspect the LLM can change maps to a --var here.
═══════════════════════════════════════════════════════════════ */

/* ── Variables (mutation surface) ─────────────────────────── */
:root {
  --bg:             #08080e;
  --surface:        #0e0e18;
  --border:         #1e1e2e;
  --accent:         #8fb8e8;
  --accent2:        #e88fb8;
  --text:           #e8e8f4;
  --text-dim:       #8888a8;
  --creature-body:  #8fb8e8;
  --creature-eye:   #e8e8f8;
  --creature-pupil: #08080e;
  --creature-detail:#b8d8f8;
  --creature-inner: #6898c8;
  --world-sky:      #08080e;
  --world-ground:   #0c0c16;
  --particle:       #8fb8e8;
  --glow:           rgba(143,184,232,0.12);
  --font-display:   'Courier Prime', monospace;
  --font-body:      'Cormorant Garamond', serif;
  --panel-world:    62%;
  --creature-size:  180px;
  --ui-integrity:   1;
  --transition-speed: 0.9s;
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html {
  width: 100%;
  height: 100%;
  -webkit-text-size-adjust: 100%;
}
body {
  width: 100%;
  min-height: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  transition: background var(--transition-speed) ease;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ── App layout ──────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: var(--panel-world) 1fr;
  height: 100%;
  min-height: 0;
  transition: grid-template-columns 1.8s ease;
}

@media (max-width: 768px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 38vh) minmax(0, 1fr);
  }
  #world {
    border-bottom: 1px solid var(--border);
    min-height: 0;
  }
  #chat-panel {
    border-left: none;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  #messages {
    min-height: 0;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  #chat-header {
    padding: 14px 16px 12px;
  }
  #chat-header h1 {
    font-size: 11px;
    letter-spacing: 0.2em;
  }
  #chat-header p {
    font-size: 15px;
  }
  #input-area {
    padding: 12px 16px 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  #user-input {
    min-height: 48px;
    padding: 12px 14px;
    font-size: 16px;
  }
  #send-btn {
    min-height: 44px;
    padding: 12px 20px;
    font-size: 10px;
  }
  #world-label {
    font-size: 11px;
    letter-spacing: 0.15em;
    white-space: normal;
    text-align: center;
    max-width: 90%;
  }
  #creature-svg-wrap {
    width: min(var(--creature-size), 140px);
    height: min(var(--creature-size), 140px);
  }
  .echo-float {
    font-size: clamp(1rem, 4vw, 1.75rem);
  }
  #echo-collection {
    font-size: 8px;
    left: 8px;
    bottom: 36px;
  }
  #payment-form #payment-submit {
    min-height: 48px;
  }
}

/* ═══════════════════════════════════════════════════════════════
   WORLD PANEL
═══════════════════════════════════════════════════════════════ */
#world {
  position: relative;
  overflow: hidden;
  transition: background 1.5s ease;
}

#world-svg-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#world-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: background 1.5s ease;
}

#mutation-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: var(--creature-body);
  mix-blend-mode: screen;
  transition: opacity 0.05s;
}

/* Stars */
.star {
  position: absolute;
  background: var(--particle);
  border-radius: 50%;
  animation: twinkle var(--tw-dur, 3s) ease-in-out var(--tw-delay, 0s) infinite;
  transition: background 2s ease, opacity 2s ease;
}

@keyframes twinkle {
  0%, 100% { opacity: calc(var(--tw-op, 0.4) * 0.35); transform: scale(0.85); }
  50%       { opacity: var(--tw-op, 0.4);               transform: scale(1.25); }
}

/* World objects */
.world-object {
  position: absolute;
  opacity: 0;
  transition: opacity 2.5s ease;
  pointer-events: none;
}
.world-object.visible { opacity: 1; }

/* Word echo */
.echo-float {
  position: absolute;
  font-family: var(--font-display), monospace;
  font-size: clamp(1.5rem, 4vw, 3rem);
  font-weight: 700;
  opacity: 0;
  animation: echoFloatIn 3s ease forwards;
  pointer-events: none;
  color: #fff;
}
@keyframes echoFloatIn {
  to { opacity: 0.12; }
}

#echo-collection {
  position: absolute;
  bottom: 48px;
  left: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: var(--font-display), monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  opacity: 0.35;
  pointer-events: none;
}
.echo-collection-item { white-space: nowrap; }

.echo-corrupt-char { transition: opacity 0.06s ease; }
.echo-retrocolour { }

.retro-glow { }
.retro-strike { text-decoration: line-through; }
.retro-blur { }
.retro-word { }

.msg.second-voice .msg-label { letter-spacing: 0.2em; }
.msg.second-voice-fragment .msg-text { opacity: 0.7; }
.msg.second-voice-echo .msg-text { font-style: italic; margin-left: 12px; }

/* ═══════════════════════════════════════════════════════════════
   CREATURE
═══════════════════════════════════════════════════════════════ */
#creature-container {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  transition: top 1.5s ease, left 1.5s ease;
}

#creature-name-label {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.35em;
  color: var(--text);
  opacity: 0.9;
  text-transform: uppercase;
  user-select: none;
  transition: color var(--transition-speed) ease, letter-spacing 1s ease;
}

#creature-svg-wrap {
  width: var(--creature-size);
  height: var(--creature-size);
  filter: drop-shadow(0 0 28px var(--creature-body));
  animation: breathe 4s ease-in-out infinite;
  transition: filter var(--transition-speed) ease, width 1.5s ease, height 1.5s ease;
}

#creature-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

@keyframes breathe {
  0%, 100% { transform: translateY(0)   scale(1);    }
  50%       { transform: translateY(-7px) scale(1.025); }
}

/* Mutation animation */
@keyframes mutate {
  0%   { transform: scale(1)    rotate(0deg);   filter: drop-shadow(0 0 28px var(--creature-body)); }
  20%  { transform: scale(0.75) rotate(-6deg);  filter: drop-shadow(0 0 60px var(--creature-body)) brightness(2.2); }
  50%  { transform: scale(1.2)  rotate(4deg);   filter: drop-shadow(0 0 90px var(--creature-body)) brightness(3); }
  80%  { transform: scale(0.9)  rotate(-2deg);  filter: drop-shadow(0 0 40px var(--creature-body)); }
  100% { transform: scale(1)    rotate(0deg);   filter: drop-shadow(0 0 28px var(--creature-body)); }
}

#creature-svg-wrap.mutating {
  animation: mutate 1.4s ease-in-out, breathe 4s ease-in-out infinite 1.4s;
}

/* Gesture animations */
@keyframes gestureWink {
  0%   { filter: drop-shadow(0 0 28px var(--creature-body)); }
  40%  { filter: drop-shadow(0 0 45px var(--creature-body)) brightness(1.3); }
  100% { filter: drop-shadow(0 0 28px var(--creature-body)); }
}

#creature-svg-wrap.gesture-wink {
  animation: gestureWink 0.5s ease;
}

@keyframes gestureTail {
  0%   { transform: translateY(0) scale(1); }
  30%  { transform: translateY(-3px) scale(1.01) rotate(1.5deg); }
  60%  { transform: translateY(-1px) scale(1.005) rotate(-1deg); }
  100% { transform: translateY(0) scale(1) rotate(0deg); }
}

#creature-svg-wrap.gesture-tail {
  animation: gestureTail 0.6s ease;
}

#creature-svg-wrap.cursor-aware {
  transform: translate(
    calc((var(--cursor-x, 0.5) - 0.5) * 6px),
    calc((var(--cursor-y, 0.5) - 0.5) * 6px)
  );
}

#world-svg-layer.world-cursor-react {
  animation: worldReactPulse 1.5s ease;
}
@keyframes worldReactPulse {
  0%, 100% { filter: brightness(1); }
  30% { filter: brightness(1.15); }
}

/* Glitch effect from neglect */
@keyframes glitch {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-2px); }
  40%  { transform: translateX(2px); }
  60%  { transform: translateX(-1px); }
  80%  { transform: translateX(1px); }
  100% { transform: translateX(0); }
}

#creature-svg-wrap.glitching {
  animation: breathe 4s ease-in-out infinite, glitch 0.4s ease-in-out infinite;
}

/* Mood bar */
#mood-bar {
  display: flex;
  gap: 7px;
  align-items: center;
}

.mood-pip {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border);
  transition: background var(--transition-speed) ease, transform 0.35s ease;
}

.mood-pip.active {
  background: var(--accent);
  transform: scale(1.35);
  transition: background var(--transition-speed) ease, transform 0.35s ease;
}

/* World label */
#world-label {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.25em;
  color: var(--text);
  opacity: 0.9;
  text-transform: uppercase;
  white-space: nowrap;
  user-select: none;
  transition: color var(--transition-speed) ease;
}

/* ═══════════════════════════════════════════════════════════════
   CHAT PANEL
═══════════════════════════════════════════════════════════════ */
#chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--surface);
  transition: border-color var(--transition-speed) ease,
              background var(--transition-speed) ease;
  overflow: hidden;
}

/* Header */
#chat-header {
  padding: 22px 26px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  transition: border-color var(--transition-speed) ease;
}

#chat-header h1 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.28em;
  color: var(--accent);
  margin-bottom: 5px;
  transition: color var(--transition-speed) ease;
}

#chat-header p {
  font-family: var(--font-body);
  font-size: 17px;
  font-weight: 500;
  color: var(--text);
  font-style: italic;
  line-height: 1.4;
  opacity: 0.9;
}

#player-label {
  font-family: var(--font-display);
  font-size: 8px;
  letter-spacing: 0.38em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 6px;
  min-height: 1em;
}

/* Messages */
#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 26px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  -webkit-overflow-scrolling: touch;
}

#messages::-webkit-scrollbar        { width: 3px; }
#messages::-webkit-scrollbar-track  { background: transparent; }
#messages::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 2px; }

.msg {
  display: flex;
  flex-direction: column;
  gap: 5px;
  animation: msgIn 0.32s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-label {
  font-family: var(--font-display);
  font-size: 8px;
  letter-spacing: 0.38em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.msg-text {
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  font-family: var(--font-body);
  transition: color var(--transition-speed) ease;
}

.msg.creature .msg-label {
  color: var(--accent);
  transition: color var(--transition-speed) ease;
}

.msg.creature .msg-text {
  font-style: italic;
}

.msg.user .msg-label {
  color: var(--accent2);
  transition: color var(--transition-speed) ease;
}

.msg.system .msg-label {
  color: var(--text-dim);
}

.msg.system .msg-text {
  font-size: 11px;
  font-family: var(--font-display);
  letter-spacing: 0.1em;
  opacity: 0.5;
}

/* Thinking dots */
.thinking {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 6px 0;
}

.thinking-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: thinkPulse 1.1s ease-in-out infinite;
  transition: background var(--transition-speed) ease;
}

.thinking-dot:nth-child(2) { animation-delay: 0.18s; }
.thinking-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes thinkPulse {
  0%, 100% { opacity: 0.2; transform: scale(0.75); }
  50%       { opacity: 1;   transform: scale(1.25); }
}

/* Input area */
#input-area {
  padding: 16px 26px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
  transition: border-color var(--transition-speed) ease;
}

#user-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  padding: 10px 14px;
  resize: none;
  outline: none;
  min-height: 62px;
  line-height: 1.5;
  transition: border-color 0.25s ease,
              background var(--transition-speed) ease;
}

#user-input:focus {
  border-color: var(--accent);
}

#user-input::placeholder {
  color: var(--text-dim);
  font-style: italic;
}

#user-input:disabled {
  opacity: 0.5;
}

#send-btn {
  align-self: flex-end;
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.28em;
  padding: 9px 22px;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.2s ease, color 0.2s ease,
              border-color var(--transition-speed) ease;
}

#send-btn:hover:not(:disabled) {
  background: var(--accent);
  color: var(--bg);
}

#send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

@keyframes transmitWait {
  0%   { box-shadow: 0 0 0 0 rgba(143,184,232,0.0); }
  50%  { box-shadow: 0 0 0 4px rgba(143,184,232,0.18); }
  100% { box-shadow: 0 0 0 0 rgba(143,184,232,0.0); }
}

#send-btn.send-waiting {
  animation: transmitWait 1.1s ease-in-out infinite;
}

/* ═══════════════════════════════════════════════════════════════
   PRE-BREAK DEGRADATION
   --ui-integrity: 1 (normal) → 0 (broken)
═══════════════════════════════════════════════════════════════ */

/* Chat panel gets slight misalignment */
#chat-panel {
  transform: translateX(calc((1 - var(--ui-integrity)) * 2px));
}

/* Messages container drifts */
#messages {
  letter-spacing: calc((1 - var(--ui-integrity)) * 0.04em);
}

/* Creature glow intensifies before break */
#creature-svg-wrap {
  filter: drop-shadow(0 0 calc(28px + (1 - var(--ui-integrity)) * 60px) var(--creature-body));
}

/* ═══════════════════════════════════════════════════════════════
   PAYMENT GATE
═══════════════════════════════════════════════════════════════ */
#app.hidden {
  display: none !important;
}

#payment-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  z-index: 1000;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#payment-gate.hidden {
  display: none !important;
}

.payment-gate-inner {
  width: 100%;
  max-width: 420px;
  padding: calc(2rem + env(safe-area-inset-top)) calc(2rem + env(safe-area-inset-right)) calc(2rem + env(safe-area-inset-bottom)) calc(2rem + env(safe-area-inset-left));
  text-align: center;
}

.payment-gate-inner h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  letter-spacing: 0.2em;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.payment-gate-tagline {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

#payment-element {
  margin-bottom: 1rem;
  min-height: 120px;
}

#payment-form #payment-submit {
  width: 100%;
  margin-top: 0.5rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  padding: 0.75rem 1.5rem;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

#payment-form #payment-submit:hover:not(:disabled) {
  opacity: 0.9;
}

#payment-form #payment-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.payment-error {
  color: #c85858;
  font-size: 0.85rem;
  min-height: 1.2em;
}

#payment-form.hidden {
  display: none;
}

.payment-gate-fallback {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 1rem;
  line-height: 1.5;
}

/* New-tab intrusion prompt (in-world gateway for new tabs) */
#muta-new-tab-prompt {
  position: absolute;
  bottom: 18px;
  right: 24px;
  padding: 6px 10px;
  border-radius: 2px;
  border: 1px solid var(--accent);
  background: rgba(0, 0, 0, 0.4);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  opacity: 0.0;
  transform: translateY(6px);
  transition: opacity 0.3s ease, transform 0.3s ease, border-color var(--transition-speed) ease;
  pointer-events: auto;
  z-index: 20;
}

#muta-new-tab-prompt.visible {
  opacity: 0.9;
  transform: translateY(0);
}

#world-bleed-overlay {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  pointer-events: none;
  transition: width 0.4s ease, opacity 0.4s ease;
}

