:root {
  --paper: #f7f2ea;
  --paper-deep: #eee6dc;
  --card: #fffdf9;
  --ink: #2a2032;
  --muted: #695f6f;
  --purple: #5f3b6e;
  --purple-dark: #442550;
  --purple-soft: #eee5f1;
  --gold: #a57636;
  --green: #2e6952;
  --green-soft: #e4f1eb;
  --red: #a03742;
  --red-soft: #f9e7e8;
  --line: #d8cfc5;
  --shadow: 0 14px 35px rgba(45, 31, 51, 0.08);
  --sans: "Jost", "Segoe UI", system-ui, sans-serif;
  --serif: "Cormorant Garamond", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.6;
}

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

button,
a,
label[for] {
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

:focus-visible {
  outline: 3px solid #7a4d8d;
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 500;
  padding: 10px 15px;
  color: white;
  background: var(--purple-dark);
  transform: translateY(-150%);
}

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

/* Header and persistent notice */

.desk-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  min-height: 76px;
  padding: 12px 28px;
  gap: 25px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 249, 0.96);
  backdrop-filter: blur(10px);
}

.desk-brand {
  display: flex;
  gap: 11px;
  align-items: center;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.45rem;
  text-decoration: none;
}

.desk-brand > span:first-child {
  color: var(--gold);
  font-family: var(--sans);
  font-size: 1rem;
}

.desk-brand strong {
  color: var(--purple);
}

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

.save-status {
  margin: 0;
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 600;
}

.save-status.dirty {
  color: var(--gold);
}

.save-status.error {
  color: var(--red);
}

.device-warning {
  position: relative;
  z-index: 10;
  padding: 12px 28px;
  color: #31210c;
  border-bottom: 1px solid #d2ad72;
  background: #f3dfbd;
  font-size: 0.86rem;
}

.device-warning > div {
  display: flex;
  max-width: 1180px;
  margin: 0 auto;
  gap: 12px;
  align-items: baseline;
  justify-content: center;
}

.device-warning strong {
  white-space: nowrap;
}

/* Layout and navigation */

.desk-layout {
  display: grid;
  min-height: calc(100vh - 126px);
  grid-template-columns: 280px minmax(0, 1fr);
}

.desk-nav {
  position: sticky;
  top: 76px;
  height: calc(100vh - 76px);
  padding: 32px 20px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--paper-deep);
}

.nav-label {
  margin: 0 10px 16px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.desk-nav-button {
  display: flex;
  width: 100%;
  min-height: 53px;
  margin-bottom: 6px;
  padding: 12px 14px;
  gap: 12px;
  align-items: center;
  color: var(--ink);
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-weight: 500;
  text-align: left;
}

.desk-nav-button > span {
  display: grid;
  width: 27px;
  height: 27px;
  flex: 0 0 auto;
  color: var(--purple);
  border-radius: 50%;
  background: var(--purple-soft);
  place-items: center;
}

.desk-nav-button:hover {
  border-color: var(--line);
  background: rgba(255, 253, 249, 0.65);
}

.desk-nav-button.active {
  color: white;
  background: var(--purple);
}

.desk-nav-button.active > span {
  color: var(--purple-dark);
  background: white;
}

.nav-help {
  margin-top: 32px;
  padding: 17px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 249, 0.72);
  font-size: 0.78rem;
}

.nav-help strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
}

.nav-help p {
  margin: 0;
}

.desk-main {
  width: 100%;
  min-width: 0;
  max-width: 1320px;
  margin: 0 auto;
  padding: clamp(38px, 5vw, 70px) clamp(24px, 5vw, 70px) 100px;
}

.editor-panel {
  width: 100%;
}

.panel-heading {
  max-width: 810px;
  margin-bottom: 42px;
}

.panel-heading.with-action {
  display: flex;
  max-width: none;
  gap: 30px;
  align-items: flex-end;
  justify-content: space-between;
}

.panel-heading h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2.7rem, 5vw, 4.25rem);
  line-height: 1;
}

.panel-heading p:last-child {
  max-width: 70ch;
  margin: 17px 0 0;
  color: var(--muted);
}

