:root {
  color-scheme: light;
  --ink: #173b3d;
  --ink-soft: #526c69;
  --ocean: #16565a;
  --ocean-deep: #0c3f43;
  --sea-glass: #a9d7cf;
  --foam: #edf7f3;
  --paper: #fbf7ed;
  --paper-deep: #f2ead9;
  --white: #fffefa;
  --coral: #dd735b;
  --coral-deep: #a94535;
  --gold: #d6a94a;
  --red: #a33b3b;
  --green: #28745f;
  --line: rgba(23, 59, 61, 0.16);
  --line-strong: rgba(23, 59, 61, 0.28);
  --shadow: 0 18px 55px rgba(36, 65, 62, 0.12);
  --shadow-small: 0 7px 24px rgba(36, 65, 62, 0.1);
  --radius: 18px;
  --serif: Iowan Old Style, Baskerville, Palatino Linotype, Book Antiqua, Palatino, Georgia, serif;
  --sans: Avenir Next, Avenir, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 8%, rgba(214, 169, 74, 0.09) 0 1px, transparent 2px) 0 0 / 19px 19px,
    linear-gradient(135deg, var(--paper) 0%, #f8f5eb 48%, #edf5ef 100%);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}

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

button,
select,
input[type="range"],
input[type="radio"] {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(221, 115, 91, 0.45);
  outline-offset: 3px;
}

img {
  display: block;
  max-width: 100%;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  text-wrap: balance;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  transform: translateY(-160%);
  border-radius: 8px;
  padding: 10px 15px;
  color: white;
  background: var(--ocean-deep);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  position: sticky;
  z-index: 30;
  top: 0;
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  padding: 10px clamp(16px, 3vw, 42px);
  background: rgba(251, 247, 237, 0.93);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid rgba(22, 86, 90, 0.12);
  border-radius: 50%;
  color: var(--ocean);
  background: var(--foam);
}

.brand-mark svg {
  width: 36px;
  fill: currentColor;
}

.brand-mark .brand-line {
  fill: none;
  stroke: var(--paper);
  stroke-linecap: round;
  stroke-width: 2;
}

.brand strong {
  display: block;
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.1;
}

.brand small {
  display: block;
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-actions form {
  margin: 0;
}

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-right: 4px;
  color: var(--ink-soft);
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(214, 169, 74, 0.15);
}

.connection-status.is-connected .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(40, 116, 95, 0.14);
}

.connection-status.is-offline .status-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(163, 59, 59, 0.12);
}

.quiet-button,
.primary-button,
.secondary-button,
.icon-button,
.decision-button,
.text-button {
  border: 0;
  border-radius: 999px;
  padding: 10px 15px;
  font-weight: 700;
  transition: transform 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}

.quiet-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  background: transparent;
}

.quiet-button:hover {
  background: rgba(22, 86, 90, 0.08);
}

.quiet-button svg {
  width: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.primary-button {
  color: white;
  background: var(--ocean);
  box-shadow: 0 6px 16px rgba(22, 86, 90, 0.2);
}

.primary-button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: var(--ocean-deep);
  box-shadow: 0 9px 20px rgba(22, 86, 90, 0.24);
}

.primary-button:disabled,
.secondary-button:disabled,
.decision-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary-button {
  border: 1px solid var(--line-strong);
  color: var(--ink);
  background: var(--white);
}

.secondary-button:hover:not(:disabled) {
  background: var(--foam);
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  padding: 0;
  color: var(--ink);
  background: rgba(22, 86, 90, 0.08);
  font-size: 25px;
  font-weight: 400;
}

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

.page-rail {
  position: sticky;
  top: 77px;
  align-self: start;
  height: calc(100vh - 77px);
  overflow-y: auto;
  border-right: 1px solid var(--line);
  padding: 25px 16px 40px;
  background: rgba(255, 254, 250, 0.47);
}

.rail-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 9px 12px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.page-count {
  display: grid;
  min-width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  color: var(--ocean);
  background: var(--sea-glass);
  font-size: 11px;
}

