@font-face {
  font-family: "SPACE Open Sans";
  src: url("fonts/OpenSans-Latin.woff2") format("woff2");
  font-style: normal;
  font-weight: 300 800;
  font-display: swap;
}

:root {
  --rose: #bd717f;
  --rose-dark: #9c4e5e;
  --rose-pale: #f3e7e9;
  --ink: #262326;
  --muted: #716b70;
  --line: #ded8dc;
  --panel: #ffffff;
  --page: #f4f2f3;
  --content-max: 1296px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--page); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--page);
  font-family: "SPACE Open Sans", sans-serif;
  font-size: 16px;
}
button, input, textarea { font: inherit; }
a { color: inherit; }
.admin-nav { display: flex; align-items: center; gap: 20px; }

.admin-shell {
  width: min(var(--content-max), calc(100% - 60px));
  margin: 30px auto 60px;
}

.admin-topbar,
.chapter-panel,
.admin-panel,
.save-bar {
  border: 1px solid var(--rose);
  background: var(--panel);
}

.admin-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 30px;
  padding: 30px;
  margin-bottom: 30px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(2rem, 4vw, 3.2rem); line-height: 1.08; }
h2 { margin-bottom: 0; font-size: clamp(1.35rem, 2vw, 1.75rem); line-height: 1.2; }
.eyebrow, .step {
  margin-bottom: 8px;
  color: var(--rose-dark);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.lede { max-width: 720px; margin-bottom: 0; color: var(--muted); line-height: 1.5; }
.text-link { color: var(--rose-dark); font-weight: 700; text-underline-offset: 0.2em; white-space: nowrap; }

.chapter-panel, .admin-panel { padding: 30px; }
.chapter-panel { margin-bottom: 30px; }
.chapter-manager { margin-bottom: 30px; }
.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 25px;
}

