/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Splash Screen ── */
.splash {
  position: fixed; inset: 0; z-index: 9999;
  background: #0f0f0f;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .5s ease, visibility .5s ease;
}
.splash.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.splash-inner { display: flex; flex-direction: column; align-items: center; gap: 16px; }

.splash-logo {
  display: flex; align-items: center; gap: 16px;
  animation: splashFadeUp .6s ease both;
}
.splash-mark { width: 52px; height: 52px; flex-shrink: 0; }
.splash-titles { display: flex; flex-direction: column; gap: 2px; }
.splash-subtitle {
  font-size: 11px; letter-spacing: .14em; color: rgba(255,255,255,.4);
  font-family: 'Helvetica Neue', Arial, sans-serif;
}
.splash-name {
  font-size: 34px; font-weight: 900; letter-spacing: .1em;
  color: #ffffff; font-family: 'Helvetica Neue', Arial, sans-serif;
  line-height: 1;
}
.splash-by {
  font-size: 12px; color: rgba(255,255,255,.4); letter-spacing: .08em;
  animation: splashFadeUp .6s .15s ease both;
}
.splash-by strong { color: rgba(255,255,255,.7); font-weight: 600; }

@keyframes splashFadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

:root {
  --bg: #ffffff;
  --surface: #f7f6f3;
  --surface2: #eeecea;
  --border: #e0ddd9;
  --text: #37352f;
  --text-secondary: #787672;
  --accent: #2eaadc;
  --accent-hover: #1a9ccc;
  --danger: #eb5757;
  --ai: #9b59b6;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.12);
  --font: 'Helvetica Neue', 'Noto Sans JP', Arial, sans-serif;
  --sidebar-w: 240px;
}

html, body { height: 100%; font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); }

/* ── Layout ── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 12px;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 12px;
  border-bottom: 1px solid var(--border);
}

/* Brand block */
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark { width: 28px; height: 28px; border-radius: 5px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; gap: 1px; }
.brand-name { font-size: 13px; font-weight: 900; letter-spacing: .08em; color: var(--text); line-height: 1; }
.brand-sub  { font-size: 9px; color: var(--text-secondary); letter-spacing: .06em; }