.page-nav-list {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.page-nav-link {
  display: grid;
  min-height: 45px;
  align-items: center;
  grid-template-columns: 28px 1fr auto;
  gap: 7px;
  border-radius: 12px;
  padding: 7px 9px;
  color: var(--ink-soft);
  text-decoration: none;
}

.page-nav-link:hover {
  color: var(--ink);
  background: rgba(22, 86, 90, 0.06);
}

.page-nav-link[aria-current="page"] {
  color: var(--ocean-deep);
  background: var(--foam);
  box-shadow: inset 3px 0 var(--coral);
  font-weight: 800;
}

.page-number {
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.page-nav-title {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-state {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line-strong);
}

.nav-state.has-master {
  background: var(--green);
}

.nav-state.has-pending {
  background: var(--gold);
  animation: pulse 1.6s ease-in-out infinite;
}

#workspace-main {
  width: min(100%, 1500px);
  margin: 0 auto;
  padding: 42px clamp(20px, 4vw, 64px) 90px;
}

.book-heading {
  margin-bottom: 52px;
}

.book-heading h1,
.book-page-heading h2 {
  font-family: var(--serif);
  font-weight: 600;
}

.book-heading h1 {
  font-size: clamp(38px, 6vw, 72px);
}

.book-scroll {
  display: grid;
  gap: 100px;
}

.identity-reference-library {
  margin-bottom: 54px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: clamp(16px, 2.5vw, 28px);
  background: var(--white);
}

.identity-reference-heading {
  margin-bottom: 18px;
}

.identity-reference-heading h2 {
  margin-bottom: 6px;
  font-family: var(--serif);
}

.identity-reference-heading p:last-child {
  margin-bottom: 0;
  color: var(--ink-soft);
}

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

.identity-reference-area {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 14px;
  background: var(--paper-deep);
}

.identity-reference-area > header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.identity-reference-area > header span,
.identity-reference-empty {
  color: var(--ink-soft);
}

.identity-reference-list {
  display: grid;
  gap: 12px;
}

.identity-reference-card {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(0, 1.2fr);
  gap: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.identity-reference-image img,
.identity-reference-image .image-unavailable {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.identity-reference-record dl {
  display: grid;
  gap: 6px;
  margin: 0 0 10px;
}

.identity-reference-record .meta-item {
  min-width: 0;
}

.identity-reference-record dd {
  overflow-wrap: anywhere;
}

.identity-reference-record pre {
  overflow: auto;
  max-height: 180px;
  white-space: pre-wrap;
}

.identity-reference-empty {
  min-height: 130px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

@media (max-width: 650px) {
  .identity-reference-columns,
  .identity-reference-card {
    grid-template-columns: 1fr;
  }
}

.book-page {
  scroll-margin-top: 90px;
}

.book-page-heading {
  margin-bottom: 18px;
}

.book-page-heading h2 {
  font-size: clamp(32px, 5vw, 56px);
}

.book-page-image {
  width: 100%;
  min-height: 65vh;
  background: var(--paper-deep);
}

.book-page-image img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100vh;
  object-fit: contain;
}

.variation-strip {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.variation-item {
  width: 180px;
  flex: 0 0 auto;
}

.variation-thumbnail {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 104px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0;
  background: #111;
  opacity: 0.68;
}

.variation-info {
  margin-top: 5px;
  font-size: 10px;
}

.variation-info > summary {
  cursor: pointer;
  color: var(--ink-soft);
}

.variation-info[open] {
  position: relative;
  z-index: 4;
  width: min(720px, 88vw);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #111;
}

.variation-info pre {
  overflow: auto;
  max-height: 360px;
  white-space: pre-wrap;
}

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

.variation-thumbnail:hover,
.variation-thumbnail.is-selected {
  border-color: #fff;
  opacity: 1;
}

.variation-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.variation-thumbnail span {
  position: absolute;
  right: 4px;
  bottom: 4px;
  min-width: 18px;
  border-radius: 3px;
  padding: 1px 4px;
  color: #fff;
  background: rgba(0, 0, 0, 0.78);
  font-size: 10px;
}

.book-revision-form {
  display: grid;
  gap: 20px;
  padding: clamp(26px, 5vw, 56px) 0;
}

.book-revision-form > button {
  justify-self: start;
}

.book-rounds {
  border-top: 1px solid var(--line);
  padding-top: 4px;
}

.book-rounds > summary {
  cursor: pointer;
  padding: 22px 0;
  font-weight: 800;
}

/* Compact internal book dashboard */
:root {
  color-scheme: dark;
  --ink: #f2f2f2;
  --ink-soft: #a9a9a9;
  --paper: #050505;
  --paper-deep: #111;
  --white: #0d0d0d;
  --foam: #171717;
  --line: rgba(255, 255, 255, 0.14);
  --line-strong: rgba(255, 255, 255, 0.24);
  --shadow: none;
  --shadow-small: none;
}

body {
  color: var(--ink);
  background: #050505;
}

.visually-hidden {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.site-header {
  min-height: 54px;
  border-color: var(--line);
  padding: 6px 18px;
  background: rgba(5, 5, 5, 0.94);
}

.brand-mark,
.brand small {
  display: none;
}

.brand strong {
  font-family: var(--sans);
  font-size: 14px;
}

.app-shell {
  display: block;
}

.page-rail {
  position: sticky;
  z-index: 25;
  top: 54px;
  width: 100%;
  height: auto;
  min-height: 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 7px 14px;
  background: rgba(5, 5, 5, 0.94);
  backdrop-filter: blur(14px);
}

.rail-heading {
  display: none;
}

.page-nav-list {
  display: flex;
  gap: 5px;
  overflow-x: auto;
}

.page-nav-link {
  display: flex;
  min-height: 30px;
  flex: 0 0 auto;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  color: var(--ink-soft);
}

.page-nav-title {
  max-width: 120px;
  font-size: 11px;
}

#workspace-main {
  width: min(100%, 1600px);
  padding: 22px clamp(12px, 2vw, 30px) 80px;
}

.book-scroll {
  gap: 70px;
}

.book-page-heading {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}

.book-page-heading .eyebrow {
  margin: 0;
}

.book-page-heading h2 {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 700;
}

.book-page-image {
  min-height: 50vh;
  background: #0b0b0b;
}

.page-reference-strip {
  display: flex;
  min-height: 54px;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 7px 0;
  color: var(--ink-soft);
  font-size: 12px;
}

.reference-label {
  color: var(--ink);
  font-weight: 700;
}

.reference-thumbnail {
  overflow: hidden;
  width: 62px;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
}

.reference-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reference-missing {
  color: #777;
}

.character-reference-workspace {
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
}

.character-reference-workspace > summary {
  padding: 10px 2px;
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}

.character-reference-workspace > summary span {
  margin-left: 6px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 500;
}

.reference-workspace-body {
  padding: 0 0 12px;
}

.reference-help,
.reference-empty {
  margin: 0 0 9px;
  color: #888;
  font-size: 12px;
}

.reference-groups {
  display: grid;
  gap: 10px;
}

.reference-group {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  background: #0b0b0b;
}

.reference-group header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.reference-group header span {
  color: #777;
  font-size: 10px;
  text-transform: capitalize;
}

.reference-options {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.reference-group-viewer {
  display: grid;
  min-height: min(52vw, 620px);
  margin-bottom: 9px;
  place-items: center;
  overflow: hidden;
  border-radius: 4px;
  background: #050505;
}

.reference-group-viewer img {
  width: 100%;
  max-height: min(70vh, 760px);
  object-fit: contain;
}

.reference-option {
  display: grid;
  grid-template-columns: auto 62px;
  align-items: center;
  gap: 5px;
  font-size: 10px;
}

.reference-option .variation-info {
  grid-column: 1 / -1;
}

.reference-option .text-button {
  grid-column: 2;
  justify-self: start;
  padding: 2px 0;
  color: #aaa;
  font-size: 10px;
}

.round-source {
  display: grid;
  grid-template-columns: minmax(150px, 240px) minmax(180px, 1fr);
  gap: 8px 12px;
  margin: 8px 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  background: #080808;
}

.round-comment,
.generation-comment {
  margin: 8px 0 12px;
  border-left: 3px solid #666;
  padding: 7px 10px;
  color: var(--ink);
  background: #0b0b0b;
}

.round-comment p,
.generation-comment p,
.generation-comment h4 {
  margin: 0;
}

.round-comment strong,
.generation-comment h4 {
  display: block;
  margin-bottom: 3px;
  color: var(--ink-soft);
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.round-source > strong,
.round-source > .variation-info {
  grid-column: 1;
}

.round-source-image {
  grid-column: 2;
  grid-row: 1 / span 2;
  overflow: hidden;
  border: 0;
  border-radius: 4px;
  padding: 0;
  background: #000;
}

.round-source-image img {
  width: 100%;
  max-height: 340px;
  object-fit: contain;
}

.round-variation-strip,
.generation-input-grid {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.generation-input-gallery {
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #080808;
}

.generation-input-gallery h4 {
  margin: 0 0 8px;
  font-size: 12px;
}

.generation-input-card {
  display: grid;
  flex: 0 0 150px;
  gap: 4px;
  border: 1px solid transparent;
  padding: 5px;
  color: var(--ink);
  text-align: left;
  text-decoration: none;
  background: #050505;
}

.generation-input-card:hover,
.generation-input-card.is-selected {
  border-color: #fff;
}

.generation-input-card > span {
  display: grid;
  height: 100px;
  place-items: center;
  overflow: hidden;
  border-radius: 4px;
  background: #000;
}

.generation-input-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.generation-input-card small {
  color: var(--ink-soft);
}

.generation-input-card em {
  color: #ccc;
  font-size: 10px;
  font-style: normal;
}

.viewer-selection-status {
  min-height: 18px;
  padding-top: 4px;
  color: #aaa;
  font-size: 11px;
}

@media (max-width: 700px) {
  .round-source {
    grid-template-columns: 1fr;
  }

  .round-source-image,
  .round-source > strong,
  .round-source > .variation-info {
    grid-column: 1;
    grid-row: auto;
  }
}

.reference-option small {
  grid-column: 2;
}

.new-reference-group-form,
.character-generation-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(150px, 240px) auto;
  gap: 8px;
  margin-top: 10px;
}

.new-reference-group-form input,
.new-reference-group-form select,
.character-generation-form input,
.character-generation-form select {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 7px 9px;
  color: var(--ink);
  background: #111;
}

@media (max-width: 760px) {
  .new-reference-group-form,
  .character-generation-form {
    grid-template-columns: 1fr;
  }
}

/* Final compact overrides for the continuous dashboard history. */
.book-rounds {
  margin-top: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  padding: 0;
  color: #eee;
  background: #050505;
}

.book-rounds > summary {
  padding: 10px 12px;
  color: #ddd;
  background: #050505;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.book-rounds[open] > summary {
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.book-rounds .round-list {
  gap: 10px;
  padding: 10px;
  background: #050505;
}

.book-rounds .round-card {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 5px;
  padding: 10px;
  color: #eee;
  background: #090909;
  box-shadow: none;
}

.book-rounds .round-card h3 {
  margin: 2px 0 7px;
  font-family: var(--sans);
  font-size: 13px;
}

.book-rounds .variation-item {
  width: 150px;
}

.book-rounds .variation-thumbnail {
  height: 86px;
  background: #000;
  opacity: .82;
}

.book-rounds .variation-thumbnail span {
  width: auto;
  padding: 2px 6px;
}

.book-revision-form {
  grid-template-columns: minmax(220px, 1fr) minmax(160px, 220px) minmax(80px, 100px) minmax(130px, 175px) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}

.book-revision-form > *,
.book-revision-form select {
  min-width: 0;
}

.book-revision-form select {
  width: 100%;
}

@media (max-width: 1050px) {
  .book-revision-form {
    grid-template-columns: minmax(220px, 1fr) minmax(150px, 210px) minmax(80px, 100px) minmax(130px, 170px);
  }

  .book-revision-form .primary-button {
    grid-column: 4;
  }
}

.compact-comment textarea {
  display: block;
  width: 100%;
  min-height: 42px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 9px 11px;
  color: var(--ink);
  background: #111;
}

.compact-comment {
  position: relative;
}

.compact-comment small {
  position: absolute;
  right: 8px;
  bottom: 3px;
  color: #777;
  font-size: 9px;
}

.compact-comment [data-exact-mode-note] {
  display: block;
  margin-top: 4px;
  color: #bbb;
  font-size: 10px;
  font-style: normal;
}

.compact-comment [data-exact-mode-note][hidden] {
  display: none;
}

.compact-comment textarea.is-not-applied {
  color: #777;
  border-style: dashed;
}

.book-revision-form .select-field > span {
  display: none;
}

.book-revision-form select {
  min-height: 42px;
  color: var(--ink);
  background: #111;
}

.book-revision-form .charge-confirmation {
  border: 0;
  padding: 0;
  color: var(--ink-soft);
  background: transparent;
  font-size: 11px;
}

.book-revision-form .primary-button {
  min-height: 42px;
  border-radius: 6px;
  white-space: nowrap;
}

.book-revision-form .form-error {
  grid-column: 1 / -1;
}

.book-job-status:empty {
  display: none;
}

.book-job-card {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  background: #111;
}

.book-job-card .status-dot {
  flex: 0 0 auto;
  background: var(--gold);
  animation: pulse 1.6s ease-in-out infinite;
}

.book-job-card.failed .status-dot {
  background: var(--red);
  animation: none;
}

.book-job-card strong,
.book-job-card small {
  display: block;
}

.book-job-card small {
  color: var(--ink-soft);
}

.book-job-card [data-retry-generation] {
  margin-left: auto;
}

.book-rounds {
  border-color: var(--line);
}

@media (max-width: 900px) {
  .book-revision-form {
    grid-template-columns: 1fr;
  }
}

.workspace-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 32px;
}

.founder-session-panel {
  margin: 0 0 1.5rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
}

.founder-session-panel .section-heading { align-items: flex-start; }
.founder-session-panel .section-heading p { max-width: 62rem; }
.session-history { display: grid; gap: .75rem; margin-top: 1rem; }
.session-input-card { display: grid; grid-template-columns: 88px 1fr; gap: 1rem; padding: .85rem; border: 1px solid var(--border); border-radius: 14px; }
.session-input-card img { width: 88px; height: 88px; object-fit: cover; border-radius: 10px; background: var(--surface-muted); }
.session-input-card code { overflow-wrap: anywhere; }
.session-input-composer { margin-top: 1rem; }
.session-input-composer summary { cursor: pointer; font-weight: 700; }
.session-input-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; margin-top: 1rem; }
.session-input-form .text-field:has(textarea), .session-input-form .form-error, .session-input-form button { grid-column: 1 / -1; }

@media (max-width: 680px) {
  .session-input-form { grid-template-columns: 1fr; }
  .session-input-card { grid-template-columns: 64px 1fr; }
  .session-input-card img { width: 64px; height: 64px; }
}

.eyebrow {
  margin-bottom: 7px;
  color: var(--coral-deep);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.workspace-header h1 {
  margin-bottom: 6px;
  font-family: var(--serif);
  font-size: clamp(36px, 5vw, 58px);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1;
}

.page-summary {
  max-width: 720px;
  margin-bottom: 0;
  color: var(--ink-soft);
}

.workspace-tabs {
  display: flex;
  gap: 6px;
  width: fit-content;
  margin: 36px 0 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 5px;
  background: rgba(255, 254, 250, 0.72);
  box-shadow: var(--shadow-small);
}

.workspace-tabs button {
  min-width: 210px;
  border: 0;
  border-radius: 11px;
  padding: 10px 16px;
  color: var(--ink-soft);
  background: transparent;
  text-align: left;
}

.workspace-tabs button span,
.workspace-tabs button small {
  display: block;
}

.workspace-tabs button span {
  font-weight: 850;
}

.workspace-tabs button small {
  margin-top: 1px;
  font-size: 11px;
}

.workspace-tabs button[aria-selected="true"] {
  color: var(--ocean-deep);
  background: var(--foam);
  box-shadow: 0 4px 12px rgba(22, 86, 90, 0.11);
}

.inline-alert {
  margin-bottom: 24px;
  border: 1px solid rgba(163, 59, 59, 0.2);
  border-radius: 12px;
  padding: 13px 15px;
  color: #6b2e2e;
  background: #fff1ed;
}

.master-card {
  position: relative;
  display: grid;
  overflow: hidden;
  min-height: 390px;
  grid-template-columns: minmax(290px, 1.25fr) minmax(260px, 0.75fr);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.master-card::after {
  position: absolute;
  right: -70px;
  bottom: -90px;
  width: 240px;
  height: 240px;
  border: 1px solid rgba(169, 215, 207, 0.6);
  border-radius: 47% 53% 52% 48%;
  content: "";
  transform: rotate(28deg);
  pointer-events: none;
}

.master-visual,
.output-visual,
.context-visual,
.parent-preview-image,
.detail-hero-image {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #dcece5, #accdc8);
}

.master-visual {
  min-height: 390px;
}

.master-visual img,
.output-visual img,
.context-visual img,
.parent-preview-image img,
.detail-hero-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-unavailable {
  display: grid;
  min-height: 180px;
  place-items: center;
  padding: 28px;
  color: var(--ink-soft);
  background:
    linear-gradient(135deg, transparent 48%, rgba(22, 86, 90, 0.08) 49% 51%, transparent 52%),
    var(--foam);
  text-align: center;
}

.master-copy {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(28px, 4vw, 54px);
}

.master-copy h2 {
  margin-bottom: 11px;
  font-family: var(--serif);
  font-size: clamp(28px, 3vw, 41px);
  font-weight: 600;
  line-height: 1.05;
}

.master-copy > p:not(.eyebrow) {
  color: var(--ink-soft);
}

.master-actions,
.output-actions,
.dialog-actions,
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.empty-master {
  min-height: 245px;
  border: 1px dashed var(--line-strong);
  border-radius: 22px;
  padding: clamp(28px, 5vw, 55px);
  background: rgba(255, 254, 250, 0.65);
}

.empty-master h2 {
  margin-bottom: 8px;
  font-family: var(--serif);
  font-size: 31px;
  font-weight: 600;
}

.empty-master p {
  max-width: 640px;
  color: var(--ink-soft);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.section-heading h2 {
  margin-bottom: 0;
  font-family: var(--serif);
  font-size: 29px;
  font-weight: 600;
}

.pending-region,
.history-region {
  margin-top: 48px;
}

.pending-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 13px;
}

.pending-card {
  overflow: hidden;
  border: 1px solid rgba(214, 169, 74, 0.34);
  border-radius: 16px;
  padding: 18px;
  background: rgba(255, 251, 235, 0.92);
  box-shadow: var(--shadow-small);
}

.pending-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pending-card h3 {
  margin: 0;
  font-size: 15px;
}

.pending-card p {
  margin: 8px 0 12px;
  color: var(--ink-soft);
  font-size: 13px;
}

.pending-time {
  color: var(--ink-soft);
  font-size: 11px;
}

.progress-track {
  overflow: hidden;
  height: 5px;
  border-radius: 999px;
  background: rgba(214, 169, 74, 0.18);
}

.progress-track span {
  display: block;
  width: 35%;
  height: 100%;
  border-radius: inherit;
  background: var(--gold);
  animation: pending-slide 1.8s ease-in-out infinite alternate;
}

.compact-select,
.select-field,
.text-field {
  display: grid;
  gap: 6px;
}

.compact-select span,
.select-field > span,
.text-field > span {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
}

select,
textarea {
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  color: var(--ink);
  background: var(--white);
}

select {
  min-height: 42px;
  padding: 7px 38px 7px 12px;
}

.round-list {
  display: grid;
  gap: 22px;
}

.round-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(18px, 3vw, 27px);
  background: rgba(255, 254, 250, 0.78);
  box-shadow: var(--shadow-small);
}

.round-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.round-header h3 {
  margin-bottom: 3px;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
}

.round-meta {
  color: var(--ink-soft);
  font-size: 12px;
}

.status-chip,
.role-chip,
.favorite-chip,
.master-chip,
.provenance-chip {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.status-chip {
  color: var(--ocean-deep);
  background: var(--foam);
}

.status-chip.rejected {
  color: var(--red);
  background: #fff0ed;
}

.status-chip.approved,
.status-chip.completed {
  color: var(--green);
  background: #eaf5ee;
}

.favorite-chip {
  color: #68490d;
  background: #fff2c7;
}

.master-chip {
  color: white;
  background: var(--ocean);
}

.provenance-chip {
  color: #6b4c13;
  background: #fff1cb;
}

.output-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 14px;
}

.output-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--white);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.output-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-small);
}

.output-card.is-master {
  border-color: rgba(22, 86, 90, 0.5);
  box-shadow: inset 0 0 0 2px var(--ocean);
}

.output-visual {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 0;
  border-radius: 0;
  padding: 0;
}

.output-visual:hover::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: white;
  background: rgba(12, 63, 67, 0.35);
  content: "Inspect";
  font-weight: 800;
}

.output-badges {
  position: absolute;
  z-index: 2;
  top: 9px;
  left: 9px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  pointer-events: none;
}

.output-copy {
  padding: 12px;
}

.output-copy h4 {
  margin: 0 0 3px;
  font-size: 13px;
}

.output-copy p {
  margin-bottom: 0;
  color: var(--ink-soft);
  font-size: 11px;
}

.output-actions {
  margin-top: 10px;
}

.decision-button,
.text-button {
  padding: 7px 10px;
  color: var(--ink-soft);
  background: rgba(22, 86, 90, 0.06);
  font-size: 11px;
}

.decision-button:hover,
.text-button:hover {
  color: var(--ocean-deep);
  background: var(--foam);
}

.decision-button.is-active {
  color: white;
  background: var(--ocean);
}

.empty-history {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 42px;
  color: var(--ink-soft);
  background: rgba(255, 254, 250, 0.5);
  text-align: center;
}

.skeleton {
  overflow: hidden;
  min-height: 250px;
  border-radius: 20px;
  background: #e8eee9;
}

.skeleton::after {
  display: block;
  width: 45%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.65), transparent);
  content: "";
  animation: shimmer 1.5s infinite;
}

