:root {
  color-scheme: dark;
  --night: #0e211d;
  --panel: #0e211d;
  --panel-strong: #0e211d;
  --cream: #f5eee1;
  --accent-text: #f0d187;
  --muted: rgba(245, 238, 225, 0.62);
  --gold: #e8bd67;
  --gold-light: #ffe0a0;
  --line: rgba(245, 238, 225, 0.15);
  --red: #bd4b43;
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: #0e211d;
  color: var(--cream);
}

body {
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body.modal-scroll-locked {
  position: fixed;
  right: 0;
  left: 0;
  overflow: hidden;
  width: 100%;
  touch-action: none;
}

button, input, textarea { color: inherit; font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.editor-shell {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: max(30px, env(safe-area-inset-top)) 0 48px;
}

.editor-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 0 28px;
}

.eyebrow, .section-index {
  margin: 0 0 9px;
  color: var(--gold);
  font-size: 10px;
  letter-spacing: 0.22em;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 10px;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(38px, 7vw, 70px);
  font-weight: 400;
  letter-spacing: 0;
  line-height: 0.98;
  color: var(--accent-text);
}

.header-copy {
  max-width: 430px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

.back-link {
  flex: 0 0 auto;
  padding: 10px 0;
  color: var(--gold-light);
  font-size: 13px;
  text-decoration: none;
  border-bottom: 1px solid rgba(232, 189, 103, 0.5);
}

.editor-section {
  margin-top: 14px;
  padding: clamp(20px, 4vw, 32px);
  border-top: 1px solid var(--line);
  background: #0e211d;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.section-heading h2 {
  margin: 0;
  font-family: Georgia, "Songti SC", serif;
  font-size: 28px;
  font-weight: 400;
  color: var(--accent-text);
}

.section-heading > p {
  max-width: 370px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
  text-align: right;
}

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

.photo-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(16, 41, 31, 0.64);
}

.photo-preview {
  position: relative;
  display: grid;
  aspect-ratio: 4 / 3;
  place-items: center;
  overflow: hidden;
  margin-bottom: 10px;
  border: 1px dashed rgba(232, 189, 103, 0.32);
  background: rgba(4, 14, 11, 0.42);
}

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

.photo-preview span {
  padding: 12px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  line-height: 1.6;
}

.photo-file-input,
.upload-voice input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.photo-card-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.photo-caption-preview {
  min-width: 0;
  margin: 8px 1px 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-action {
  min-width: 0;
  min-height: 34px;
  padding: 0 6px;
  overflow: hidden;
  border: 1px solid rgba(232, 189, 103, 0.35);
  border-radius: 3px;
  background: rgba(7, 23, 19, 0.48);
  color: var(--gold-light);
  cursor: pointer;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-action:hover,
.photo-action:focus-visible {
  border-color: rgba(232, 189, 103, 0.78);
  outline: none;
}

.photo-action:disabled {
  border-color: rgba(245, 238, 225, 0.08);
  color: rgba(245, 238, 225, 0.28);
  cursor: not-allowed;
}

.center-text-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.center-text-field span,
.voice-label {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

input[type="text"], input:not([type]), textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 3px;
  outline: none;
  background: rgba(3, 13, 10, 0.5);
  color: var(--cream);
  font-size: 13px;
}

input:focus, textarea:focus {
  border-color: rgba(232, 189, 103, 0.78);
}

textarea, input[type="text"], input:not([type]) { padding: 9px 10px; }

.center-text-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.center-text-grid input {
  padding: 13px 14px;
  font-size: 16px;
  color: var(--accent-text);
}

.voice-editor {
  display: grid;
  gap: 14px;
}

.voice-box {
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.upload-voice {
  position: relative;
  display: grid;
  min-height: 105px;
  place-items: center;
  align-content: center;
  gap: 5px;
  border: 1px dashed rgba(232, 189, 103, 0.4);
  border-radius: 6px;
  cursor: pointer;
  background: #0e211d;
}

.voice-icon {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  color: var(--gold-light);
  line-height: 1;
}

.voice-icon svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.upload-voice strong { color: var(--accent-text); font-size: 13px; font-weight: 500; }
.upload-voice small, .field-note { margin: 0; color: var(--muted); font-size: 11px; }

.voice-preview {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 42px;
  margin-top: 15px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
}

.voice-preview audio { display: none; }

.voice-message {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
  min-height: 42px;
  padding: 0 52px 0 18px;
  border: 0;
  border-radius: 6px;
  background: #285a3d;
  color: var(--cream);
  cursor: pointer;
  text-align: left;
}

.voice-time {
  order: 2;
  font-variant-numeric: tabular-nums;
  color: rgba(247, 241, 226, 0.92);
  font-size: 12px;
  white-space: nowrap;
}

.voice-wave {
  order: 1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 3px;
  height: 20px;
}

.voice-wave::before,
.voice-wave::after {
  content: "";
  display: block;
  width: 3px;
  height: 9px;
  border-radius: 2px;
  background: currentColor;
  box-shadow: 7px -4px 0 currentColor, 14px 2px 0 currentColor, 21px -7px 0 currentColor, 28px 1px 0 currentColor, 35px -3px 0 currentColor;
  color: rgba(247, 241, 226, 0.85);
}

.voice-wave::after {
  margin-left: 41px;
  height: 6px;
  box-shadow: 7px 4px 0 currentColor, 14px -3px 0 currentColor, 21px 6px 0 currentColor, 28px -2px 0 currentColor;
}

.voice-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: #edaaa0;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.text-button, .primary-button, .secondary-button {
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
}

.text-button {
  padding: 7px 0;
  background: transparent;
  color: var(--gold-light);
  font-size: 12px;
}

.text-button.danger { color: #edaaa0; }

.qr-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  max-width: 470px;
  margin-bottom: 18px;
}

.qr-card {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(245, 238, 225, 0.96);
  color: #10271f;
}

.qr-card canvas { width: 100%; max-width: 168px; height: auto; }
.qr-card strong { font-size: 12px; font-weight: 600; }
.qr-card span { font-size: 11px; opacity: 0.64; }

.qr-section > .secondary-button {
  display: block;
  margin: 0 auto;
}

.editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 36px 0 0;
}

.editor-divider {
  height: 1px;
  margin: 21px 0 0;
  background: var(--line);
}

.caption-modal {
  position: fixed;
  inset: 0;
  z-index: 11;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 12, 9, 0.72);
  overscroll-behavior: contain;
  touch-action: none;
}

.caption-modal[hidden] { display: none; }

.caption-dialog {
  width: min(520px, 100%);
  padding: clamp(18px, 4vw, 28px);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0d271d;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
  touch-action: pan-y;
}

.caption-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.caption-header h2 {
  margin: 0;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(25px, 6vw, 36px);
  font-weight: 400;
  color: var(--accent-text);
}

.caption-title-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 10px;
}

