:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel-2: #1d2740;
  --border: #2a3550;
  --text: #e8ecf6;
  --muted: #8b96b3;
  --accent: #4f7cff;
  --accent-2: #22c58b;
  --danger: #e5534b;
  --warn: #d9a13b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", "PingFang SC", sans-serif;
  line-height: 1.6;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 24px 32px 8px;
}

.topbar h1 { margin: 0; font-size: 24px; }
.vs { color: var(--accent); font-style: italic; }
.subtitle { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

main { padding: 16px 32px 40px; max-width: 1440px; margin: 0 auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 16px;
}

.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

textarea {
  width: 100%;
  resize: vertical;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}
textarea:focus, select:focus, input:focus { outline: 1px solid var(--accent); }

.settings-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
  margin-top: 12px;
}
.settings-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
.settings-row select, .modal-grid select, .modal-grid input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 10px;
  font-size: 13px;
}
.checkbox-label { flex-direction: row !important; align-items: center; gap: 6px !important; padding-bottom: 8px; }

.auth-box { max-width: 360px; }
.auth-box input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
}
.auth-box .error-box { margin-top: 10px; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; margin-left: auto; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-outline { background: transparent; color: var(--accent); border: 1px solid var(--accent); width: 100%; margin-top: 12px; }
.btn:hover:not(:disabled) { opacity: 0.85; }

.badge { font-size: 12px; padding: 4px 10px; border-radius: 999px; }
.badge-ok { background: rgba(34, 197, 139, 0.15); color: var(--accent-2); }
.badge-muted { background: var(--panel-2); color: var(--muted); }
.badge-err { background: rgba(229, 83, 75, 0.15); color: var(--danger); }

/* 价格面板 */
.cost-panel { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 20px; }
.cost-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.cost-line { display: flex; justify-content: space-between; font-size: 14px; padding: 2px 0; }
.cost-line strong { font-variant-numeric: tabular-nums; }
.cost-note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.cost-delta { border-left: 1px solid var(--border); border-right: 1px solid var(--border); padding: 0 20px; }
.delta-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.delta-value.positive { color: var(--warn); }
.delta-value.negative { color: var(--accent-2); }
.delta-bar { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.delta-bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--warn)); transition: width 0.4s; }

/* 卡片 */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
}
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card-head h2 { margin: 0; font-size: 17px; }
.tag { font-size: 11px; padding: 3px 10px; border-radius: 999px; }
.tag-gray { background: var(--panel-2); color: var(--muted); }
.tag-blue { background: rgba(79, 124, 255, 0.15); color: var(--accent); }
.card-desc { font-size: 13px; color: var(--muted); margin: 8px 0 12px; }

.stages { list-style: none; margin: 0 0 12px; padding: 0; }
.stages li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
}
.stages li + li { margin-top: 4px; }
.stages li.pending { color: var(--muted); }
.stages li.running { background: var(--panel-2); color: var(--text); }
.stages li.done { color: var(--accent-2); }
.stages li.failed { background: rgba(229, 83, 75, 0.1); color: var(--danger); }
.stage-icon { width: 18px; text-align: center; flex-shrink: 0; }
.stage-label { flex: 1; }
.stage-meta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result video { width: 100%; border-radius: 8px; background: #000; margin-top: 4px; }
.result .error-box {
  background: rgba(229, 83, 75, 0.1);
  border: 1px solid rgba(229, 83, 75, 0.4);
  color: var(--danger);
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 8px;
  word-break: break-all;
}
.result .placeholder { color: var(--muted); font-size: 13px; text-align: center; padding: 28px 0; border: 1px dashed var(--border); border-radius: 8px; }

.artifacts { margin-bottom: 12px; }
.artifacts details {
  background: var(--panel-2);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
}
.artifacts summary { cursor: pointer; color: var(--accent); }
.artifacts pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  color: var(--muted);
  max-height: 260px;
  overflow: auto;
}
.keyframe-box { margin-top: 10px; }
.artifact-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.keyframe-box img { width: 100%; border-radius: 8px; display: block; }

.hidden { display: none !important; }
.footnote { color: var(--muted); font-size: 12px; text-align: center; margin-top: 24px; }

/* 弹层 */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
}
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 24px;
  width: 520px;
  max-width: calc(100vw - 40px);
  max-height: 85vh;
  overflow: auto;
}
.modal-box h3 { margin: 0 0 4px; }
.modal-note { font-size: 12px; color: var(--muted); margin: 0 0 14px; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-actions .btn-primary { margin-left: 0; }

@media (max-width: 960px) {
  .cards, .cost-panel { grid-template-columns: 1fr; }
  .cost-delta { border: none; padding: 0; }
  .topbar { flex-direction: column; }
  .btn-primary { margin-left: 0; }
}

/* タブ */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 22px;
  font-size: 14px;
  cursor: pointer;
}
.tab.active { color: var(--text); border-color: var(--accent); background: var(--panel-2); }

/* 履歴 */
.history-item { margin-bottom: 16px; }
.history-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.history-when { font-size: 13px; color: var(--muted); }
.history-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 11px; background: var(--panel-2); border-radius: 999px; padding: 2px 10px; color: var(--muted); }
.history-prompt { font-size: 14px; margin: 8px 0 12px; word-break: break-all; }
.history-paths { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.history-path { background: var(--panel-2); border-radius: 10px; padding: 12px 14px; }
.history-path-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 8px; }
.history-path-head strong { font-variant-numeric: tabular-nums; }
.stages-compact li { padding: 3px 6px; font-size: 12px; }
.history-extra { margin-top: 8px; font-size: 12px; }
.history-extra summary { cursor: pointer; color: var(--accent); }
.history-extra img { width: 100%; border-radius: 6px; margin-top: 6px; display: block; }
.history-extra pre {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
  max-height: 220px;
  overflow: auto;
}
@media (max-width: 960px) { .history-paths { grid-template-columns: 1fr; } }

/* キーフレーム(複数枚) */
.keyframe-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.keyframe-grid img { width: 100%; border-radius: 8px; display: block; }