.kicker {
  margin: 0 0 10px;
  color: var(--purple);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Buttons */

.button {
  display: inline-flex;
  min-height: 50px;
  padding: 11px 20px;
  gap: 8px;
  align-items: center;
  justify-content: center;
  border: 2px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
}

.button.primary {
  color: white;
  border-color: var(--purple);
  background: var(--purple);
}

.button.primary:hover {
  border-color: var(--purple-dark);
  background: var(--purple-dark);
}

.button.secondary {
  color: var(--purple-dark);
  border-color: #9b84a3;
  background: white;
}

.button.secondary:hover {
  border-color: var(--purple);
  background: var(--purple-soft);
}

.button.danger {
  color: white;
  border-color: var(--red);
  background: var(--red);
}

.button.danger:hover {
  background: #7c2530;
}

.button.small {
  min-height: 42px;
  padding: 8px 14px;
  font-size: 0.78rem;
}

.text-button {
  min-height: 44px;
  padding: 8px 4px;
  color: var(--purple);
  border: 0;
  background: transparent;
  cursor: pointer;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.danger-text {
  color: var(--red);
}

/* Dashboard */

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

.quick-card {
  display: grid;
  min-height: 150px;
  padding: 25px;
  grid-template-columns: auto 1fr auto;
  gap: 19px;
  align-items: center;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  box-shadow: 0 2px 0 rgba(47, 30, 55, 0.02);
  cursor: pointer;
  text-align: left;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.quick-card:hover {
  border-color: #a88bb0;
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.quick-icon {
  display: grid;
  width: 52px;
  height: 52px;
  color: var(--purple);
  border-radius: 50%;
  background: var(--purple-soft);
  font-size: 1.25rem;
  place-items: center;
}

.quick-card strong {
  display: block;
  margin-bottom: 7px;
  font-family: var(--serif);
  font-size: 1.45rem;
  line-height: 1.1;
}

.quick-card small {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.quick-arrow {
  color: var(--purple);
  font-size: 1.35rem;
}

.dashboard-row {
  display: grid;
  margin-top: 35px;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.dashboard-card {
  padding: 27px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

.dashboard-card h2 {
  margin: 0 0 18px;
  font-family: var(--serif);
  font-size: 1.7rem;
}

.dashboard-card > p {
  margin: 0;
  color: var(--muted);
}

.calm-note {
  border-color: #bdd4c9;
  background: var(--green-soft);
}

.content-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 13px;
}

.count-chip {
  padding: 9px 13px;
  color: var(--purple-dark);
  border-radius: 999px;
  background: var(--purple-soft);
  font-size: 0.82rem;
  font-weight: 600;
}

/* Forms */

.editor-form {
  display: flex;
  flex-direction: column;
  gap: 25px;
}

.form-card {
  padding: clamp(24px, 4vw, 39px);
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  box-shadow: 0 2px 0 rgba(47, 30, 55, 0.02);
}

.form-card > h2 {
  margin: 0 0 22px;
  font-family: var(--serif);
  font-size: 1.75rem;
}

.form-card-heading {
  display: flex;
  margin-bottom: 30px;
  gap: 17px;
  align-items: flex-start;
}

.form-card-heading h2,
.section-toolbar h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.9rem;
  line-height: 1.1;
}

.form-card-heading p,
.section-toolbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.step-number {
  display: grid;
  width: 39px;
  height: 39px;
  flex: 0 0 auto;
  color: white;
  border-radius: 50%;
  background: var(--purple);
  font-weight: 600;
  place-items: center;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field + .field,
.field-group + .field {
  margin-top: 22px;
}

.field label,
.field-group legend {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 600;
}

.field input,
.field textarea,
.field select,
.story-editor input,
.story-editor textarea,
.story-editor select {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  color: var(--ink);
  border: 1px solid #bcb1aa;
  border-radius: 6px;
  background: white;
}

.field textarea,
.story-editor textarea {
  min-height: 125px;
  resize: vertical;
}

.field .writing-area {
  min-height: 390px;
  font-family: Georgia, serif;
  font-size: 1.05rem;
  line-height: 1.75;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
.story-editor input:focus,
.story-editor textarea:focus,
.story-editor select:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(95, 59, 110, 0.12);
  outline: none;
}

.field-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.field-grid {
  display: grid;
  gap: 18px;
}

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-grid > .field + .field {
  margin-top: 0;
}

.field-group {
  min-width: 0;
  margin: 26px 0 0;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.field-group legend {
  padding: 0 7px;
}

.save-bar {
  position: sticky;
  bottom: 15px;
  z-index: 20;
  display: flex;
  padding: 17px 20px;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid #bfaec5;
  border-radius: 10px;
  background: rgba(255, 253, 249, 0.97);
  box-shadow: 0 9px 30px rgba(40, 26, 46, 0.14);
  backdrop-filter: blur(8px);
}

.save-bar > p {
  max-width: 39ch;
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.save-bar > div {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Images */

.image-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.image-editor {
  min-width: 0;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf8f3;
}

.image-editor h3 {
  margin: 0 0 13px;
  font-family: var(--serif);
  font-size: 1.35rem;
}

.image-preview {
  display: grid;
  min-height: 190px;
  margin-bottom: 13px;
  overflow: hidden;
  color: var(--muted);
  border: 1px dashed #aa9da9;
  border-radius: 7px;
  background: var(--purple-soft);
  font-size: 0.8rem;
  text-align: center;
  place-items: center;
}

.image-preview img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: inherit;
  object-fit: cover;
}

.image-preview.wide {
  aspect-ratio: 16 / 10;
}

.file-button {
  display: inline-flex;
  min-height: 46px;
  padding: 9px 14px;
  align-items: center;
  justify-content: center;
  color: var(--purple-dark);
  border: 2px solid #9b84a3;
  border-radius: 7px;
  background: white;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
}

.file-button:hover {
  background: var(--purple-soft);
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.file-button:has(+ .file-input:focus-visible) {
  outline: 3px solid var(--purple);
  outline-offset: 3px;
}

.image-editor .text-button {
  display: block;
}

.image-editor .field {
  margin-top: 10px;
}

.single-image-row {
  display: grid;
  grid-template-columns: minmax(220px, 0.75fr) minmax(260px, 1fr);
  gap: 25px;
  align-items: start;
}

.single-image-row .field {
  margin-top: 13px;
}

/* My Story chapter editors */

.section-toolbar {
  display: flex;
  margin-top: 12px;
  gap: 22px;
  align-items: flex-end;
  justify-content: space-between;
}

.story-section-list {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.story-editor {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  overflow: hidden;
}

.story-editor summary {
  display: flex;
  min-height: 68px;
  padding: 15px 20px;
  gap: 16px;
  align-items: center;
  cursor: pointer;
  list-style: none;
}

.story-editor summary::-webkit-details-marker {
  display: none;
}

.story-editor summary::before {
  width: 23px;
  content: "▸";
  color: var(--purple);
  font-size: 1.2rem;
  text-align: center;
  transition: transform 120ms ease;
}

.story-editor[open] summary::before {
  transform: rotate(90deg);
}

.story-summary-title {
  flex: 1;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
}

.status-badge {
  padding: 5px 9px;
  color: var(--muted);
  border-radius: 999px;
  background: var(--paper-deep);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.status-badge.published {
  color: var(--green);
  background: var(--green-soft);
}

.story-editor-body {
  padding: 24px 24px 27px 59px;
  border-top: 1px solid var(--line);
}

.story-editor-actions {
  display: flex;
  margin-top: 19px;
  gap: 15px;
  flex-wrap: wrap;
  align-items: center;
}

/* Journal item editors */

.content-editor-layout {
  display: grid;
  grid-template-columns: minmax(230px, 0.38fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.entry-sidebar {
  position: sticky;
  top: 105px;
  max-height: calc(100vh - 135px);
  padding: 19px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

.entry-sidebar h2 {
  margin: 0 0 15px;
  font-family: var(--serif);
  font-size: 1.55rem;
}

.entry-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.entry-list-button {
  display: block;
  width: 100%;
  min-height: 64px;
  padding: 11px 12px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  cursor: pointer;
  text-align: left;
}

.entry-list-button:hover,
.entry-list-button.active {
  border-color: var(--purple);
  background: var(--purple-soft);
}

.entry-list-button strong {
  display: block;
  margin-bottom: 3px;
  line-height: 1.25;
}

.entry-list-button small {
  color: var(--muted);
  font-size: 0.7rem;
}

.entry-empty {
  display: grid;
  min-height: 350px;
  padding: 40px;
  color: var(--muted);
  border: 1px dashed #a99da8;
  border-radius: 10px;
  text-align: center;
  place-content: center;
}

.entry-empty > span {
  color: var(--purple);
  font-size: 2rem;
}

.entry-empty h2 {
  margin: 12px 0 5px;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.8rem;
}

.entry-empty p {
  margin: 0;
}

.compact-form .form-card {
  padding: clamp(23px, 4vw, 34px);
}

.publish-card {
  display: grid;
  grid-template-columns: minmax(260px, 0.7fr) 1fr;
  gap: 25px;
  align-items: end;
  border-color: #c6b1cb;
  background: #fbf7fc;
}

.publish-card > p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.intro-card {
  display: flex;
  margin-bottom: 25px;
  gap: 22px;
  align-items: flex-end;
}

.intro-card .field {
  flex: 1;
}

/* Backup */

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

.backup-card {
  display: flex;
  min-height: 310px;
  flex-direction: column;
  align-items: flex-start;
}

.backup-icon {
  display: grid;
  width: 48px;
  height: 48px;
  margin-bottom: 20px;
  color: var(--purple);
  border-radius: 50%;
  background: var(--purple-soft);
  place-items: center;
}

.backup-card h2 {
  margin-bottom: 12px;
}

.backup-card > p {
  margin: 0 0 24px;
  color: var(--muted);
  flex: 1;
}

.danger-card {
  border-color: #e3b7bb;
  background: #fffafa;
}

.danger-card .backup-icon {
  color: var(--red);
  background: var(--red-soft);
}

.storage-card {
  display: flex;
  margin-top: 24px;
  padding: 23px 27px;
  gap: 30px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

.storage-card h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.45rem;
}

.storage-card p {
  max-width: 60ch;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

/* Toast */

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 100;
  max-width: min(420px, calc(100% - 44px));
  padding: 15px 19px;
  color: white;
  border-radius: 8px;
  background: var(--green);
  box-shadow: 0 10px 35px rgba(25, 48, 38, 0.25);
  font-size: 0.86rem;
  font-weight: 600;
}

.toast.error {
  background: var(--red);
}

/* Responsive */

@media (max-width: 1080px) {
  .desk-layout {
    grid-template-columns: 235px minmax(0, 1fr);
  }

  .desk-nav {
    padding-inline: 13px;
  }

  .quick-grid,
  .image-grid {
    grid-template-columns: 1fr;
  }

  .image-editor {
    display: grid;
    grid-template-columns: 170px 1fr;
    gap: 6px 18px;
    align-items: start;
  }

  .image-editor h3 {
    grid-column: 1 / -1;
  }

  .image-editor .image-preview {
    grid-row: span 4;
  }

  .image-editor .field {
    margin-top: 0;
  }

  .field-grid.three {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .desk-header {
    position: static;
  }

  .header-actions .save-status {
    display: none;
  }

  .device-warning > div {
    display: block;
  }

  .device-warning strong {
    display: block;
    white-space: normal;
  }

  .desk-layout {
    display: block;
  }

  .desk-nav {
    position: static;
    display: flex;
    width: 100%;
    height: auto;
    padding: 12px 16px;
    overflow-x: auto;
    gap: 7px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-label,
  .nav-help {
    display: none;
  }

  .desk-nav-button {
    width: auto;
    min-width: max-content;
    margin: 0;
    padding: 9px 12px;
  }

  .desk-main {
    padding: 38px 20px 90px;
  }

  .panel-heading.with-action {
    align-items: flex-start;
    flex-direction: column;
  }

  .dashboard-row,
  .field-grid.two,
  .content-editor-layout,
  .backup-grid {
    grid-template-columns: 1fr;
  }

  .entry-sidebar {
    position: static;
    max-height: none;
  }

  .entry-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .publish-card {
    grid-template-columns: 1fr;
  }

  .save-bar {
    position: static;
    align-items: stretch;
    flex-direction: column;
  }

  .save-bar > div {
    justify-content: flex-start;
  }

  .single-image-row {
    grid-template-columns: minmax(180px, 0.6fr) 1fr;
  }

  .storage-card {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }
}

@media (max-width: 570px) {
  body {
    font-size: 17px;
  }

  .desk-header {
    padding: 11px 15px;
  }

  .desk-brand {
    font-size: 1.15rem;
  }

  .header-actions .button {
    padding-inline: 10px;
  }

  .device-warning {
    padding-inline: 16px;
  }

  .quick-grid,
  .dashboard-row {
    grid-template-columns: 1fr;
  }

  .quick-card {
    grid-template-columns: auto 1fr;
  }

  .quick-arrow {
    display: none;
  }

  .form-card {
    padding: 22px 17px;
  }

  .image-editor {
    display: block;
  }

  .image-editor .field {
    margin-top: 10px;
  }

  .single-image-row {
    grid-template-columns: 1fr;
  }

  .section-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .story-editor summary {
    padding-inline: 13px;
  }

  .story-editor-body {
    padding: 19px 15px 22px;
  }

  .entry-list {
    grid-template-columns: 1fr;
  }

  .intro-card {
    align-items: stretch;
    flex-direction: column;
  }

  .save-bar > div,
  .save-bar .button {
    width: 100%;
  }

  .save-bar .button {
    flex: 1 1 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
