:root {
  --ink: #1c2430;
  --ink-soft: #4b5c70;
  --paper: #ffffff;
  --paper-2: #f5f8fc;
  --accent: #007f73;
  --accent-2: #f58a2e;
  --line: #dde5ef;
  --ok: #0d9b5f;
  --warn: #ad4f12;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(130deg, #fef9f1 0%, #eef4ff 55%, #f4fff6 100%);
  min-height: 100vh;
}

.bg-shape {
  position: fixed;
  border-radius: 999px;
  filter: blur(80px);
  z-index: 0;
  pointer-events: none;
}

.bg-shape-a {
  width: 300px;
  height: 300px;
  top: -50px;
  left: -70px;
  background: rgba(245, 138, 46, 0.22);
}

.bg-shape-b {
  width: 360px;
  height: 360px;
  right: -80px;
  bottom: -120px;
  background: rgba(0, 127, 115, 0.2);
}

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 0.95fr 1.05fr;
  gap: 14px;
  min-height: 100vh;
  padding: 14px;
}

.panel {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 10px 32px rgba(20, 34, 52, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 700;
}

h1 {
  font-size: 1.1rem;
}

h2 {
  font-size: 1rem;
}

h3 {
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.status {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e8eff9;
  color: #40566d;
}

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

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

.chat-log {
  flex: 1;
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  border-radius: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--paper);
  animation: fade-slide 0.2s ease;
}

.message.user {
  border-color: #cbe4ff;
  background: #eff6ff;
}

.message.assistant {
  border-color: #d9efea;
  background: #f1fbf8;
}

.message .head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 0.76rem;
  color: var(--ink-soft);
}

.message .text {
  font-size: 0.93rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.message .speak-btn {
  border: 1px solid #c5d5ea;
  background: #fff;
  border-radius: 8px;
  font-size: 0.72rem;
  padding: 3px 8px;
  cursor: pointer;
}

.selection-chip {
  margin: 0 14px 10px;
  border: 1px dashed #b8cadf;
  background: #f7fbff;
  border-radius: 10px;
  padding: 8px 10px;
  color: #46607a;
  font-size: 0.8rem;
}

.chat-form {
  border-top: 1px solid var(--line);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid #cdd8e7;
  padding: 10px;
  resize: vertical;
  font: inherit;
  min-height: 70px;
  background: #fcfdff;
}

.chat-actions {
  display: flex;
  gap: 8px;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

button:active {
  transform: translateY(1px);
}

#mic-btn {
  background: #0b8a7d;
  color: #fff;
}

#mic-btn.recording {
  background: #ad4f12;
}

#clear-selection-btn {
  background: #eaf0f8;
  color: #36506d;
}

#send-btn {
  margin-left: auto;
  background: var(--accent-2);
  color: #fff;
}

.code-wrap {
  flex: 1;
  overflow: auto;
  background: var(--paper-2);
  border-bottom: 1px solid var(--line);
}

.code-output {
  margin: 0;
  min-height: 180px;
  padding: 14px;
  font-size: 0.86rem;
  line-height: 1.55;
  font-family: "IBM Plex Mono", "Cascadia Mono", monospace;
  white-space: pre;
}

.preview-wrap {
  border-bottom: 1px solid var(--line);
  background: #f8fbff;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.preview-open-btn {
  border: 1px solid #c8d5e6;
  background: #fff;
  color: #385571;
  font-size: 0.78rem;
  padding: 6px 10px;
  border-radius: 8px;
}

.preview-open-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.preview-stage {
  position: relative;
  min-height: 240px;
  max-height: 360px;
  overflow: hidden;
  background: #ffffff;
}

.preview-frame {
  width: 100%;
  height: 320px;
  border: 0;
  display: none;
}

.preview-empty {
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #607891;
  font-size: 0.84rem;
  padding: 18px;
  text-align: center;
}

.meta {
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.log-wrap {
  padding: 10px 14px 12px;
  background: #fff;
}

.terminal-log {
  margin: 8px 0 0;
  max-height: 170px;
  overflow: auto;
  background: #fcfdff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: #294a35;
  font-family: "IBM Plex Mono", "Cascadia Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
}

@keyframes fade-slide {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(44vh, auto) minmax(44vh, auto);
  }

  .chat-actions {
    flex-wrap: wrap;
  }

  #send-btn {
    margin-left: 0;
  }

  .preview-stage {
    max-height: 280px;
  }

  .preview-frame {
    height: 250px;
  }
}