.caption-title-row .eyebrow {
  flex-basis: 100%;
}

.caption-photo {
  display: block;
  width: 33.333%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  margin: 0 auto 14px;
  border-radius: 4px;
  background: #f1ebdf;
}

.caption-input-wrap {
  position: relative;
}

.caption-close {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--cream);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.caption-dialog textarea {
  min-height: 130px;
  padding-bottom: 30px;
  resize: vertical;
  line-height: 1.7;
}

.caption-count {
  position: absolute;
  right: 10px;
  bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  pointer-events: none;
}

.caption-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.caption-actions button {
  flex: 1;
}

.primary-button, .secondary-button {
  min-height: 42px;
  padding: 0 18px;
  font-size: 13px;
}

.primary-button {
  background: var(--gold);
  color: #18241a;
}

.secondary-button {
  border-color: rgba(232, 189, 103, 0.45);
  background: rgba(16, 41, 31, 0.6);
  color: var(--gold-light);
}

.editor-toast {
  position: fixed;
  right: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 3;
  max-width: calc(100% - 32px);
  padding: 11px 15px;
  border: 1px solid rgba(232, 189, 103, 0.35);
  border-radius: 4px;
  background: rgba(8, 24, 18, 0.94);
  color: var(--gold-light);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translate(50%, 10px);
  transition: 180ms ease;
}

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

.crop-modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 12, 9, 0.82);
  overscroll-behavior: contain;
  touch-action: none;
}

.crop-modal[hidden] { display: none; }

.crop-dialog {
  width: min(620px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: clamp(18px, 4vw, 30px);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0d271d;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
  touch-action: pan-y;
}

.crop-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.crop-header h2 {
  margin: 0;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(25px, 6vw, 36px);
  font-weight: 400;
  color: var(--accent-text);
}

.crop-close {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--cream);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.crop-copy {
  margin: 16px 0 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.crop-stage {
  position: relative;
  width: min(100%, 540px);
  aspect-ratio: 4 / 3;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid rgba(232, 189, 103, 0.46);
  background: #030b08;
  cursor: grab;
  touch-action: none;
}

.crop-stage:active { cursor: grabbing; }

#crop-canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
}

.crop-frame {
  position: absolute;
  z-index: 2;
  border: 2px solid var(--gold-light);
  box-shadow: 0 0 0 999px rgba(3, 11, 8, 0.18);
  pointer-events: none;
}

.crop-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  width: min(100%, 540px);
  margin: 20px auto 0;
}

@media (max-width: 700px) {
  .editor-shell { width: min(100% - 24px, 540px); padding-bottom: 32px; }
  .editor-header { display: block; }
  .back-link { display: inline-block; margin-top: 18px; }
  .section-heading { display: block; }
  .section-heading > p { margin-top: 8px; text-align: left; }
  .photo-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .photo-card { padding: 6px; }
  .photo-preview { margin-bottom: 7px; }
  .photo-action { min-height: 30px; padding: 0 2px; font-size: 9px; }
  .center-text-field { grid-template-columns: 42px minmax(0, 1fr); gap: 8px; }
  .voice-preview,
  .voice-message { min-height: 42px; }
  .editor-actions { position: static; padding: 26px 0 0; background: none; }
  .editor-actions button { flex: 1; }
  .crop-actions button { flex: 1; }
}

@media (max-width: 390px) {
  .qr-pair { grid-template-columns: 1fr; }
}
