:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --text: #eee;
  --text-muted: #9a9abf;
  --border: #2a2a4a;
  --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
}

.header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

header h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}

header .subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

header .subtitle-privacy {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.7;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  gap: 0;
  height: calc(100vh - 72px);
}

/* ---------- panels ---------- */

.panel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
}

.panel:last-child {
  border-right: none;
  border-left: 1px solid var(--border);
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ---------- upload ---------- */

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 12px;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.08);
}

.drop-zone p {
  font-size: 14px;
  color: var(--text);
}

.drop-zone-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.drop-zone .icon {
  font-size: 32px;
  margin-bottom: 8px;
  display: block;
  transition: font-size 0.2s;
}


.drop-zone.enlarged {
  padding: 36px 16px;
  position: relative;
  overflow: visible;
}

.drop-zone.enlarged::before,
.drop-zone.enlarged::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  opacity: 0;
  animation: ripple-out 2.4s ease-out infinite;
}

.drop-zone.enlarged::after {
  animation-delay: 1.2s;
}

@keyframes ripple-out {
  0% { inset: -2px; opacity: 0.6; }
  70% { inset: -16px; opacity: 0; }
  100% { inset: -16px; opacity: 0; }
}

.drop-zone.enlarged .icon {
  font-size: 44px;
}


.image-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.image-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--surface2);
  border-radius: var(--radius);
  cursor: grab;
  position: relative;
  transition: background 0.15s;
}

.image-item:hover {
  background: #1a4a80;
}

.image-item.dragging {
  opacity: 0.4;
}

.image-item .thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.image-item .name {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.image-item .order-num {
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.image-item .btn-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px;
  line-height: 1;
  flex-shrink: 0;
}

.image-item .btn-remove:hover {
  color: var(--accent);
}

/* ---------- preview ---------- */

.preview-area {
  background: var(--bg);
  overflow-y: auto;
}

.preview-flow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px 24px 32px;
  max-width: 600px;
  margin: 0 auto;
}

.preview-options {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.preview-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
}

.preview-size-label {
  font-size: 11px;
  color: var(--text-muted);
}

.preview-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: #111;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-container img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.preview-container img:active {
  cursor: grabbing;
}

.pixiv-overlay-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 7;
  pointer-events: none;
}

.slot-indicator {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(233, 69, 96, 0.85);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 12px;
  border-radius: 12px;
  z-index: 6;
  pointer-events: none;
}

.crop-overlay {
  position: absolute;
  overflow: hidden;
  z-index: 5;
  pointer-events: none;
  border-radius: 2px;
}

.crop-overlay img {
  position: absolute;
  max-width: none;
  user-select: none;
  -webkit-user-select: none;
}

.slot-highlight {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.15s;
}

.slot-highlight.visible {
  opacity: 1;
}

.preview-container .placeholder {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 32px;
}

.preview-area.disabled {
  position: relative;
  overflow: hidden;
}

.preview-area.disabled::after {
  content: "画像がアップロードされていません";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 18px;
}

.preview-area.disabled .placeholder {
  visibility: hidden;
}

.preview-area.disabled .preview-flow {
  pointer-events: none;
}