dialog {
  border: 0;
  color: var(--ink);
  background: var(--white);
  box-shadow: 0 30px 90px rgba(16, 47, 49, 0.28);
}

dialog::backdrop {
  background: rgba(12, 41, 42, 0.52);
  backdrop-filter: blur(4px);
}

.sheet-dialog {
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 30px);
  overflow-y: auto;
  border-radius: 22px;
  padding: 0 0 28px;
}

.detail-dialog {
  width: min(1120px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  border-radius: 22px;
  padding: 0 0 38px;
}

.dialog-close-row {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  justify-content: flex-end;
  height: 0;
  margin: 0;
  padding: 14px;
}

.feedback-form {
  display: grid;
  gap: 24px;
  padding: clamp(28px, 5vw, 52px);
}

.dialog-heading h2,
.detail-heading h2 {
  margin-bottom: 8px;
  font-family: var(--serif);
  font-size: clamp(30px, 5vw, 45px);
  font-weight: 600;
  line-height: 1.05;
}

.dialog-heading > p:last-child,
.detail-heading > p:last-child {
  margin-bottom: 0;
  color: var(--ink-soft);
}

.parent-preview {
  display: grid;
  align-items: center;
  grid-template-columns: 92px 1fr;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 10px;
  background: var(--paper);
}

.parent-preview-image {
  width: 92px;
  aspect-ratio: 4 / 3;
  border-radius: 9px;
}

.parent-preview h3 {
  margin: 0 0 3px;
  font-size: 13px;
}

.parent-preview p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 11px;
}

