.dream-machine-page {
  --sd-bg: #f4f7f5;
  --sd-panel: rgba(255, 255, 255, 0.92);
  --sd-panel-strong: #ffffff;
  --sd-ink: #1d211d;
  --sd-muted: #6f746a;
  --sd-soft: #929789;
  --sd-line: #d7ded8;
  --sd-green: #2f4938;
  --sd-green-soft: #dfeade;
  --sd-amber: #b57535;
  --sd-shadow: 0 28px 70px rgba(33, 29, 22, 0.14);
  min-height: 100vh;
  background:
    radial-gradient(circle at 24% 0%, rgba(255, 255, 255, 0.92), transparent 32%),
    linear-gradient(180deg, #f7faf8 0%, #eef4f1 100%);
}

.dream-machine-page::before,
.dream-machine-page .studio-strip {
  display: none;
}

.dream-machine-page .site-header {
  position: static;
  background: rgba(247, 250, 248, 0.84);
}

.sd-page {
  width: min(calc(100% - 2rem), 900px);
  min-height: calc(100vh - 160px);
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 3rem) 0 2rem;
}

.sd-card {
  display: grid;
  grid-template-rows: auto minmax(300px, 1fr) auto;
  min-height: min(760px, calc(100vh - 190px));
  overflow: hidden;
  border: 1px solid var(--sd-line);
  border-radius: 8px;
  background: var(--sd-panel);
  box-shadow: var(--sd-shadow);
  backdrop-filter: blur(18px);
}

.sd-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid rgba(29, 33, 29, 0.08);
}

.sd-mark {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--sd-ink);
  text-decoration: none;
}

.sd-mark span {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(47, 73, 56, 0.24);
  border-radius: 8px;
  color: var(--sd-green);
  background: var(--sd-green-soft);
}

.sd-mark svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.sd-mark strong {
  font-size: 1rem;
  letter-spacing: 0;
  max-width: 24ch;
}

