/* ============================================================
   silicon-arch-creator — design system
   Ported from siliconfriendly.com (cream/dark, 0 radius, no shadow)
   Fonts: TikTok Sans (-2% tracking) + JetBrains Mono
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=TikTok+Sans:wght@300..900&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --bg: #ede8e0;
  --surface: #ede8e0;
  --surface-2: #e5e0d7;
  --fg: #1a1a1a;
  --fg-muted: #666;
  --border: #d4cfc7;
  --border-strong: #1a1a1a;
  --accent: #1a1a1a;
  --terminal-bg: #1a1a1a;
  --terminal-fg: #ede8e0;
  --error: #b85c5c;
  --radius: 0px;
  --transition: 0.2s ease;
  --font-sans: 'TikTok Sans', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --header-h: 56px;
  --chat-w: 30%;
}

/* === RESET === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
::selection { background: var(--fg); color: var(--bg); }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  letter-spacing: -0.02em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}
body { display: flex; flex-direction: column; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }

/* === SPLASH === */
.splash-screen {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--terminal-bg);
  display: flex; align-items: center; justify-content: center;
}
.splash-screen canvas { display: block; background: transparent; }

/* === KEYFRAMES === */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes breathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.38; }
}
@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}
@keyframes caretBlink {
  0%, 60% { opacity: 1; }
  61%, 100% { opacity: 0; }
}

/* === APP SHELL === */
.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  opacity: 0;
  animation: fadeIn 0.5s ease 0.05s forwards;
}

/* === HEADER === */
.header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  display: flex; align-items: center;
  gap: 1rem;
  padding: 0 clamp(1rem, 3vw, 1.75rem);
  background: rgba(237, 232, 224, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand {
  display: flex; align-items: center; gap: 0.6rem;
  text-decoration: none; color: var(--fg);
}
.brand img {
  width: 24px; height: 24px; display: block;
  image-rendering: -webkit-optimize-contrast;
}
.brand .name {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.03em;
  text-transform: lowercase;
}
.brand .name .dim { color: var(--fg-muted); font-weight: 500; }
.spacer { flex: 1; }
.header-actions { display: flex; gap: 0.5rem; align-items: center; }

.btn {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.55rem 0.95rem;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--fg);
  border-radius: 0;
  transition: background var(--transition), color var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--fg); color: var(--bg); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.ghost { border-color: var(--border); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--fg); }

/* === MAIN === */
.main {
  flex: 1;
  display: grid;
  grid-template-columns: calc(100% - var(--chat-w)) var(--chat-w);
  min-height: 0;
  position: relative;
}

/* === RENDERER PANE === */
.stage-pane {
  position: relative;
  min-width: 0; min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--bg);
  overflow: hidden;
}
.stage-pane iframe {
  width: 100%; height: 100%; border: 0; display: block;
  background: var(--bg);
  opacity: 0;
  transition: opacity 0.4s ease;
}
.stage-pane iframe.ready { opacity: 1; }

/* Overlay download button (top-right of the canvas) — mirrors header Download.
   Hidden until the first architecture renders, in sync with the zoom chrome. */
.stage-action {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 5;
  background: var(--fg);
  color: var(--bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, background 0.2s ease, color 0.2s ease;
}
.stage-action.visible {
  opacity: 1;
  pointer-events: auto;
}
.stage-action:hover:not(:disabled) {
  background: var(--bg);
  color: var(--fg);
}
@media (max-width: 860px) {
  .stage-action { top: 10px; right: 10px; padding: 0.4rem 0.7rem; font-size: 10px; }
}

/* Empty-state overlay (shown until first code arrives) */
.empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 2rem;
  text-align: center;
  background: var(--bg);
  pointer-events: none;
  animation: fadeIn 0.6s ease 0.4s both;
}
.empty-state.gone {
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
.empty-state .es-mark {
  width: 64px; height: 64px;
  margin-bottom: 1.5rem;
  opacity: 0.85;
}
.empty-state h2 {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: clamp(1.3rem, 2.4vw, 1.75rem);
  letter-spacing: -0.03em;
  line-height: 1.2;
  max-width: 32ch;
  color: var(--fg);
}
.empty-state p {
  margin-top: 0.85rem;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-muted);
  max-width: 44ch;
  line-height: 1.7;
}

/* === CHAT PANE === */
.chat-pane {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--bg);
}
.chat-scroll {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 1.1rem 1.1rem 0.5rem;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;   /* anchor messages to the bottom of the column */
}
/* don't let bubbles stretch full-width inside the flex column */
.chat-scroll > .msg { flex: 0 0 auto; }
.chat-scroll > .thinking { flex: 0 0 auto; }
.chat-scroll::-webkit-scrollbar { width: 6px; }
.chat-scroll::-webkit-scrollbar-thumb { background: var(--border); }
.chat-scroll::-webkit-scrollbar-track { background: transparent; }

.msg {
  margin-bottom: 1.1rem;
  max-width: 92%;
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: -0.015em;
  animation: fadeInUp 0.35s ease both;
}
.msg .who {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 0.4rem;
}
.msg .body { white-space: pre-wrap; word-wrap: break-word; }
.msg.user {
  margin-left: auto;
  text-align: left;
  padding: 0.7rem 0.9rem;
  background: var(--fg);
  color: var(--bg);
  animation: slideInRight 0.32s ease both;
}
.msg.user .who { color: rgba(237,232,224,0.55); }