.sentiment-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border: 0;
  margin: 0;
  padding: 0;
}

.sentiment-picker legend {
  width: 100%;
  margin-bottom: 7px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
}

.sentiment-picker label {
  position: relative;
}

.sentiment-picker input {
  position: absolute;
  opacity: 0;
}

.sentiment-picker label > span,
.sentiment-picker label {
  border-radius: 999px;
}

.sentiment-picker label {
  border: 1px solid var(--line);
  padding: 9px 12px;
  color: var(--ink-soft);
  background: var(--white);
  font-size: 12px;
  font-weight: 750;
}

.sentiment-picker label:has(input:checked) {
  border-color: var(--ocean);
  color: var(--ocean-deep);
  background: var(--foam);
  box-shadow: inset 0 0 0 1px var(--ocean);
}

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

.rating-control {
  display: grid;
  gap: 8px;
}

.rating-control > span,
.rating-control small {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.rating-control strong {
  font-size: 12px;
}

.rating-control output {
  display: grid;
  width: 23px;
  height: 23px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--ocean);
  font-size: 11px;
  font-weight: 800;
}

.rating-control input {
  accent-color: var(--ocean);
}

.rating-control small,
.text-field small,
.select-field small {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink-soft);
  font-size: 10px;
}

.text-field textarea {
  width: 100%;
  resize: vertical;
  padding: 13px;
  line-height: 1.55;
}

