:root {
  color-scheme: light;
  --bg: #f5f6f2;
  --paper: #ffffff;
  --paper-soft: #fafaf7;
  --ink: #171a17;
  --muted: #68716b;
  --line: #dfe3dc;
  --line-strong: #c7cec5;
  --teal: #0b7d6d;
  --teal-dark: #075c50;
  --coral: #e5553f;
  --amber: #c8841b;
  --danger: #bd2e24;
  --shadow: 0 22px 70px -48px rgba(20, 24, 20, 0.55);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(245, 246, 242, 0.92)),
    repeating-linear-gradient(90deg, rgba(23, 26, 23, 0.025) 0, rgba(23, 26, 23, 0.025) 1px, transparent 1px, transparent 64px);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.app-shell {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  padding: 20px;
  backdrop-filter: blur(18px);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: inline-flex;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid #17221e;
  border-radius: 8px;
  background: #17221e;
  color: #fff;
  font-weight: 800;
}

.brand-copy {
  display: grid;
  gap: 2px;
}

.brand-copy strong {
  font-size: 16px;
  line-height: 1.2;
}

.brand-copy span {
  color: var(--muted);
  font-size: 12px;
}

.primary-action,
.tool-button,
.segment,
.field-control,
.status-pill,
.session-card,
.result-card,
.turn-block,
.composer {
  border-radius: 8px;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: var(--teal);
  color: #fff;
  font-weight: 700;
  padding: 12px 14px;
}

.primary-action:hover {
  background: var(--teal-dark);
}

