:root {
  --editor-width: 460px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, var(--editor-width)) 12px minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
}

.editor-panel,
.preview-panel {
  border: 1px solid #ccc;
  border-radius: 28px;
}

.editor-panel {
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.preview-panel {
  padding: 28px;
  overflow: hidden;
  min-width: 0;
}

.panel-resizer {
  position: relative;
  width: 12px;
  cursor: col-resize;
  touch-action: none;
}

.panel-resizer::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #ccc;
  opacity: 0.7;
  transition: opacity 180ms ease, transform 180ms ease;
}

.panel-resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 72px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: white;
}

.panel-resizer:hover::before,
.app-shell.is-resizing .panel-resizer::before {
  opacity: 1;
  transform: scaleX(1.08);
}

.app-shell.is-resizing,
.app-shell.is-resizing * {
  cursor: col-resize;
  user-select: none;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.75rem;
  font-weight: 700;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-weight: 700;
  line-height: 1.05;
}

h1 {
  font-size: clamp(2.1rem, 4vw, 3.2rem);
}

h2 {
  font-size: 1.55rem;
}

.document-settings {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.field-group,
.page-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label,
.page-label {
  font-size: 0.92rem;
  font-weight: 700;
}

input[type="text"],
textarea,
select,
input[type="file"] {
  width: 100%;
  border: 1px solid #ccc;
  border-radius: 16px;
  padding: 12px 14px;
  font: inherit;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

input[type="color"] {
  width: 48px;
  height: 48px;
  padding: 4px;
  border: 1px solid #ccc;
  border-radius: 12px;
  cursor: pointer;
  flex-shrink: 0;
}

button {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button.primary {
  background: #000;
  color: white;
}

button.secondary {
  background: #eee;
}

.icon-button {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: #eee;
  font-size: 1.6rem;
  line-height: 1;
}

.instructions {
  padding: 18px;
  border: 1px solid #ccc;
  border-radius: 22px;
}

.image-info {
  padding: 18px;
  border: 1px solid #ccc;
  border-radius: 22px;
}

.image-info p {
  margin: 10px 0 0;
}

.instructions ol {
  margin: 12px 0 0;
  padding-left: 18px;
}

.page-editor {
  display: grid;
  gap: 14px;
}

.page-card {
  padding: 18px;
  border: 1px solid #ccc;
  border-radius: 22px;
}

.page-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.page-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #eee;
  font-weight: 800;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 20px;
}

.sheet-stage {
  overflow: auto;
  padding-bottom: 10px;
}

.print-sheet {
  position: relative;
  width: 1122px;
  aspect-ratio: 1.414 / 1;
  background: white;
  border-radius: 24px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.15);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
  overflow: hidden;
  isolation: isolate;
}

.print-sheet::before,
.print-sheet::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.print-sheet::before {
  background:
    linear-gradient(to right, transparent calc(25% - 0.5px), rgba(0, 0, 0, 0.15) 25%, transparent calc(25% + 0.5px), transparent calc(50% - 0.5px), rgba(0, 0, 0, 0.15) 50%, transparent calc(50% + 0.5px), transparent calc(75% - 0.5px), rgba(0, 0, 0, 0.15) 75%, transparent calc(75% + 0.5px)),
    linear-gradient(to bottom, transparent calc(50% - 0.5px), rgba(0, 0, 0, 0.15) 50%, transparent calc(50% + 0.5px));
}

.print-sheet::after {
  top: calc(50% - 2px);
  left: 25%;
  width: 50%;
  height: 4px;
  inset: auto;
  background: repeating-linear-gradient(to right, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6) 18px, transparent 18px, transparent 28px);
}

.sheet-page {
  position: relative;
  padding: 24px;
  border-right: 1px solid transparent;
  border-bottom: 1px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}

.sheet-page.bottom-row {
  transform: rotate(180deg);
}

.sheet-page::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 18px;
  background: var(--page-bg, white);
  z-index: -1;
}

.sheet-page.has-image::after {
  display: none;
}

.sheet-page.page-cover::before {
  background: var(--page-bg-cover, #eee);
}

.sheet-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.86rem;
}

.sheet-tag {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  font-weight: 700;
}

.sheet-page.page-cover .sheet-tag {
  background: rgba(255, 255, 255, 0.18);
}

.sheet-title {
  font-family: "Fraunces", serif;
  font-size: clamp(1.2rem, 1vw + 0.9rem, 2rem);
  margin: 0;
}