.charge-confirmation {
  border: 1px solid rgba(214, 169, 74, 0.55);
  border-radius: 13px;
  padding: 14px;
  background: rgba(255, 248, 224, 0.72);
}

.charge-confirmation label {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  cursor: pointer;
}

.charge-confirmation input {
  width: 19px;
  height: 19px;
  margin-top: 2px;
  accent-color: var(--ocean);
}

.charge-confirmation span {
  display: grid;
  gap: 4px;
}

.charge-confirmation strong {
  font-size: 13px;
}

.charge-confirmation small {
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.45;
}

.form-error {
  border-radius: 10px;
  padding: 11px 13px;
  color: #762c2c;
  background: #fff0ed;
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 0;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(330px, 0.9fr) minmax(0, 1.1fr);
}

.inline-image-detail {
  display: block;
  width: 100%;
}

.inline-image-detail .detail-hero {
  position: relative;
  min-height: 0;
  padding: 0;
  background: transparent;
}

.inline-image-detail .detail-hero-image {
  width: 100%;
  max-height: none;
  aspect-ratio: auto;
  border-radius: 0;
  box-shadow: none;
}

.inline-image-detail .detail-hero-image img {
  width: 100%;
  height: auto;
  max-height: none;
  object-fit: contain;
}

.inline-image-detail .detail-actions {
  padding: 0 0 22px;
}