.sidebar-section {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.session-list {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.session-card {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--paper-soft);
  padding: 10px;
  text-align: left;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.session-card:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.session-card.active {
  border-color: rgba(11, 125, 109, 0.46);
  background: #edf7f4;
}

.session-title {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
}

.icon-button {
  display: inline-flex;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.icon-button:hover {
  border-color: var(--line-strong);
}

.icon-button.quiet {
  width: 28px;
  height: 28px;
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  height: 100vh;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 246, 242, 0.76);
  padding: 16px clamp(18px, 4vw, 44px);
  backdrop-filter: blur(14px);
}

.topbar-title {
  min-width: 0;
  flex: 1;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(20px, 2vw, 28px);
  line-height: 1.1;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  white-space: nowrap;
}

.status-pill.accent {
  border-color: rgba(229, 85, 63, 0.24);
  background: #fff2ef;
  color: var(--coral);
}

.result-surface {
  min-height: 0;
  overflow: auto;
  padding: 24px clamp(18px, 4vw, 44px) 18px;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 100%;
  gap: 14px;
  text-align: center;
}

.empty-state h2 {
  margin: 0;
  font-size: 24px;
}

.empty-state p {
  max-width: 560px;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.sample-grid {
  display: grid;
  width: min(620px, 100%);
  grid-template-columns: 1.1fr 0.9fr 1fr;
  gap: 10px;
  margin-bottom: 8px;
}

.sample-thumb {
  min-height: 168px;
  border: 1px solid rgba(23, 26, 23, 0.1);
  border-radius: 8px;
  background-position: center;
  background-size: cover;
  box-shadow: var(--shadow);
}

.sample-a {
  background:
    linear-gradient(145deg, rgba(7, 92, 80, 0.18), transparent 38%),
    linear-gradient(25deg, #f8f1e6 0 22%, #f29f7d 22% 38%, #315a5a 38% 62%, #f7d96b 62% 100%);
}

.sample-b {
  background:
    radial-gradient(circle at 42% 34%, #f8f8f5 0 12%, transparent 13%),
    linear-gradient(160deg, #1f2420 0 36%, #d65f4a 36% 54%, #f1ba4a 54% 70%, #f8f8f5 70% 100%);
}

.sample-c {
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.42), transparent 38%),
    repeating-linear-gradient(45deg, #0b7d6d 0 20px, #f4f5ef 20px 40px, #e5553f 40px 60px, #20251f 60px 80px);
}

.turn-list {
  display: grid;
  gap: 18px;
  max-width: 1120px;
  margin: 0 auto;
}

.turn-block {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  padding: 16px;
  box-shadow: var(--shadow);
}

.turn-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.turn-title {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.turn-title strong {
  color: var(--ink);
  font-size: 15px;
}

.turn-title p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.turn-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.mini-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  padding: 7px 9px;
}

.mini-button:hover {
  border-color: var(--line-strong);
}

.reference-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.reference-preview img,
.reference-item img {
  width: 64px;
  height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.result-card {
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--paper);
}

.result-image-button {
  display: block;
  width: 100%;
  border: 0;
  background: #ecefea;
  padding: 0;
}

.result-image-button img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
}

.result-meta span {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-actions {
  display: flex;
  gap: 6px;
}

.loading-tile,
.error-tile {
  display: grid;
  min-height: 220px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #f7f8f5;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.loader {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(11, 125, 109, 0.18);
  border-top-color: var(--teal);
  border-radius: 999px;
  animation: spin 800ms linear infinite;
}

.error-tile {
  border-color: rgba(189, 46, 36, 0.28);
  background: #fff2f0;
  color: var(--danger);
}

.composer-shell {
  border-top: 1px solid var(--line);
  background: rgba(245, 246, 242, 0.88);
  padding: 12px clamp(18px, 4vw, 44px) 20px;
  backdrop-filter: blur(14px);
}

.reference-tray {
  display: flex;
  max-width: 980px;
  min-height: 0;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 auto 8px;
}

.reference-item {
  position: relative;
}

.reference-remove {
  position: absolute;
  top: -7px;
  right: -7px;
  display: inline-flex;
  width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
}

.composer {
  max-width: 980px;
  margin: 0 auto;
  border: 1px solid var(--line-strong);
  background: var(--paper);
  box-shadow: 0 22px 80px -58px rgba(20, 24, 20, 0.7);
}

#promptInput {
  display: block;
  width: 100%;
  min-height: 112px;
  resize: vertical;
  border: 0;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.65;
  padding: 16px 16px 10px;
  outline: none;
}

#promptInput::placeholder {
  color: #8a918c;
}

.composer-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 10px;
}

.controls {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-wrap: wrap;
  gap: 8px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f0f2ed;
  padding: 3px;
}

.segment {
  min-height: 34px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  padding: 6px 10px;
}

.segment.active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.tool-button,
.field-control {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  padding: 7px 10px;
}

.field-control span {
  color: var(--muted);
  font-size: 12px;
}

.field-control input,
.field-control select {
  min-width: 58px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 750;
  outline: 0;
}

.field-control.wide select {
  min-width: 86px;
}

.size-control input {
  width: 112px;
}

.key-control input {
  width: 148px;
}

.send-button {
  display: inline-flex;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  background: var(--coral);
  color: #fff;
  font-size: 22px;
  font-weight: 900;
}

.send-button:hover {
  background: #c94634;
}

.send-button:disabled {
  background: #bec6be;
}

.lightbox {
  width: min(92vw, 1120px);
  max-width: 1120px;
  max-height: 92vh;
  border: 0;
  border-radius: 8px;
  background: #111512;
  color: #fff;
  padding: 16px;
}

.lightbox::backdrop {
  background: rgba(16, 18, 16, 0.76);
}

.lightbox img {
  display: block;
  max-width: 100%;
  max-height: 78vh;
  margin: 0 auto;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.lightbox-caption {
  margin-top: 10px;
  color: rgba(255, 255, 255, 0.76);
  font-size: 13px;
  text-align: center;
}

.mobile-menu,
.mobile-backdrop {
  display: none;
}

.hidden {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 920px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    z-index: 30;
    width: min(310px, 86vw);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(19, 24, 21, 0.32);
  }

  .mobile-backdrop.open,
  .mobile-menu {
    display: inline-flex;
  }

  .workspace {
    min-height: 100vh;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-pills {
    display: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 14px;
  }

  .result-surface {
    padding: 16px 12px 12px;
  }

  .composer-shell {
    padding: 10px 10px 14px;
  }

  .sample-grid {
    width: min(calc(100vw - 24px), 280px);
    max-width: 280px;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .sample-thumb {
    min-height: 76px;
  }

  .empty-state {
    gap: 10px;
    overflow: hidden;
    padding: 8px 0;
  }

  .empty-state h2 {
    font-size: 21px;
  }

  .empty-state p {
    width: 100%;
    max-width: min(calc(100vw - 24px), 280px);
    font-size: 14px;
  }

  .turn-block {
    padding: 12px;
  }

  .turn-head,
  .composer-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .turn-actions {
    justify-content: flex-start;
  }

  .controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segmented {
    grid-column: 1 / -1;
  }

  .segment {
    flex: 1 1 0;
  }

  .send-button {
    width: 100%;
    border-radius: 8px;
  }

  .field-control,
  .tool-button,
  .segmented {
    justify-content: center;
    width: 100%;
  }
}