.sheet-text {
  margin: 0;
  font-size: 0.93rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.sheet-image {
  width: 100%;
  min-height: 120px;
  max-height: 160px;
  object-fit: cover;
  border-radius: 16px;
  border: 0;
  background: #fff;
}

.sheet-image-placeholder {
  min-height: 120px;
  border-radius: 16px;
  border: 1px dashed #ccc;
  display: grid;
  place-items: center;
  background: white;
  font-size: 0.88rem;
}

body.is-exporting .sheet-running-title,
body.is-exporting .sheet-image-placeholder {
  display: none;
}

body.is-exporting .sheet-image {
  border: 0;
  box-shadow: none;
}

.sheet-license-block {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sheet-license-badge {
  display: inline-flex;
  align-self: flex-start;
  padding: 6px 10px;
  border-radius: 999px;
  background: #eee;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.sheet-license-meta {
  margin: 0;
  font-size: 0.8rem;
}

.page-note {
  margin: 0;
  font-size: 0.82rem;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 180ms ease, visibility 180ms ease;
  z-index: 30;
}

.modal.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
}

.modal-card {
  position: relative;
  width: min(920px, 100%);
  max-height: min(88vh, 920px);
  overflow: auto;
  padding: 28px;
  border-radius: 28px;
  background: white;
  border: 1px solid #ccc;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.25);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 20px;
}

.modal-intro {
  margin: 10px 0 0;
  max-width: 56ch;
}

.help-copy {
  display: grid;
  gap: 14px;
}

.help-copy h3 {
  margin: 0;
  font-size: 1.2rem;
}

.help-copy ul,
.help-copy ol {
  margin: 12px 0 0;
  padding-left: 18px;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.help-step {
  padding: 18px;
  border-radius: 24px;
  background: white;
  border: 1px solid #ccc;
}

.help-step h3 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 1.2rem;
}

.help-step p {
  margin: 0;
}

.help-visual {
  position: relative;
  height: 170px;
  border-radius: 22px;
  margin-bottom: 14px;
  background: white;
  border: 1px solid #ccc;
  overflow: hidden;
}

.sheet-flat::before,
.sheet-flat::after,
.cut-middle::before,
.fold-together::before,
.booklet::before {
  content: "";
  position: absolute;
}

.sheet-flat::before {
  inset: 20px;
  border-radius: 16px;
  background: white;
  box-shadow: inset 0 0 0 1px #ccc;
}

.sheet-flat .line,
.sheet-flat .fold-band,
.cut-middle .cut-line {
  position: absolute;
}

.sheet-flat .line {
  background: #ccc;
}

.sheet-flat .line-vertical {
  top: 20px;
  bottom: 20px;
  left: 50%;
  width: 1px;
}

.sheet-flat .line-horizontal {
  left: 20px;
  right: 20px;
  top: 50%;
  height: 1px;
}

.sheet-flat .fold-band {
  left: 20px;
  right: 20px;
  top: calc(50% - 10px);
  height: 20px;
  border-top: 2px dashed #999;
  border-bottom: 2px dashed #999;
  background: #f5f5f5;
}

.cut-middle .paper-top,
.cut-middle .paper-bottom,
.fold-together .paper-side,
.booklet .book-cover,
.booklet .book-pages {
  position: absolute;
  border-radius: 16px;
  background: white;
  box-shadow: inset 0 0 0 1px #ccc;
}

.cut-middle .paper-top {
  left: 26px;
  right: 26px;
  top: 24px;
  height: 52px;
}

.cut-middle .paper-bottom {
  left: 26px;
  right: 26px;
  bottom: 24px;
  height: 52px;
}

.cut-middle .cut-line {
  left: 50%;
  transform: translateX(-50%);
  top: calc(50% - 2px);
  width: 120px;
  height: 4px;
  background: repeating-linear-gradient(to right, #999, #999 12px, transparent 12px, transparent 20px);
}

.arrow {
  position: absolute;
  width: 56px;
  height: 56px;
  border-right: 3px solid #999;
  border-bottom: 3px solid #999;
}

.arrow.down {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -72%) rotate(45deg);
}

.fold-together .paper-side.left {
  left: 20px;
  top: 28px;
  bottom: 28px;
  width: 110px;
}

.fold-together .paper-side.right {
  right: 20px;
  top: 28px;
  bottom: 28px;
  width: 110px;
}

.arrow.inward-left {
  left: 122px;
  top: 50%;
  transform: translateY(-50%) rotate(-45deg);
}

.arrow.inward-right {
  right: 122px;
  top: 50%;
  transform: translateY(-50%) rotate(135deg);
}

.booklet .book-cover {
  left: 68px;
  right: 68px;
  top: 30px;
  bottom: 30px;
  background: #ccc;
}

.booklet .book-pages {
  left: 84px;
  right: 56px;
  top: 42px;
  bottom: 42px;
  background: white;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .panel-resizer {
    display: none;
  }

  .print-sheet {
    width: 100%;
    min-width: 900px;
  }
}

@media (max-width: 720px) {
  .app-shell,
  .editor-panel,
  .preview-panel {
    padding: 16px;
  }

  .preview-header {
    flex-direction: column;
    align-items: start;
  }

  .help-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: white;
  }

  .editor-panel,
  .preview-header {
    display: none !important;
  }

  .app-shell,
  .preview-panel {
    padding: 0;
    margin: 0;
    border: none;
    box-shadow: none;
    background: white;
  }

  .sheet-stage {
    overflow: visible;
  }

  .print-sheet {
    width: 297mm;
    height: 210mm;
    border-radius: 0;
    box-shadow: none;
  }

  .sheet-running-title,
  .sheet-image-placeholder {
    display: none;
  }

  .sheet-image {
    border: 0;
    box-shadow: none;
  }

  @page {
    size: A4 landscape;
    margin: 0;
  }
}