.inline-regenerate-workspace {
  margin: 0 0 28px;
  border-top: 1px solid var(--line);
  padding: 28px 0 8px;
}

.inline-regenerate-workspace .feedback-form {
  width: 100%;
  max-width: none;
  padding: 0;
}

.detail-back {
  margin-bottom: 12px;
}

.detail-disclosure {
  border-top: 1px solid var(--line);
}

.detail-disclosure > summary {
  cursor: pointer;
  padding: 20px 0;
  color: var(--ink);
  font-weight: 700;
}

.detail-disclosure .detail-body {
  padding: 8px 0 48px;
}

.detail-hero {
  position: sticky;
  top: 0;
  align-self: start;
  min-height: 500px;
  padding: clamp(34px, 5vw, 58px);
  background: var(--paper-deep);
}

.detail-hero-image {
  width: 100%;
  max-height: 64vh;
  aspect-ratio: 4 / 3;
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.detail-hero .detail-actions {
  margin-top: 18px;
}

.detail-body {
  min-width: 0;
  padding: clamp(45px, 6vw, 74px) clamp(28px, 5vw, 58px);
}

.detail-heading {
  padding-right: 30px;
}

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

.meta-item {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px;
  background: var(--paper);
}

.meta-item dt {
  color: var(--ink-soft);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.meta-item dd {
  overflow-wrap: anywhere;
  margin: 3px 0 0;
  font-size: 12px;
  font-weight: 700;
}

.detail-section {
  margin-top: 33px;
}

.detail-section h3 {
  margin-bottom: 12px;
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 600;
}

.detail-section > p {
  color: var(--ink-soft);
}

.context-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 10px;
}

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

.context-visual {
  aspect-ratio: 4 / 3;
}

.context-card figcaption {
  padding: 9px;
  color: var(--ink-soft);
  font-size: 10px;
}

.context-card strong {
  display: block;
  margin-bottom: 2px;
  color: var(--ink);
  font-size: 11px;
}

.empty-context {
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  padding: 14px;
  color: var(--ink-soft);
  background: var(--paper);
  font-size: 12px;
}

.provenance-warning {
  border-left: 3px solid var(--gold);
  padding: 11px 13px;
  color: #68490d;
  background: #fff6dc;
  font-size: 12px;
}

.record-panel {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--paper);
}

