:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #dbe3ef;
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --accent: #0ea5e9;
  --danger: #dc2626;
  --soft-blue: #eef6ff;
  --footer-blue: #1565c0;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", sans-serif;
  background: linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.app-shell {
  width: min(1240px, calc(100% - 24px));
  margin: 18px auto 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 260px;
}

.logo-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 12px 24px rgba(79, 70, 229, 0.24);
}

.logo-mark svg {
  width: 30px;
  height: 30px;
}

h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2.5vw, 1.8rem);
  line-height: 1.2;
}

.lead {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 9px 15px;
  color: #fff;
  background: var(--primary);
  border-radius: 12px;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.18);
  transition: transform 0.05s ease, background 0.2s ease, box-shadow 0.2s ease;
}

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

.btn:active {
  transform: translateY(1px);
}

.btn.secondary {
  color: #374151;
  background: #f7fafc;
  border: 1px solid var(--line);
  box-shadow: none;
}

.btn.secondary:hover {
  background: #edf2f7;
}

.btn.danger {
  background: var(--danger);
  box-shadow: 0 8px 18px rgba(220, 38, 38, 0.14);
}

.btn.small {
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 0.85rem;
}

.workspace {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.sidebar {
  padding: 16px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-title h2,
.settings-title {
  margin: 0;
  font-size: 1.05rem;
}

.clip-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.clip-list {
  display: grid;
  gap: 10px;
  max-height: 510px;
  overflow: auto;
  padding: 2px 4px 2px 2px;
}

.clip-card {
  display: grid;
  grid-template-columns: 28px 84px minmax(0, 1fr) 24px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.clip-card.selected {
  border-color: #7c86ff;
  background: #f7f8ff;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.clip-card.drag-over {
  border-style: dashed;
  border-color: var(--primary);
}

.clip-number {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  background: #2563eb;
  font-size: 0.78rem;
  font-weight: 800;
}

.clip-thumb {
  width: 84px;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  background: #111827;
  object-fit: cover;
  border: 1px solid #d6deea;
}

.clip-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 800;
  font-size: 0.9rem;
}

.clip-meta,
.clip-duration-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.8rem;
}

.clip-duration-row input {
  width: 72px;
  padding: 4px 6px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
}

.drag-handle {
  color: #6b7280;
  font-size: 1.2rem;
  text-align: center;
  cursor: grab;
  user-select: none;
}

.total-box,
.bulk-box,
.help-box,
.support-box {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdff;
}

.total-box {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 800;
}

.bulk-box h3,
.help-box h3,
.support-box h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.form-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

input[type="number"],
select,
input[type="range"] {
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #fff;
  padding: 8px 10px;
}

input[type="number"] {
  width: 96px;
}

.main-panel {
  padding: 16px;
  min-width: 0;
}

.preview-panel {
  padding: 16px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.preview-canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  overflow: hidden;
  background: #0f172a;
  border: 1px solid #111827;
}

#previewCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #dbeafe;
  text-align: center;
  pointer-events: none;
}

.empty-state-inner {
  display: grid;
  gap: 14px;
  line-height: 1.75;
  max-width: min(92%, 720px);
}

.empty-state-title {
  font-size: clamp(1.25rem, 3vw, 2rem);
  font-weight: 800;
  letter-spacing: 0.02em;
}

.empty-state-note {
  font-size: clamp(0.95rem, 1.9vw, 1.18rem);
  font-weight: 500;
}

.preview-controls {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

#seekBar {
  width: 100%;
}

.time-display {
  min-width: 150px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #4b5563;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.settings-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.settings-card.full {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.field label {
  font-size: 0.85rem;
  color: #4b5563;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.6;
}

.progress-wrap {
  margin-top: 12px;
  display: none;
}

.progress-wrap.active {
  display: block;
}

.progress-track {
  height: 12px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #06b6d4);
  transition: width 0.15s linear;
}

.notice {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--soft-blue);
  color: #1d4ed8;
  font-size: 0.88rem;
  line-height: 1.7;
}

.help-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: 14px;
  margin-top: 16px;
}

.help-box {
  background: #f8fbff;
}

.support-box {
  background: #f4fff7;
}

.help-box ol,
.support-box ul {
  margin: 0;
  padding-left: 1.2em;
  line-height: 1.85;
  color: #374151;
  font-size: 0.9rem;
}

.hidden-input {
  display: none;
}

.footer {
  width: min(1240px, calc(100% - 24px));
  margin: 12px auto 0;
  text-align: center;
  padding: 8px 0 14px;
  border-top: 1px solid #d7e6f8;
  background: rgba(255, 255, 255, 0.55);
  color: var(--footer-blue);
  font-size: 0.82rem;
}

.footer a {
  color: var(--footer-blue);
  text-decoration: none;
  font-weight: 800;
}

.footer a:hover {
  color: #0d47a1;
}

.ad-panel {
  width: min(1240px, calc(100% - 24px));
  margin: 12px auto 0;
  padding: 0;
  border: 1px solid #d7e6f8;
  border-radius: 12px;
  background: #ffffff;
  overflow: hidden;
}

.ad-panel[hidden] {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
}

.ad-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  background: #f4f8ff;
  border-bottom: 1px solid #d7e6f8;
}

.ad-label {
  font-size: 0.72rem;
  color: #4f6f91;
  line-height: 1;
}

.ad-wait-label {
  margin-left: auto;
  color: #4f6f91;
  font-size: 0.72rem;
}

.ad-close-btn {
  display: none;
  margin: 0 !important;
  padding: 3px 8px !important;
  min-height: 0;
  height: auto;
  line-height: 1.2;
  border: none;
  border-radius: 999px;
  background: #1565c0;
  color: #ffffff;
  font-size: 0.72rem !important;
  font-weight: 700;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.ad-close-btn:hover {
  background: #0d47a1;
}

.ad-body {
  padding: 8px;
  background: #ffffff;
}

@media (max-width: 960px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .clip-list {
    max-height: none;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 14px, 1240px);
    margin-top: 8px;
  }

  .app-header,
  .sidebar,
  .main-panel,
  .preview-panel {
    padding: 12px;
    border-radius: 14px;
  }

  .brand {
    min-width: 0;
    align-items: flex-start;
  }

  .logo-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
  }

  .btn {
    width: 100%;
  }

  .clip-toolbar .btn,
  .preview-controls .btn,
  .form-row .btn {
    width: auto;
  }

  .clip-card {
    grid-template-columns: 24px 72px minmax(0, 1fr) 20px;
    gap: 8px;
  }

  .clip-thumb {
    width: 72px;
  }

  .settings-grid,
  .help-grid {
    grid-template-columns: 1fr;
  }

  .preview-controls {
    grid-template-columns: 1fr;
  }

  .time-display {
    text-align: left;
  }
}
