:root {
  --bg: #fbf7f1;
  --paper: #ffffff;
  --line: #eadfd3;
  --ink: #2b2927;
  --navy: #425265;
  --muted: #81776d;
  --accent: #f08972;
  --accent-deep: #9d4b35;
  --accent-soft: #fbddc8;
  --shadow: 0 18px 44px rgba(75, 55, 39, 0.09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(240, 137, 114, 0.13), transparent 28%),
    linear-gradient(180deg, #fffaf4 0%, var(--bg) 100%);
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
  line-height: 1.7;
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid rgba(66, 82, 101, 0.12);
  backdrop-filter: blur(12px);
}

.brand { color: var(--accent-deep); font-weight: 800; letter-spacing: 0.12em; }
.save-status { color: var(--muted); font-size: 12px; }
.save-status.is-error { color: #b54137; }

.editor-shell { width: min(100% - 24px, 760px); margin: 18px auto 80px; }
.editor-hero, .movie-panel, .section-card, .loading-card {
  margin-bottom: 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
}

.editor-hero { padding: clamp(22px, 5vw, 34px); text-align: center; }
.editor-hero h1 { margin: 4px 0 8px; color: var(--navy); font-size: clamp(30px, 8vw, 46px); }
.editor-hero p:last-child { margin: 0; color: var(--muted); font-size: 14px; }
.eyebrow { margin: 0; color: var(--accent); font-size: 11px; letter-spacing: 0.2em; }

.movie-panel { display: grid; gap: 14px; padding: clamp(18px, 4vw, 26px); }
.panel-label {
  padding: 12px 14px;
  border-radius: 6px;
  background: #f5f0ec;
  color: var(--navy);
  font-size: 18px;
  font-weight: 700;
}
.template-label { color: var(--muted); font-size: 13px; }
.movie-panel select {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
.sample-frame { aspect-ratio: 16 / 9; overflow: hidden; border-radius: 14px; background: #222; }
.sample-frame iframe { display: block; width: 100%; height: 100%; border: 0; }

.sections { display: grid; gap: 18px; }
.loading-card { padding: 28px; color: var(--muted); text-align: center; }
.section-card { padding: 0; overflow: hidden; }
.section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 66px;
  padding: 0 18px;
  border: 0;
  background: #f5f0ec;
  color: var(--navy);
  font-weight: 800;
  cursor: pointer;
  text-align: left;
}
.section-toggle::after { content: "›"; order: 3; font-size: 34px; line-height: 1; transition: transform 160ms ease; }
.section-card.open .section-toggle::after { transform: rotate(90deg); }
.section-count {
  margin-left: auto;
  margin-right: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(66, 82, 101, 0.1);
  font-size: 12px;
}
.section-body { display: none; padding: 18px; }
.section-card.open .section-body { display: block; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 4px 0 6px; color: var(--navy); font-size: 22px; }
.section-title::before { content: ""; width: 5px; height: 24px; border-radius: 999px; background: var(--navy); }
.section-guide { margin: 0; color: var(--muted); font-size: 13px; }
.slots { display: grid; gap: 14px; margin-top: 18px; }

.slot {
  position: relative;
  padding: 12px;
  border: 1px solid rgba(234, 223, 211, 0.9);
  border-radius: 16px;
  background: #f2eadc;
}
.slot-top { display: flex; align-items: center; justify-content: space-between; min-height: 28px; }
.slot-top strong { color: var(--navy); font-size: 15px; }
.drag-handle {
  display: grid;
  flex: 0 0 auto;
  width: 42px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(66, 82, 101, 0.1);
  color: var(--navy);
  cursor: grab;
  font-size: 20px;
  line-height: 1;
  place-items: center;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.drag-handle span { pointer-events: none; }
.drag-handle:active { cursor: grabbing; }
.sequence-placeholder {
  position: relative;
  border: 2px dashed rgba(240, 137, 114, 0.75);
  border-radius: 16px;
  background: rgba(251, 221, 200, 0.46);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.56);
  animation: placeholder-pulse 900ms ease-in-out infinite alternate;
}
.sequence-placeholder::after {
  position: absolute;
  inset: 0;
  display: grid;
  color: var(--accent-deep);
  content: "ここに移動";
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  place-items: center;
}
.drag-ghost {
  position: fixed;
  z-index: 100;
  margin: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: 0.97;
  transform: rotate(-1deg) scale(1.025);
  transform-origin: center;
  box-shadow: 0 26px 58px rgba(75, 55, 39, 0.28);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  will-change: top, left, transform;
}
.drag-ghost.is-dropping {
  transition: top 120ms ease-out, left 120ms ease-out, transform 120ms ease-out, box-shadow 120ms ease-out;
  transform: rotate(0) scale(1);
  box-shadow: 0 8px 20px rgba(75, 55, 39, 0.14);
}
body.is-sorting { cursor: grabbing; user-select: none; }
body.is-sorting .drag-handle { cursor: grabbing; }
@keyframes placeholder-pulse {
  from { background-color: rgba(251, 221, 200, 0.3); }
  to { background-color: rgba(251, 221, 200, 0.62); }
}
.scene-content { display: grid; gap: 10px; margin-top: 10px; }
.scene-photos { display: grid; gap: 10px; }
.scene-photos.multi-photo { grid-template-columns: 1fr 1fr; }
.photo-entry { position: relative; min-width: 0; }
.photo-entry.is-busy { opacity: 0.55; pointer-events: none; }
.photo-picker {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 4 / 3;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(66, 82, 101, 0.14);
  border-radius: 12px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}
.photo-picker.has-image.adjust-enabled { cursor: grab; touch-action: none; }
.photo-picker.has-image.is-adjusting { cursor: grabbing; }
.photo-picker.frame-16-9 { aspect-ratio: 16 / 9; }
.photo-picker img {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  width: auto;
  height: 100%;
  max-width: none;
  max-height: none;
  transform-origin: center;
  user-select: none;
  pointer-events: none;
  -webkit-user-drag: none;
}
.photo-picker span { font-size: 13px; letter-spacing: 0.05em; }
.crop-hint {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: none;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(43, 41, 39, 0.68);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  pointer-events: none;
}
.photo-picker.adjust-enabled .crop-hint { display: inline-flex; }
.adjust-done {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: rgba(66, 82, 101, 0.94);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}
.photo-clear {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(43, 41, 39, 0.72);
  color: #fff;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}
.comment-grid { display: grid; gap: 8px; }
.comment-grid label { color: var(--muted); font-size: 12px; }
.text-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  resize: vertical;
}
.text-input:focus { border-color: var(--accent); outline: 3px solid rgba(240, 137, 114, 0.18); }
.title-slot .comment-grid { margin-top: 10px; }
.fatal-error { padding: 20px; border-radius: 16px; background: #fff; color: #b54137; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(35, 37, 38, 0.46);
  backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.modal-card {
  display: grid;
  gap: 10px;
  width: min(100%, 380px);
  padding: 16px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(35, 37, 38, 0.22);
}
.menu-button {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-weight: 700;
  cursor: pointer;
}
.menu-button--soft { background: #f5f0ec; color: var(--muted); }

.start-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at top left, #fff 0, var(--bg) 58%, var(--accent-soft) 150%);
}
.start-card { width: min(100%, 520px); padding: 36px 28px; background: rgba(255,255,255,0.94); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.start-card h1 { margin: 4px 0 12px; color: var(--navy); font-size: 34px; }
.start-card > p:not(.eyebrow, .message) { color: var(--muted); }
.primary-button { width: 100%; min-height: 52px; margin-top: 16px; border: 0; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 700; }
.primary-button:disabled { opacity: 0.45; }
.message { color: #b54137; font-size: 13px; }

@media (max-width: 520px) {
  .editor-shell { width: min(100% - 18px, 760px); margin-top: 10px; }
  .editor-hero, .movie-panel { border-radius: 20px; }
  .section-card { border-radius: 16px; }
  .section-body { padding: 14px 10px; }
  .scene-photos.multi-photo { grid-template-columns: 1fr; }
}
