:root {
  --bg: #f2ede3;
  --panel: rgba(19, 23, 29, 0.88);
  --panel-border: rgba(255, 255, 255, 0.18);
  --ink: #111318;
  --ink-soft: rgba(17, 19, 24, 0.66);
  --ink-inverse: #f5f1e8;
  --accent: #ea6f42;
  --success: #2f8f65;
  --danger: #c74836;
  --shadow-lg: 0 24px 80px rgba(31, 27, 21, 0.16);
  --shadow-md: 0 18px 40px rgba(31, 27, 21, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.7), transparent 32%),
    radial-gradient(circle at top right, rgba(234, 111, 66, 0.14), transparent 26%),
    linear-gradient(180deg, #f7f2e8 0%, #eee5d8 52%, #efe9df 100%);
}

body::before,
body::after {
  position: fixed;
  z-index: 0;
  width: 40vw;
  height: 40vw;
  border-radius: 999px;
  content: "";
  filter: blur(14px);
  pointer-events: none;
}

body::before {
  top: -12vw;
  right: -8vw;
  background: rgba(28, 96, 118, 0.12);
}

body::after {
  bottom: -12vw;
  left: -10vw;
  background: rgba(234, 111, 66, 0.14);
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  padding: 18px;
  gap: 14px;
}

.topbar,
.workspace {
  width: min(1200px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: grid;
  gap: 4px;
}

.brand-mark {
  font-size: clamp(1.2rem, 2vw, 1.6rem);
  font-weight: 700;
  letter-spacing: -0.04em;
}

.brand-subtitle,
.eyebrow,
.field-help,
.meta-label,
.empty-copy {
  color: var(--ink-soft);
}

.brand-subtitle,
.eyebrow,
.field-help,
.meta-label {
  font-size: 0.82rem;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.menu-toggle,
.panel-close,
.ghost-button,
.prompt-chip,
.generate-button,
.download-link {
  border: 0;
  transition:
    transform 180ms ease,
    background-color 180ms ease,
    border-color 180ms ease,
    opacity 180ms ease;
}

.menu-toggle {
  display: inline-grid;
  gap: 5px;
  padding: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  backdrop-filter: blur(14px);
}

.menu-toggle span {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: var(--ink);
}

.workspace {
  min-height: 0;
}

.viewer-card {
  position: relative;
  min-height: clamp(520px, 82vh, 920px);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: var(--radius-xl);
  background:
    radial-gradient(circle at top, rgba(234, 111, 66, 0.14), transparent 32%),
    radial-gradient(circle at 18% 18%, rgba(97, 182, 212, 0.12), transparent 20%),
    linear-gradient(180deg, #18212b 0%, #0d131b 100%);
  box-shadow: var(--shadow-lg);
}

.viewer-card::before,
.viewer-card::after {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
}

.viewer-card::before {
  background:
    radial-gradient(circle at center, transparent 24%, rgba(8, 12, 16, 0.14) 100%);
}

.viewer-card::after {
  background:
    linear-gradient(180deg, transparent 0%, transparent 62%, rgba(7, 11, 15, 0.78) 100%);
}

.viewer {
  position: absolute;
  inset: 0;
}

.viewer canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.viewer-empty,
.viewer-status {
  position: absolute;
  left: 28px;
  right: 28px;
  z-index: 2;
  pointer-events: none;
}

.viewer-empty {
  top: 28px;
  max-width: 460px;
  padding: 20px 22px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  background: rgba(10, 15, 20, 0.56);
  color: var(--ink-inverse);
  backdrop-filter: blur(16px);
  animation: slide-up 500ms ease;
}

.viewer-empty[data-tone="loading"] {
  background: rgba(14, 20, 27, 0.66);
}

.viewer-empty[data-tone="error"] {
  max-width: 560px;
  border-color: rgba(255, 146, 128, 0.26);
  background: rgba(60, 22, 18, 0.72);
}

.viewer-empty[data-tone="error"] .eyebrow {
  color: #ffb8aa;
}

.viewer-empty[data-tone="error"] p:last-child {
  color: rgba(255, 230, 224, 0.86);
}

.viewer-empty h1 {
  margin: 0 0 12px;
  font-size: clamp(1.9rem, 4vw, 3.2rem);
  line-height: 0.96;
  letter-spacing: -0.05em;
}

.viewer-empty p:last-child {
  margin: 0;
  color: rgba(245, 241, 232, 0.7);
}

.viewer-status {
  top: 28px;
  display: flex;
  justify-content: flex-end;
}

.viewer-status span {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(10, 15, 20, 0.56);
  color: var(--ink-inverse);
  backdrop-filter: blur(16px);
}

.viewer-status span::before {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(234, 111, 66, 0.14);
  content: "";
  animation: pulse 1.2s infinite;
}

.composer {
  position: absolute;
  left: 50%;
  bottom: 28px;
  z-index: 3;
  width: min(920px, calc(100% - 56px));
  margin: 0;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "input button"
    "hint hint";
  gap: 14px;
  align-items: end;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 26px;
  background: rgba(7, 11, 15, 0.72);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
}

.composer textarea {
  grid-area: input;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  font: inherit;
  color: var(--ink-inverse);
  background: rgba(255, 255, 255, 0.08);
  min-height: 74px;
  resize: vertical;
  padding: 18px 20px;
  font-size: 1rem;
  line-height: 1.5;
}

.composer-hint {
  grid-area: hint;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px 2px;
}

.session-badge,
.history-hint {
  font-size: 0.8rem;
  color: rgba(245, 241, 232, 0.72);
}

.session-badge {
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.text-input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  font: inherit;
  color: var(--ink-inverse);
  background: rgba(255, 255, 255, 0.08);
}

.composer textarea::placeholder,
.text-input::placeholder {
  color: rgba(245, 241, 232, 0.42);
}

.composer textarea:focus,
.text-input:focus {
  outline: 0;
  border-color: rgba(234, 111, 66, 0.5);
  box-shadow: 0 0 0 4px rgba(234, 111, 66, 0.12);
}

.generate-button {
  min-width: 142px;
  padding: 18px 20px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent) 0%, #f09053 100%);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 14px 30px rgba(234, 111, 66, 0.24);
}

.generate-button:hover,
.menu-toggle:hover,
.prompt-chip:hover,
.download-link:hover,
.ghost-button:hover,
.panel-close:hover {
  transform: translateY(-1px);
}

.generate-button:disabled {
  cursor: progress;
  opacity: 0.72;
}

.side-panel {
  position: fixed;
  top: 18px;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  width: min(390px, calc(100vw - 36px));
  padding: 22px;
  overflow-y: auto;
  border: 1px solid var(--panel-border);
  border-radius: 30px;
  background: var(--panel);
  color: var(--ink-inverse);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(22px);
  transform: translateX(calc(100% + 24px));
  transition: transform 240ms ease;
}

.side-panel[data-open="true"] {
  transform: translateX(0);
}

.panel-scrim {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(14, 16, 19, 0.36);
  backdrop-filter: blur(6px);
}

.panel-header,
.section-heading,
.download-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-header {
  margin-bottom: 26px;
}

.panel-header h2,
.panel-section h3 {
  margin: 0;
}

.panel-section + .panel-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.side-panel .eyebrow,
.side-panel .field-help,
.side-panel .meta-label,
.side-panel .empty-copy {
  color: rgba(245, 241, 232, 0.68);
}

.panel-close,
.ghost-button {
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink-inverse);
  cursor: pointer;
}

.panel-close {
  font-size: 1.5rem;
  line-height: 1;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.92rem;
}

.text-input {
  padding: 14px 16px;
}

.field-help,
.task-message,
.empty-copy {
  margin: 10px 0 0;
  line-height: 1.45;
}

.task-message {
  color: rgba(245, 241, 232, 0.82);
}

.state-pill {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.86rem;
}

.state-pill[data-state="completed"] {
  background: rgba(47, 143, 101, 0.18);
  color: #9cf2c8;
}

.state-pill[data-state="running"],
.state-pill[data-state="pending"] {
  background: rgba(234, 111, 66, 0.18);
  color: #ffc29f;
}

.state-pill[data-state="failed"] {
  background: rgba(199, 72, 54, 0.2);
  color: #ffb1a6;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.meta-value {
  display: block;
  margin-top: 4px;
  word-break: break-word;
}

.download-actions {
  gap: 12px;
  margin-top: 18px;
}

.download-link,
.prompt-chip {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  padding: 11px 14px;
  border-radius: 999px;
  text-decoration: none;
  cursor: pointer;
}

.download-link {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink-inverse);
}

