:root {
  --bg: #0b2348;
  --bg-glow: #16345f;
  --embed-bg: transparent;
  --panel: #0f274d;
  --book: #ffffff;
  --book-edge: #d8dde5;
  --text: #f5f7fa;
  --muted: #9ca7b5;
  --accent: #d1a95b;
  --shadow: 0 32px 80px rgba(0, 0, 0, 0.45);
  --book-shadow: 0 28px 60px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

body.transparent-mode {
  background: transparent;
}

body.embed-mode:not(.transparent-mode) {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--embed-bg, var(--bg)) 92%, transparent), color-mix(in srgb, var(--embed-bg, var(--bg)) 100%, transparent));
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  padding: 10px 18px 14px;
}

body.embed-mode .app-shell {
  min-height: 100vh;
  padding: 0;
  gap: 0;
  grid-template-rows: auto 1fr auto;
}

.topbar,
.footer {
  width: min(1400px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 0.82rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
}

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

.nav-button,
.utility-button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 180ms ease, background-color 180ms ease, border-color 180ms ease;
}

.nav-button:hover,
.utility-button:hover,
.nav-button:focus-visible,
.utility-button:focus-visible {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.26);
  outline: none;
}

.nav-button {
  width: 52px;
  height: 52px;
  font-size: 1.25rem;
}

.utility-button {
  padding: 0 18px;
  min-height: 52px;
  font-size: 0.96rem;
}

.stage {
  display: grid;
  place-items: center;
}

.book-frame {
  position: relative;
  width: min(1400px, 100%);
  min-height: min(78vh, 960px);
  padding: clamp(6px, 1vw, 12px);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: hidden;
}

body.embed-mode .book-frame {
  min-height: calc(100vh - 8px);
  height: calc(100vh - 8px);
  padding: 0;
}

body.transparent-mode .book-frame {
  background: transparent;
  box-shadow: none;
}

.book-shadow {
  display: none;
}

body.transparent-mode .book-shadow {
  display: none;
}

.book {
  position: relative;
  z-index: 1;
  height: min(72vh, 860px);
  min-height: 540px;
  background: var(--book);
  border-radius: 0;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  perspective: 1800px;
}

.book::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(216, 221, 229, 0.9) 0, rgba(255, 255, 255, 0) 3%, rgba(255, 255, 255, 0) 97%, rgba(216, 221, 229, 0.9) 100%),
    linear-gradient(90deg, transparent 49.7%, rgba(216, 221, 229, 0.95) 50%, transparent 50.3%);
  pointer-events: none;
}

body.embed-mode .book {
  height: 100%;
  min-height: 0;
}

.book-surface {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

.page-slot {
  position: absolute;
  inset: 0;
  width: min(980px, 92%);
  height: 100%;
  overflow: hidden;
  margin: auto;
}

.page-slot.is-under-page::after {
  content: none;
}

.static-page,
.turn-sheet {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.turn-layer {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  perspective: 2200px;
  transform-style: preserve-3d;
}

.turn-sheet {
  width: min(980px, 92%);
  margin: auto;
  z-index: 9;
}

.turn-sheet.is-next-turn {
  inset: 0;
}

.turn-sheet.is-prev-turn {
  inset: 0;
}

.sheet-3d {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 900ms cubic-bezier(0.22, 0.61, 0.24, 1);
  will-change: transform;
}

.turn-sheet.is-next-turn .sheet-3d {
  transform-origin: left center;
}

.turn-sheet.is-prev-turn .sheet-3d {
  transform-origin: right center;
}

.turn-sheet.is-next-turn.is-animating {
  z-index: 9;
}

.turn-sheet.is-prev-turn.is-animating {
  z-index: 9;
}

.turn-sheet.is-next-turn.is-animating .sheet-3d {
  transform: rotateY(-180deg);
}

.turn-sheet.is-prev-turn.is-animating .sheet-3d {
  transform: rotateY(180deg);
}

.page-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 1vw, 14px);
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-style: preserve-3d;
}

.page-face.front.is-right-face,
.page-face.front.is-left-face,
.page-slot-single .page-face {
  border-left: 1px solid rgba(216, 221, 229, 0.35);
  border-right: 1px solid rgba(216, 221, 229, 0.35);
}

