:root {
  --bg: #ede6d8;
  --bg-deep: #e3d7c4;
  --paper: rgba(252, 249, 242, 0.86);
  --paper-strong: rgba(255, 252, 246, 0.96);
  --ink: #181511;
  --muted: #6d655c;
  --line: rgba(24, 21, 17, 0.12);
  --line-strong: rgba(24, 21, 17, 0.2);
  --shadow: 0 26px 80px rgba(63, 47, 22, 0.14);
  --green: #1f6a43;
  --amber: #9a6420;
  --blue: #224e87;
  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua",
    Palatino, Georgia, serif;
  --font-ui: "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(34, 78, 135, 0.18), transparent 34%),
    radial-gradient(circle at right 18%, rgba(154, 100, 32, 0.18), transparent 28%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(24, 21, 17, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(24, 21, 17, 0.022) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.6), transparent 90%);
}

.page-shell {
  width: min(980px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0;
  display: grid;
}

.stage {
  display: grid;
  justify-items: center;
  align-items: start;
}

.panel,
.chat-shell {
  background: var(--paper);
  backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.panel-stack {
  width: min(100%, 820px);
  min-height: 560px;
}

.panel {
  display: none;
  position: relative;
  border-radius: 30px;
  padding: 38px;
  animation: panel-rise 420ms ease;
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(24, 21, 17, 0.08),
    transparent
  );
}

.panel::after {
  content: "";
  position: absolute;
  top: 18px;
  right: 18px;
  width: 110px;
  height: 110px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.35), transparent 70%);
  pointer-events: none;
}

.panel.is-active {
  display: block;
}

.panel-checking,
.panel-unsupported {
  align-content: center;
  min-height: 560px;
}

.panel-supported {
  height: min(760px, calc(100vh - 56px));
  min-height: 580px;
}

.panel-head,
.actions {
  display: flex;
  align-items: center;
}

.panel-head {
  gap: 10px;
  margin-bottom: 14px;
}

.panel-kicker,
.field-label {
  font-family: var(--font-ui);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.panel-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
}

.panel h1 {
  margin: 0;
  max-width: 11ch;
  font-family: var(--font-display);
  font-size: clamp(2.7rem, 5vw, 5rem);
  line-height: 0.92;
  letter-spacing: -0.05em;
}

.panel-copy,
textarea,
button,
#responseMeta {
  font-family: var(--font-ui);
}

input,
textarea,
button,
label,
small,
pre {
  font-family: var(--font-ui);
}

textarea::placeholder {
  font-family: var(--font-ui);
  color: rgba(109, 101, 92, 0.76);
}

.panel-copy {
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.7;
  font-size: 1rem;
  max-width: 32ch;
}

.panel-unsupported .panel-copy {
  max-width: 28ch;
}

.support-notes {
  display: grid;
  gap: 8px;
  margin-top: 24px;
  max-width: 34rem;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.6;
}

.support-notes p {
  margin: 0;
}

.support-notes code {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(24, 21, 17, 0.1);
  background: rgba(255, 255, 255, 0.58);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.support-notes code + code {
  margin-top: 10px;
}

.support-hint {
  margin-top: 4px;
  font-size: 0.9rem;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
}

.dot-pulse {
  background: var(--blue);
  box-shadow: 0 0 0 rgba(36, 79, 136, 0.5);
  animation: pulse 1.8s infinite;
}

.dot-success {
  background: var(--green);
}

.dot-warning {
  background: var(--amber);
}

.progress-track {
  margin-top: 28px;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(24, 21, 17, 0.07);
}

.progress-bar {
  width: 38%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #c79b4f, #315f9d);
  animation: sweep 1.8s ease-in-out infinite;
}

.playground {
  margin-top: 34px;
  padding-top: 22px;
  border-top: 1px solid rgba(24, 21, 17, 0.08);
  display: grid;
  gap: 16px;
}

.panel-supported .playground {
  margin-top: 8px;
  padding-top: 0;
  border-top: 0;
  grid-template-rows: minmax(0, 1fr) auto auto;
  height: 100%;
  min-height: 0;
}

.field-label {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.74rem;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: clamp(44px, 6vh, 72px);
  max-height: 120px;
  border-radius: 24px;
  border: 1px solid rgba(24, 21, 17, 0.1);
  padding: 12px 16px;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(248, 244, 236, 0.82));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

textarea:focus,
button:focus {
  outline: 2px solid rgba(34, 78, 135, 0.28);
  outline-offset: 2px;
}

.actions {
  gap: 12px;
  margin-top: 0;
  justify-content: space-between;
}

button {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 14px 22px;
  font-size: 0.92rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition:
    transform 140ms ease,
    opacity 140ms ease,
    background 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease;
}

button:hover {
  transform: translateY(-2px);
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

.primary-btn {
  background: linear-gradient(135deg, #244f88, #1f6a43);
  color: white;
  box-shadow: 0 12px 26px rgba(34, 78, 135, 0.18);
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.52);
  border-color: rgba(24, 21, 17, 0.12);
  color: var(--ink);
}

.chat-shell {
  height: 100%;
  min-height: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
  overflow: hidden;
}

.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.chat-thread::before {
  content: "";
  flex: 1 0 auto;
}

.chat-thread::-webkit-scrollbar {
  width: 10px;
}

.chat-thread::-webkit-scrollbar-thumb {
  background: rgba(24, 21, 17, 0.12);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.message {
  display: block;
  max-width: min(88%, 560px);
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid rgba(24, 21, 17, 0.08);
  align-self: flex-start;
}

.message-user {
  margin-left: auto;
  background: linear-gradient(135deg, rgba(36, 79, 136, 0.1), rgba(31, 106, 67, 0.08));
}

.message-assistant {
  width: fit-content;
  background: rgba(255, 255, 255, 0.7);
}

.message-pending {
  opacity: 0.72;
}

.message-meta,
.status-line {
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.message-meta {
  display: block;
  margin-bottom: 8px;
}

.message-body {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.7;
}

.message-assistant .message-body {
  white-space: normal;
}

.status-line {
  display: block;
  min-height: 1em;
}

@keyframes panel-rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(36, 79, 136, 0.36);
  }

  70% {
    box-shadow: 0 0 0 16px rgba(36, 79, 136, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(36, 79, 136, 0);
  }
}

@keyframes sweep {
  0% {
    transform: translateX(-120%);
  }

  50% {
    transform: translateX(70%);
  }

  100% {
    transform: translateX(220%);
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100vw - 20px, 980px);
    padding: 10px 0;
  }

  .panel {
    padding: 22px;
    border-radius: 24px;
  }

  .panel h1 {
    max-width: none;
  }

  .actions,
  .panel-head {
    align-items: center;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  button {
    width: 100%;
  }

  .support-notes code {
    font-size: 0.82rem;
  }
}
