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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3345;
  --text: #e4e6ed;
  --text-dim: #8b90a0;
  --accent: #6c5ce7;
  --accent-hover: #7f71ef;
  --danger: #e74c3c;
  --success: #2ecc71;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

header {
  text-align: center;
  padding: 2rem 1rem 1rem;
}

header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #a29bfe);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 0.3rem;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

.section {
  margin-bottom: 2rem;
}

/* ドロップゾーン */
#drop-zone {
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 4rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

#drop-zone:hover,
#drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(108, 92, 231, 0.05);
}

.drop-zone-content svg {
  color: var(--text-dim);
  margin-bottom: 1rem;
}

.drop-zone-content p {
  color: var(--text-dim);
  font-size: 1rem;
}

/* エディタレイアウト */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }
}

/* プレビュー */
.preview-area h2 {
  font-size: 1.1rem;
  margin-bottom: 0.8rem;
  color: var(--text-dim);
}

#video-container {
  position: relative;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  line-height: 0;
}

#video-player {
  width: 100%;
  display: block;
  border-radius: 8px;
}

/* クロップオーバーレイ */
#crop-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}


#crop-box {
  position: absolute;
  border: 2px solid var(--accent);
  background: transparent;
  cursor: move;
  pointer-events: auto;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 2px;
  pointer-events: auto;
}

.crop-handle.nw { top: -6px; left: -6px; cursor: nw-resize; }
.crop-handle.ne { top: -6px; right: -6px; cursor: ne-resize; }
.crop-handle.sw { bottom: -6px; left: -6px; cursor: sw-resize; }
.crop-handle.se { bottom: -6px; right: -6px; cursor: se-resize; }
.crop-handle.n { top: -6px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.crop-handle.s { bottom: -6px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.crop-handle.e { top: 50%; right: -6px; transform: translateY(-50%); cursor: e-resize; }
.crop-handle.w { top: 50%; left: -6px; transform: translateY(-50%); cursor: w-resize; }

/* ビデオコントロール */
.video-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0;
  margin-top: 0.5rem;
}

.video-controls span {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 3.5em;
}

.seek-time-input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  font-family: inherit;
  width: 4.5em;
  padding: 0.15rem 0.3rem;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}

.seek-time-input:hover {
  border-color: var(--border);
  background: var(--surface2);
}

.seek-time-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface2);
  color: var(--text);
}

#seek-bar-container {
  flex: 1;
  position: relative;
  height: 14px;
  display: flex;
  align-items: center;
}

#seek-bar-ranges {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  border-radius: 2px;
  overflow: hidden;
}

.seek-range-block {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(108, 92, 231, 0.35);
  border-radius: 2px;
}

#seek-bar {
  flex: 1;
  position: relative;
  z-index: 1;
}

/* 設定パネル */
.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.setting-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.setting-group h3 {
  font-size: 0.95rem;
  margin-bottom: 0.8rem;
  color: var(--text);
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.sub-settings {
  margin-top: 0.8rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border);
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.25s ease, margin-top 0.3s ease, padding-top 0.3s ease;
  margin-top: 0;
  padding-top: 0;
}

.sub-settings.open {
  max-height: 300px;
  opacity: 1;
  margin-top: 0.8rem;
  padding-top: 0.8rem;
}

.input-row {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 0.5rem;
}

.input-row label {
  flex: 1;
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  color: var(--text-dim);
  gap: 0.3rem;
}

.input-row-vertical {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.input-row-vertical label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  color: var(--text-dim);
  gap: 0.3rem;
}

.aspect-ratio-row {
  margin-top: 0.5rem;
}

.aspect-ratio-row label {
  font-size: 0.8rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

input[type="number"],
input[type="text"].time-input,
select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  color: var(--text);
  font-size: 0.9rem;
  width: 100%;
}

input[type="number"]:focus,
input[type="text"].time-input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

/* タイムラインバー */
#timeline-bar {
  padding: 0.8rem 0;
}

#timeline-track {
  position: relative;
  height: 32px;
  background: var(--surface2);
  border-radius: 6px;
  overflow: hidden;
}

.timeline-range-block {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(108, 92, 231, 0.4);
  border-left: 2px solid var(--accent);
  border-right: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.7);
  min-width: 2px;
}

/* 範囲リスト */
#range-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.range-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.6rem;
  background: var(--surface2);
  border-radius: 8px;
  border: 1px solid var(--border);
  position: relative;
}

.range-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.range-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.range-inputs {
  display: flex;
  gap: 0.5rem;
}

.range-inputs label {
  flex: 1;
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
  color: var(--text-dim);
  gap: 0.2rem;
}

.btn-remove-range {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--text-dim);
}

.btn-remove-range:hover {
  color: var(--danger);
  background: rgba(231, 76, 60, 0.15);
}

.range-buttons-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  margin-bottom: 0.75rem;
}

.btn-add-range {
  flex: 1;
  padding: 0.5rem;
  font-size: 0.85rem;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-dim);
}

.btn-add-range:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(108, 92, 231, 0.05);
}

.btn-clear-ranges {
  flex-shrink: 0;
  padding: 0.5rem 0.8rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
}

.btn-clear-ranges:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(231, 76, 60, 0.1);
}

.time-input-group {
  display: flex;
  gap: 0.3rem;
}

.time-input-group .time-input {
  flex: 1;
  min-width: 0;
}

.btn-set-time {
  flex-shrink: 0;
  padding: 0.4rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 6px;
}

.loop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.btn-loop {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 6px;
  white-space: nowrap;
}

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

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

/* ボタン */
.btn {
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  transition: background 0.2s;
  color: var(--text);
  background: var(--surface2);
}

.btn:hover {
  background: var(--border);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
}

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

.btn-large {
  padding: 0.9rem 1.5rem;
  font-size: 1rem;
  width: 100%;
}

/* プログレスバー */
#progress-area {
  margin-top: 0.8rem;
}

#progress-bar-container {
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}

#progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #a29bfe);
  border-radius: 4px;
  width: 0%;
  transition: width 0.3s;
}

#progress-text {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 0.4rem;
  text-align: center;
}

/* レンジスライダー */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}

/* チェックボックス */
input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

/* 動画ファイルリスト */
#video-file-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.video-file-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  background: var(--surface2);
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.2s;
}

.video-file-item:hover {
  border-color: var(--accent);
}

.video-file-item.active {
  border-color: var(--accent);
  background: rgba(108, 92, 231, 0.1);
}

.video-file-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.video-file-duration {
  flex-shrink: 0;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
}

.video-file-controls {
  display: flex;
  gap: 0.2rem;
  flex-shrink: 0;
}

.btn-icon-sm {
  width: 22px;
  height: 22px;
  padding: 0;
  font-size: 0.7rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: var(--text-dim);
}

.btn-icon-sm:hover {
  color: var(--text);
}

.btn-remove-video:hover {
  color: var(--danger);
  background: rgba(231, 76, 60, 0.15);
}

/* タイムラインの動画境界マーカー */
.timeline-video-boundary {
  position: absolute;
  top: 0;
  height: 100%;
  width: 2px;
  background: var(--text-dim);
  opacity: 0.6;
  z-index: 1;
  pointer-events: none;
}

.seek-video-boundary {
  position: absolute;
  top: 0;
  height: 100%;
  width: 1px;
  background: var(--text-dim);
  opacity: 0.4;
  pointer-events: none;
}

footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-dim);
  font-size: 0.8rem;
}