.preview-mini {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.preview-container-mini {
  position: relative;
  width: 184px;
  height: 184px;
  background: #111;
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.pixiv-overlay-img-mini {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 7;
  pointer-events: none;
}

.preview-container-mini img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.placeholder-mini {
  width: 100%;
  height: 100%;
}

.btn-download-wide {
  width: 100%;
  max-width: 360px;
  padding: 10px 20px;
  font-size: 13px;
}

/* ---------- buttons ---------- */

.btn {
  padding: 8px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled {
  background: #555;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
}

.btn-secondary:hover { background: #1a4a80; }

.btn-secondary.active {
  background: var(--accent);
  color: #fff;
}

/* ---------- settings panel ---------- */

.setting-group {
  margin-bottom: 20px;
}

.setting-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.layout-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 16px;
}

.layout-tab {
  flex: 1 1 calc(25% - 4px);
  min-width: 0;
  padding: 6px 2px 5px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.layout-tab:hover { border-color: var(--accent); }

.layout-tab.active {
  background: rgba(233, 69, 96, 0.12);
  color: #fff;
  border-color: var(--accent);
}

/* ---------- layout icons ---------- */

.layout-icon {
  width: 48px;
  height: 48px;
  position: relative;
  border-radius: 3px;
  overflow: hidden;
  background: var(--bg);
  flex-shrink: 0;
}

.li-mv { background: var(--accent) !important; opacity: 0.6; }
.li-at  { background: #556 !important; opacity: 0.45; }
.layout-tab.active .li-mv { opacity: 1; }
.layout-tab.active .li-at  { opacity: 0.6; }

/* -- classic 1+3 -- */
.layout-icon--classic { display: flex; gap: 2px; padding: 3px; }
.layout-icon--classic .li-main { flex: 2; border-radius: 2px; }
.layout-icon--classic .li-side { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.layout-icon--classic .li-cell { flex: 1; border-radius: 2px; }

/* -- classic2 1+2 -- */
.layout-icon--classic2 { display: flex; gap: 2px; padding: 3px; }
.layout-icon--classic2 .li-main { flex: 2; border-radius: 2px; }
.layout-icon--classic2 .li-side { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.layout-icon--classic2 .li-cell { flex: 1; border-radius: 2px; }

/* -- strips: col (vertical) / row (horizontal) -- */
.layout-icon--col {
  display: flex; flex-direction: row;
  gap: 2px; padding: 3px;
}
.layout-icon--col .li-strip { flex: 1; border-radius: 2px; }

.layout-icon--row {
  display: flex; flex-direction: column;
  gap: 2px; padding: 3px;
}
.layout-icon--row .li-strip { flex: 1; border-radius: 2px; }

/* -- scatter -- */
.layout-icon--scatter { display: flex; padding: 3px; gap: 1px; }
.layout-icon--scatter .li-main { width: 55%; border-radius: 2px; }
.layout-icon--scatter .li-side { flex: 1; position: relative; }
.layout-icon--scatter .li-piece {
  position: absolute; width: 44%; height: 26%;
  border-radius: 2px; border: 1px solid rgba(255,255,255,0.3);
}

/* -- collage -- */
.layout-icon--collage { padding: 3px; }
.layout-icon--collage .li-grid {
  display: grid; grid-template-columns: repeat(3,1fr); grid-template-rows: repeat(2,1fr);
  gap: 2px; width: 100%; height: 100%;
}
.layout-icon--collage .li-gcell { border-radius: 1px; }
.layout-icon--collage .li-over {
  position: absolute; border-radius: 2px; border: 1px solid rgba(255,255,255,0.3);
}
.li-over1 { width: 40%; height: 38%; top: 10%; left: 28%; transform: rotate(3deg); }
.li-over2 { width: 36%; height: 34%; top: 48%; left: 8%; transform: rotate(-6deg); }
.li-over3 { width: 36%; height: 34%; top: 42%; left: 52%; transform: rotate(5deg); }

.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-row input[type="color"] {
  width: 36px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px;
  cursor: pointer;
  background: var(--surface2);
}

.color-label {
  font-size: 12px;
  color: var(--text-muted);
  font-family: monospace;
}

.bg-upload-area {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.bg-preview {
  width: 64px;
  height: 64px;
  border-radius: 6px;
  background: #222;
  border: 2px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

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

.bg-preview .bg-placeholder {
  font-size: 11px;
  color: var(--text-muted);
}

.bg-preview.has-image {
  border-color: var(--accent);
}

.bg-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 11px;
}

.btn-shuffle {
  width: 100%;
  margin-bottom: 16px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.btn-shuffle:hover {
  border-color: var(--accent);
  color: var(--text);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

select {
  width: 100%;
  padding: 6px 8px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.range-row input { flex: 1; }

.range-row .val {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 36px;
  text-align: right;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}

.toggle-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.toggle-row span {
  font-size: 13px;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* ---------- conditional sections ---------- */

.section-collage,
.section-scatter {
  display: none;
}

.section-collage.visible,
.section-scatter.visible {
  display: block;
}

/* ---------- loading ---------- */

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: var(--radius);
}

.loading-overlay.active {
  display: flex;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- full-page drop overlay ---------- */

.page-drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(233, 69, 96, 0.15);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.page-drop-overlay.active {
  display: flex;
}

.page-drop-content {
  background: var(--surface);
  border: 3px dashed var(--accent);
  border-radius: 16px;
  padding: 40px 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

.page-drop-icon {
  font-size: 48px;
}

/* ---------- responsive ---------- */

@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    height: auto;
  }
  .panel { border-right: none !important; border-left: none !important; }
  .panel:first-child { order: 2; }
  .preview-area { order: 3; min-height: 50vh; }
  .panel:last-child { order: 1; }
}
