:root {
  --bg: #f3efe7;
  --paper: #fffef9;
  --ink: #1f2328;
  --muted: #6b7280;
  --accent: #1f6feb;
  --accent-strong: #1359bd;
  --line: #d6dbe1;
  --shadow: 0 14px 40px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Space Grotesk", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, #fff8e7 0%, transparent 40%),
    radial-gradient(circle at 80% 90%, #e8f2ff 0%, transparent 35%),
    var(--bg);
}

body {
  padding: 1rem;
}

.app-shell {
  height: calc(100vh - 2rem);
  min-height: 540px;
  display: grid;
  grid-template-columns: minmax(320px, 36%) 1fr;
  gap: 1rem;
}

.chat-panel,
.preview-panel {
  background: color-mix(in srgb, var(--paper) 92%, white 8%);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.chat-header,
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0.55));
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 1.1rem;
}

h2 {
  font-size: 1rem;
  color: var(--muted);
  font-weight: 600;
}

.chat-header p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.chat-log {
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message {
  max-width: 88%;
  padding: 0.72rem 0.84rem;
  border-radius: 12px;
  white-space: pre-wrap;
  line-height: 1.38;
  font-size: 0.95rem;
  animation: fade-in-up 160ms ease-out;
}

.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: #ffffff;
}

.message.assistant {
  align-self: flex-start;
  background: #eef2f7;
  border: 1px solid #dde3ec;
}

.stream-line {
  line-height: 1.55;
  min-height: 1.4em;
}

.stream-ellipsis {
  display: flex;
  gap: 0.22rem;
  align-items: center;
  padding: 0.35rem 0 0;
}

.stream-ellipsis span {
  width: 0.32rem;
  height: 0.32rem;
  border-radius: 50%;
  background: #8390a4;
  opacity: 0.15;
  animation: stream-dot-fade 1.2s infinite ease-in-out;
}

.stream-ellipsis span:nth-child(2) {
  animation-delay: 200ms;
}

.stream-ellipsis span:nth-child(3) {
  animation-delay: 400ms;
}

@keyframes stream-dot-fade {
  0%,
  100% {
    opacity: 0.15;
  }
  50% {
    opacity: 1;
  }
}

.loading-message {
  display: inline-flex;
  align-items: center;
  gap: 0.36rem;
  min-height: 2.25rem;
}

.loading-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: #8390a4;
  animation: pulse-dot 1s infinite ease-in-out;
}

.loading-dot:nth-child(2) {
  animation-delay: 120ms;
}

.loading-dot:nth-child(3) {
  animation-delay: 240ms;
}

.chat-form {
  border-top: 1px solid var(--line);
  padding: 0.85rem;
  display: grid;
  gap: 0.6rem;
  background: #ffffff;
}

#chatInput {
  resize: vertical;
  min-height: 76px;
  max-height: 240px;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  outline: none;
  font: inherit;
}

#chatInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.16);
}

.primary-button,
.secondary-button {
  border: 0;
  border-radius: 10px;
  padding: 0.55rem 0.88rem;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}

.primary-button {
  justify-self: end;
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  background: #eef2f7;
  color: var(--ink);
}

.secondary-button:hover {
  background: #e4eaf2;
}

.preview-panel {
  display: grid;
  grid-template-rows: auto 1fr;
}

.workspace-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #ffffff;
}

.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;
}

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse-dot {
  0%,
  80%,
  100% {
    opacity: 0.32;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

@media (max-width: 960px) {
  body {
    padding: 0.65rem;
  }

  .app-shell {
    height: calc(100vh - 1.3rem);
    grid-template-columns: 1fr;
    grid-template-rows: minmax(380px, 42vh) 1fr;
  }

  .message {
    max-width: 95%;
  }
}
