/* Digital Book Mosaic studio: settings panel on the left, the poster hung on a wall on the right. */

.studio-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- top bar ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 64px;
  padding: 10px clamp(16px, 2.4vw, 28px);
  border-bottom: 1px solid var(--line);
  background: var(--wall);
}

.bar .brand {
  margin-right: 0;
}

.bar .logo {
  height: 28px;
}

.bar-title {
  flex: 1;
  min-width: 0;
  padding-left: 20px;
  border-left: 1px solid var(--line);
}

.bar-title h1 {
  margin: 0;
  overflow: hidden;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.bar-title p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.bar-actions {
  display: flex;
  gap: 10px;
}

.sample-note {
  margin: 0;
  padding: 10px clamp(16px, 2.4vw, 28px);
  background: var(--ink);
  color: var(--wall);
  font-size: 0.92rem;
}

.sample-note a {
  margin-left: 6px;
  color: inherit;
  font-weight: 700;
  text-underline-offset: 4px;
}

/* ---------- desk: panel + stage ---------- */

.desk {
  flex: 1;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
}

.panel {
  position: sticky;
  top: 64px;
  align-self: start;
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  padding: 8px 22px 28px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.step {
  min-width: 0;
  margin: 0;
  padding: 20px 0 22px;
  border: 0;
  border-bottom: 1px solid var(--line);
}

.step legend {
  display: flex;
  align-items: center;
  gap: 10px;
  float: left;
  width: 100%;
  margin-bottom: 14px;
  padding: 0;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.step legend + * {
  clear: left;
}

.step-no {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  background: var(--ink);
  color: var(--wall);
  font-family: var(--display);
  font-size: 0.82rem;
  letter-spacing: 0;
}

.step > * + * {
  margin-top: 14px;
}

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

.field > span:first-child {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.field small {
  font-weight: 400;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: 2px;
  background: var(--wall);
  color: var(--ink);
  font: inherit;
}

.field input:focus,
.field select:focus {
  border-color: var(--ink);
  outline: none;
}

#ctl-text {
  font-family: var(--display);
  font-size: 1.3rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.count {
  margin-bottom: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.btn-block {
  width: 100%;
}

/* Shape picker: four square tiles. */
.shape-picks {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.shape-pick {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 12px 4px 10px;
  border: 2px solid var(--line);
  border-radius: 2px;
  background: var(--wall);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.shape-pick input,
.seg-opt input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.shape-pick svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

.shape-pick:hover {
  border-color: var(--ink);
}

.shape-pick:has(input:checked) {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--wall);
}

.shape-pick:has(input:focus-visible),
.seg-opt:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Segmented choices. */
.seg {
  display: flex;
  border: 2px solid var(--ink);
  border-radius: 2px;
}

.seg-opt {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 38px;
  padding: 4px 6px;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}

.seg-opt + .seg-opt {
  border-left: 2px solid var(--ink);
}

.seg-opt:hover {
  background: var(--sunk);
}

.seg-opt:has(input:checked) {
  background: var(--ink);
  color: var(--wall);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.94rem;
  cursor: pointer;
}

.check input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.link-btn {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: 600 0.92rem var(--text);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
  cursor: pointer;
}

.link-btn:hover {
  color: var(--accent);
}

#reset-btn {
  margin-top: 20px;
  color: var(--muted);
}

/* The poster on its wall. */
.stage {
  min-width: 0;
  padding: clamp(20px, 3.4vw, 48px);
  background:
    radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--surface) 55%, transparent), transparent 70%),
    var(--sunk);
  outline: none;
}

.stage-wall {
  display: grid;
  justify-items: center;
}

/* Fit the poster in the visible height: the sheet's aspect ratio is √2. */
.stage-poster {
  width: min(100%, calc((100vh - 64px - 150px) / 1.4142));
  min-width: 240px;
  padding: clamp(8px, 1.4vw, 14px);
  border: clamp(6px, 0.9vw, 10px) solid #111;
  background: #fbfbf8;
  box-shadow: var(--shadow);
}

.stage-poster[data-orientation='landscape'] {
  width: min(100%, calc((100vh - 64px - 150px) * 1.4142));
}

.story-host {
  display: grid;
  gap: 24px;
}

.stage-note {
  max-width: 62ch;
  margin: 22px auto 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

/* ---------- post picker and tile details ---------- */

dialog {
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 30px 80px rgb(0 0 0 / 0.35);
}

dialog::backdrop {
  background: rgb(10 10 10 / 0.6);
}

.sheet {
  width: min(1100px, 100% - 32px);
  height: min(86vh, 900px);
  overflow: hidden;
}

.sheet[open] {
  display: flex;
  flex-direction: column;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
}

.sheet-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.6rem;
  font-weight: 400;
  letter-spacing: -0.02em;
}

.sheet-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 24px 28px;
}

.pk-year + .pk-year {
  border-top: 1px solid var(--line);
}

.pk-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 16px 0 10px;
  background: var(--surface);
}

.pk-head h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.3rem;
  font-weight: 400;
}

.pk-count {
  color: var(--muted);
  font-size: 0.88rem;
}

.pk-tools {
  display: flex;
  gap: 14px;
  margin-left: auto;
}

.pk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 185px), 1fr));
  gap: 8px;
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
}

.pk-post {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--sunk);
  color: var(--ink);
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.pk-post img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.pk-copy {
  display: grid;
  align-content: start;
  gap: 4px;
  padding: 8px 32px 10px 10px;
  overflow-wrap: anywhere;
}

.pk-date,
.pk-place {
  font-size: 0.77rem;
  font-weight: 700;
}

.pk-date {
  color: var(--muted);
}

