:root {
  --ink: #171916;
  --muted: #73766e;
  --line: #dcded7;
  --paper: #f5f5f1;
  --panel: #ebece6;
  --white: #fcfcf9;
  --acid: #d9ff43;
  --acid-dark: #bfe728;
  --danger: #ee6d61;
  --sidebar-width: 326px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--paper); }

body { overflow-x: hidden; }

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

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  padding: 24px 20px 20px;
  background: #e9eae4;
  border-right: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 4px 28px; }
.brand h1 { margin: 0; font-size: 16px; line-height: 1.1; letter-spacing: -.02em; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.brand-mark { position: relative; width: 34px; height: 34px; transform: rotate(-7deg); }
.brand-mark span { position: absolute; inset: 5px 13px 5px 4px; border-radius: 4px; background: var(--ink); }
.brand-mark span:last-child { inset: 5px 4px 5px 19px; background: var(--acid); border: 2px solid var(--ink); }
.sidebar-close { display: none; margin-left: auto; }

.sidebar-section-label {
  display: flex;
  justify-content: space-between;
  padding: 0 6px 9px;
  color: #777a72;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.sidebar-section-label span:last-child {
  min-width: 19px;
  height: 19px;
  padding: 3px 5px;
  border-radius: 10px;
  color: #60635b;
  background: #d7d8d1;
  text-align: center;
  letter-spacing: 0;
}

.variant-tabs { display: grid; gap: 4px; }

.variant-tab {
  position: relative;
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 9px;
  min-height: 50px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 150ms, border-color 150ms, transform 150ms;
}

.variant-tab:hover { background: rgba(255,255,255,.5); }
.variant-tab.active { background: var(--white); border-color: #d7d8d1; box-shadow: 0 1px 2px rgba(0,0,0,.025); }
.variant-tab.active::before { content: ""; position: absolute; left: -1px; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; background: var(--ink); }
.variant-number { color: #898c84; font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.variant-info { min-width: 0; }
.variant-name { display: block; overflow: hidden; font-size: 13px; font-weight: 650; white-space: nowrap; text-overflow: ellipsis; }
.variant-label { display: block; overflow: hidden; margin-top: 3px; color: var(--muted); font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }
.variant-menu { opacity: 0; padding: 4px; border: 0; background: transparent; color: #777; cursor: pointer; }
.variant-tab:hover .variant-menu, .variant-tab.active .variant-menu { opacity: 1; }

.add-variant {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 7px 4px 19px;
  padding: 10px 8px;
  border: 0;
  color: #62655d;
  background: transparent;
  font-size: 12px;
  cursor: pointer;
}
.add-variant:hover { color: var(--ink); }
.add-variant span { font-size: 18px; font-weight: 300; }

.prompt-panel {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  padding-top: 18px;
  border-top: 1px solid #d5d6d0;
}
.prompt-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.prompt-panel-head label { padding-left: 5px; font-size: 11px; font-weight: 700; letter-spacing: .04em; }
.prompt-actions { display: flex; align-items: center; gap: 3px; }
.text-button, .icon-button { border: 0; background: transparent; cursor: pointer; }
.text-button { display: flex; align-items: center; gap: 4px; padding: 5px 7px; color: #686b63; font-size: 10px; }
.text-button svg, .icon-button svg { width: 16px; height: 16px; }
.icon-button { display: grid; width: 31px; height: 31px; padding: 0; place-items: center; border-radius: 6px; }
.icon-button:hover, .text-button:hover { color: var(--ink); background: #dcddd7; }

#promptEditor {
  width: 100%;
  min-height: 150px;
  flex: 1;
  resize: none;
  padding: 13px 14px;
  border: 1px solid #d1d3cb;
  border-radius: 9px;
  outline: none;
  background: rgba(252,252,249,.78);
  color: #3f423c;
  font: 11.5px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace;
  transition: border-color 150ms, background 150ms;
}
#promptEditor:focus { border-color: #9b9e94; background: var(--white); }
.editor-meta { display: flex; justify-content: space-between; padding: 8px 5px 12px; color: #888b82; font-size: 9px; }
.status-dot { display: inline-block; width: 5px; height: 5px; margin: 0 5px 1px 0; border-radius: 50%; background: #77a956; }

.run-button {
  position: relative;
  min-height: 47px;
  overflow: hidden;
  border: 1px solid #141512;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}
.run-button:hover { background: #282a25; }
.run-button:disabled { cursor: wait; }
.run-label { position: relative; z-index: 2; display: flex; align-items: center; justify-content: center; gap: 7px; }
.run-label svg { width: 15px; fill: currentColor; stroke: none; }
.run-progress { position: absolute; z-index: 1; inset: 0 auto 0 0; width: 0; background: #343730; transition: width 250ms ease; }

.workspace { min-height: 100vh; margin-left: var(--sidebar-width); }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 87px; padding: 19px 34px; border-bottom: 1px solid var(--line); background: rgba(245,245,241,.94); }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.menu-button { display: none; }
.eyebrow { color: #85887e; font-size: 9px; font-weight: 750; letter-spacing: .16em; }
.topbar h2 { margin: 6px 0 0; font-size: 18px; letter-spacing: -.025em; }
.title-edit { margin-left: 5px; padding: 0; border: 0; background: transparent; color: #8b8e86; font-size: 12px; cursor: pointer; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.saved-state { margin-right: 6px; color: #74776f; font-size: 10px; }
.saved-state i { display: inline-block; width: 5px; height: 5px; margin: 0 5px 1px 0; border-radius: 50%; background: #7db35b; }
.saved-state.missing { color: #9a5c54; }
.saved-state.missing i { background: var(--danger); }
.secondary-button, .primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid #d1d3cc;
  border-radius: 7px;
  background: var(--white);
  font-size: 10.5px;
  font-weight: 650;
  cursor: pointer;
}
.secondary-button:hover { background: #eeeeea; }
.secondary-button svg { width: 15px; height: 15px; }
.primary-button { min-height: 40px; padding: 0 18px; border-color: var(--ink); background: var(--ink); color: white; }
.primary-button:hover { background: #292b27; }
.more-button { width: 36px; height: 36px; border: 1px solid #d1d3cc; border-radius: 7px; background: var(--white); cursor: pointer; letter-spacing: 1px; }

.matrix-toolbar { display: flex; align-items: flex-end; justify-content: space-between; padding: 30px 34px 19px; }
.matrix-title-row { display: flex; align-items: center; gap: 10px; }
.matrix-title-row h3 { margin: 0; font-size: 15px; letter-spacing: -.015em; }
.matrix-toolbar p { margin: 7px 0 0; color: var(--muted); font-size: 10px; }
.version-pill { padding: 4px 7px; border-radius: 4px; background: #e2e3dd; color: #686b63; font-size: 8px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.view-controls { display: flex; gap: 10px; }
.batch-switch, .density-switch { display: flex; padding: 3px; border: 1px solid #d8dad3; border-radius: 7px; background: #ebebe6; }
.batch-switch button, .density-switch button { min-width: 54px; height: 29px; padding: 0 9px; border: 0; border-radius: 5px; background: transparent; color: #80837a; font: 9px ui-monospace, SFMono-Regular, Menlo, monospace; cursor: pointer; }
.batch-switch button.active, .density-switch button.active { background: var(--white); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.07); }
.density-switch button { min-width: 31px; padding: 0; }
.density-switch svg { width: 14px; fill: currentColor; stroke: none; }

.image-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 23px 17px; padding: 0 34px 48px; }
.image-grid.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px 13px; }
.image-card { min-width: 0; }
.image-frame { position: relative; overflow: hidden; aspect-ratio: 16 / 9; border-radius: 8px; background: #dfe1da; cursor: zoom-in; isolation: isolate; }
.image-frame.empty-frame { cursor: default; background: #e7e8e2; }
.image-frame.empty-frame::before { content: ""; position: absolute; inset: 0; opacity: .38; background-image: radial-gradient(#b9bbb3 0.7px, transparent 0.7px); background-size: 12px 12px; }
.image-frame::after { content: ""; position: absolute; inset: 0; z-index: 2; border: 1px solid rgba(10,12,9,.12); border-radius: inherit; pointer-events: none; }
.image-frame img { width: 100%; height: 100%; display: block; object-fit: cover; transition: transform 350ms cubic-bezier(.2,.7,.2,1), filter 250ms; }
.image-frame:hover img { transform: scale(1.025); }
.result-number { position: absolute; z-index: 3; top: 10px; left: 10px; display: grid; min-width: 29px; height: 22px; padding: 0 6px; place-items: center; border-radius: 4px; background: rgba(15,17,14,.78); color: white; backdrop-filter: blur(5px); font: 9px ui-monospace, SFMono-Regular, Menlo, monospace; }
.zoom-indicator { position: absolute; z-index: 3; right: 10px; top: 10px; display: grid; width: 27px; height: 27px; place-items: center; border: 0; border-radius: 50%; opacity: 0; background: rgba(250,250,246,.9); color: var(--ink); transform: translateY(-4px); transition: opacity 160ms, transform 160ms; }
.image-frame:hover .zoom-indicator { opacity: 1; transform: translateY(0); }
.zoom-indicator svg { width: 13px; height: 13px; }
.card-meta { display: grid; grid-template-columns: 25px 1fr auto; align-items: start; gap: 8px; padding: 10px 3px 0; }
.card-index { color: #969990; font: 9px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.card-copy { min-width: 0; }
.card-copy h4 { overflow: hidden; margin: 0; font-size: 10.5px; font-weight: 670; white-space: nowrap; text-overflow: ellipsis; }
.card-copy p { overflow: hidden; margin: 3px 0 0; color: #81847b; font-size: 9px; white-space: nowrap; text-overflow: ellipsis; }
.card-menu { padding: 0 2px; border: 0; background: transparent; color: #92958c; cursor: pointer; letter-spacing: 1px; }
.empty-result { position: absolute; z-index: 3; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; padding: 35px; color: #7e8178; text-align: center; }
.empty-result-mark { display: grid; width: 28px; height: 28px; margin-bottom: 9px; place-items: center; border: 1px solid #c0c2ba; border-radius: 50%; color: #8d9087; font-size: 18px; font-weight: 300; }
.empty-result strong { color: #686b63; font-size: 10.5px; font-weight: 650; }
.empty-result small { max-width: 260px; overflow: hidden; margin-top: 5px; color: #969990; font-size: 8.5px; line-height: 1.45; text-overflow: ellipsis; white-space: nowrap; }
.error-result .empty-result-mark { border-color: #e1aaa4; background: #f6d9d5; color: #9e443b; font-weight: 700; }
.error-result strong { color: #934c44; }
.image-card.has-error .image-frame::after { border-color: rgba(190,76,64,.45); }
.image-card.is-loading .image-frame { background: linear-gradient(105deg, #dedfd8 20%, #f0f0ec 40%, #dedfd8 60%); background-size: 200% 100%; animation: shimmer 1.1s infinite linear; }
.image-card.is-loading img { opacity: 0; }
.image-card.is-loading .empty-result-mark { border-color: transparent; border-top-color: #71746c; animation: spin .8s linear infinite; }
@keyframes shimmer { to { background-position-x: -200%; } }
@keyframes spin { to { transform: rotate(360deg); } }

.modal { position: fixed; z-index: 100; inset: 0; display: none; }
.modal.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10,11,9,.75); backdrop-filter: blur(8px); animation: fade-in 180ms ease; }
@keyframes fade-in { from { opacity: 0; } }
.image-viewer { position: absolute; inset: 0; display: grid; padding: 70px 80px 54px; place-items: center; }
.image-viewer > img { z-index: 1; max-width: min(1400px, 88vw); max-height: 80vh; border-radius: 7px; box-shadow: 0 18px 70px rgba(0,0,0,.45); object-fit: contain; }
.viewer-topbar { position: absolute; z-index: 3; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; height: 64px; padding: 0 25px; color: white; }
.viewer-index { margin-right: 15px; color: #aeb0aa; font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; }
.viewer-title { font-size: 12px; font-weight: 650; }
.viewer-actions { display: flex; align-items: center; gap: 10px; }
.viewer-actions .secondary-button { border-color: #555751; background: #292b27; color: white; }
.modal-close { display: grid; width: 36px; height: 36px; padding: 0 0 2px; place-items: center; border: 1px solid #555751; border-radius: 50%; background: #292b27; color: white; font-size: 23px; font-weight: 300; cursor: pointer; }
.modal-close.dark { border-color: #d3d5ce; background: transparent; color: var(--ink); }
.viewer-arrow { position: absolute; z-index: 3; top: 50%; width: 42px; height: 42px; border: 1px solid #555751; border-radius: 50%; background: rgba(28,30,26,.8); color: white; font-size: 18px; cursor: pointer; }
.viewer-arrow:hover { background: #41433d; }
.viewer-arrow.previous { left: 21px; }
.viewer-arrow.next { right: 21px; }
.viewer-caption { position: absolute; z-index: 3; bottom: 20px; max-width: 750px; color: #c6c8c1; font-size: 11px; text-align: center; }

.modal-sheet { position: absolute; z-index: 2; inset: 4vh 4vw; display: flex; flex-direction: column; overflow: hidden; border-radius: 12px; background: var(--paper); box-shadow: 0 20px 80px rgba(0,0,0,.35); animation: sheet-in 220ms ease; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(10px) scale(.99); } }
.sheet-header { display: flex; align-items: center; min-height: 86px; gap: 20px; padding: 20px 25px; border-bottom: 1px solid var(--line); }
.sheet-header h2 { margin: 6px 0 0; font-size: 18px; }
.sheet-header p { margin: 6px 0 0; color: var(--muted); font-size: 10px; }
.sheet-header .modal-close { margin-left: auto; flex: 0 0 auto; }
.sheet-footer { display: flex; align-items: center; justify-content: space-between; min-height: 68px; padding: 12px 24px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.prompt-sheet textarea { width: 100%; min-height: 0; flex: 1; resize: none; padding: 38px max(5vw, 40px); border: 0; outline: 0; background: var(--white); color: #2e312c; font: 15px/1.85 ui-monospace, SFMono-Regular, Menlo, monospace; }
.diff-select-wrap { display: flex; align-items: center; gap: 8px; margin-left: auto; color: var(--muted); font-size: 10px; }
.diff-select-wrap select { min-width: 160px; height: 35px; padding: 0 28px 0 10px; border: 1px solid var(--line); border-radius: 6px; outline: none; background: var(--white); color: var(--ink); font-size: 11px; }
.diff-select-wrap + .modal-close { margin-left: 0; }
.diff-legend { display: flex; gap: 18px; padding: 14px 28px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.diff-legend i { display: inline-block; width: 9px; height: 9px; margin-right: 5px; border-radius: 2px; }
.removed-key { background: #ffc9c3; }
.added-key { background: #cdeca8; }
.diff-content { min-height: 0; flex: 1; overflow: auto; padding: 32px max(4vw, 35px); background: var(--white); font: 14px/2.05 ui-monospace, SFMono-Regular, Menlo, monospace; }
.diff-content .removed { padding: 2px 3px; border-radius: 3px; background: #ffd7d2; color: #9b3029; text-decoration: line-through; }
.diff-content .added { padding: 2px 3px; border-radius: 3px; background: #dff5c2; color: #396118; }
.diff-heading { display: grid; grid-template-columns: 1fr 1fr; gap: 25px; margin-bottom: 16px; color: var(--muted); font: 10px ui-sans-serif, sans-serif; letter-spacing: .08em; text-transform: uppercase; }
.diff-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 25px; }
.diff-column { padding: 22px; border: 1px solid var(--line); border-radius: 8px; background: #f7f7f3; }

.prompts-sheet { inset: 3vh max(5vw, 40px); }
.user-prompt-list { min-height: 0; overflow: auto; padding: 12px 25px 30px; counter-reset: prompt; }
.user-prompt-row { display: grid; grid-template-columns: 34px minmax(130px, .32fr) 1fr; gap: 11px; align-items: center; padding: 10px 0; border-bottom: 1px solid #e0e1da; }
.user-prompt-number { color: #90938a; font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; }
.user-prompt-row input, .user-prompt-row textarea { width: 100%; padding: 9px 10px; border: 1px solid transparent; border-radius: 6px; outline: none; background: transparent; color: var(--ink); font-size: 11px; }
.user-prompt-row input { font-weight: 650; }
.user-prompt-row textarea { height: 39px; resize: none; line-height: 1.7; }
.user-prompt-row input:focus, .user-prompt-row textarea:focus { border-color: #cfd1ca; background: var(--white); }

.toast { position: fixed; z-index: 200; left: 50%; bottom: 25px; padding: 11px 16px; border-radius: 7px; opacity: 0; pointer-events: none; background: var(--ink); color: white; font-size: 10.5px; transform: translate(-50%, 12px); transition: opacity 180ms, transform 180ms; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 1500px) {
  .image-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .image-grid.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); transition: transform 220ms ease; box-shadow: 18px 0 50px rgba(0,0,0,.18); }
  body.sidebar-open::after { content: ""; position: fixed; z-index: 29; inset: 0; background: rgba(20,21,19,.35); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-close, .menu-button { display: grid; }
  .workspace { margin-left: 0; }
  .saved-state { display: none; }
}

@media (max-width: 680px) {
  .topbar { min-height: 74px; padding: 14px 18px; }
  .topbar-actions .secondary-button { display: none; }
  .matrix-toolbar { align-items: flex-start; padding: 23px 18px 15px; gap: 15px; }
  .view-controls { flex-direction: column; align-items: flex-end; }
  .density-switch { display: none; }
  .image-grid, .image-grid.compact { grid-template-columns: 1fr; gap: 20px; padding: 0 18px 35px; }
  .modal-sheet, .prompts-sheet { inset: 0; border-radius: 0; }
  .diff-columns, .diff-heading { grid-template-columns: 1fr; }
  .diff-heading span:last-child { display: none; }
  .user-prompt-row { grid-template-columns: 28px 1fr; }
  .user-prompt-row textarea { grid-column: 2; }
  .image-viewer { padding: 70px 10px 54px; }
  .image-viewer > img { max-width: 96vw; }
  .viewer-arrow { top: auto; bottom: 66px; }
  .viewer-arrow.previous { left: 15px; }
  .viewer-arrow.next { right: 15px; }
}