.record-panel + .record-panel {
  margin-top: 8px;
}

.record-panel summary {
  padding: 13px;
  cursor: pointer;
  font-weight: 800;
}

.record-panel pre,
.prompt-record {
  overflow: auto;
  max-height: 500px;
  margin: 0;
  border-top: 1px solid var(--line);
  padding: 16px;
  color: #143c3e;
  background: #f3f8f4;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.lineage-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.lineage-button {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  background: var(--paper);
  text-align: left;
}

.lineage-button img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.lineage-button span {
  display: block;
  padding: 8px;
  font-size: 10px;
  font-weight: 700;
}

.toast-region {
  position: fixed;
  z-index: 90;
  right: 20px;
  bottom: 20px;
  display: grid;
  width: min(360px, calc(100vw - 40px));
  gap: 8px;
}

.toast {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 12px 14px;
  color: white;
  background: var(--ocean-deep);
  box-shadow: var(--shadow);
  animation: toast-in 180ms ease-out;
}

.toast.is-error {
  background: #762f2f;
}

@keyframes shimmer {
  from { transform: translateX(-120%); }
  to { transform: translateX(260%); }
}

@keyframes pulse {
  50% { opacity: 0.36; }
}

@keyframes pending-slide {
  from { transform: translateX(-15%); }
  to { transform: translateX(200%); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .page-rail {
    position: sticky;
    z-index: 20;
    top: 76px;
    height: auto;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 14px;
    background: rgba(251, 247, 237, 0.95);
    backdrop-filter: blur(14px);
  }

  .rail-heading {
    display: none;
  }

  .page-nav-list {
    display: flex;
    width: max-content;
  }

  .page-nav-link {
    min-height: 38px;
    grid-template-columns: auto 1fr auto;
    padding: 6px 10px;
  }

  #workspace-main {
    padding-top: 32px;
  }

  .master-card,
  .detail-layout {
    grid-template-columns: 1fr;
  }

  .master-visual {
    min-height: 330px;
  }

  .detail-hero {
    position: relative;
    min-height: auto;
  }
}

