/* ─── Morse Dreamworld — ZSky AI ───
   HTML/CSS overlay layer only.
   All 3D visuals are handled by Three.js / shaders.
   The canvas fills the viewport; this file styles
   the nav, chat, input bar, and loading screen
   that float on top of it. */

/* ─── COLOR TOKENS ─── */
:root {
  --bg: #020205;
  --text: #ededf5;
  --text-dim: rgba(237, 237, 245, 0.52);
  --text-muted: rgba(237, 237, 245, 0.2);
  --text-warm: rgba(255, 245, 230, 0.9);
  --accent: #6ec8ff;
  --accent-warm: #f0c27a;
  --accent2: #818cf8;
  --accent3: #c084fc;
  --border: rgba(255, 255, 255, 0.06);
  --border-mid: rgba(255, 255, 255, 0.1);
  --border-accent: rgba(110, 200, 255, 0.18);
  --r: 14px;
  --r-lg: 22px;
  --r-xl: 30px;
  --blur: blur(28px) saturate(1.5);
  --ease: cubic-bezier(0.4, 0, 0.15, 1);
  --t: 0.35s var(--ease);
  --t-slow: 0.6s var(--ease);
}

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

/* ─── BODY — locked viewport, no scroll ─── */
html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Hide footer globally on Morse */
footer, .footer, #footer { display: none !important; }

/* Thin scrollbars wherever they appear (messages list) */
*::-webkit-scrollbar { width: 3px; height: 3px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.08); border-radius: 2px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.14); }
*::-webkit-scrollbar-corner { background: transparent; }
* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.08) transparent; }

/* ─── CANVAS — base layer ─── */
#morseCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

/* ─── OVERLAY — pointer-events: none container ─── */
#morseOverlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  /* children that need interaction get pointer-events: auto */
}

/* ─── LOADING SCREEN ─── */
#morseLoading {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: opacity var(--t-slow);
}

#morseLoading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.loading-text {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.4rem;
  font-style: italic;
  font-weight: 400;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  animation: loadPulse 2.4s ease-in-out infinite;
}

@keyframes loadPulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.85; }
}

/* ─── NAV ─── */
#morseNav {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 3rem;
  /* Transparent background — no glass panel */
  background: transparent;
  border-bottom: 1px solid transparent;
  transition: opacity var(--t-slow), border-color var(--t-slow);
  pointer-events: auto;
}

/* Nav fades when world state is active */
#morseNav.world-hidden {
  opacity: 0;
  pointer-events: none;
}

.logo {
  font-family: 'Silkscreen', monospace;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 1px;
}
.logo span { color: var(--accent); }

.nav-links { display: flex; list-style: none; gap: 0.15rem; }
.nav-links a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.8rem;
  padding: 0.3rem 0.65rem;
  border-radius: 7px;
  transition: color var(--t), background var(--t);
}
.nav-links a:hover,
.nav-links a.active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.nav-actions { display: flex; gap: 0.5rem; align-items: center; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  border: none;
  padding: 0.3rem 0.85rem;
  border-radius: 7px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  transition: opacity var(--t), transform var(--t);
}
.btn-primary:hover { opacity: 0.88; transform: translateY(-1px); }

/* ─── MASTER PRESENCE ─── */
/* Shown in WORLD state — centered, gold editorial */
.master-presence {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  opacity: 0;
  transition: opacity var(--t-slow);
  pointer-events: none;
  text-align: center;
}

.master-presence.visible { opacity: 1; }

.master-name {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 2.2rem;
  font-style: italic;
  font-weight: 500;
  color: var(--accent-warm);
  text-shadow:
    0 0 40px rgba(240, 194, 122, 0.35),
    0 0 80px rgba(240, 194, 122, 0.12);
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.master-period {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ─── CHAT MESSAGES ─── */
.chat-messages {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 7rem;    /* sits above input bar */
  width: min(560px, calc(100vw - 2rem));
  max-height: 40vh;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.5rem 0.25rem 0.25rem;
  pointer-events: auto;
  scroll-behavior: smooth;
  scrollbar-width: none;  /* hidden on all browsers */
  -ms-overflow-style: none;
  /* Fade at top and bottom */
  mask-image: linear-gradient(transparent 0%, black 10%, black 88%, transparent 100%);
  -webkit-mask-image: linear-gradient(transparent 0%, black 10%, black 88%, transparent 100%);
}
.chat-messages::-webkit-scrollbar { display: none; }
.chat-messages:empty { display: none; }

/* ─── MESSAGE FLOAT ANIMATION ─── */
@keyframes msgFloat {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── MESSAGE STYLES ─── */
.msg {
  position: relative;
  max-width: 100%;
  word-wrap: break-word;
  animation: msgFloat 0.4s var(--ease) both;
}

/* AI messages — Cormorant Garamond, centered editorial */
.msg-ai {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.1rem;
  font-style: italic;
  line-height: 1.8;
  color: var(--text);
  text-align: center;
  padding: 0.4rem 0.5rem;
}

/* User messages — smaller, warm tint, with top/bottom border */
.msg-user {
  font-size: 0.85rem;
  font-style: italic;
  line-height: 1.6;
  color: var(--text-warm);
  text-align: center;
  padding: 0.45rem 0.5rem;
  border-top: 1px solid rgba(240, 194, 122, 0.1);
  border-bottom: 1px solid rgba(240, 194, 122, 0.1);
  margin: 0.2rem 0;
}

.msg-user img {
  max-width: 200px;
  border-radius: 8px;
  margin-top: 0.3rem;
}

/* AI Markdown elements — keep editorial feel */
.msg-ai h1, .msg-ai h2, .msg-ai h3 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 600;
  font-style: italic;
  margin: 0.5rem 0 0.2rem;
  line-height: 1.3;
  color: var(--accent);
}
.msg-ai h1 { font-size: 1.2rem; }
.msg-ai h2 { font-size: 1.05rem; }
.msg-ai h3 { font-size: 0.95rem; }
.msg-ai p { margin: 0.25rem 0; }
.msg-ai ul, .msg-ai ol { margin: 0.3rem 0 0.3rem 1.2rem; text-align: left; }
.msg-ai li { margin-bottom: 0.1rem; }
.msg-ai strong { color: var(--accent); font-weight: 600; }
.msg-ai em { color: var(--text-dim); }
.msg-ai code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.05);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
}
.msg-ai pre {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  overflow-x: auto;
  margin: 0.35rem 0;
  text-align: left;
}
.msg-ai pre code { background: none; padding: 0; }
.msg-ai blockquote {
  border-left: 2px solid var(--accent-warm);
  padding-left: 0.6rem;
  margin: 0.35rem 0;
  color: var(--text-dim);
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-style: italic;
  font-size: 1rem;
  text-align: left;
}