.page-face.back {
  transform: rotateY(180deg);
  background:
    linear-gradient(180deg, #f8f8f8 0%, #f1f1f1 100%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.04), transparent 18%);
}

.page-face.is-blank {
  background: #ffffff;
}

.page-image-wrap {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.page-image {
  width: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  box-shadow: none;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 0.95rem;
}

.embed-topbar {
  width: min(1400px, 100%);
  margin: 0 auto;
}

.embed-footer {
  width: min(1400px, 100%);
  margin: 0 auto;
  justify-content: flex-end;
}

.embed-title h1 {
  font-size: clamp(1.1rem, 2.8vw, 1.6rem);
}

body.embed-mode .eyebrow {
  margin-bottom: 4px;
}

body.embed-mode .embed-topbar,
body.embed-mode .embed-footer {
  width: min(1400px, calc(100% - 18px));
}

body.embed-mode .embed-topbar {
  padding: 6px 0 0;
}

body.embed-mode .embed-topbar h1 {
  font-size: clamp(1rem, 2.2vw, 1.4rem);
}

body.embed-mode .embed-topbar,
body.embed-mode .embed-footer {
  flex: 0 0 auto;
}

body.embed-mode .stage {
  min-height: 0;
}

code {
  color: var(--text);
}

a {
  color: inherit;
}

.catalog-shell {
  width: min(1400px, 100%);
  margin: 0 auto;
}

.catalog-hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 22px;
}

.catalog-card {
  display: flex;
  flex-direction: column;
  min-height: 320px;
  padding: 22px;
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
  box-shadow: var(--shadow);
  text-decoration: none;
}

.catalog-cover {
  min-height: 220px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(209, 169, 91, 0.22), rgba(255, 255, 255, 0.06));
  overflow: hidden;
  display: grid;
  place-items: center;
}

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

.catalog-meta {
  padding-top: 16px;
}

.catalog-meta h2,
.catalog-meta h3 {
  margin: 0 0 8px;
  font-size: 1.35rem;
}

.catalog-empty,
.admin-card {
  border-radius: 28px;
  padding: 28px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
  box-shadow: var(--shadow);
}

.admin-shell {
  width: min(1100px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 20px;
}

.admin-hero {
  margin-bottom: 0;
}

.admin-card-soft {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.025));
}

.admin-note-card {
  display: grid;
  align-content: start;
}

.admin-note-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.admin-form-grid {
  display: grid;
  gap: 14px;
}

.admin-form-grid label {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.admin-form-grid input,
.admin-form-grid textarea,
.admin-form-grid select {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.admin-button-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.admin-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.admin-toolbar-title h2,
.admin-toolbar-title p {
  margin: 0;
}

.admin-toolbar-title p {
  margin-top: 6px;
  color: var(--muted);
}

.admin-count-pill {
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--muted);
}

.status-success {
  color: #b7f3c7;
}

.status-error {
  color: #ffb9b9;
}

.page-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.page-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.embed-code-block {
  margin: 12px 0 18px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
}

.embed-code-label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
}

.embed-code-field {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
  resize: vertical;
}

.flipbook-list {
  display: grid;
  gap: 18px;
}

.flipbook-row-card {
  display: grid;
  grid-template-columns: 140px 112px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  padding: 20px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.flipbook-row-status {
  display: grid;
  gap: 12px;
  align-content: center;
}

.flipbook-row-pages {
  color: var(--muted);
  font-size: 0.95rem;
}

.flipbook-row-cover {
  min-height: 150px;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(209, 169, 91, 0.22), rgba(255, 255, 255, 0.06));
}

.flipbook-admin-cover {
  min-height: 176px;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(209, 169, 91, 0.22), rgba(255, 255, 255, 0.06));
}

.flipbook-row-cover img,
.flipbook-admin-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.flipbook-admin-placeholder {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.flipbook-admin-content {
  display: grid;
  gap: 14px;
}

.flipbook-row-main {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.flipbook-row-head h3 {
  margin: 0 0 8px;
  font-size: 1.9rem;
}

.flipbook-row-embed {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.flipbook-card-actions {
  padding-top: 4px;
}

.flipbook-row-actions {
  padding-top: 2px;
}

.flipbook-admin-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.flipbook-admin-head h3 {
  margin: 0 0 8px;
  font-size: 1.35rem;
}

.flipbook-admin-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin: 0;
  color: var(--muted);
}

.visibility-pill {
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}

.visibility-pill.is-live {
  background: rgba(86, 180, 119, 0.18);
  color: #c8f3d4;
}

.visibility-pill.is-draft {
  background: rgba(255, 255, 255, 0.08);
  color: #d0d5dc;
}

.embed-code-inline {
  display: grid;
  gap: 8px;
}

.embed-inline-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.embed-code-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
}

.utility-button-primary {
  background: rgba(209, 169, 91, 0.18);
  border-color: rgba(209, 169, 91, 0.34);
}

.utility-button-primary:hover,
.utility-button-primary:focus-visible {
  background: rgba(209, 169, 91, 0.28);
  border-color: rgba(209, 169, 91, 0.5);
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 12, 16, 0.72);
  backdrop-filter: blur(6px);
}

