:root {
  --bg: #191816;
  --bg-soft: #1d1c19;
  --bg-card: #23221f;
  --border: #38352f;
  --text: #e9e6df;
  --text-dim: #a49f94;
  --accent: #c9a15f;
  --accent-dark: #9a7332;
  --accent-soft: rgba(201, 161, 95, 0.12);
  --accent-soft-2: rgba(201, 161, 95, 0.22);
  --accent-border: rgba(201, 161, 95, 0.42);
  --error: #cf7b6b;
  --mono: "Cascadia Mono", Consolas, "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

::selection {
  background: var(--accent-soft-2);
  color: var(--text);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

main, header.site-header {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 16px;
}

header.site-header {
  padding-top: 32px;
  padding-bottom: 8px;
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 8px;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.lead {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin: 0 0 16px;
}

section {
  border-top: 1px solid var(--border);
  padding-top: 26px;
  padding-bottom: 26px;
  margin: 0;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 8px;
  border-left: 4px solid var(--accent-dark);
  padding-left: 8px;
}

.section-note {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0 0 12px;
}

/* GUI選択と割り当て一覧 */
.assign-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.assign-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--text-dim);
}

.assigned-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.assigned-list:empty {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-card);
}

.chip.active {
  border-color: var(--accent);
}

.chip-select {
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 4px 9px;
  cursor: pointer;
}

.chip.active .chip-select {
  color: var(--accent);
}

.chip-remove {
  border: none;
  border-left: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
}

.chip-remove:hover {
  color: var(--error);
}

/* 元動画(枠を動かして切り取り) */
.editor-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pane {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.pane-title {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* タイムバー(開始/終了 + 再生ヘッド) */
.timeline {
  user-select: none;
}

.timeline.disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* 再生/停止 + タイムバーを1行のメディアプレイヤー風に */
.player {
  display: flex;
  align-items: center;
  gap: 10px;
}

.play-toggle {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #1b1710;
  cursor: pointer;
}

.play-toggle:hover:not(:disabled) {
  background: #d8b273;
}

.play-toggle:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.play-toggle .icon-pause {
  display: none;
}

.play-toggle.playing .icon-play {
  display: none;
}

.play-toggle.playing .icon-pause {
  display: block;
}

.timeline-track {
  position: relative;
  flex: 1 1 auto;
  height: 22px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  touch-action: none;
}

.timeline-selection {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--accent-soft-2);
  border-left: 1px solid var(--accent-dark);
  border-right: 1px solid var(--accent-dark);
  pointer-events: none;
}

.timeline-playhead {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
  pointer-events: none;
}

.timeline-handle {
  position: absolute;
  top: 50%;
  width: 8px;
  height: 18px;
  margin: -9px 0 0 -4px;
  padding: 0;
  border-radius: 3px;
  background: var(--accent);
  border: 1px solid var(--accent-dark);
  cursor: ew-resize;
}

.timeline-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.78rem;
  font-family: var(--mono);
  color: var(--text-dim);
}

.tl-current-label {
  color: var(--accent);
}

.button.small {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.pane-tools {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.gui-select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.95rem;
  font-family: var(--mono);
}

.badge {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-border);
  border-radius: 999px;
  font-size: 0.75rem;
  font-family: var(--mono);
  padding: 2px 10px;
}

.texture-note {
  color: var(--text-dim);
  font-size: 0.78rem;
  font-family: var(--mono);
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 18px 12px;
  text-align: center;
  cursor: pointer;
  color: var(--text-dim);
  transition: border-color 0.15s, background 0.15s;
  align-self: center;
  width: 100%;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.dropzone:focus-visible {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.dropzone.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.drop-hint {
  font-size: 0.85rem;
}

.file-name {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--accent);
  word-break: break-all;
}

.dropzone.has-file {
  border-style: solid;
  border-color: var(--accent-dark);
}

canvas.source-canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #000;
  cursor: move;
  touch-action: none;
}

.editor-body.crop-off canvas.source-canvas {
  cursor: default;
}

.meta {
  font-size: 0.82rem;
  color: var(--text-dim);
  font-family: var(--mono);
}

.meta.error {
  color: var(--error);
}

/* オプション + 生成 */
.output-panel {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
}

.options {
  flex: 1 1 340px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.options label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--text-dim);
}

.output-panel #generate {
  flex: 0 0 auto;
}

select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.92rem;
}

/* ボタン */
.button {
  display: inline-block;
  border-radius: 8px;
  padding: 10px 22px;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  border: 1px solid transparent;
}

.button.primary {
  background: var(--accent);
  color: #1b1710;
  font-weight: 600;
}

.button.primary:hover:not(:disabled) {
  background: #d8b273;
}

.button.secondary {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent-dark);
}

.button.secondary:hover:not(:disabled) {
  background: var(--accent-soft);
}

button.button:disabled, .button[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

/* 進捗・ログ・結果 */
#progress-wrap {
  margin-top: 14px;
}

#progress-label {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-family: var(--mono);
  margin-bottom: 6px;
}

progress {
  width: 100%;
  height: 14px;
  appearance: none;
}

progress::-webkit-progress-bar {
  background: var(--bg-card);
  border-radius: 4px;
}

progress::-webkit-progress-value {
  background: var(--accent-dark);
  border-radius: 4px;
}

progress::-moz-progress-bar {
  background: var(--accent-dark);
  border-radius: 4px;
}

#log {
  background: #131210;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 14px;
  max-height: 240px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: pre-wrap;
}

#log:empty {
  display: none;
}

.log-error {
  color: var(--error);
}

/* 注意書き */
.notes ul {
  margin: 0;
  padding-left: 20px;
  font-size: 0.86rem;
  color: var(--text-dim);
}

.notes a {
  color: var(--accent);
}

/* 見出しの改行はモバイルのみ有効 */
br.sp {
  display: none;
}

@media (max-width: 640px) {
  br.sp {
    display: inline;
  }
  .output-panel {
    flex-direction: column;
    align-items: stretch;
  }
  #generate {
    width: 100%;
  }
}