.download-link.is-disabled {
  opacity: 0.35;
  pointer-events: none;
}

.prompt-list,
.history-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.prompt-chip {
  justify-content: flex-start;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink-inverse);
  text-align: left;
}

.history-item {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
}

.history-prompt {
  margin: 0;
  font-size: 0.94rem;
  line-height: 1.5;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.8rem;
  color: rgba(245, 241, 232, 0.68);
}

.history-open {
  justify-self: start;
  padding: 0;
  border: 0;
  color: #ffccad;
  background: none;
  cursor: pointer;
  font: inherit;
}

.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 pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.18);
    opacity: 1;
  }
}

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

@media (max-width: 900px) {
  .app-shell {
    padding: 16px;
  }

  .viewer-card {
    min-height: 72vh;
  }

  .viewer-empty,
  .viewer-status {
    left: 18px;
    right: 18px;
  }

  .composer {
    grid-template-columns: 1fr;
    width: calc(100% - 36px);
    bottom: 18px;
  }

  .generate-button {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
  }

  .brand-subtitle {
    max-width: 180px;
  }

  .viewer-empty {
    padding: 18px;
  }

  .viewer-empty h1 {
    font-size: 2rem;
  }

  .viewer-status {
    justify-content: flex-start;
    top: auto;
    bottom: 150px;
  }

  .side-panel {
    top: 10px;
    right: 10px;
    bottom: 10px;
    width: calc(100vw - 20px);
    padding: 18px;
  }
}