@media (max-width: 650px) {
  .site-header {
    min-height: 65px;
    padding: 8px 13px;
  }

  .brand-mark {
    width: 41px;
    height: 41px;
  }

  .brand small,
  .connection-status,
  .header-actions form,
  .quiet-button svg,
  #refresh-button {
    display: none;
  }

  .page-rail {
    top: 65px;
  }

  #workspace-main {
    padding: 27px 14px 70px;
  }

  .workspace-header {
    display: grid;
    gap: 19px;
  }

  .workspace-header .primary-button {
    width: 100%;
  }

  .workspace-tabs {
    width: 100%;
  }

  .workspace-tabs button {
    min-width: 0;
    flex: 1;
    text-align: center;
  }

  .workspace-tabs button small {
    display: none;
  }

  .master-card {
    min-height: 0;
  }

  .master-visual {
    min-height: 250px;
  }

  .section-heading,
  .round-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .compact-select,
  .compact-select select {
    width: 100%;
  }

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

  .output-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .rating-grid,
  .detail-meta-grid {
    grid-template-columns: 1fr;
  }

  .sentiment-picker {
    display: grid;
  }

  .sheet-dialog,
  .detail-dialog {
    width: 100vw;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border-radius: 0;
  }

  .feedback-form {
    padding: 39px 20px 28px;
  }

  .detail-hero,
  .detail-body {
    padding: 44px 20px 26px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