/* Save indicator */
.save-indicator {
  font-size: 11px;
  color: transparent;
  transition: color .3s;
  white-space: nowrap;
}
.save-indicator.ok { color: #16a34a; }
.save-indicator.warn { color: var(--danger); }

.local-file-name {
  font-size: 11px;
  color: #16a34a;
  padding: 2px 0 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-btn {
  text-align: left;
  padding: 6px 10px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--surface2); color: var(--text); font-weight: 500; }

.sidebar-actions { display: flex; flex-direction: column; gap: 6px; }
.divider { height: 1px; background: var(--border); margin: 2px 0; }

.sidebar-footer { margin-top: auto; padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.scene-count { font-size: 12px; color: var(--text-secondary); }
.footer-brand { font-size: 10px; color: #c8c4c0; letter-spacing: .04em; }

.help-btn {
  display: flex; align-items: center; gap: 7px;
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 12px; font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.help-btn::before { content: '?'; display: flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 50%; background: var(--text); color: #fff; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.help-btn:hover { background: var(--surface); border-color: var(--text-secondary); }
.help-btn:active { transform: scale(0.97); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 7px 12px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, opacity .15s;
  width: 100%;
  gap: 4px;
}
.btn-primary { background: var(--text); color: #fff; }
.btn-primary:hover { background: #555; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-ai { background: var(--ai); color: #fff; opacity: .7; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 8px; font-size: 12px; width: auto; }
.icon-btn { background: transparent; border: none; cursor: pointer; padding: 4px 8px; border-radius: var(--radius); font-size: 18px; color: var(--text-secondary); }
.icon-btn:hover { background: var(--surface2); }

/* ── Main ── */
.main { flex: 1; overflow-y: auto; background: var(--bg); }

.view { padding: 32px 40px; max-width: 1100px; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.view-header h2 { font-size: 22px; font-weight: 700; color: var(--text); }

/* Undo / Redo */
.history-btns { display: flex; gap: 4px; }
.history-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.history-btn:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.history-btn:disabled { opacity: .3; cursor: default; }

/* ── Project Form ── */
.project-form { display: flex; flex-direction: column; gap: 20px; max-width: 600px; }

/* ── Fields ── */
.field-group { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em; }
.field-input, .field-textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  transition: border-color .15s;
  width: 100%;
  resize: vertical;
}
.field-input:focus, .field-textarea:focus { outline: none; border-color: var(--accent); }

/* ── Scenes Grid ── */
.scenes { display: flex; flex-direction: column; gap: 12px; }
.scenes.grid-mode { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }

/* ── Scene Card ── */
.scene-card {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
  min-height: 120px;
}
.scene-card:hover { box-shadow: var(--shadow-md); border-color: #ccc; }

.scene-image {
  width: 192px;
  min-width: 192px;
  height: 108px; /* 16:9 = 192×108 */
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  align-self: center;
  border-radius: 4px 0 0 4px;
}
.scene-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.scene-image-placeholder {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: var(--text-secondary); font-size: 12px;
}
.scene-image-placeholder span { font-size: 28px; }

.scene-body {
  flex: 1;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.scene-header { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.scene-num { font-size: 11px; font-weight: 700; color: var(--text-secondary); background: var(--surface2); padding: 2px 8px; border-radius: 3px; white-space: nowrap; }
.scene-time { font-size: 11px; color: var(--text-secondary); }

/* Labeled rows */
.scene-row { display: flex; gap: 6px; align-items: flex-start; }
.scene-label {
  font-size: 9px; font-weight: 800; letter-spacing: .04em;
  color: var(--text-secondary); background: var(--surface2);
  padding: 2px 5px; border-radius: 3px;
  white-space: nowrap; flex-shrink: 0; margin-top: 2px;
  text-transform: uppercase;
}
.scene-camera { font-size: 12px; color: var(--accent); font-weight: 500; line-height: 1.5; }
.scene-desc { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.5; }
.scene-memo { font-size: 12px; color: var(--text-secondary); line-height: 1.5; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.scene-actions {
  display: flex;
  gap: 4px;
  align-items: flex-start;
  padding: 8px 8px 8px 0;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity .15s;
}
.scene-card:hover .scene-actions { opacity: 1; }
.scene-action-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}
.scene-action-btn:hover { background: var(--surface2); }

/* Grid mode card adjustments */
.scenes.grid-mode .scene-card { flex-direction: column; }
.scenes.grid-mode .scene-image {
  width: 100%; min-width: unset;
  height: auto;
  aspect-ratio: 16 / 9;
  border-radius: 4px 4px 0 0;
  align-self: auto;
}
.scenes.grid-mode .scene-actions { padding: 0 8px 8px; opacity: 1; justify-content: flex-end; }

/* Drag & Drop */
.scene-card.drag-over { border: 2px dashed var(--accent); }
.scene-card.dragging { opacity: .4; }

/* ── Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 80px 0;
  color: var(--text-secondary);
}
.empty-icon { font-size: 48px; }
.empty-state p { font-size: 14px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal {
  background: var(--bg);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: transparent; border: none; cursor: pointer;
  font-size: 16px; color: var(--text-secondary);
  width: 28px; height: 28px; border-radius: 4px; display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--surface2); }

.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

.modal-image-section { display: flex; flex-direction: column; gap: 8px; }
.image-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  min-height: 180px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  overflow: hidden;
  position: relative;
}
.image-drop-zone:hover, .image-drop-zone.drag-active { border-color: var(--accent); background: #f0f9ff; }
.image-drop-placeholder { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--text-secondary); text-align: center; padding: 16px; }
.image-drop-placeholder span { font-size: 32px; }
.image-drop-placeholder p { font-size: 12px; }

.modal-fields-section { display: flex; flex-direction: column; gap: 14px; }

.modal-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px 18px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-footer-right { display: flex; gap: 8px; }
.modal-footer .btn { width: auto; }

/* Print footer (hidden on screen) */
.print-footer { display: none; }

/* ── Print / PDF ── */
@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .sidebar, .scene-actions, .modal-overlay,
  #addSceneBtn, .history-btns, #toggleLayoutBtn,
  .view-header-actions { display: none !important; }

  html, body { height: auto; overflow: visible; }
  .app { display: block; height: auto; overflow: visible; }
  .main { overflow: visible; height: auto; }

  .view { padding: 12px 16px; max-width: 100%; }
  .view-header { margin-bottom: 12px; }
  .view-header h2 { font-size: 16px; }

  /* Force block layout so break-inside works reliably */
  .scenes { display: block !important; }

  .scene-card {
    display: flex !important;
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 10px;
    border: 1px solid #ccc;
    min-height: unset;
  }

  .scene-image {
    width: 160px !important;
    min-width: 160px !important;
    height: 90px !important; /* 16:9 */
    flex-shrink: 0;
    align-self: center;
  }
  .scene-image img { width: 100%; height: 100%; object-fit: cover; }

  .scene-body { padding: 8px 12px; }
  .scene-label { display: inline-block; }
  .scene-desc { -webkit-line-clamp: unset; display: block; }
  .scene-memo { white-space: normal; overflow: visible; display: block; -webkit-line-clamp: unset; }

  .print-footer {
    display: block;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    padding: 8px 24px;
    border-top: 1px solid #ddd;
    background: #fff;
    text-align: center;
  }
  .print-footer-brand {
    font-size: 9px;
    letter-spacing: .08em;
    color: #999;
    font-family: 'Helvetica Neue', Arial, sans-serif;
  }
}

/* ── AI Image Generation ── */
.btn-ai-all {
  background: linear-gradient(135deg, #7c3aed, #9b59b6);
  color: #fff;
  border: none;
}
.btn-ai-all:hover { background: linear-gradient(135deg, #6d28d9, #8e44ad); }
.btn-ai-all:disabled { opacity: .5; cursor: not-allowed; }

.btn-ai-modal {
  background: linear-gradient(135deg, #7c3aed, #9b59b6);
  color: #fff;
  border: none;
}
.btn-ai-modal:hover { background: linear-gradient(135deg, #6d28d9, #8e44ad); }
.btn-ai-modal:disabled { opacity: .5; cursor: not-allowed; }

.api-key-section { display: flex; flex-direction: column; gap: 5px; }
.api-key-row { display: flex; gap: 4px; align-items: center; }
.api-key-input { font-size: 12px; padding: 6px 8px; flex: 1; min-width: 0; }
.api-key-toggle {
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; padding: 5px 7px; font-size: 13px; flex-shrink: 0;
}
.api-key-toggle:hover { background: var(--surface2); }
.api-key-note { font-size: 10px; color: var(--text-secondary); line-height: 1.4; }

.image-btn-row { display: flex; gap: 6px; }
.image-btn-row .btn { flex: 1; }

.ai-status {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--radius);
  margin-top: 2px;
  text-align: center;
}
.ai-status.loading { background: #f3e8ff; color: #7c3aed; animation: pulse 1.2s infinite; }
.ai-status.error { background: #fef2f2; color: var(--danger); }
.ai-status.success { background: #f0fdf4; color: #16a34a; }

@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.5; } }

/* AI generate button on scene card */
.scene-gen-btn {
  background: linear-gradient(135deg, #7c3aed, #9b59b6);
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: #fff;
}
.scene-gen-btn:hover { opacity: .85; }
.scene-gen-btn:disabled { opacity: .4; cursor: not-allowed; }

/* Image drop target on card */
.scene-image.img-drop-hover {
  outline: 3px dashed var(--accent);
  outline-offset: -3px;
  background: #e8f7ff;
}
.scene-image.img-drop-hover::after {
  content: '画像をドロップ';
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: var(--accent);
  background: rgba(255,255,255,.7);
  pointer-events: none;
}

.scene-gen-overlay {
  position: absolute; inset: 0;
  background: rgba(124,58,237,.15);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: #7c3aed; font-weight: 600;
  animation: pulse 1.2s infinite;
}

/* ── Paste Modal ── */
.paste-modal { max-width: 600px; }
.paste-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.7; margin-bottom: 12px; }
.paste-desc code { background: var(--surface2); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.paste-textarea {
  width: 100%; height: 300px;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; font-size: 12px; font-family: monospace;
  resize: vertical; color: var(--text); background: var(--surface);
  line-height: 1.6;
}
.paste-textarea:focus { outline: none; border-color: var(--accent); background: #fff; }
.paste-error {
  margin-top: 8px; padding: 8px 12px;
  background: #fef2f2; color: var(--danger);
  border-radius: var(--radius); font-size: 12px;
}

/* ── Help Modal ── */
.help-modal { max-width: 820px; }

.help-body { display: flex; flex-direction: column; gap: 24px; }

.help-section { display: flex; flex-direction: column; gap: 10px; }
.help-section-title {
  font-size: 12px; font-weight: 700; color: var(--text);
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}

.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* AI GPT box */
.help-ai-box {
  background: linear-gradient(135deg, #0a0a12 0%, #0d0d1e 100%);
  border: 1px solid rgba(120, 100, 255, 0.35);
  border-radius: 10px;
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.help-ai-lead { font-size: 12px; color: #b8b8cc; line-height: 1.6; }
.help-ai-link {
  display: block;
  background: linear-gradient(135deg, #5b4af0 0%, #7c6af7 100%);
  color: #fff;
  text-decoration: none;
  font-size: 13px; font-weight: 700;
  padding: 11px 16px;
  border-radius: 8px;
  text-align: center;
  letter-spacing: 0.01em;
  box-shadow: 0 2px 12px rgba(92, 74, 240, 0.45);
  transition: opacity 0.15s, box-shadow 0.15s;
}
.help-ai-link:hover { opacity: 0.9; box-shadow: 0 4px 20px rgba(92, 74, 240, 0.65); }
.help-ai-steps { display: flex; flex-direction: column; gap: 8px; }
.help-ai-step {
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 12px; color: #e0e0f4; line-height: 1.5;
}
.help-ai-tag {
  font-size: 10px; font-weight: 700;
  background: rgba(120, 100, 255, 0.3);
  color: #c8b8ff;
  border: 1px solid rgba(160, 140, 255, 0.25);
  border-radius: 4px;
  padding: 2px 7px;
  flex-shrink: 0; margin-top: 1px; white-space: nowrap;
}
.help-ai-note {
  font-size: 11px; color: #c0aaff;
  background: rgba(120, 100, 255, 0.12);
  border: 1px solid rgba(160, 140, 255, 0.15);
  border-radius: 6px;
  padding: 8px 12px;
  line-height: 1.5;
}

/* Steps */
.help-steps { display: flex; flex-direction: column; gap: 10px; }
.help-step {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 10px 12px; background: var(--surface); border-radius: var(--radius);
}
.help-step-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--text); color: #fff;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 1px;
}
.help-step strong { font-size: 13px; }
.help-step-sub { font-size: 11px; color: var(--text-secondary); margin-top: 2px; display: block; }

/* List items */
.help-list { display: flex; flex-direction: column; gap: 6px; }
.help-item {
  display: flex; gap: 8px; align-items: flex-start;
  font-size: 12px; color: var(--text); line-height: 1.5;
}
.help-tag {
  font-size: 10px; font-weight: 700;
  background: var(--surface2); color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 3px;
  white-space: nowrap; flex-shrink: 0; margin-top: 1px;
}
.help-tag.kbd {
  background: var(--text); color: #fff;
  border-color: var(--text);
  font-family: monospace; letter-spacing: 0;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