.sd-ghost,
.sd-send,
.sd-modes button {
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.sd-ghost {
  padding: 0 1rem;
  color: var(--sd-muted);
  background: transparent;
}

.sd-ghost:hover {
  color: var(--sd-ink);
  background: rgba(29, 33, 29, 0.05);
}

.sd-thread {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 0;
  overflow-y: auto;
  padding: clamp(1rem, 3vw, 1.5rem);
}

.sd-message {
  max-width: 760px;
  animation: sd-rise 220ms ease both;
}

.sd-message-user {
  align-self: flex-end;
  max-width: min(680px, 92%);
  padding: 0.9rem 1rem;
  border-radius: 8px 8px 4px 8px;
  color: #ffffff;
  background: var(--sd-green);
  line-height: 1.55;
  white-space: pre-wrap;
}

.sd-message-answer {
  align-self: flex-start;
  width: min(760px, 100%);
  padding: clamp(1rem, 3vw, 1.35rem);
  border: 1px solid rgba(29, 33, 29, 0.1);
  border-radius: 8px;
  background: var(--sd-panel-strong);
}

.sd-kicker {
  margin: 0 0 0.55rem;
  color: var(--sd-soft);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.sd-message h1,
.sd-message h2 {
  margin: 0;
  color: var(--sd-ink);
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.sd-message h1 {
  font-size: clamp(2rem, 6vw, 4rem);
}

.sd-message h2 {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
}

.sd-message p {
  margin: 0.85rem 0 0;
  color: var(--sd-muted);
  line-height: 1.6;
}

.sd-runlog {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1rem;
}

.sd-runlog span {
  min-height: 28px;
  padding: 0.36rem 0.55rem;
  border: 1px solid rgba(47, 73, 56, 0.14);
  border-radius: 6px;
  color: var(--sd-green);
  background: rgba(223, 234, 222, 0.58);
  font-size: 0.76rem;
  font-weight: 850;
}

.sd-answer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.sd-answer-block {
  min-width: 0;
  padding: 0.9rem;
  border: 1px solid rgba(29, 33, 29, 0.1);
  border-radius: 8px;
  background: rgba(244, 247, 245, 0.72);
}

.sd-answer-block h3 {
  margin: 0 0 0.45rem;
  color: var(--sd-ink);
  font-size: 0.85rem;
}

.sd-answer-block ul,
.sd-answer-block ol {
  display: grid;
  gap: 0.42rem;
  margin: 0;
  padding-left: 1.1rem;
  color: var(--sd-muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.sd-answer-block li::marker {
  color: var(--sd-amber);
}

.sd-answer-block.sd-wide {
  grid-column: 1 / -1;
}

.sd-script {
  margin-top: 1rem;
  padding: 0.95rem;
  border-radius: 8px;
  color: var(--sd-ink);
  background: var(--sd-green-soft);
  font-weight: 750;
  line-height: 1.55;
}

.sd-composer {
  padding: 1rem;
  border-top: 1px solid rgba(29, 33, 29, 0.08);
  background: rgba(255, 253, 248, 0.8);
}

.sd-composer textarea {
  width: 100%;
  max-height: 420px;
  min-height: 190px;
  resize: vertical;
  border: 1px solid var(--sd-line);
  border-radius: 8px;
  outline: none;
  padding: 1rem;
  color: var(--sd-ink);
  background: #ffffff;
  font: inherit;
  font-size: 1rem;
  line-height: 1.55;
}

.sd-composer textarea:focus {
  border-color: rgba(47, 73, 56, 0.42);
  box-shadow: 0 0 0 4px rgba(47, 73, 56, 0.1);
}

.sd-composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-top: 0.8rem;
}

.sd-modes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.sd-modes button {
  min-height: 34px;
  padding: 0 0.85rem;
  color: var(--sd-muted);
  background: transparent;
}

.sd-modes button.is-active {
  color: #fffdf8;
  background: var(--sd-ink);
}

.sd-send {
  flex: 0 0 auto;
  padding: 0 1.15rem;
  color: #fffdf8;
  background: var(--sd-green);
  box-shadow: 0 10px 22px rgba(47, 73, 56, 0.16);
}

.sd-send:disabled {
  cursor: wait;
  opacity: 0.62;
}

.sd-message-loading {
  opacity: 0.88;
}

.sd-playbook {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.6rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(29, 33, 29, 0.1);
}

.sd-playbook label {
  display: grid;
  gap: 0.35rem;
}

.sd-playbook span {
  color: var(--sd-ink);
  font-size: 0.86rem;
  font-weight: 850;
}

.sd-playbook input {
  min-height: 42px;
  border: 1px solid var(--sd-line);
  border-radius: 6px;
  padding: 0 0.75rem;
  color: var(--sd-ink);
  background: #ffffff;
  font: inherit;
}

.sd-playbook button {
  align-self: end;
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 0.95rem;
  color: #fffdf8;
  background: var(--sd-ink);
  font: inherit;
  font-weight: 850;
  cursor: pointer;
}

.sd-playbook p {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--sd-muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.sd-save-note {
  margin: 0.7rem 0 0;
  color: var(--sd-soft);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.4;
}

.sd-note {
  margin: 0.9rem 0 0;
  color: var(--sd-muted);
  font-size: 0.86rem;
  text-align: center;
}

.sd-toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 70;
  transform: translateY(18px);
  max-width: min(360px, calc(100vw - 2rem));
  padding: 0.8rem 0.9rem;
  border-radius: 8px;
  color: #fffdf8;
  background: var(--sd-ink);
  box-shadow: var(--sd-shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  font-size: 0.85rem;
  font-weight: 800;
}

.sd-toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

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

@media (max-width: 720px) {
  .sd-page {
    width: min(calc(100% - 1rem), 900px);
    padding-top: 0.7rem;
  }

  .sd-card {
    min-height: calc(100vh - 132px);
    border-radius: 8px;
  }

  .sd-thread {
    padding: 0.75rem;
  }

  .sd-message-answer {
    border-radius: 8px;
  }

  .sd-answer-grid {
    grid-template-columns: 1fr;
  }

  .sd-composer {
    padding: 0.75rem;
  }

  .sd-composer textarea {
    min-height: 170px;
  }

  .sd-composer-foot {
    align-items: stretch;
    flex-direction: column;
  }

  .sd-modes {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .sd-modes button {
    padding: 0;
    font-size: 0.8rem;
  }

  .sd-playbook {
    grid-template-columns: 1fr;
  }
}