.form-grid { display: grid; grid-template-columns: minmax(160px, 0.3fr) minmax(0, 1fr); gap: 20px; }
label > span:first-child { display: block; margin-bottom: 8px; font-weight: 700; }
input[type="text"], input[type="number"], textarea {
  width: 100%;
  border: 1px solid #aaa2a7;
  border-radius: 0;
  padding: 12px 13px;
  color: var(--ink);
  background: white;
}
textarea { min-height: 150px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus { outline: 3px solid rgba(189, 113, 127, 0.25); border-color: var(--rose-dark); }
.publish-toggle { display: flex; align-items: center; gap: 9px; font-weight: 700; }
.publish-toggle span { margin: 0 !important; }
.publish-toggle input { width: 18px; height: 18px; accent-color: var(--rose-dark); }

.admin-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 30px; align-items: start; }
.image-column { position: sticky; top: 20px; }
.upload-box {
  display: grid;
  place-items: center;
  gap: 4px;
  min-height: 125px;
  border: 2px dashed var(--rose);
  padding: 20px;
  color: var(--rose-dark);
  background: var(--rose-pale);
  text-align: center;
  cursor: pointer;
}
.upload-box.compact { min-height: 100px; }
.upload-box input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.upload-box.is-dragover { background: #ead2d7; border-style: solid; }
.format-hint { margin: 18px 0 25px; color: var(--muted); }
.format-hint summary { cursor: pointer; font-weight: 700; }
.format-hint pre { overflow-x: auto; margin: 12px 0 0; padding: 15px; color: var(--ink); background: #f5f3f4; font: 14px/1.5 Consolas, monospace; white-space: pre-wrap; }
.helper { color: var(--muted); font-size: 0.9rem; line-height: 1.5; }

.button {
  border: 1px solid var(--rose-dark);
  border-radius: 0;
  padding: 11px 16px;
  font-weight: 800;
  cursor: pointer;
}
.button-primary { color: white; background: var(--rose-dark); }
.button-secondary { color: var(--rose-dark); background: white; }
.button-danger { color: #9c2239; border-color: #9c2239; background: white; }
.button:hover { filter: brightness(0.96); }
.button:focus-visible { outline: 3px solid rgba(189, 113, 127, 0.35); outline-offset: 2px; }

.story-editor-list { display: grid; gap: 18px; }
.story-editor {
  border: 1px solid var(--line);
  padding: 20px;
  background: #fcfbfb;
}
.story-editor.is-drop-target { border-color: var(--rose-dark); box-shadow: inset 0 0 0 2px var(--rose); }
.story-editor-header { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.story-number { color: var(--rose-dark); font-weight: 800; }
.remove-story { border: 0; padding: 0; color: var(--muted); background: none; text-decoration: underline; cursor: pointer; }
.story-fields { display: grid; gap: 14px; }
.assigned-image {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  align-items: center;
  gap: 15px;
  min-height: 92px;
  border: 1px dashed #aaa2a7;
  padding: 10px;
  color: var(--muted);
  background: white;
}
.assigned-image img { width: 90px; height: 90px; object-fit: cover; display: block; }
.assigned-image strong { display: block; color: var(--ink); overflow-wrap: anywhere; }

.image-library { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.image-item {
  position: relative;
  border: 2px solid transparent;
  padding: 0;
  color: var(--ink);
  background: #eee;
  cursor: grab;
  text-align: left;
}
.image-item.is-selected { border-color: var(--rose-dark); }
.image-item img { width: 100%; aspect-ratio: 1; display: block; object-fit: cover; }
.image-item span { display: block; padding: 7px; overflow: hidden; font-size: 0.8rem; text-overflow: ellipsis; white-space: nowrap; }
.image-card { position: relative; min-width: 0; }
.delete-image {
  position: absolute;
  z-index: 2;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  border: 1px solid #8a1b30;
  border-radius: 0;
  padding: 0;
  color: white;
  background: rgba(138, 27, 48, 0.94);
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}
.delete-image:focus-visible { outline: 3px solid white; outline-offset: 1px; }

.chapter-list { display: grid; gap: 10px; }
.chapter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.chapter-row:first-child { border-top: 0; padding-top: 0; }
.chapter-summary strong { display: block; }
.chapter-summary span { display: block; margin-top: 2px; color: var(--muted); font-size: 0.88rem; }
.chapter-summary .is-removed { color: #9c2239; font-weight: 700; }
.chapter-action {
  border: 0;
  padding: 5px 0;
  color: var(--rose-dark);
  background: none;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 0.2em;
  cursor: pointer;
}
.chapter-action.remove { color: #9c2239; }
.empty-state { margin: 20px 0 0; color: var(--muted); font-style: italic; line-height: 1.5; }

.save-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-top: 30px;
  padding: 20px 30px;
}
.status { margin: 0; color: var(--muted); line-height: 1.4; }
.status.is-error { color: #a11b31; font-weight: 700; }
.status.is-success { color: #1f6b3a; font-weight: 700; }

.login-shell { max-width: 720px; margin-top: clamp(30px, 8vh, 100px); }
.login-panel { padding: clamp(25px, 5vw, 48px); }
.login-panel h1 { margin-bottom: 24px; }
.login-panel .button-primary { justify-self: start; margin-top: 5px; }
.login-back { margin: 24px 0 0; }
.setup-lede { margin-bottom: 24px; }
.password-panel { margin-top: 30px; }
.password-form { display: grid; gap: 22px; }
.password-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.password-submit { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.password-submit .status { margin: 0; }

@media (max-width: 940px) {
  .admin-workspace { grid-template-columns: 1fr; }
  .image-column { position: static; }
  .image-library { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 650px) {
  .admin-shell { width: min(100% - 30px, var(--content-max)); margin-top: 15px; }
  .admin-topbar, .panel-heading, .save-bar { flex-direction: column; }
  .admin-nav { width: 100%; justify-content: space-between; }
  .chapter-panel, .admin-panel, .admin-topbar { padding: 20px; }
  .form-grid { grid-template-columns: 1fr; }
  .password-grid { grid-template-columns: 1fr; }
  .password-submit { align-items: stretch; flex-direction: column; }
  .image-library { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .save-bar { align-items: stretch; padding: 20px; }
  .button-primary { width: 100%; }
  .chapter-row { grid-template-columns: minmax(0, 1fr) auto; }
  .chapter-row .remove { grid-column: 2; }
}
