:root {
  --bg-top: #252830;
  --bg-bottom: #15171c;
  --surface: #242832;
  --surface-strong: #1d212a;
  --line: #3a3f4d;
  --text: #eef2f8;
  --muted: #9ea8ba;
  --brand: #f3f6fb;
  --brand-text: #111723;
  --user: #2f72f3;
  --user-strong: #2a61cc;
  --ok: #6ce6a3;
  --warn: #f5d178;
  --bad: #ef9ea5;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Pretendard", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 50% -220px, #3a4150 0%, transparent 68%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

button {
  border: 0;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease, opacity 0.15s ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.app-shell {
  max-width: 1120px;
  height: 100vh;
  margin: 0 auto;
  padding: 14px 18px 18px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 4px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.brand-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-sub {
  color: var(--muted);
  font-size: 0.95rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ghost {
  background: #2b303b;
  border: 1px solid #3f4553;
  color: #e4e9f3;
  border-radius: 999px;
  padding: 0.48rem 0.8rem;
  font: 600 0.84rem/1 "Space Grotesk", sans-serif;
}

.ghost:hover {
  background: #323846;
  transform: translateY(-1px);
}

.chat-viewport {
  position: relative;
  overflow-y: auto;
  padding: 8px 4px 16px;
  scroll-behavior: smooth;
}

.empty-state {
  min-height: 100%;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
  padding: 24px;
}

.empty-state h1 {
  margin: 0;
  font-size: clamp(2.1rem, 4.6vw, 3rem);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 900px;
  margin: 0 auto;
}

.message {
  display: flex;
  animation: message-in 0.23s ease;
}

.message.user {
  justify-content: flex-end;
}

.bubble {
  max-width: min(84%, 680px);
  border-radius: 16px 16px 6px 16px;
  padding: 12px 14px;
  background: linear-gradient(140deg, var(--user), var(--user-strong));
  color: #fff;
  line-height: 1.46;
  white-space: pre-wrap;
  box-shadow: 0 10px 24px #00000038;
}

.message.assistant {
  justify-content: flex-start;
}

.assistant-card {
  width: min(100%, 860px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-strong);
  padding: 12px 12px 10px;
  box-shadow: 0 14px 34px #0000002f;
}

.message.pending .assistant-card {
  border-style: dashed;
}

.message.error .assistant-card {
  border-color: #6f3a42;
}

.message-meta {
  color: #afb8ca;
  margin-bottom: 8px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.assistant-note {
  margin: 0 0 8px;
  color: #dee5f2;
  font-size: 0.96rem;
}

.assistant-code {
  margin: 0;
  max-height: 56vh;
  overflow: auto;
  border: 1px solid #353c4f;
  border-radius: 12px;
  background: #13161c;
  padding: 12px;
  font: 500 0.86rem/1.52 "IBM Plex Mono", "JetBrains Mono", monospace;
  color: #e9eefb;
  white-space: pre;
  tab-size: 2;
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.action-btn {
  border: 1px solid #47506a;
  border-radius: 999px;
  background: #2f3544;
  color: #ebf0f9;
  padding: 0.45rem 0.78rem;
  font: 600 0.82rem/1 "Space Grotesk", sans-serif;
}

.action-btn:hover {
  background: #394157;
  transform: translateY(-1px);
}

.action-btn-primary {
  border-color: #8bd5ff;
  background: linear-gradient(135deg, #f0fbff, #b8e8ff);
  color: #05213d;
  font-weight: 700;
  box-shadow: 0 0 0 1px #9ad9ff inset, 0 6px 18px #56b9ff45;
}

.action-btn-primary:hover {
  background: linear-gradient(135deg, #f7fdff, #c9efff);
  transform: translateY(-1px) scale(1.01);
}

.composer-wrap {
  padding: 4px 0 2px;
}

.status {
  max-width: 900px;
  min-height: 1.25rem;
  margin: 0 auto 6px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 0.88rem;
}

.status.ok {
  color: var(--ok);
}

.status.warn {
  color: var(--warn);
}

.status.bad {
  color: var(--bad);
}

.composer {
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 8px;
  padding: 8px 10px 8px 8px;
  border: 1px solid #3a404e;
  border-radius: 24px;
  background: #232730f0;
  backdrop-filter: blur(8px);
  box-shadow: 0 18px 40px #00000042;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  padding: 0;
  display: grid;
  place-items: center;
  background: #2f3440;
  border: 1px solid #4a5061;
  color: #f0f3fa;
  font-size: 1.35rem;
  line-height: 1;
}

.icon-btn:hover {
  background: #3a4151;
  transform: translateY(-1px);
}

#promptInput {
  width: 100%;
  min-height: 36px;
  max-height: 190px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: #f8fbff;
  font: 500 1rem/1.45 "Space Grotesk", sans-serif;
  padding: 7px 6px;
}

#promptInput::placeholder {
  color: #9da8bc;
}

.send-btn {
  height: 36px;
  border-radius: 999px;
  padding: 0 14px;
  background: var(--brand);
  color: var(--brand-text);
  font: 700 0.9rem/1 "Space Grotesk", sans-serif;
}

.send-btn:hover {
  background: #ffffff;
  transform: translateY(-1px);
}

.preview-overlay[hidden] {
  display: none;
}

.preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  grid-template-rows: auto 1fr;
  background: #0f1116;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  background: #171a22;
  border-bottom: 1px solid #2f3444;
}

.preview-head strong {
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.preview-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.zoom-tools {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 999px;
  border: 1px solid #4a5574;
  background: #232b3d;
}

.zoom-label {
  min-width: 46px;
  text-align: center;
  color: #dbe4f8;
  font: 700 0.78rem/1 "IBM Plex Mono", monospace;
}

.chip {
  border: 1px solid #5f6c8d;
  border-radius: 999px;
  background: #3b4560;
  color: #f7f9ff;
  padding: 0.48rem 0.85rem;
  font: 700 0.84rem/1 "Space Grotesk", sans-serif;
  box-shadow: 0 0 0 1px #7c8cb3 inset;
}

.chip:hover {
  background: #4a5777;
  transform: translateY(-1px);
}

.ghost-chip {
  background: #2f3950;
  border-color: #5f6f92;
  color: #f0f5ff;
  padding: 0.36rem 0.62rem;
  min-width: 34px;
}

.ghost-chip:hover {
  background: #3d4a69;
}

#previewAutoFitBtn.active {
  background: linear-gradient(135deg, #f0fbff, #c6ecff);
  color: #06243e;
  border-color: #91d6ff;
  box-shadow: 0 0 0 1px #9ad9ff inset;
}

#closePreviewBtn {
  border-color: #ff9ca9;
  background: linear-gradient(135deg, #ff6d7e, #f14e63);
  color: #ffffff;
  box-shadow: 0 0 0 1px #ffc4cc inset, 0 8px 20px #ff5f7344;
}

#closePreviewBtn:hover {
  background: linear-gradient(135deg, #ff7a89, #ff6074);
}

#previewFrame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

body.overlay-open {
  overflow: hidden;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 860px) {
  .app-shell {
    padding: 10px 10px 14px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .top-actions {
    width: 100%;
  }

  .ghost {
    flex: 1;
    text-align: center;
  }

  .bubble {
    max-width: 92%;
  }

  .assistant-card {
    width: 100%;
  }

  .composer {
    border-radius: 20px;
  }

  #promptInput {
    font-size: 0.95rem;
  }
}