.msg.assistant {
  margin-right: auto;
  padding: 0.7rem 0.9rem;
  background: var(--surface-2);            /* slightly darker cream than --bg */
  color: var(--fg);
  border: 1px solid var(--border);
  animation: slideInLeft 0.32s ease both;
}
.msg.assistant .who { color: var(--fg-muted); }
.msg.assistant .body.markdown { white-space: normal; }
.msg.assistant .body.markdown > *:first-child { margin-top: 0; }
.msg.assistant .body.markdown > *:last-child { margin-bottom: 0; }
.msg.assistant .body.markdown p { margin: 0.5em 0; }
.msg.assistant .body.markdown strong { font-weight: 700; }
.msg.assistant .body.markdown em { font-style: italic; color: var(--fg-muted); }
.msg.assistant .body.markdown ul,
.msg.assistant .body.markdown ol { margin: 0.5em 0 0.5em 1.2em; padding: 0; }
.msg.assistant .body.markdown li { margin: 0.2em 0; }
.msg.assistant .body.markdown code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 0.05em 0.35em;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.msg.assistant .body.markdown pre {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 0.7em 0.85em;
  background: var(--terminal-bg);
  color: var(--terminal-fg);
  border: 1px solid var(--border-strong);
  overflow-x: auto;
  margin: 0.6em 0;
}
.msg.assistant .body.markdown pre code { background: transparent; border: 0; padding: 0; }
.msg.assistant .body.markdown a { color: var(--fg); text-decoration: underline; text-underline-offset: 2px; }
.msg.assistant .body.markdown a:hover { opacity: 0.6; }
.msg.assistant .body.markdown blockquote {
  border-left: 2px solid var(--border-strong);
  padding-left: 0.7em;
  margin: 0.5em 0;
  color: var(--fg-muted);
}
.msg.assistant .body.markdown h1,
.msg.assistant .body.markdown h2,
.msg.assistant .body.markdown h3,
.msg.assistant .body.markdown h4 {
  font-family: var(--font-sans);
  letter-spacing: -0.025em;
  margin: 0.7em 0 0.35em;
  line-height: 1.25;
}
.msg.assistant .body.markdown h1 { font-size: 1.15em; font-weight: 700; }
.msg.assistant .body.markdown h2 { font-size: 1.05em; font-weight: 700; }
.msg.assistant .body.markdown h3 { font-size: 1.0em;  font-weight: 600; }
.msg.assistant .body.markdown h4 { font-size: 0.95em; font-weight: 600; }
.msg.assistant .caret {
  display: inline-block;
  width: 8px; height: 1em;
  margin-left: 2px;
  background: var(--fg);
  vertical-align: -2px;
  animation: caretBlink 1s steps(1, end) infinite;
}

/* Thinking spinner — cycles through messages with a Claude-style slow breathe */
.thinking {
  display: flex; align-items: center; gap: 0.6rem;
  margin: 0 0 1rem;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--fg);
  animation: breathe 1.8s ease-in-out infinite, fadeIn 0.3s ease both;
}
.thinking .sq {
  width: 9px; height: 9px;
  background: var(--fg);
  flex-shrink: 0;
}
.thinking .txt {
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.thinking .txt.swap {
  opacity: 0;
  transform: translateY(-2px);
}
.thinking.gone { animation: fadeIn 0.25s ease reverse forwards; }

/* Input area */
.chat-input {
  flex-shrink: 0;
  padding: 0.85rem 1.1rem 1.1rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.chat-input form {
  display: flex; gap: 0.5rem;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  transition: border-color var(--transition);
}
.chat-input form:focus-within { border-color: var(--fg); }
.chat-input textarea {
  flex: 1;
  border: 0; outline: 0;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 14px;
  letter-spacing: -0.015em;
  line-height: 1.5;
  padding: 0.75rem 0.9rem;
  resize: none;
  max-height: 140px;
  overflow-y: auto;
  color: var(--fg);
}
.chat-input textarea::placeholder { color: var(--fg-muted); }
.chat-input .send {
  border: 0;
  border-left: 1px solid var(--border-strong);
  background: var(--fg);
  color: var(--bg);
  padding: 0 1rem;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: opacity var(--transition);
}
.chat-input .send:hover:not(:disabled) { opacity: 0.85; }
.chat-input .send:disabled { opacity: 0.3; cursor: not-allowed; }

.chat-input .hint {
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

/* === ERROR BANNER === */
.banner {
  margin: 0 1.1rem 0.5rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--error);
  color: var(--error);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  animation: fadeIn 0.3s ease;
}

/* === MOBILE === */
@media (max-width: 860px) {
  :root { --header-h: 50px; }
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: 50vh 1fr;
  }
  .stage-pane {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .empty-state .es-mark { width: 48px; height: 48px; margin-bottom: 1rem; }
  .empty-state h2 { font-size: 1.15rem; }
  .empty-state p { font-size: 11px; }
  .brand .name { font-size: 0.85rem; }
  .header { padding: 0 0.85rem; gap: 0.6rem; }
  .btn { padding: 0.45rem 0.7rem; font-size: 10px; }
  .msg { font-size: 13.5px; max-width: 95%; }
  .chat-input textarea { font-size: 13.5px; padding: 0.65rem 0.75rem; }
}

@media (max-width: 480px) {
  .main { grid-template-rows: 42vh 1fr; }
  .brand .name .dim { display: none; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