/* ─── INPUT BAR ─── */
.input-bar {
  position: absolute;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 2rem));
  border-radius: 24px;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  background: rgba(4, 4, 14, 0.6);
  border: 1px solid var(--border-mid);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    0 1px 0 rgba(255, 255, 255, 0.03) inset;
  transition: opacity var(--t), box-shadow var(--t), background var(--t);
  pointer-events: auto;
}

/* Ghost mode — FLOAT state (before world entered) */
.input-bar.ghost {
  opacity: 0.3;
}
.input-bar.ghost:hover {
  opacity: 0.65;
}

/* Full opacity once in world */
.input-bar:not(.ghost) {
  opacity: 1;
}
.input-bar:not(.ghost):hover {
  box-shadow:
    0 12px 48px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(110, 200, 255, 0.08),
    0 1px 0 rgba(255, 255, 255, 0.03) inset;
}

.input-wrap {
  display: flex;
  align-items: center;
  padding: 0 0.5rem;
}

.input-wrap textarea {
  flex: 1;
  resize: none;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 0.95rem;
  font-style: italic;
  padding: 0.85rem 0.4rem;
  line-height: 1.5;
  min-height: 3rem;
  max-height: 6rem;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}
.input-wrap textarea::placeholder {
  color: var(--text-muted);
  font-style: italic;
}
.input-wrap textarea:focus { outline: none; }

/* + upload button */
.btn-plus {
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  margin: 0.2rem 0.25rem 0.2rem 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 1.05rem;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  transition: all var(--t);
  padding: 0;
  font-family: inherit;
}
.btn-plus:hover {
  color: var(--accent);
  border-color: var(--border-accent);
  transform: rotate(90deg);
}

/* Send button — warm gradient, round */
.btn-send {
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  margin: 0.2rem 0.35rem 0.2rem 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  transition: all var(--t);
  background: linear-gradient(135deg, var(--accent-warm), var(--accent3));
  color: #fff;
}
.btn-send:hover {
  transform: scale(1.08);
  box-shadow: 0 2px 14px rgba(240, 194, 122, 0.3);
}
.btn-send:disabled {
  opacity: 0.2;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn-send svg { width: 12px; height: 12px; }

/* ─── EXIT HINT ─── */
.exit-hint {
  position: absolute;
  bottom: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  text-transform: uppercase;
  opacity: 0;
  transition: opacity var(--t-slow);
  white-space: nowrap;
  pointer-events: none;
}

.exit-hint.visible { opacity: 1; }

/* ─── PROMPT CARD — inline link style ─── */
.prompt-card { display: inline; }
.prompt-card .prompt-label,
.prompt-card .prompt-text,
.prompt-card .prompt-meta { display: none; }
.prompt-card .btn-create {
  display: inline;
  background: none;
  color: var(--accent);
  font-size: 0.85rem;
  font-style: italic;
  padding: 0;
  border: none;
  border-radius: 0;
  text-decoration: none;
  letter-spacing: 0.01em;
  transition: color var(--t);
  cursor: pointer;
}
.prompt-card .btn-create:hover { color: var(--text); }

/* ─── RESPONSIVE ─── */
@media (max-width: 600px) {
  .master-name { font-size: 1.6rem; }

  .chat-messages {
    width: calc(100vw - 1.5rem);
    max-height: 38vh;
    bottom: 6rem;
  }

  .msg-ai { font-size: 0.95rem; }

  .input-bar {
    width: calc(100vw - 1.5rem);
    bottom: 0.75rem;
  }

  #morseNav .nav-links { display: none; }

  .loading-text { font-size: 1.1rem; }
}

@media (min-width: 2000px) {
  .chat-messages { width: 680px; }
  .input-bar { width: 680px; }
  .master-name { font-size: 2.8rem; }
}
