@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500;600;700&family=Newsreader:opsz,wght@6..72,400..700&display=swap");

:root {
  --paper: #f3efe3;
  --paper-strong: #fbf7ea;
  --ink: #11110f;
  --ink-soft: #4d4a43;
  --line: #191814;
  --line-soft: rgba(17, 17, 15, 0.18);
  --wash: rgba(255, 255, 255, 0.52);
  --green: #214f3d;
  --green-soft: #d8e2c6;
  --red: #b94b3f;
  --blue: #2d5f86;
  --shadow: 0 22px 55px rgba(17, 17, 15, 0.14);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  color-scheme: light;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "IBM Plex Sans", "Avenir Next", sans-serif;
}

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

button {
  color: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

svg {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.paper-grid {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    repeating-linear-gradient(90deg, rgba(17, 17, 15, 0.04) 0 1px, transparent 1px 72px),
    repeating-linear-gradient(0deg, rgba(17, 17, 15, 0.035) 0 1px, transparent 1px 72px),
    linear-gradient(135deg, rgba(185, 75, 63, 0.08), transparent 28%),
    linear-gradient(315deg, rgba(33, 79, 61, 0.08), transparent 30%);
}

.studio-shell {
  width: min(1480px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(14px, 2.2vw, 28px) 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: "Newsreader", Georgia, serif;
  font-size: 2.15rem;
  font-weight: 650;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

h2 {
  font-family: "Newsreader", Georgia, serif;
  font-size: 1.9rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0;
}

.model-pill {
  display: flex;
  min-width: 190px;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  padding-left: 16px;
  border-left: 1px solid var(--line);
  text-align: right;
}

.label,
.section-number,
.panel-heading,
.char-count,
.board-header p,
#status-line {
  font-family: "IBM Plex Mono", monospace;
}

.label,
.section-number {
  color: var(--ink-soft);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.model-pill strong {
  max-width: 210px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.92rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.studio-grid {
  display: grid;
  grid-template-areas: "command result";
  grid-template-columns: minmax(620px, 1fr) minmax(360px, 420px);
  gap: 16px;
  align-items: start;
}

.command-board {
  grid-area: command;
}

.result-board {
  grid-area: result;
}

.command-board,
.result-board {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(251, 247, 234, 0.88);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.mode-switch__button,
.secondary-action,
.dropzone,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
}

.command-board,
.result-board {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.board-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.board-header p {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.model-pill span {
  color: var(--ink-soft);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
}

.result-board .board-header {
  grid-template-columns: 34px minmax(0, 1fr);
}

.result-board .section-number {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--paper-strong);
  background: var(--ink);
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.mode-switch__button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 0;
  background: rgba(255, 255, 255, 0.24);
  font-weight: 700;
}

.mode-switch__button + .mode-switch__button {
  border-left: 1px solid var(--line);
}

.mode-switch__button.is-active {
  color: var(--paper-strong);
  background: var(--ink);
}

.icon {
  display: inline-grid;
  width: 21px;
  height: 21px;
  place-items: center;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink-soft);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.74rem;
  text-transform: uppercase;
}

.field--prompt {
  gap: 8px;
}

.char-count {
  font-size: 0.7rem;
}

textarea,
select {
  width: 100%;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.48);
  outline: none;
}

textarea:focus,
select:focus,
button:focus-visible {
  box-shadow: 0 0 0 3px rgba(33, 79, 61, 0.22);
}

textarea {
  min-height: 180px;
  resize: vertical;
  padding: 12px;
  font-size: 1rem;
  line-height: 1.65;
}

select {
  min-height: 42px;
  padding: 0 10px;
}

.reference-panel,
.response-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.28);
  overflow: hidden;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  font-size: 0.75rem;
  text-transform: uppercase;
}

.icon-button {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-color: var(--line-soft);
  color: var(--ink);
  background: var(--paper-strong);
}

.icon-button:hover,
.icon-button:focus-visible {
  color: var(--paper-strong);
  background: var(--red);
  border-color: var(--red);
}

.dropzone {
  display: grid;
  min-height: 68px;
  place-items: center;
  gap: 6px;
  width: calc(100% - 18px);
  margin: 9px;
  border-style: dashed;
  background: rgba(33, 79, 61, 0.06);
  font-family: "IBM Plex Mono", monospace;
  text-transform: uppercase;
}

.dropzone.is-dragging {
  color: var(--paper-strong);
  background: var(--green);
}

.dropzone__mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
}

.image-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  gap: 8px;
  padding: 0 10px 10px;
}