.pk-text {
  display: -webkit-box;
  overflow: hidden;
  font: 1.1rem/1.2 'Instrument Serif', Georgia, serif;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.pk-mark {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 2px solid #fff;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.pk-mark::before {
  content: '✓';
}

.pk-post[aria-pressed='false'] img {
  opacity: 0.45;
  filter: grayscale(1);
}

.pk-post[aria-pressed='false'] .pk-mark {
  background: rgb(0 0 0 / 0.45);
}

.pk-post[aria-pressed='false'] .pk-mark::before {
  content: '';
}

.pk-post.is-out-of-range img {
  opacity: 0.45;
}

.pk-post.is-out-of-range .pk-copy {
  color: var(--muted);
}

.peek {
  width: min(820px, 100% - 32px);
}

.peek[open] {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
}

.peek--text[open] {
  width: min(580px, 100% - 32px);
  grid-template-columns: minmax(0, 1fr);
}

#peek-img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 70vh;
  object-fit: cover;
  background: var(--sunk);
}

.peek-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 28px 26px;
}

.peek-info p {
  margin: 0;
}

.peek-date {
  font-family: var(--display);
  font-size: 1.4rem;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.peek-place {
  color: var(--accent);
  font-weight: 700;
}

.peek-text {
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.peek-actions {
  display: grid;
  gap: 10px;
  margin-top: auto;
  padding-top: 18px;
}

/* ---------- loading, errors, toast, footer ---------- */

.state {
  flex: 1;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  padding: 64px 16px;
  text-align: center;
}

.state-title {
  margin: 8px 0 0;
  font-family: var(--display);
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  font-weight: 400;
  letter-spacing: -0.02em;
}

.state-text {
  max-width: 34em;
  margin: 0;
  color: var(--muted);
}

.state-actions {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}

/* A 3×3 grid of tiles filling in, instead of a ring spinner. */
.spinner {
  display: grid;
  grid-template-columns: repeat(3, 14px);
  gap: 3px;
  width: max-content;
}

.spinner::before {
  grid-column: 1 / -1;
  height: 48px;
  background:
    linear-gradient(var(--accent) 0 0) 0 0 / 14px 14px no-repeat,
    linear-gradient(var(--ink) 0 0) 17px 0 / 14px 14px no-repeat,
    linear-gradient(var(--ink) 0 0) 34px 17px / 14px 14px no-repeat,
    linear-gradient(var(--accent) 0 0) 17px 34px / 14px 14px no-repeat,
    linear-gradient(var(--ink) 0 0) 0 34px / 14px 14px no-repeat;
  content: '';
  animation: tiles 1.2s steps(4) infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner::before {
    animation: none;
  }
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 40;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  background: var(--ink);
  color: var(--wall);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s, transform 0.2s;
}

.toast.is-shown {
  opacity: 1;
  transform: translate(-50%, 0);
}

.studio-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 22px;
  padding: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}

.studio-foot a {
  color: inherit;
}

/* ---------- occasions, hints, story preview ---------- */

.occasions {
  padding: 18px 0 20px;
  border-bottom: 1px solid var(--line);
}

.occasions h2 {
  margin: 0 0 12px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

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

.occasion-pick {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 2px;
  background: var(--wall);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.occasion-pick strong {
  font-size: 0.92rem;
}

.occasion-pick span {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.3;
}

.occasion-pick:hover {
  border-color: var(--accent);
}

.hint {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.hint:empty {
  display: none;
}

.check small {
  color: var(--muted);
}

.stage-story {
  margin-top: 36px;
}

.stage-label {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-align: center;
  text-transform: uppercase;
}

.peek-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

/* ---------- occasion and print dialogs ---------- */

.small-sheet {
  width: min(440px, 100% - 32px);
}

.small-sheet-in {
  display: grid;
  gap: 14px;
  padding: 26px;
}

.small-sheet h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.6rem;
  font-weight: 400;
  letter-spacing: -0.02em;
}

.small-sheet p {
  margin: 0;
}

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.print-sheet {
  width: min(860px, 100% - 32px);
}

.print-files {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.print-file {
  position: relative;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 14px 14px 14px 42px;
  border: 2px solid var(--line);
  border-radius: 2px;
  cursor: pointer;
}

.print-file input {
  position: absolute;
  top: 16px;
  left: 14px;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.print-file span {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.print-file:has(input:checked) {
  border-color: var(--ink);
}

.print-go-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  margin-top: 18px;
}

.print-go-row .hint {
  flex: 1 1 260px;
  margin: 0;
}

.guide {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.guide h3 {
  margin: 0 0 6px;
  font-family: var(--display);
  font-size: 1.3rem;
  font-weight: 400;
}

.guide-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
  padding: 0;
  list-style: none;
}

.guide-list li {
  padding: 14px 16px;
  background: var(--wall);
}

.guide-list h4 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.guide-list p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

/* ---------- small screens: poster first, settings below ---------- */

@media (max-width: 900px) {
  .bar {
    flex-wrap: wrap;
    gap: 10px 16px;
  }

  .bar-title {
    order: 3;
    flex-basis: 100%;
    padding-left: 0;
    border-left: 0;
  }

  .bar-actions {
    margin-left: auto;
  }

  .desk {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel {
    position: static;
    max-height: none;
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .stage {
    order: -1;
  }

  .stage-poster,
  .stage-poster[data-orientation='landscape'] {
    width: 100%;
    min-width: 0;
  }

  .peek[open] {
    grid-template-columns: minmax(0, 1fr);
  }

  .print-files,
  .guide-list {
    grid-template-columns: minmax(0, 1fr);
  }

  #peek-img {
    max-height: 46vh;
  }
}

@media (max-width: 480px) {
  .bar-actions .btn {
    padding-inline: 12px;
    font-size: 0.9rem;
  }
}