.dialog-card {
  width: min(1080px, 100%);
  border-radius: 28px;
  padding: 28px;
  background: linear-gradient(180deg, rgba(20, 26, 34, 0.98), rgba(15, 20, 27, 0.96));
  box-shadow: var(--shadow);
}

.dialog-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.dialog-head h2 {
  margin: 0;
}

.dialog-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 18px;
}

.dialog-form-grid label {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.dialog-form-grid input,
.dialog-form-grid textarea {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.dialog-form-wide {
  grid-column: 1 / -1;
}

.dialog-checkbox {
  align-self: end;
}

.dialog-actions {
  grid-column: 1 / -1;
  justify-content: flex-start;
}

.admin-footer-note {
  color: var(--muted);
  text-align: center;
  padding: 4px 12px 18px;
}

.admin-footer-note p {
  margin: 0;
  line-height: 1.6;
}

.utility-danger {
  border-color: rgba(255, 125, 125, 0.24);
  color: #ffd0d0;
}

.compact-details summary {
  cursor: pointer;
  font-weight: 700;
}

.compact-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.compact-preview-card {
  display: grid;
  gap: 8px;
  justify-items: center;
  padding: 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  text-align: center;
  color: var(--muted);
}

.page-thumb {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 140px;
  object-fit: contain;
  border-radius: 4px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-row input[type="checkbox"] {
  width: auto;
  padding: 0;
  margin: 0;
  flex: 0 0 auto;
}

.checkbox-row label {
  display: inline;
  color: var(--muted);
}

@media (max-width: 900px) {
  .app-shell {
    padding: 8px;
  }

  .topbar,
  .footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .actions {
    width: 100%;
  }

  .utility-button {
    margin-left: auto;
  }

  .book {
    min-height: auto;
    height: min(84vh, 820px);
  }

  body.embed-mode .app-shell {
    padding: 0;
    gap: 0;
    grid-template-rows: auto 1fr;
  }

  body.embed-mode .embed-topbar,
  body.embed-mode .embed-footer {
    width: calc(100% - 12px);
  }

  body.embed-mode .embed-topbar {
    padding: 4px 0 0;
  }

  body.embed-mode .actions {
    justify-content: flex-end;
    gap: 8px;
  }

  body.embed-mode .nav-button {
    width: 42px;
    height: 42px;
    font-size: 1rem;
  }

  body.embed-mode .utility-button {
    min-height: 42px;
    padding: 0 14px;
    font-size: 0.9rem;
  }

  body.embed-mode .book-frame {
    min-height: calc(100vh - 78px);
    height: calc(100vh - 78px);
  }

  body.embed-mode .book {
    height: 100%;
    min-height: 0;
  }

  .catalog-hero,
  .admin-toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .flipbook-row-card,
  .flipbook-row-embed,
  .flipbook-admin-card,
  .embed-inline-row {
    grid-template-columns: 1fr;
  }

  .flipbook-row-cover {
    min-height: 220px;
  }

  .dialog-form-grid {
    grid-template-columns: 1fr;
  }

  .dialog-form-wide,
  .dialog-actions {
    grid-column: auto;
  }

  .page-face {
    padding: 10px;
  }

  .page-slot {
    width: min(100%, calc(100% - 12px));
  }

  .turn-sheet {
    width: min(100%, calc(100% - 12px));
  }
}

@media (max-width: 640px) {
  body.embed-mode .app-shell {
    grid-template-rows: 1fr;
  }

  body.embed-mode .embed-topbar {
    position: absolute;
    top: 6px;
    left: 6px;
    right: 6px;
    z-index: 30;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    width: auto;
    margin: 0;
    padding: 0;
  }

  body.embed-mode .embed-title h1 {
    font-size: 1rem;
  }

  body.embed-mode .embed-title .eyebrow {
    display: none;
  }

  body.embed-mode .embed-footer {
    display: none;
  }

  body.embed-mode .actions {
    width: auto;
  }

  body.embed-mode .nav-button {
    width: 40px;
    height: 40px;
  }

  body.embed-mode .utility-button {
    min-height: 40px;
    padding: 0 12px;
  }

  body.embed-mode .book-frame {
    min-height: 100vh;
    height: 100vh;
    padding-top: 56px;
  }

  body.embed-mode .book {
    height: 100%;
    min-height: 0;
  }

  .page-face {
    padding: 6px;
  }
}