.image-chip {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--ink);
}

.image-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-chip button {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border: 1px solid var(--paper-strong);
  border-radius: 50%;
  color: var(--paper-strong);
  background: rgba(17, 17, 15, 0.78);
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.primary-action,
.secondary-action {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 6px;
  padding: 0 18px;
  font-weight: 700;
}

.primary-action {
  flex: 1 1 180px;
  border: 1px solid var(--line);
  color: var(--paper-strong);
  background: var(--green);
}

.primary-action:hover,
.primary-action:focus-visible {
  background: var(--ink);
}

.secondary-action {
  flex: 0 0 auto;
  min-width: 112px;
  background: rgba(255, 255, 255, 0.24);
}

.secondary-action:hover,
.secondary-action:focus-visible {
  color: var(--paper-strong);
  background: var(--blue);
}

.stage {
  position: relative;
  display: grid;
  min-height: 360px;
  aspect-ratio: 1;
  overflow: hidden;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    repeating-linear-gradient(135deg, rgba(17, 17, 15, 0.08) 0 1px, transparent 1px 14px),
    #ede7d8;
}

.stage img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 640px;
  object-fit: contain;
  background: #0f0f0d;
}

.empty-state {
  display: grid;
  gap: 12px;
  place-items: center;
  color: rgba(17, 17, 15, 0.58);
  font-family: "IBM Plex Mono", monospace;
  text-transform: uppercase;
}

.empty-state svg {
  width: 62px;
  height: 62px;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.result-tile {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper-strong);
}

.result-tile img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--ink);
}

.tile-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--line);
}

.tile-actions a,
.tile-actions button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  text-decoration: none;
  text-transform: uppercase;
}

.tile-actions a + a,
.tile-actions a + button,
.tile-actions button + a {
  border-left: 1px solid var(--line);
}

.tile-actions a:hover,
.tile-actions button:hover {
  color: var(--paper-strong);
  background: var(--ink);
}

#response-json {
  max-height: 180px;
  margin: 0;
  overflow: auto;
  padding: 12px;
  color: var(--green-soft);
  background: #11110f;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.76rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

.is-loading .primary-action .icon {
  animation: slide 880ms ease-in-out infinite;
}

@keyframes slide {
  0%,
  100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(5px);
  }
}

[hidden] {
  display: none !important;
}

@media (max-width: 1120px) {
  .studio-grid {
    grid-template-areas:
      "command"
      "result";
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .studio-shell {
    width: min(100% - 24px, 760px);
    padding: 14px 0;
  }

  .studio-grid,
  .result-board,
  .board-header {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 2rem;
  }
}

@media (max-width: 620px) {
  .board-header {
    gap: 12px;
  }

  .model-pill {
    min-width: 0;
    align-items: flex-start;
    padding-left: 0;
    border-left: 0;
    text-align: left;
  }

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

  h1 {
    font-size: 1.72rem;
    white-space: normal;
  }

  h2 {
    font-size: 1.55rem;
  }

  .mode-switch__button + .mode-switch__button {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .mode-switch,
  .gallery {
    grid-template-columns: 1fr;
  }

  textarea {
    min-height: 180px;
  }

  .stage {
    min-height: 260px;
  }
}
